onClick "Powered by Osmand" now asks if user wants to restore osmand or get back to client app.

This commit is contained in:
madwasp79 2019-01-08 08:08:59 +02:00
parent 37b283ebc9
commit 49d7529f9c
8 changed files with 309 additions and 45 deletions

View file

@ -119,34 +119,166 @@
<!-- android matches non-greedy : http://stackoverflow.com/questions/3400072/pathpattern-to-match-file-extension-does-not-work-if-a-period-exists-elsewhere-i-->
<!-- mimeType&host are both needed or you will either have unwanted matching or no match when needed -->
<intent-filter>
<!-- Capture file open requests (pathPattern is honoured) where no MIME type is provided in the Intent. An Intent with a null
MIME type will never be matched by a filter with a set MIME type, so we need a second intent-filter if we wish to also
match files with this extension and a non-null MIME type (even if it is non-null but zero length).
https://stackoverflow.com/a/31028507/4654078 -->
<intent-filter
android:label="@string/app_name"
android:priority="50">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\.gpx" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\.gpx" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\.gpx" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\..*\\.gpx" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\..*\\..*\\.gpx" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\.kml" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\.kml" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\.kml" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\..*\\.kml" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\..*\\..*\\.kml" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\.kmz" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\.kmz" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\.kmz" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\..*\\.kmz" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\..*\\..*\\.kmz" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\.obf" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\.obf" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\.obf" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\..*\\.obf" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\..*\\..*\\.obf" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\.sqlitedb" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\.sqlitedb" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\.sqlitedb" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\..*\\.sqlitedb" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\..*\\..*\\.sqlitedb" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"/>
<data android:scheme="content"/>
<data android:host="*"/>
<data android:pathPattern=".*\\.gpx" />
<data android:pathPattern=".*\\..*\\.gpx" />
<data android:pathPattern=".*\\..*\\..*\\.gpx" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.gpx" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.gpx" />
</intent-filter>
<intent-filter
android:label="@string/app_name"
android:priority="50">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"/>
<data android:scheme="content"/>
<data android:host="*"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.gpx" />
<data android:pathPattern=".*\\..*\\.gpx" />
<data android:pathPattern=".*\\..*\\..*\\.gpx" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.gpx" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.gpx" />
</intent-filter>
<intent-filter
android:label="@string/app_name"
android:priority="50">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"/>
<data android:host="*"/>
<data android:pathPattern=".*\\.kml" />
<data android:pathPattern=".*\\..*\\.kml" />
<data android:pathPattern=".*\\..*\\..*\\.kml" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.kml" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.kml" />
</intent-filter>
<intent-filter
android:label="@string/app_name"
android:priority="50">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"/>
<data android:host="*"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.kml" />
<data android:pathPattern=".*\\..*\\.kml" />
<data android:pathPattern=".*\\..*\\..*\\.kml" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.kml" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.kml" />
</intent-filter>
<intent-filter
android:label="@string/app_name"
android:priority="50">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"/>
<data android:host="*"/>
<data android:pathPattern=".*\\.kmz" />
<data android:pathPattern=".*\\..*\\.kmz" />
<data android:pathPattern=".*\\..*\\..*\\.kmz" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.kmz" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.kmz" />
</intent-filter>
<intent-filter
android:label="@string/app_name"
android:priority="50">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"/>
<data android:host="*"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.kmz" />
<data android:pathPattern=".*\\..*\\.kmz" />
<data android:pathPattern=".*\\..*\\..*\\.kmz" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.kmz" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.kmz" />
</intent-filter>
<intent-filter
android:label="@string/app_name"
android:priority="50">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"/>
<data android:host="*"/>
<data android:pathPattern=".*\\.obf" />
<data android:pathPattern=".*\\..*\\.obf" />
<data android:pathPattern=".*\\..*\\..*\\.obf" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.obf" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.obf" />
</intent-filter>
<intent-filter
android:label="@string/app_name"
android:priority="50">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"/>
<data android:host="*"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.obf" />
<data android:pathPattern=".*\\..*\\.obf" />
<data android:pathPattern=".*\\..*\\..*\\.obf" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.obf" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.obf" />
</intent-filter>
<intent-filter
android:label="@string/app_name"
android:priority="50">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"/>
<data android:host="*"/>
<data android:pathPattern=".*\\.sqlitedb" />
<data android:pathPattern=".*\\..*\\.sqlitedb" />
<data android:pathPattern=".*\\..*\\..*\\.sqlitedb" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.sqlitedb" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.sqlitedb" />
</intent-filter>
<intent-filter
android:label="@string/app_name"
android:priority="50">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"/>
<data android:host="*"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.sqlitedb" />
<data android:pathPattern=".*\\..*\\.sqlitedb" />
<data android:pathPattern=".*\\..*\\..*\\.sqlitedb" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.sqlitedb" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.sqlitedb" />
</intent-filter>
<!--trying to handle emails-->

View file

@ -160,4 +160,12 @@ interface IOsmAndAidlInterface {
boolean getActiveSqliteDbFiles(out List<ASqliteDbFile> files);
boolean showSqliteDbFile(String fileName);
boolean hideSqliteDbFile(String fileName);
boolean setNavDrawerLogoWithIntent(in String imageUri, String packageName, String intent);
boolean setNavDrawerFooterAction(in String packageName, String intent, String appName);
boolean setPointMenuEnabledIds(in List<String> ids);
boolean setPointMenuDisabledIds(in List<String> ids);
boolean setPointMenuEnabledPatterns(in List<String> patterns);
boolean setPointMenuDisabledPatterns(in List<String> patterns);
}

View file

@ -1822,7 +1822,7 @@ public class OsmandAidlApi {
}
boolean setNavDrawerLogo(@Nullable String uri) {
return app.getAppCustomization().setNavDrawerLogo(uri);
return app.getAppCustomization().setNavDrawerLogo(uri,null, null);
}
boolean setEnabledIds(Collection<String> ids) {
@ -1860,6 +1860,34 @@ public class OsmandAidlApi {
return true;
}
boolean setNavDrawerLogoWithIntent(
@Nullable String uri, @Nullable String packageName, @Nullable String intent) {
return app.getAppCustomization().setNavDrawerLogoWithIntent(uri, packageName, intent);
}
boolean setNavDrawerFooterAction(@Nullable String packageName, @Nullable String intent, @Nullable String appName) {
return app.getAppCustomization().setNavDrawerFooterAction(packageName, intent, appName);
}
boolean setPointMenuEnabledIds(List<String> ids){
return true;
}
boolean setPointMenuDisabledIds(List<String> ids){
return true;
}
boolean setPointMenuEnabledPatterns(List<String> patterns){
return true;
}
boolean setPointMenuDisabledPatterns(List<String> patterns){
return true;
}
private static AGpxFileDetails createGpxFileDetails(@NonNull GPXTrackAnalysis a) {
return new AGpxFileDetails(a.totalDistance, a.totalTracks, a.startTime, a.endTime,
a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown,

View file

@ -771,5 +771,37 @@ public class OsmandAidlService extends Service {
OsmandAidlApi api = getApi("hideSqliteDbFile");
return api != null && api.hideSqliteDbFile(fileName);
}
@Override
public boolean setNavDrawerLogoWithIntent(String imageUri, String packageName, String intent) throws RemoteException {
OsmandAidlApi api = getApi("setNavDrawerLogoWithIntent");
return api != null && api.setNavDrawerLogoWithIntent(imageUri, packageName, intent);
}
@Override
public boolean setNavDrawerFooterAction(String packageName, String intent, String appName) throws RemoteException {
OsmandAidlApi api = getApi ("setNavDrawerFooterAction");
return api != null && api.setNavDrawerFooterAction(packageName, intent, appName);
}
@Override
public boolean setPointMenuEnabledIds(List<String> ids) throws RemoteException {
return true;
}
@Override
public boolean setPointMenuDisabledIds(List<String> ids) throws RemoteException {
return true;
}
@Override
public boolean setPointMenuEnabledPatterns(List<String> patterns) throws RemoteException {
return true;
}
@Override
public boolean setPointMenuDisabledPatterns(List<String> patterns) throws RemoteException {
return true;
}
};
}

View file

@ -9,6 +9,7 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
@ -42,6 +43,7 @@ public class OsmAndAppCustomization {
protected OsmandSettings osmandSettings;
private Bitmap navDrawerLogo;
private ArrayList<String> navDrawerParams;
private Set<String> featuresEnabledIds = new HashSet<>();
private Set<String> featuresDisabledIds = new HashSet<>();
@ -199,7 +201,10 @@ public class OsmAndAppCustomization {
return navDrawerLogo;
}
public boolean setNavDrawerLogo(@Nullable String uri) {
@Nullable
public ArrayList<String> getNavDrawerLogoParams() {return navDrawerParams; }
public boolean setNavDrawerLogo(@Nullable String uri, @Nullable String packageName, @Nullable String intent) {
if (TextUtils.isEmpty(uri)) {
navDrawerLogo = null;
} else {
@ -208,16 +213,25 @@ public class OsmAndAppCustomization {
if (is != null) {
navDrawerLogo = BitmapFactory.decodeStream(is);
is.close();
}
} catch (FileNotFoundException e) {
return false;
} catch (IOException e) {
// ignore
}
if(packageName!=null && intent!=null) {
Log.d("setNavDrawerLogo", packageName + ", " + intent);
navDrawerParams = new ArrayList<>();
navDrawerParams.add(packageName);
navDrawerParams.add(intent);
}
}
return true;
}
public void setFeaturesEnabledIds(@NonNull Collection<String> ids) {
featuresEnabledIds.clear();
featuresEnabledIds.addAll(ids);
@ -272,6 +286,15 @@ public class OsmAndAppCustomization {
return set.contains(appMode);
}
public boolean setNavDrawerLogoWithIntent(String uri, @Nullable String packageName, @Nullable String intent) {
return setNavDrawerLogo(uri, packageName, intent);
}
public boolean setNavDrawerFooterAction(String packageName, String intent, String appName) {
//todo implement custom action to "Powered by Osmand" action in NavDrawer
return true;
}
@NonNull
private HashSet<ApplicationMode> getAppModesSet(@Nullable List<String> appModeKeys) {
HashSet<ApplicationMode> set = new HashSet<>();

View file

@ -51,6 +51,7 @@ import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.Version;
import net.osmand.plus.activities.actions.OsmAndDialogs;
import net.osmand.plus.audionotes.SortByMenuBottomSheetDialogFragment;
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
import net.osmand.plus.dialogs.FavoriteDialogs;
import net.osmand.plus.download.IndexItem;
@ -990,6 +991,26 @@ public class MapActivityActions implements DialogProvider {
menu.show();
}
public void restoreOrReturnDialog(final String packageName) {
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
builder.setTitle("Restore OsmAnd");
builder.setMessage("Do you want to Restore OsmAnd or get back to the Client App?");
builder.setPositiveButton("Restore", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
restoreOsmand();
}
});
builder.setNeutralButton("Return", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
executeHeadersIntent(packageName);
}
});
builder.setNegativeButton("Cancel", null);
builder.show();
}
protected void updateDrawerMenu() {
boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
final ListView menuItemsListView = (ListView) mapActivity.findViewById(R.id.menuItems);
@ -1001,6 +1022,8 @@ public class MapActivityActions implements DialogProvider {
menuItemsListView.removeHeaderView(drawerLogoHeader);
menuItemsListView.removeFooterView(drawerOsmAndFooter);
Bitmap navDrawerLogo = getMyApplication().getAppCustomization().getNavDrawerLogo();
final ArrayList<String> navDrawerLogoParams = getMyApplication().getAppCustomization().getNavDrawerLogoParams();
boolean customHeader = false;
if (navDrawerLogo != null) {
customHeader = true;
@ -1019,9 +1042,9 @@ public class MapActivityActions implements DialogProvider {
mapActivity.dismissCardDialog();
boolean hasHeader = menuItemsListView.getHeaderViewsCount() > 0;
boolean hasFooter = menuItemsListView.getFooterViewsCount() > 0;
if ((hasHeader && position == 0) || (hasFooter && position == menuItemsListView.getCount() - 1)) {
getMyApplication().getAppCustomization().restoreOsmand();
mapActivity.closeDrawer();
if (hasHeader && position ==0 || (hasFooter && position== menuItemsListView.getCount() - 1)) {
if(navDrawerLogoParams!=null) executeHeadersIntent(navDrawerLogoParams.get(0));
else restoreOsmand();
} else {
position -= menuItemsListView.getHeaderViewsCount();
ContextMenuItem item = contextMenuAdapter.getItem(position);
@ -1032,6 +1055,7 @@ public class MapActivityActions implements DialogProvider {
}
}
}
});
if (customHeader) {
menuItemsListView.post(new Runnable() {
@ -1056,9 +1080,8 @@ public class MapActivityActions implements DialogProvider {
footerLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getMyApplication().getAppCustomization().restoreOsmand();
mapActivity.closeDrawer();
if(navDrawerLogoParams!=null) showReturnConfirmationDialog(navDrawerLogoParams.get(0));
else restoreOsmand();
}
});
} else {
@ -1069,6 +1092,23 @@ public class MapActivityActions implements DialogProvider {
}
}
private void executeHeadersIntent(String packageName) {
Intent launchIntent = mapActivity.getPackageManager().getLaunchIntentForPackage(packageName);
if(launchIntent!=null) mapActivity.startActivity(launchIntent);
mapActivity.closeDrawer();
}
private void showReturnConfirmationDialog(String packageName) {
restoreOrReturnDialog(packageName);
mapActivity.closeDrawer();
}
private void restoreOsmand(){
getMyApplication().getAppCustomization().restoreOsmand();
mapActivity.closeDrawer();
}
public void setFirstMapMarkerAsTarget() {
if (getMyApplication().getMapMarkersHelper().getMapMarkers().size() > 0) {
MapMarkersHelper.MapMarker marker = getMyApplication().getMapMarkersHelper().getMapMarkers().get(0);

View file

@ -237,6 +237,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
.setOrder(MARK_AS_PARKING_POS_ITEM_ORDER)
.setListener(addListener)
.createItem());
}
/**

View file

@ -5,8 +5,8 @@
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit