void execute(AsyncTask
task, P... requests) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, requests); + } else { + task.execute(requests); + } + } } 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 b2c90a56ce..b7285bdb8b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -1,10 +1,11 @@ package net.osmand.plus.mapcontextmenu.builders.cards; +import android.content.res.ColorStateList; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.os.AsyncTask; -import android.os.Build; import android.support.annotation.NonNull; +import android.support.v7.widget.AppCompatButton; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; @@ -18,6 +19,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapillary.MapillaryContributeCard; import net.osmand.plus.mapillary.MapillaryImageCard; import net.osmand.util.Algorithms; @@ -58,10 +60,19 @@ public abstract class ImageCard extends AbstractCard { // Image high resolution bitmap url private String imageHiresUrl; - private int defaultImageLayoutId = R.layout.context_menu_card_image; + protected int topIconId; + protected int buttonIconId; + protected String buttonText; + protected int buttonIconColor; + protected int buttonColor; + protected int buttonTextColor; + + private int defaultCardLayoutId = R.layout.context_menu_card_image; protected Drawable icon; + protected Drawable buttonIcon; protected OnClickListener onClickListener; + protected OnClickListener onButtonClickListener; private static final DateFormat DATE_FORMAT = SimpleDateFormat.getDateTimeInstance(FULL, FULL, Locale.US); //"yyyy-MM-dd'T'HH:mm:ss"); private boolean downloading; @@ -106,11 +117,49 @@ public abstract class ImageCard extends AbstractCard { if (imageObject.has("imageHiresUrl")) { this.imageHiresUrl = imageObject.getString("imageHiresUrl"); } - } catch (JSONException e) { + if (imageObject.has("topIcon") && !imageObject.isNull("topIcon")) { + this.topIconId = getDrawableId(imageObject.getString("topIcon")); + } + if (imageObject.has("buttonIcon") && !imageObject.isNull("buttonIcon")) { + this.buttonIconId = getDrawableId(imageObject.getString("buttonIcon")); + } + if (imageObject.has("buttonText") && !imageObject.isNull("buttonText")) { + this.buttonText = imageObject.getString("buttonText"); + } + if (imageObject.has("buttonIconColor") && !imageObject.isNull("buttonIconColor")) { + try { + this.buttonIconColor = Algorithms.parseColor(imageObject.getString("buttonIconColor")); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + } + if (imageObject.has("buttonColor") && !imageObject.isNull("buttonColor")) { + try { + this.buttonColor = Algorithms.parseColor(imageObject.getString("buttonColor")); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + } + if (imageObject.has("buttonTextColor") && !imageObject.isNull("buttonTextColor")) { + try { + this.buttonTextColor = Algorithms.parseColor(imageObject.getString("buttonTextColor")); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + } + } catch (Exception e) { e.printStackTrace(); } } + private int getDrawableId(String id) { + if (Algorithms.isEmpty(id)) { + return 0; + } else { + return getMyApplication().getResources().getIdentifier(id, "drawable", getMyApplication().getPackageName()); + } + } + private static ImageCard createCard(MapActivity mapActivity, JSONObject imageObject) { ImageCard imageCard = null; try { @@ -166,13 +215,37 @@ public abstract class ImageCard extends AbstractCard { return imageHiresUrl; } - public int getDefaultImageLayoutId() { - return defaultImageLayoutId; + public int getTopIconId() { + return topIconId; + } + + public int getButtonIconId() { + return buttonIconId; + } + + public String getButtonText() { + return buttonText; + } + + public int getButtonIconColor() { + return buttonIconColor; + } + + public int getButtonColor() { + return buttonColor; + } + + public int getButtonTextColor() { + return buttonTextColor; + } + + public int getDefaultCardLayoutId() { + return defaultCardLayoutId; } @Override public int getCardLayoutId() { - return defaultImageLayoutId; + return defaultCardLayoutId; } public Drawable getIcon() { @@ -222,6 +295,10 @@ public abstract class ImageCard extends AbstractCard { ImageView iconImageView = (ImageView) view.findViewById(R.id.icon); TextView watermarkTextView = (TextView) view.findViewById(R.id.watermark); ProgressBar progress = (ProgressBar) view.findViewById(R.id.progress); + AppCompatButton button = (AppCompatButton) view.findViewById(R.id.button); + if (icon == null && topIconId != 0) { + icon = getMyApplication().getIconsCache().getIcon(topIconId); + } if (icon == null) { iconImageView.setVisibility(View.GONE); } else { @@ -238,7 +315,7 @@ public abstract class ImageCard extends AbstractCard { progress.setVisibility(View.VISIBLE); image.setImageBitmap(null); } else if (!downloaded) { - execute(new DownloadImageTask()); + MenuBuilder.execute(new DownloadImageTask()); } else { progress.setVisibility(View.GONE); image.setImageBitmap(bitmap); @@ -253,15 +330,36 @@ public abstract class ImageCard extends AbstractCard { } else { view.findViewById(R.id.image_card).setOnClickListener(null); } - } - } - @SuppressWarnings("unchecked") - public static
void execute(AsyncTask
task, P... requests) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, requests); - } else { - task.execute(requests); + if (!Algorithms.isEmpty(buttonText)) { + button.setText(buttonText); + } + if (buttonIcon == null && buttonIconId != 0) { + if (buttonIconColor != 0) { + buttonIcon = getMyApplication().getIconsCache().getPaintedIcon(buttonIconId, buttonIconColor); + } else { + buttonIcon = getMyApplication().getIconsCache().getIcon(buttonIconId); + } + } + button.setCompoundDrawablesWithIntrinsicBounds(buttonIcon, null, null, null); + if (buttonColor != 0) { + button.setSupportBackgroundTintList(ColorStateList.valueOf(buttonColor)); + } + if (buttonTextColor != 0) { + button.setTextColor(buttonTextColor); + } + if (onButtonClickListener != null) { + button.setVisibility(View.VISIBLE); + button.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + onButtonClickListener.onClick(v); + } + }); + } else { + button.setVisibility(View.GONE); + button.setOnClickListener(null); + } } } @@ -296,6 +394,13 @@ public abstract class ImageCard extends AbstractCard { pms.put("myLocation", "" + myLocation.getLatitude() + "," + myLocation.getLongitude()); } pms.put("app", Version.isPaidVersion(app) ? "paid" : "free"); + String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); + if (Algorithms.isEmpty(preferredLang)) { + preferredLang = app.getLanguage(); + } + if (!Algorithms.isEmpty(preferredLang)) { + pms.put("lang", preferredLang); + } String response = AndroidNetworkUtils.sendRequest(app, "http://osmand.net/api/cm_place.php", pms, "Requesting location images...", false, false); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java index cee2010716..267fa36f8e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java @@ -1,13 +1,17 @@ package net.osmand.plus.mapcontextmenu.builders.cards; import android.content.Intent; +import android.content.res.ColorStateList; import android.net.Uri; +import android.support.v7.widget.AppCompatButton; import android.view.View; +import android.view.View.OnClickListener; import android.widget.ImageView; import android.widget.TextView; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapillary.MapillaryPlugin; import net.osmand.util.Algorithms; import org.json.JSONObject; @@ -16,9 +20,8 @@ public class UrlImageCard extends ImageCard { public UrlImageCard(MapActivity mapActivity, JSONObject imageObject) { super(mapActivity, imageObject); - this.icon = getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_osmand_logo, R.color.osmand_orange); - if (!Algorithms.isEmpty(getImageUrl())) { - this.onClickListener = new View.OnClickListener() { + if (!Algorithms.isEmpty(getUrl())) { + OnClickListener onClickListener = new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW); @@ -26,6 +29,11 @@ public class UrlImageCard extends ImageCard { v.getContext().startActivity(intent); } }; + if (!Algorithms.isEmpty(buttonText)) { + this.onButtonClickListener = onClickListener; + } else { + this.onClickListener = onClickListener; + } } } } diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java index 4235a8f93d..31cfef3536 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java @@ -1,10 +1,12 @@ package net.osmand.plus.mapillary; import android.view.View; +import android.view.View.OnClickListener; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; +import net.osmand.util.Algorithms; import org.json.JSONObject; @@ -12,8 +14,10 @@ public class MapillaryImageCard extends ImageCard { public MapillaryImageCard(final MapActivity mapActivity, final JSONObject imageObject) { super(mapActivity, imageObject); - this.icon = getMyApplication().getIconsCache().getIcon(R.drawable.ic_logo_mapillary); - this.onClickListener = new View.OnClickListener() { + if (topIconId == 0) { + topIconId = R.drawable.ic_logo_mapillary; + } + OnClickListener onClickListener = new OnClickListener() { @Override public void onClick(View v) { getMapActivity().getContextMenu().hideMenues(); @@ -21,5 +25,10 @@ public class MapillaryImageCard extends ImageCard { getCa(), getMyApplication().getString(R.string.mapillary), null); } }; + if (!Algorithms.isEmpty(buttonText)) { + this.onButtonClickListener = onClickListener; + } else { + this.onClickListener = onClickListener; + } } } diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java index 170abbdd3c..d4fca11c33 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java @@ -25,7 +25,7 @@ import net.osmand.AndroidUtils; import net.osmand.data.LatLon; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; +import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.builders.cards.dialogs.ContextMenuCardDialog; import net.osmand.plus.mapcontextmenu.builders.cards.dialogs.ContextMenuCardDialogFragment; import net.osmand.plus.views.OsmandMapTileView; @@ -141,7 +141,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { } public View getContentView() { - if (MapillaryPlugin.isWebGlSupported()) { + if (getMapActivity().getMyApplication().getSettings().WEBGL_SUPPORTED.get()) { return getWebView(); } else { return getStaticImageView(); @@ -184,7 +184,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { if (!Algorithms.isEmpty(consoleMessage.message()) && consoleMessage.message().contains(WEBGL_ERROR_MESSAGE)) { - MapillaryPlugin.setWebGlSupported(false); + getMapActivity().getMyApplication().getSettings().WEBGL_SUPPORTED.set(false); show(getMapActivity(), key, imageUrl, viewerUrl, getLatLon(), getCa(), getTitle(), getDescription()); } return false; @@ -233,7 +233,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { ll.addView(imageView); if (!Algorithms.isEmpty(imageUrl)) { - ImageCard.execute(new DownloadImageTask(progressBar, imageView)); + MenuBuilder.execute(new DownloadImageTask(progressBar, imageView)); } return ll; } diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java index cb9a7a9b24..f717e08d4b 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java @@ -45,8 +45,6 @@ public class MapillaryPlugin extends OsmandPlugin { private TextInfoWidget mapillaryControl; private MapWidgetRegInfo mapillaryWidgetRegInfo; - private static boolean webGlSupported = true; - public MapillaryPlugin(OsmandApplication app) { this.app = app; settings = app.getSettings(); @@ -83,14 +81,6 @@ public class MapillaryPlugin extends OsmandPlugin { registerWidget(activity); } - public static boolean isWebGlSupported() { - return webGlSupported; - } - - public static void setWebGlSupported(boolean webGlSupported) { - MapillaryPlugin.webGlSupported = webGlSupported; - } - private void createLayers() { rasterLayer = new MapillaryLayer(); }