From c8418eae4c754b219d0c7a0d31a71cb2265909b8 Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 2 May 2018 16:23:12 +0300 Subject: [PATCH 1/5] fix button padding and colors of lang button --- .../WikipediaDialogFragment.java | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java index e2d17b8792..b24534c55d 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java @@ -112,17 +112,27 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p, R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p); + ColorStateList selectedLangColorStateList = AndroidUtils.createPressedColorStateList( + getContext(), darkMode, + R.color.icon_color, R.color.wikivoyage_active_light, + R.color.icon_color, R.color.wikivoyage_active_dark + ); + readFullArticleButton = (TextView) mainView.findViewById(R.id.read_full_article); readFullArticleButton.setBackgroundResource(darkMode ? R.drawable.bt_round_long_night : R.drawable.bt_round_long_day); readFullArticleButton.setTextColor(buttonColorStateList); - readFullArticleButton.setCompoundDrawablesWithIntrinsicBounds(getIcon(R.drawable.ic_world_globe_dark), null, null, null); + readFullArticleButton.setCompoundDrawablesWithIntrinsicBounds(getActiveIcon(R.drawable.ic_world_globe_dark), null, null, null); readFullArticleButton.setCompoundDrawablePadding((int) getResources().getDimension(R.dimen.content_padding_small)); + int paddingLeft = (int) getResources().getDimension(R.dimen.wikipedia_button_left_padding); + int paddingRight = (int) getResources().getDimension(R.dimen.dialog_content_margin); + readFullArticleButton.setPadding(paddingLeft, 0, paddingRight, 0); + + selectLanguageTextView = (TextView) mainView.findViewById(R.id.select_language_text_view); + selectLanguageTextView.setTextColor(selectedLangColorStateList); + selectLanguageTextView.setCompoundDrawablesWithIntrinsicBounds(getSelectedLangIcon(), null, null, null); + selectLanguageTextView.setBackgroundResource(darkMode + ? R.drawable.wikipedia_select_lang_bg_dark_n : R.drawable.wikipedia_select_lang_bg_light_n); - selectLanguageTextView = mainView.findViewById(R.id.select_language_text_view); - selectLanguageTextView.setTextColor(buttonColorStateList); - selectLanguageTextView.setCompoundDrawablesWithIntrinsicBounds(getIcon(R.drawable.ic_action_map_language), null, null, null); - selectLanguageTextView.setCompoundDrawablePadding((int) getResources().getDimension(R.dimen.context_menu_padding_margin_small)); - selectLanguageTextView.setBackgroundResource(darkMode ? R.drawable.wikipedia_select_lang_bg_dark : R.drawable.wikipedia_select_lang_bg_light); contentWebView = (WebView) mainView.findViewById(R.id.content_web_view); WebSettings webSettings = contentWebView.getSettings(); webSettings.setJavaScriptEnabled(true); @@ -130,6 +140,16 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { return mainView; } + @NonNull + private Drawable getSelectedLangIcon() { + Drawable normal = getIcon(R.drawable.ic_action_map_language, R.color.icon_color); + if (Build.VERSION.SDK_INT >= 21) { + Drawable active = getActiveIcon(R.drawable.ic_action_map_language); + return AndroidUtils.createPressedStateListDrawable(normal, active); + } + return normal; + } + @NonNull private String getBaseUrl() { File wikivoyageDir = getMyApplication().getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR); @@ -188,7 +208,7 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { } }); - selectLanguageTextView.setText(langSelected); + selectLanguageTextView.setText(Algorithms.capitalizeFirstLetter(langSelected)); selectLanguageTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -249,8 +269,8 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { optionsMenu.show(); } - private Drawable getIcon(int resId) { - int colorId = darkMode ? R.color.ctx_menu_controller_button_text_color_dark_n : R.color.ctx_menu_controller_button_text_color_light_n; + private Drawable getActiveIcon(int resId) { + int colorId = darkMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light; return getIcon(resId, colorId); } From 516dc06012935f88d30c5c908f262594049df5aa Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 2 May 2018 16:52:45 +0300 Subject: [PATCH 2/5] add webViewClient for work with external links --- .../WikipediaDialogFragment.java | 1 + .../WikipediaWebViewClient.java | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaWebViewClient.java diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java index b24534c55d..412dbafd02 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java @@ -136,6 +136,7 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { contentWebView = (WebView) mainView.findViewById(R.id.content_web_view); WebSettings webSettings = contentWebView.getSettings(); webSettings.setJavaScriptEnabled(true); + contentWebView.setWebViewClient(new WikipediaWebViewClient(getActivity(), darkMode)); return mainView; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaWebViewClient.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaWebViewClient.java new file mode 100644 index 0000000000..a4c336ec70 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaWebViewClient.java @@ -0,0 +1,55 @@ +package net.osmand.plus.mapcontextmenu; + +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.support.v4.app.FragmentActivity; +import android.support.v7.app.AlertDialog; +import android.webkit.WebView; +import android.webkit.WebViewClient; + +import net.osmand.plus.R; + + +public class WikipediaWebViewClient extends WebViewClient { + + private static final String PAGE_PREFIX_HTTP = "http://"; + private static final String PAGE_PREFIX_HTTPS = "https://"; + + private Context context; + private boolean nightMode; + + public WikipediaWebViewClient(FragmentActivity context, boolean nightMode) { + this.context = context; + this.nightMode = nightMode; + } + + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + if (url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS)) { + warnAboutExternalLoad(url, context, nightMode); + } else { + Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + context.startActivity(i); + } + return true; + } + + private static void warnAboutExternalLoad(final String url, final Context context, final boolean nightMode) { + if (context == null) { + return; + } + new AlertDialog.Builder(context) + .setTitle(url) + .setMessage(R.string.online_webpage_warning) + .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + WikipediaDialogFragment.showFullArticle(context, Uri.parse(url), nightMode); + } + }) + .setNegativeButton(R.string.shared_string_cancel, null) + .show(); + } +} From bebc2c060447419f97d9cc7106dd3b3c6bdd9c71 Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 2 May 2018 17:18:41 +0300 Subject: [PATCH 3/5] fix readFullArticleButton icon color --- .../plus/mapcontextmenu/WikipediaDialogFragment.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java index 412dbafd02..7976c73996 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java @@ -121,7 +121,7 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { readFullArticleButton = (TextView) mainView.findViewById(R.id.read_full_article); readFullArticleButton.setBackgroundResource(darkMode ? R.drawable.bt_round_long_night : R.drawable.bt_round_long_day); readFullArticleButton.setTextColor(buttonColorStateList); - readFullArticleButton.setCompoundDrawablesWithIntrinsicBounds(getActiveIcon(R.drawable.ic_world_globe_dark), null, null, null); + readFullArticleButton.setCompoundDrawablesWithIntrinsicBounds(getIcon(R.drawable.ic_world_globe_dark), null, null, null); readFullArticleButton.setCompoundDrawablePadding((int) getResources().getDimension(R.dimen.content_padding_small)); int paddingLeft = (int) getResources().getDimension(R.dimen.wikipedia_button_left_padding); int paddingRight = (int) getResources().getDimension(R.dimen.dialog_content_margin); @@ -270,6 +270,11 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { optionsMenu.show(); } + private Drawable getIcon(int resId) { + int colorId = darkMode ? R.color.ctx_menu_controller_button_text_color_dark_n : R.color.ctx_menu_controller_button_text_color_light_n; + return getIcon(resId, colorId); + } + private Drawable getActiveIcon(int resId) { int colorId = darkMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light; return getIcon(resId, colorId); From ca13f7295763c11264b291375be33f68d2bdbc63 Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 2 May 2018 18:51:04 +0300 Subject: [PATCH 4/5] added updateWebSettings for webview and toolbar options --- .../WikipediaDialogFragment.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java index 7976c73996..520f6daf7f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java @@ -20,6 +20,7 @@ import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.view.Gravity; import android.view.LayoutInflater; +import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -32,6 +33,7 @@ import net.osmand.AndroidUtils; import net.osmand.IndexConstants; import net.osmand.data.Amenity; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.base.BaseOsmAndDialogFragment; import net.osmand.plus.helpers.FileNameTranslationHelper; @@ -137,6 +139,7 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { WebSettings webSettings = contentWebView.getSettings(); webSettings.setJavaScriptEnabled(true); contentWebView.setWebViewClient(new WikipediaWebViewClient(getActivity(), darkMode)); + updateWebSettings(); return mainView; } @@ -299,6 +302,23 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { } } + private void updateWebSettings() { + OsmandSettings.WikivoyageShowImages showImages = getSettings().WIKIVOYAGE_SHOW_IMAGES.get(); + WebSettings webSettings = contentWebView.getSettings(); + switch (showImages) { + case ON: + webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); + break; + case OFF: + webSettings.setCacheMode(WebSettings.LOAD_CACHE_ONLY); + break; + case WIFI: + webSettings.setCacheMode(getMyApplication().getSettings().isWifiConnected() ? + WebSettings.LOAD_DEFAULT : WebSettings.LOAD_CACHE_ONLY); + break; + } + } + public static boolean showInstance(AppCompatActivity activity, Amenity amenity) { return showInstance(activity, amenity, null); } @@ -306,6 +326,40 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { protected void setupToolbar(Toolbar toolbar) { toolbar.setNavigationIcon(getIcon(R.drawable.ic_arrow_back, R.color.icon_color)); toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); + Menu menu = toolbar.getMenu(); + MenuItem itemShow = menu.add(R.string.shared_string_show); + itemShow.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.ON); + } + return true; + } + }); + MenuItem itemWifi = menu.add(R.string.shared_string_only_with_wifi); + itemWifi.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.WIFI); + } + return true; + } + }); + MenuItem itemNo = menu.add(R.string.shared_string_dont); + itemNo.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.OFF); + } + return true; + } + }); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { From 14d08eafb389c38a192848143da46402220bce85 Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 2 May 2018 19:26:56 +0300 Subject: [PATCH 5/5] refactored setupToolbar --- .../WikipediaDialogFragment.java | 54 +++++++++---------- .../WikivoyageShowPicturesDialogFragment.java | 2 +- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java index 520f6daf7f..cb00eb78f5 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java @@ -57,6 +57,10 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { ""; private static final String FOOTER_INNER = ""; + private static final int MENU_ITEM_NO_ID = 0; + private static final int MENU_ITEM_SHOW_ID = 1; + private static final int MENU_ITEM_WIFI_ID = 2; + private WebView contentWebView; private TextView articleToolbarText; private TextView readFullArticleButton; @@ -327,39 +331,35 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { toolbar.setNavigationIcon(getIcon(R.drawable.ic_arrow_back, R.color.icon_color)); toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); Menu menu = toolbar.getMenu(); - MenuItem itemShow = menu.add(R.string.shared_string_show); - itemShow.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + + MenuItem.OnMenuItemClickListener itemClickListener = new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { OsmandApplication app = getMyApplication(); if (app != null) { - app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.ON); + int itemId = item.getItemId(); + if (itemId == MENU_ITEM_SHOW_ID) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.ON); + return true; + } else if (itemId == MENU_ITEM_WIFI_ID) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.WIFI); + return true; + } else if (itemId == MENU_ITEM_NO_ID) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.OFF); + return true; + } } - return true; + return false; } - }); - MenuItem itemWifi = menu.add(R.string.shared_string_only_with_wifi); - itemWifi.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - OsmandApplication app = getMyApplication(); - if (app != null) { - app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.WIFI); - } - return true; - } - }); - MenuItem itemNo = menu.add(R.string.shared_string_dont); - itemNo.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - OsmandApplication app = getMyApplication(); - if (app != null) { - app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.OFF); - } - return true; - } - }); + }; + + MenuItem itemShow = menu.add(0,MENU_ITEM_SHOW_ID,0,R.string.shared_string_show); + itemShow.setOnMenuItemClickListener(itemClickListener); + MenuItem itemWifi = menu.add(0,MENU_ITEM_WIFI_ID,0,R.string.shared_string_only_with_wifi); + itemWifi.setOnMenuItemClickListener(itemClickListener); + MenuItem itemNo = menu.add(0,MENU_ITEM_NO_ID,0,R.string.shared_string_dont); + itemNo.setOnMenuItemClickListener(itemClickListener); + toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java index f7b63c9110..6811e23da9 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java @@ -59,7 +59,7 @@ public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragm } }); } else { - buttonDownload.setText(R.string.shared_string_do); + buttonDownload.setText(R.string.shared_string_show); buttonDownload.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {