From a74c81369425626a8408eb3a858476d2d8ac253f Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Mon, 8 May 2017 11:12:22 +0300 Subject: [PATCH] Added mapillary install dialog --- .../res/layout/mapillary_install_dialog.xml | 45 +++++++++++++++++++ OsmAnd/res/values/strings.xml | 3 ++ .../builders/cards/NoImagesCard.java | 2 +- .../mapillary/MapillaryContributeCard.java | 2 +- .../MapillaryInstallDialogFragment.java | 45 +++++++++++++++++++ .../plus/mapillary/MapillaryPlugin.java | 18 +++++--- 6 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 OsmAnd/res/layout/mapillary_install_dialog.xml create mode 100644 OsmAnd/src/net/osmand/plus/mapillary/MapillaryInstallDialogFragment.java diff --git a/OsmAnd/res/layout/mapillary_install_dialog.xml b/OsmAnd/res/layout/mapillary_install_dialog.xml new file mode 100644 index 0000000000..5418e05d33 --- /dev/null +++ b/OsmAnd/res/layout/mapillary_install_dialog.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 6168e7c914..23e42a93c5 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,9 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Install + Improve coverage with Mapillary + You can take your own photos or series of photos and add it to this map location.\n\nTo do this you need install Mapillary app from Google Play. Online photos Add photos We don\'t have photos for this location diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java index 632923bf24..8b2f4adb2d 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java @@ -23,7 +23,7 @@ public class NoImagesCard extends AbstractCard { view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - MapillaryPlugin.openMapillary(getMyApplication()); + MapillaryPlugin.openMapillary(getMapActivity()); } }); } diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryContributeCard.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryContributeCard.java index f4aea33415..1e50716ce9 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryContributeCard.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryContributeCard.java @@ -25,7 +25,7 @@ public class MapillaryContributeCard extends ImageCard { view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - MapillaryPlugin.openMapillary(getMyApplication()); + MapillaryPlugin.openMapillary(getMapActivity()); } }); } diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryInstallDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryInstallDialogFragment.java new file mode 100644 index 0000000000..430f92a92a --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryInstallDialogFragment.java @@ -0,0 +1,45 @@ +package net.osmand.plus.mapillary; + +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.DialogFragment; +import android.support.v7.app.AlertDialog; +import android.view.View; +import android.widget.Button; + +import net.osmand.osm.PoiCategory; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; + +public class MapillaryInstallDialogFragment extends DialogFragment { + + public static final String TAG = "MapillaryInstallDialogFragment"; + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + + final MapActivity mapActivity = (MapActivity) getActivity(); + + final AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity); + builder.setCancelable(true); + builder.setNegativeButton(mapActivity.getString(R.string.shared_string_cancel), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + builder.setPositiveButton(mapActivity.getString(R.string.shared_string_install), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + MapillaryPlugin.installMapillary(mapActivity.getMyApplication()); + } + }); + + builder.setView(mapActivity.getLayoutInflater().inflate(R.layout.mapillary_install_dialog, null)); + return builder.create(); + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java index 2df0d4b05e..26cdbb9ea3 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java @@ -174,7 +174,7 @@ public class MapillaryPlugin extends OsmandPlugin { mapillaryControl.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - openMapillary(app); + openMapillary(map); } }); @@ -195,8 +195,9 @@ public class MapillaryPlugin extends OsmandPlugin { } } - public static boolean openMapillary(OsmandApplication app) { + public static boolean openMapillary(FragmentActivity activity) { boolean success = false; + OsmandApplication app = (OsmandApplication) activity.getApplication(); if (isPackageInstalled(MAPILLARY_PACKAGE_ID, app)) { Intent launchIntent = app.getPackageManager().getLaunchIntentForPackage(MAPILLARY_PACKAGE_ID); if (launchIntent != null) { @@ -204,10 +205,15 @@ public class MapillaryPlugin extends OsmandPlugin { success = true; } } else { - success = execInstall(app, "market://search?q=pname:" + MAPILLARY_PACKAGE_ID); - if (!success) { - success = execInstall(app, "https://play.google.com/store/apps/details?id=" + MAPILLARY_PACKAGE_ID); - } + new MapillaryInstallDialogFragment().show(activity.getSupportFragmentManager(), MapillaryInstallDialogFragment.TAG); + } + return success; + } + + public static boolean installMapillary(OsmandApplication app) { + boolean success = execInstall(app, "market://search?q=pname:" + MAPILLARY_PACKAGE_ID); + if (!success) { + success = execInstall(app, "https://play.google.com/store/apps/details?id=" + MAPILLARY_PACKAGE_ID); } return success; }