diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index 7c9c022646..5b8a69b000 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -456,8 +456,7 @@ public abstract class OsmandPlugin { return collection; } - private static boolean isPackageInstalled(String packageInfo, - OsmandApplication app) { + public static boolean isPackageInstalled(String packageInfo, OsmandApplication app) { if (packageInfo == null) { return false; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java index 5be0c1a838..5a82080452 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java @@ -4,12 +4,19 @@ import android.content.Context; import android.view.LayoutInflater; import android.view.View; +import net.osmand.plus.OsmandApplication; + public abstract class AbstractCard { + private OsmandApplication app; protected View view; public abstract int getCardLayoutId(); + public AbstractCard(OsmandApplication app) { + this.app = app; + } + public View build(Context ctx) { view = LayoutInflater.from(ctx).inflate(getCardLayoutId(), null); update(); @@ -18,4 +25,7 @@ public abstract class AbstractCard { public abstract void update(); + public OsmandApplication getOsmandApplication() { + return app; + } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/CardsRowBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/CardsRowBuilder.java index aea2816c92..8e87f04b4e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/CardsRowBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/CardsRowBuilder.java @@ -22,14 +22,16 @@ public class CardsRowBuilder { private MenuBuilder menuBuilder; private View view; private OsmandApplication app; + private boolean addToLayout; private List cards = new ArrayList<>(); private LockableViewPager viewPager; private ViewsPagerAdapter pagerAdapter; private int dp10; - public CardsRowBuilder(MenuBuilder menuBuilder, View view) { + public CardsRowBuilder(MenuBuilder menuBuilder, View view, boolean addToLayout) { this.menuBuilder = menuBuilder; this.view = view; + this.addToLayout = addToLayout; this.app = menuBuilder.getApplication(); this.dp10 = AndroidUtils.dpToPx(app, 10f); } @@ -38,7 +40,7 @@ public class CardsRowBuilder { return menuBuilder; } - public LockableViewPager getViewPager() { + public View getContentView() { return viewPager; } @@ -58,7 +60,7 @@ public class CardsRowBuilder { } public void setProgressCard() { - setCards(new ProgressCard()); + setCards(new ProgressCard(app)); } public void build() { @@ -73,7 +75,9 @@ public class CardsRowBuilder { pagerAdapter = new ViewsPagerAdapter(); viewPager.setAdapter(pagerAdapter); viewPager.setSwipeLocked(itemsCount() < 2); - //((LinearLayout) view).addView(viewPager); + if (addToLayout) { + ((LinearLayout) view).addView(viewPager); + } } private int itemsCount() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java index 8cba5cda4a..75fd3818d5 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -58,7 +58,6 @@ public abstract class ImageCard extends AbstractCard { // Image bitmap url private String imageUrl; - private OsmandApplication app; private int defaultImageLayoutId = R.layout.context_menu_card_image; protected Drawable icon; @@ -76,7 +75,7 @@ public abstract class ImageCard extends AbstractCard { } public ImageCard(OsmandApplication app, JSONObject imageObject) { - this.app = app; + super(app); try { if (imageObject.has("type")) { this.type = imageObject.getString("type"); @@ -369,7 +368,7 @@ public abstract class ImageCard extends AbstractCard { @Override protected Bitmap doInBackground(Void... params) { - return AndroidNetworkUtils.downloadImage(app, imageUrl); + return AndroidNetworkUtils.downloadImage(getOsmandApplication(), imageUrl); } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ProgressCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ProgressCard.java index f692b4dfe6..bc1131eecd 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ProgressCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ProgressCard.java @@ -1,9 +1,14 @@ package net.osmand.plus.mapcontextmenu.builders.cards; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; public class ProgressCard extends AbstractCard { + public ProgressCard(OsmandApplication app) { + super(app); + } + @Override public int getCardLayoutId() { return R.layout.context_menu_card_progress; diff --git a/OsmAnd/src/net/osmand/plus/mapillary/AddMapillaryPhotoCard.java b/OsmAnd/src/net/osmand/plus/mapillary/AddMapillaryPhotoCard.java index 4443cd4018..a14467e809 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/AddMapillaryPhotoCard.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/AddMapillaryPhotoCard.java @@ -2,10 +2,15 @@ package net.osmand.plus.mapillary; import android.view.View; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard; -public class AddMapillaryPhotoCard extends AbstractCard { +class AddMapillaryPhotoCard extends AbstractCard { + + AddMapillaryPhotoCard(OsmandApplication app) { + super(app); + } @Override public int getCardLayoutId() { @@ -18,7 +23,7 @@ public class AddMapillaryPhotoCard extends AbstractCard { view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - // todo open mapillary + MapillaryPlugin.openMapillary(getOsmandApplication()); } }); } diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java index c599081ec1..dde5176389 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java @@ -8,16 +8,16 @@ import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; import org.json.JSONObject; -public class MapillaryImageCard extends ImageCard { +class MapillaryImageCard extends ImageCard { - public static class MapillaryImageCardFactory implements ImageCardFactory { + static class MapillaryImageCardFactory implements ImageCardFactory { @Override public MapillaryImageCard createCard(OsmandApplication app, JSONObject imageObject) { return new MapillaryImageCard(app, imageObject); } } - public MapillaryImageCard(OsmandApplication app, JSONObject imageObject) { + private MapillaryImageCard(OsmandApplication app, JSONObject imageObject) { super(app, imageObject); this.icon = app.getIconsCache().getIcon(R.drawable.ic_logo_mapillary); this.onClickListener = new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java index c4d9bdd3c9..ca2e564e58 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java @@ -1,6 +1,9 @@ package net.osmand.plus.mapillary; import android.app.Activity; +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.FragmentActivity; @@ -41,6 +44,7 @@ import java.util.List; public class MapillaryPlugin extends OsmandPlugin { public static final String ID = "osmand.mapillary"; + private static final String MAPILLARY_PACKAGE_ID = "app.mapillary"; private OsmandSettings settings; private OsmandApplication app; @@ -95,7 +99,7 @@ public class MapillaryPlugin extends OsmandPlugin { updateMapLayers(mapView, activity.getMapLayers()); } - public void updateMapLayers(OsmandMapTileView mapView, final MapActivityLayers layers) { + private void updateMapLayers(OsmandMapTileView mapView, final MapActivityLayers layers) { if (rasterLayer == null) { createLayers(); } @@ -108,7 +112,7 @@ public class MapillaryPlugin extends OsmandPlugin { layers.updateMapSource(mapView, null); } - public void updateLayer(OsmandMapTileView mapView, MapTileLayer layer, float layerOrder) { + private void updateLayer(OsmandMapTileView mapView, MapTileLayer layer, float layerOrder) { ITileSource mapillarySource = null; if (settings.SHOW_MAPILLARY.get()) { mapillarySource = settings.getTileSourceByName(TileSourceManager.getMapillarySource().getName(), false); @@ -181,14 +185,14 @@ public class MapillaryPlugin extends OsmandPlugin { mapillaryControl.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - // todo open mapillary app + openMapillary(app); } }); return mapillaryControl; } - public void setWidgetVisible(MapActivity mapActivity, boolean visible) { + private void setWidgetVisible(MapActivity mapActivity, boolean visible) { if (mapillaryWidgetRegInfo != null) { final List allModes = ApplicationMode.allPossibleValues(); for (ApplicationMode mode : allModes) { @@ -209,9 +213,9 @@ public class MapillaryPlugin extends OsmandPlugin { } boolean needUpdateOnly = contextMenuCardsRow != null && contextMenuCardsRow.getMenuBuilder() == menuBuilder; - contextMenuCardsRow = new CardsRowBuilder(menuBuilder, view); + contextMenuCardsRow = new CardsRowBuilder(menuBuilder, view, false); contextMenuCardsRow.build(); - CollapsableView collapsableView = new CollapsableView(contextMenuCardsRow.getViewPager(), + CollapsableView collapsableView = new CollapsableView(contextMenuCardsRow.getContentView(), app.getSettings().MAPILLARY_MENU_COLLAPSED); collapsableView.setOnCollExpListener(new CollapsableView.OnCollExpListener() { @Override @@ -243,7 +247,7 @@ public class MapillaryPlugin extends OsmandPlugin { if (!menuBuilder.isHidden()) { List cards = new ArrayList<>(); cards.addAll(cardList); - cards.add(new AddMapillaryPhotoCard()); + cards.add(new AddMapillaryPhotoCard(app)); contextMenuCardsRow.setCards(cards); contextMenuCards = cards; } @@ -257,6 +261,34 @@ public class MapillaryPlugin extends OsmandPlugin { contextMenuCards = null; } + public static boolean openMapillary(OsmandApplication app) { + boolean success = false; + if (isPackageInstalled(MAPILLARY_PACKAGE_ID, app)) { + Intent launchIntent = app.getPackageManager().getLaunchIntentForPackage(MAPILLARY_PACKAGE_ID); + if (launchIntent != null) { + app.startActivity(launchIntent); + 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); + } + } + return success; + } + + private static boolean execInstall(OsmandApplication app, String url) { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + try { + app.startActivity(intent); + return true; + } catch (ActivityNotFoundException e) { + e.printStackTrace(); + } + return false; + } + public static class MapillaryFirstDialogFragment extends BottomSheetDialogFragment { public static final String TAG = "MapillaryFirstDialogFragment";