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

View file

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

View file

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