make show location depend on plugin setting

This commit is contained in:
Daniel Gultsch 2018-05-01 12:55:11 +02:00
parent 8e17fa285d
commit 949b77c353
4 changed files with 135 additions and 122 deletions

View File

@ -17,9 +17,15 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-feature android:name="android.hardware.location" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
<uses-feature android:name="android.hardware.location.network" android:required="false" />
<uses-feature
android:name="android.hardware.location"
android:required="false"/>
<uses-feature
android:name="android.hardware.location.gps"
android:required="false"/>
<uses-feature
android:name="android.hardware.location.network"
android:required="false"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
@ -30,21 +36,26 @@
<uses-sdk tools:overrideLibrary="net.ypresto.androidtranscoder"/>
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-feature
android:name="android.hardware.camera"
android:required="false"/>
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false"/>
<application
android:networkSecurityConfig="@xml/network_security_configuration"
android:allowBackup="true"
android:appCategory="social"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_configuration"
android:theme="@style/ConversationsTheme"
android:appCategory="social"
tools:replace="android:label"
tools:targetApi="o">
<meta-data android:name="com.google.android.gms.car.application"
<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
<service android:name=".services.XmppConnectionService"/>
@ -57,6 +68,7 @@
<action android:name="android.media.RINGER_MODE_CHANGED"/>
</intent-filter>
</receiver>
<activity
android:name=".ui.ShareLocationActivity"
android:label="@string/title_activity_share_location"/>
@ -65,21 +77,11 @@
android:label="@string/search_messages"/>
<activity
android:name=".ui.RecordingActivity"
android:theme="@style/ConversationsTheme.Dialog"
android:configChanges="orientation|screenSize"/>
android:configChanges="orientation|screenSize"
android:theme="@style/ConversationsTheme.Dialog"/>
<activity
android:name=".ui.ShowLocationActivity"
android:label="@string/title_activity_show_location" >
<intent-filter>
<action android:name="eu.siacs.conversations.location.show" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="geo" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
android:label="@string/title_activity_show_location"/>
<activity
android:name=".ui.ConversationActivity"
android:theme="@style/SplashTheme">
@ -93,8 +95,8 @@
android:name=".ui.ConversationsActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:minWidth="300dp"
android:minHeight="300dp"
android:minWidth="300dp"
android:windowSoftInputMode="stateHidden"/>
<activity
android:name=".ui.ScanActivity"
@ -250,12 +252,13 @@
android:resource="@xml/file_paths"/>
</provider>
<provider
android:authorities="${applicationId}.barcodes"
android:name=".services.BarcodeProvider"
android:authorities="${applicationId}.barcodes"
android:exported="false"
android:grantUriPermissions="true"/>
<activity android:name=".ui.ShortcutActivity"
<activity
android:name=".ui.ShortcutActivity"
android:label="@string/contact">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT"/>

View File

@ -603,7 +603,7 @@ public class NotificationService {
}
private PendingIntent createShowLocationIntent(final Message message) {
Iterable<Intent> intents = GeoHelper.createGeoIntentsFromMessage(message);
Iterable<Intent> intents = GeoHelper.createGeoIntentsFromMessage(mXmppConnectionService, message);
for (Intent intent : intents) {
if (intent.resolveActivity(mXmppConnectionService.getPackageManager()) != null) {
return PendingIntent.getActivity(mXmppConnectionService, generateRequestCode(message.getConversation(), 18), intent, PendingIntent.FLAG_UPDATE_CURRENT);

View File

@ -965,7 +965,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
}
public void showLocation(Message message) {
for (Intent intent : GeoHelper.createGeoIntentsFromMessage(message)) {
for (Intent intent : GeoHelper.createGeoIntentsFromMessage(activity, message)) {
if (intent.resolveActivity(getContext().getPackageManager()) != null) {
getContext().startActivity(intent);
return;

View File

@ -1,6 +1,7 @@
package eu.siacs.conversations.utils;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
@ -18,32 +19,34 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Conversational;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.ShareLocationActivity;
import eu.siacs.conversations.ui.ShowLocationActivity;
public class GeoHelper {
private static final String SHARE_LOCATION_PACKAGE_NAME = "eu.siacs.conversations.location.request";
private static final String SHOW_LOCATION_PACKAGE_NAME = "eu.siacs.conversations.location.show";
public static Pattern GEO_URI = Pattern.compile("geo:([\\-0-9.]+),([\\-0-9.]+)(?:,([\\-0-9.]+))?(?:\\?(.*))?", Pattern.CASE_INSENSITIVE);
public static boolean isLocationPluginInstalled(Activity activity) {
return new Intent(SHARE_LOCATION_PACKAGE_NAME).resolveActivity(activity.getPackageManager()) != null;
public static boolean isLocationPluginInstalled(Context context) {
return new Intent(SHARE_LOCATION_PACKAGE_NAME).resolveActivity(context.getPackageManager()) != null;
}
public static boolean isLocationPluginInstalledAndDesired(Activity activity) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
final boolean configured = preferences.getBoolean("use_share_location_plugin", activity.getResources().getBoolean(R.bool.use_share_location_plugin));
return configured && isLocationPluginInstalled(activity);
public static boolean isLocationPluginInstalledAndDesired(Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final boolean configured = preferences.getBoolean("use_share_location_plugin", context.getResources().getBoolean(R.bool.use_share_location_plugin));
return configured && isLocationPluginInstalled(context);
}
public static Intent getFetchIntent(Activity activity) {
if (isLocationPluginInstalledAndDesired(activity)) {
public static Intent getFetchIntent(Context context) {
if (isLocationPluginInstalledAndDesired(context)) {
return new Intent(SHARE_LOCATION_PACKAGE_NAME);
} else {
return new Intent(activity, ShareLocationActivity.class);
return new Intent(context, ShareLocationActivity.class);
}
}
public static ArrayList<Intent> createGeoIntentsFromMessage(Message message) {
public static ArrayList<Intent> createGeoIntentsFromMessage(Context context, Message message) {
final ArrayList<Intent> intents = new ArrayList<>();
Matcher matcher = GEO_URI.matcher(message.getBody());
if (!matcher.matches()) {
@ -75,7 +78,8 @@ public class GeoHelper {
label = "";
}
Intent locationPluginIntent = new Intent("eu.siacs.conversations.location.show");
if (isLocationPluginInstalledAndDesired(context)) {
Intent locationPluginIntent = new Intent(SHOW_LOCATION_PACKAGE_NAME);
locationPluginIntent.putExtra("latitude", latitude);
locationPluginIntent.putExtra("longitude", longitude);
if (message.getStatus() != Message.STATUS_RECEIVED) {
@ -91,6 +95,12 @@ public class GeoHelper {
}
}
intents.add(locationPluginIntent);
} else {
Intent intent = new Intent(context, ShowLocationActivity.class);
intent.putExtra("latitude", latitude);
intent.putExtra("longitude", longitude);
intents.add(intent);
}
Intent geoIntent = new Intent(Intent.ACTION_VIEW);
geoIntent.setData(Uri.parse("geo:" + String.valueOf(latitude) + "," + String.valueOf(longitude) + "?q=" + String.valueOf(latitude) + "," + String.valueOf(longitude) + label));