Fix webgl. Added photo_id to Mapillary start intent.

This commit is contained in:
Alexey Kulish 2017-05-08 22:01:00 +03:00
parent e3ae8e6493
commit a6b99f1e41
11 changed files with 89 additions and 30 deletions

View file

@ -19,6 +19,7 @@
android:minHeight="@dimen/dashboard_map_toolbar" android:minHeight="@dimen/dashboard_map_toolbar"
android:background="@color/osmand_orange" android:background="@color/osmand_orange"
android:gravity="center_vertical" android:gravity="center_vertical"
android:clickable="true"
android:orientation="horizontal"> android:orientation="horizontal">
<android.support.v7.widget.AppCompatImageView <android.support.v7.widget.AppCompatImageView
@ -69,13 +70,13 @@
</LinearLayout> </LinearLayout>
<android.support.v7.widget.AppCompatImageView <android.support.v7.widget.AppCompatImageView
android:id="@+id/refresh_button" android:id="@+id/more_button"
style="@style/Widget.AppCompat.ActionButton" style="@style/Widget.AppCompat.ActionButton"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="56dp" android:layout_height="56dp"
android:layout_gravity="top" android:layout_gravity="top"
android:contentDescription="@string/shared_string_refresh" android:contentDescription="@string/shared_string_more"
android:src="@drawable/ic_action_refresh_dark" android:src="@drawable/ic_overflow_menu_white"
android:visibility="gone"/> android:visibility="gone"/>
</LinearLayout> </LinearLayout>

View file

@ -13,6 +13,7 @@
android:minHeight="@dimen/dashboard_map_toolbar" android:minHeight="@dimen/dashboard_map_toolbar"
android:background="@color/osmand_orange" android:background="@color/osmand_orange"
android:gravity="center_vertical" android:gravity="center_vertical"
android:clickable="true"
android:orientation="horizontal"> android:orientation="horizontal">
<android.support.v7.widget.AppCompatImageView <android.support.v7.widget.AppCompatImageView
@ -63,13 +64,13 @@
</LinearLayout> </LinearLayout>
<android.support.v7.widget.AppCompatImageView <android.support.v7.widget.AppCompatImageView
android:id="@+id/refresh_button" android:id="@+id/more_button"
style="@style/Widget.AppCompat.ActionButton" style="@style/Widget.AppCompat.ActionButton"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="56dp" android:layout_height="56dp"
android:layout_gravity="top" android:layout_gravity="top"
android:contentDescription="@string/shared_string_refresh" android:contentDescription="@string/shared_string_more"
android:src="@drawable/ic_action_refresh_dark" android:src="@drawable/ic_overflow_menu_white"
android:visibility="gone"/> android:visibility="gone"/>
</LinearLayout> </LinearLayout>

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 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 PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="open_mapillary">Open Mapillary</string>
<string name="shared_string_install">Install</string> <string name="shared_string_install">Install</string>
<string name="improve_coverage_mapillary">Improve coverage with Mapillary</string> <string name="improve_coverage_mapillary">Improve coverage with Mapillary</string>
<string name="improve_coverage_install_mapillary_desc">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.</string> <string name="improve_coverage_install_mapillary_desc">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.</string>

View file

@ -23,7 +23,7 @@ public class NoImagesCard extends AbstractCard {
view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
MapillaryPlugin.openMapillary(getMapActivity()); MapillaryPlugin.openMapillary(getMapActivity(), null);
} }
}); });
} }

View file

@ -22,22 +22,10 @@ public class UrlImageCard extends ImageCard {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(getImageUrl())); intent.setData(Uri.parse(getUrl()));
v.getContext().startActivity(intent); v.getContext().startActivity(intent);
} }
}; };
} }
} }
@Override
public void update() {
super.update();
if (view != null) {
ImageView image = (ImageView) view.findViewById(R.id.image);
image.setVisibility(View.GONE);
TextView urlText = (TextView) view.findViewById(R.id.url);
urlText.setText(getImageUrl());
urlText.setVisibility(View.VISIBLE);
}
}
} }

View file

@ -2,6 +2,8 @@ package net.osmand.plus.mapcontextmenu.builders.cards.dialogs;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -10,6 +12,8 @@ import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapillary.MapillaryImageDialog; import net.osmand.plus.mapillary.MapillaryImageDialog;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import java.util.List;
public abstract class ContextMenuCardDialog { public abstract class ContextMenuCardDialog {
private MapActivity mapActivity; private MapActivity mapActivity;
@ -56,6 +60,13 @@ public abstract class ContextMenuCardDialog {
return description; return description;
} }
protected boolean haveMenuItems() {
return false;
}
protected void createMenuItems(Menu menu) {
}
public void saveMenu(Bundle bundle) { public void saveMenu(Bundle bundle) {
bundle.putString(KEY_CARD_DIALOG_TYPE, type.name()); bundle.putString(KEY_CARD_DIALOG_TYPE, type.name());
if (title != null) { if (title != null) {

View file

@ -4,6 +4,8 @@ import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.PopupMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -13,6 +15,7 @@ import android.widget.TextView;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
public class ContextMenuCardDialogFragment extends Fragment { public class ContextMenuCardDialogFragment extends Fragment {
@ -51,6 +54,21 @@ public class ContextMenuCardDialogFragment extends Fragment {
if (!Algorithms.isEmpty(dialog.getDescription())) { if (!Algorithms.isEmpty(dialog.getDescription())) {
((TextView) view.findViewById(R.id.description)).setText(dialog.getDescription()); ((TextView) view.findViewById(R.id.description)).setText(dialog.getDescription());
} }
AppCompatImageView moreButton = (AppCompatImageView) view.findViewById(R.id.more_button);
if (dialog.haveMenuItems()) {
moreButton.setVisibility(View.VISIBLE);
moreButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu optionsMenu = new PopupMenu(getContext(), v);
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
dialog.createMenuItems(optionsMenu.getMenu());
optionsMenu.show();
}
});
} else {
moreButton.setVisibility(View.GONE);
}
return view; return view;
} }

View file

@ -25,7 +25,7 @@ public class MapillaryContributeCard extends ImageCard {
view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
MapillaryPlugin.openMapillary(getMapActivity()); MapillaryPlugin.openMapillary(getMapActivity(), null);
} }
}); });
} }

View file

@ -17,7 +17,7 @@ public class MapillaryImageCard extends ImageCard {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
getMapActivity().getContextMenu().hideMenues(); getMapActivity().getContextMenu().hideMenues();
MapillaryImageDialog.show(getMapActivity(), getImageHiresUrl(), getUrl(), getLocation(), MapillaryImageDialog.show(getMapActivity(), getKey(), getImageHiresUrl(), getUrl(), getLocation(),
getCa(), getMyApplication().getString(R.string.mapillary), null); getCa(), getMyApplication().getString(R.string.mapillary), null);
} }
}; };

View file

@ -8,6 +8,8 @@ import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.view.Gravity; import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.webkit.ConsoleMessage; import android.webkit.ConsoleMessage;
@ -21,6 +23,7 @@ import android.widget.ProgressBar;
import net.osmand.AndroidNetworkUtils; import net.osmand.AndroidNetworkUtils;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
import net.osmand.plus.mapcontextmenu.builders.cards.dialogs.ContextMenuCardDialog; import net.osmand.plus.mapcontextmenu.builders.cards.dialogs.ContextMenuCardDialog;
@ -30,6 +33,7 @@ import net.osmand.util.Algorithms;
public class MapillaryImageDialog extends ContextMenuCardDialog { public class MapillaryImageDialog extends ContextMenuCardDialog {
private static final String KEY_MAPILLARY_DIALOG_IMAGE_KEY = "key_mapillary_dialog_image_key";
private static final String KEY_MAPILLARY_DIALOG_IMAGE_URL = "key_mapillary_dialog_image_url"; private static final String KEY_MAPILLARY_DIALOG_IMAGE_URL = "key_mapillary_dialog_image_url";
private static final String KEY_MAPILLARY_DIALOG_VIEWER_URL = "key_mapillary_dialog_viewer_url"; private static final String KEY_MAPILLARY_DIALOG_VIEWER_URL = "key_mapillary_dialog_viewer_url";
private static final String KEY_MAPILLARY_DIALOG_LATLON = "key_mapillary_dialog_latlon"; private static final String KEY_MAPILLARY_DIALOG_LATLON = "key_mapillary_dialog_latlon";
@ -42,6 +46,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
private static final String WEBGL_ERROR_MESSAGE = "Error creating WebGL context"; private static final String WEBGL_ERROR_MESSAGE = "Error creating WebGL context";
private String key;
private String imageUrl; private String imageUrl;
private String viewerUrl; private String viewerUrl;
private LatLon latLon; private LatLon latLon;
@ -52,17 +57,22 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
restoreFields(bundle); restoreFields(bundle);
} }
public MapillaryImageDialog(MapActivity mapActivity, String imageUrl, String viewerUrl, LatLon latLon, double ca, public MapillaryImageDialog(MapActivity mapActivity, String key, String imageUrl, String viewerUrl, LatLon latLon, double ca,
String title, String description) { String title, String description) {
super(mapActivity, CardDialogType.MAPILLARY); super(mapActivity, CardDialogType.MAPILLARY);
this.title = title; this.title = title;
this.description = description; this.description = description;
this.key = key;
this.imageUrl = imageUrl; this.imageUrl = imageUrl;
this.viewerUrl = viewerUrl; this.viewerUrl = viewerUrl;
this.latLon = latLon; this.latLon = latLon;
this.ca = ca; this.ca = ca;
} }
public String getKey() {
return key;
}
public String getViewerUrl() { public String getViewerUrl() {
return viewerUrl; return viewerUrl;
} }
@ -77,6 +87,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
public void saveMenu(Bundle bundle) { public void saveMenu(Bundle bundle) {
super.saveMenu(bundle); super.saveMenu(bundle);
bundle.putSerializable(KEY_MAPILLARY_DIALOG_IMAGE_KEY, key);
bundle.putSerializable(KEY_MAPILLARY_DIALOG_IMAGE_URL, imageUrl); bundle.putSerializable(KEY_MAPILLARY_DIALOG_IMAGE_URL, imageUrl);
bundle.putSerializable(KEY_MAPILLARY_DIALOG_VIEWER_URL, viewerUrl); bundle.putSerializable(KEY_MAPILLARY_DIALOG_VIEWER_URL, viewerUrl);
bundle.putSerializable(KEY_MAPILLARY_DIALOG_LATLON, latLon); bundle.putSerializable(KEY_MAPILLARY_DIALOG_LATLON, latLon);
@ -86,6 +97,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
@Override @Override
protected void restoreFields(Bundle bundle) { protected void restoreFields(Bundle bundle) {
super.restoreFields(bundle); super.restoreFields(bundle);
this.key = bundle.getString(KEY_MAPILLARY_DIALOG_IMAGE_KEY);
this.imageUrl = bundle.getString(KEY_MAPILLARY_DIALOG_IMAGE_URL); this.imageUrl = bundle.getString(KEY_MAPILLARY_DIALOG_IMAGE_URL);
this.viewerUrl = bundle.getString(KEY_MAPILLARY_DIALOG_VIEWER_URL); this.viewerUrl = bundle.getString(KEY_MAPILLARY_DIALOG_VIEWER_URL);
Object latLonObj = bundle.getSerializable(KEY_MAPILLARY_DIALOG_LATLON); Object latLonObj = bundle.getSerializable(KEY_MAPILLARY_DIALOG_LATLON);
@ -136,11 +148,31 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
} }
} }
@Override
protected boolean haveMenuItems() {
return true;
}
@Override
protected void createMenuItems(Menu menu) {
MenuItem item = menu.add(R.string.open_mapillary)
.setIcon(getMapActivity().getMyApplication().getIconsCache().getThemedIcon(
R.drawable.ic_action_mapillary));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MapillaryPlugin.openMapillary(getMapActivity(), key);
return true;
}
});
}
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"}) @SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
private WebView getWebView() { private WebView getWebView() {
final WebView webView = new WebView(getMapActivity()); final WebView webView = new WebView(getMapActivity());
webView.setBackgroundColor(Color.argb(1, 0, 0, 0)); webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); //webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
webView.setScrollContainer(false); webView.setScrollContainer(false);
webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new MapillaryWebAppInterface(), "Android"); webView.addJavascriptInterface(new MapillaryWebAppInterface(), "Android");
@ -153,7 +185,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
public boolean onConsoleMessage(ConsoleMessage consoleMessage) { public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
if (!Algorithms.isEmpty(consoleMessage.message()) && consoleMessage.message().contains(WEBGL_ERROR_MESSAGE)) { if (!Algorithms.isEmpty(consoleMessage.message()) && consoleMessage.message().contains(WEBGL_ERROR_MESSAGE)) {
MapillaryPlugin.setWebGlSupported(false); MapillaryPlugin.setWebGlSupported(false);
show(getMapActivity(), imageUrl, viewerUrl, getLatLon(), getCa(), getTitle(), getDescription()); show(getMapActivity(), key, imageUrl, viewerUrl, getLatLon(), getCa(), getTitle(), getDescription());
} }
return false; return false;
} }
@ -172,6 +204,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
MapillaryImageDialog.this.latLon = latLon; MapillaryImageDialog.this.latLon = latLon;
MapillaryImageDialog.this.ca = ca; MapillaryImageDialog.this.ca = ca;
if (!Algorithms.isEmpty(key)) { if (!Algorithms.isEmpty(key)) {
MapillaryImageDialog.this.key = key;
MapillaryImageDialog.this.imageUrl = MAPILLARY_HIRES_IMAGE_URL_TEMPLATE + key; MapillaryImageDialog.this.imageUrl = MAPILLARY_HIRES_IMAGE_URL_TEMPLATE + key;
MapillaryImageDialog.this.viewerUrl = MAPILLARY_VIEWER_URL_TEMPLATE + key; MapillaryImageDialog.this.viewerUrl = MAPILLARY_VIEWER_URL_TEMPLATE + key;
} }
@ -182,6 +215,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
private View getStaticImageView() { private View getStaticImageView() {
LinearLayout ll = new LinearLayout(getMapActivity()); LinearLayout ll = new LinearLayout(getMapActivity());
ll.setClickable(true);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
isPortrait() ? ViewGroup.LayoutParams.MATCH_PARENT : AndroidUtils.dpToPx(getMapActivity(), 360f), isPortrait() ? ViewGroup.LayoutParams.MATCH_PARENT : AndroidUtils.dpToPx(getMapActivity(), 360f),
isPortrait() ? AndroidUtils.dpToPx(getMapActivity(), 270f) : ViewGroup.LayoutParams.MATCH_PARENT); isPortrait() ? AndroidUtils.dpToPx(getMapActivity(), 270f) : ViewGroup.LayoutParams.MATCH_PARENT);
@ -205,9 +239,11 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
} }
public static MapillaryImageDialog show(MapActivity mapActivity, String imageUrl, String viewerUrl, LatLon latLon, double ca, public static MapillaryImageDialog show(MapActivity mapActivity, String key, String imageUrl,
String viewerUrl, LatLon latLon, double ca,
String title, String description) { String title, String description) {
MapillaryImageDialog dialog = new MapillaryImageDialog(mapActivity, imageUrl, viewerUrl, latLon, ca, title, description); MapillaryImageDialog dialog = new MapillaryImageDialog(mapActivity, key, imageUrl, viewerUrl,
latLon, ca, title, description);
ContextMenuCardDialogFragment.showInstance(dialog); ContextMenuCardDialogFragment.showInstance(dialog);
return dialog; return dialog;
} }

View file

@ -184,7 +184,7 @@ public class MapillaryPlugin extends OsmandPlugin {
mapillaryControl.setOnClickListener(new View.OnClickListener() { mapillaryControl.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
openMapillary(map); openMapillary(map, null);
} }
}); });
@ -205,12 +205,15 @@ public class MapillaryPlugin extends OsmandPlugin {
} }
} }
public static boolean openMapillary(FragmentActivity activity) { public static boolean openMapillary(FragmentActivity activity, String imageKey) {
boolean success = false; boolean success = false;
OsmandApplication app = (OsmandApplication) activity.getApplication(); OsmandApplication app = (OsmandApplication) activity.getApplication();
if (isPackageInstalled(MAPILLARY_PACKAGE_ID, app)) { if (isPackageInstalled(MAPILLARY_PACKAGE_ID, app)) {
Intent launchIntent = app.getPackageManager().getLaunchIntentForPackage(MAPILLARY_PACKAGE_ID); Intent launchIntent = app.getPackageManager().getLaunchIntentForPackage(MAPILLARY_PACKAGE_ID);
if (launchIntent != null) { if (launchIntent != null) {
if (imageKey != null) {
launchIntent.putExtra("photo_id", imageKey);
}
app.startActivity(launchIntent); app.startActivity(launchIntent);
success = true; success = true;
} }