diff --git a/OsmAnd/res/layout/wikipedia_dialog_fragment.xml b/OsmAnd/res/layout/wikipedia_dialog_fragment.xml new file mode 100644 index 0000000000..53fb1be62a --- /dev/null +++ b/OsmAnd/res/layout/wikipedia_dialog_fragment.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java new file mode 100644 index 0000000000..33bc455d94 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java @@ -0,0 +1,101 @@ +package net.osmand.plus.mapcontextmenu; + +import android.app.Dialog; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.DialogFragment; +import android.support.v7.widget.Toolbar; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import net.osmand.data.Amenity; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.util.Algorithms; + +public class WikipediaDialogFragment extends DialogFragment { + + public static final String PREFERRED_LANGUAGE = "preferred_language"; + + private boolean darkTheme; + private Amenity amenity; + + public void setAmenity(Amenity amenity) { + this.amenity = amenity; + } + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setRetainInstance(true); + OsmandApplication app = getMyApplication(); + darkTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_DARK_THEME; + int themeId = darkTheme ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + setStyle(STYLE_NO_FRAME, themeId); + } + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + Dialog dialog = new Dialog(getContext(), getTheme()); + if (!getMyApplication().getSettings().DO_NOT_USE_ANIMATIONS.get()) { + dialog.getWindow().getAttributes().windowAnimations = R.style.Animations_Alpha; + } + return dialog; + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View mainView = inflater.inflate(R.layout.wikipedia_dialog_fragment, container, false); + + Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar); + toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back)); + toolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + } + }); + + String preferredLanguage = ""; + Bundle args = getArguments(); + if (args != null) { + preferredLanguage = args.getString(PREFERRED_LANGUAGE); + } + + if (TextUtils.isEmpty(preferredLanguage)) { + preferredLanguage = getMyApplication().getLanguage(); + } + + final String title = TextUtils.isEmpty(preferredLanguage) ? amenity.getName() : amenity.getName(preferredLanguage); + ((TextView) mainView.findViewById(R.id.title_text_view)).setText(title); + + String langSelected = amenity.getContentLanguage("content", preferredLanguage, "en"); + if (Algorithms.isEmpty(langSelected)) { + langSelected = "en"; + } + + String content = amenity.getDescription(langSelected); + + return mainView; + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + Dialog dialog = getDialog(); + if (dialog != null) { + dialog.setDismissMessage(null); + } + } + + private OsmandApplication getMyApplication() { + return (OsmandApplication) getActivity().getApplication(); + } +} diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index 052fddef22..9bad7b4a95 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -18,6 +18,7 @@ import android.support.v4.content.ContextCompat; import android.support.v4.view.MenuItemCompat; import android.support.v7.widget.PopupMenu; import android.support.v7.widget.Toolbar; +import android.text.Html; import android.text.util.Linkify; import android.util.TypedValue; import android.view.Gravity; @@ -366,6 +367,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon } }); final WebView wv = new WebView(ctx); + final TextView textView = new TextView(ctx); WebSettings settings = wv.getSettings(); settings.setDefaultTextEncodingName("utf-8"); @@ -391,6 +393,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon } } + textView.setText(Html.fromHtml(content)); wv.loadDataWithBaseURL(null, content, "text/html", "UTF-8", null); // wv.loadUrl(OsMoService.SIGN_IN_URL + app.getSettings().OSMO_DEVICE_KEY.get()); //For pinch zooming to work WebView must not be inside ScrollView @@ -400,13 +403,14 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon lp.weight = 1; //ll.addView(scrollView, lp); //scrollView.addView(wv); - ll.addView(wv, lp); +// ll.addView(wv, lp); + ll.addView(textView, lp); ll.addView(bottomBar, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); dialog.setContentView(ll); - wv.setFocusable(true); - wv.setFocusableInTouchMode(true); - wv.requestFocus(View.FOCUS_DOWN); - wv.setOnTouchListener(new View.OnTouchListener() { + textView.setFocusable(true); + textView.setFocusableInTouchMode(true); + textView.requestFocus(View.FOCUS_DOWN); + textView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) {