Process params of cm_place response

This commit is contained in:
Alexey Kulish 2017-05-10 15:29:23 +03:00
parent 9204b5b19a
commit 0842165f4b
10 changed files with 179 additions and 37 deletions

View file

@ -3,6 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/context_img_card_width"
android:layout_height="@dimen/context_img_card_height"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/bg_color"
android:orientation="vertical">
@ -20,11 +21,12 @@
android:textSize="@dimen/default_list_text_size"
android:text="@string/mapillary_action_descr"/>
<Button
<android.support.v7.widget.AppCompatButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="@drawable/mapillary_button"
android:background="@drawable/blue_button_drawable"
app:backgroundTint="@color/mapillary_color"
android:layout_gravity="bottom|center_horizontal"
android:drawableLeft="@drawable/ic_action_mapillary"
android:drawableStart="@drawable/ic_action_mapillary"

View file

@ -57,6 +57,21 @@
tools:text="\@user123"
tools:visibility="visible"/>
<android.support.v7.widget.AppCompatButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="@drawable/blue_button_drawable"
android:layout_gravity="bottom|center_horizontal"
android:drawablePadding="8dp"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:layout_marginBottom="16dp"
android:textColor="@color/color_white"
android:visibility="gone"
tools:visibility="visible"
tools:text="Button"/>
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"

View file

@ -896,6 +896,7 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> SHOW_MAPILLARY = new BooleanPreference("show_mapillary", false).makeGlobal();
public final OsmandPreference<Boolean> MAPILLARY_FIRST_DIALOG_SHOWN = new BooleanPreference("mapillary_first_dialog_shown", false).makeGlobal();
public final OsmandPreference<Boolean> MAPILLARY_MENU_COLLAPSED = new BooleanPreference("mapillary_menu_collapsed", false).makeGlobal();
public final OsmandPreference<Boolean> WEBGL_SUPPORTED = new BooleanPreference("webgl_supported", true).makeGlobal();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<String> PREFERRED_LOCALE = new StringPreference("preferred_locale", "").makeGlobal();

View file

@ -77,6 +77,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
getMyApplication().getAppInitializer().resetFirstTimeRun();
getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.set(false);
getMyApplication().getSettings().MAPILLARY_FIRST_DIALOG_SHOWN.set(false);
getMyApplication().getSettings().WEBGL_SUPPORTED.set(true);
getMyApplication().showToastMessage(R.string.shared_string_ok);
return true;
}

View file

@ -7,6 +7,8 @@ import android.content.res.Resources;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v7.view.ContextThemeWrapper;
import android.support.v7.widget.AppCompatButton;
@ -306,7 +308,7 @@ public class MenuBuilder {
private void startLoadingImages(final MenuBuilder menuBuilder) {
onlinePhotoCards = new ArrayList<>();
onlinePhotoCardsRow.setProgressCard();
ImageCard.execute(new GetImageCardsTask(mapActivity, menuBuilder.getLatLon(),
execute(new GetImageCardsTask(mapActivity, menuBuilder.getLatLon(),
new GetImageCardsListener() {
@Override
public void onFinish(List<ImageCard> cardList) {
@ -682,4 +684,13 @@ public class MenuBuilder {
}
return false;
}
@SuppressWarnings("unchecked")
public static <P> void execute(AsyncTask<P, ?, ?> task, P... requests) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, requests);
} else {
task.execute(requests);
}
}
}

View file

@ -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,10 +117,48 @@ 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;
@ -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 <P> void execute(AsyncTask<P, ?, ?> task, P... requests) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, requests);
if (!Algorithms.isEmpty(buttonText)) {
button.setText(buttonText);
}
if (buttonIcon == null && buttonIconId != 0) {
if (buttonIconColor != 0) {
buttonIcon = getMyApplication().getIconsCache().getPaintedIcon(buttonIconId, buttonIconColor);
} else {
task.execute(requests);
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);

View file

@ -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;
}
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}

View file

@ -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();
}