Start changing wikipedia

This commit is contained in:
PavelRatushnyi 2017-12-26 09:09:08 +02:00
parent f44b09fc0c
commit c0eb827eb5
3 changed files with 188 additions and 5 deletions

View file

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/actionModeBackground">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/dashboard_map_toolbar"
osmand:contentInsetLeft="54dp"
osmand:contentInsetStart="54dp">
<LinearLayout
android:gravity="end|center_vertical"
android:layout_marginLeft="@dimen/context_menu_padding_margin_small"
android:layout_marginRight="@dimen/context_menu_padding_margin_small"
android:layout_width="match_parent"
android:layout_height="match_parent">
<net.osmand.plus.widgets.TextViewEx
osmand:typeface="@string/font_roboto_medium"
android:textAllCaps="true"
android:layout_width="wrap_content"
android:layout_marginTop="@dimen/content_padding_small"
android:layout_marginBottom="@dimen/content_padding_small"
android:layout_height="match_parent"
android:background="?attr/ctx_menu_controller_bg"
android:gravity="center_vertical"
android:padding="@dimen/context_menu_padding_margin_tiny"
tools:text="RU"
android:textColor="?attr/ctx_menu_controller_text_color"
android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<TextView
android:id="@+id/title_text_view"
android:padding="@dimen/content_padding"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Title"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:padding="@dimen/content_padding"
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</ScrollView>
<TextView
android:layout_margin="@dimen/content_padding"
android:id="@+id/read_full_article"
android:layout_gravity="bottom|center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
</LinearLayout>

View file

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

View file

@ -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()) {