use of net.osmand.plus.wikivoyage.WikivoyageWebViewClient in project Osmand by osmandapp.
the class WikivoyageArticleDialogFragment method onCreateView.
@SuppressLint({ "SetJavaScriptEnabled", "AddJavascriptInterface" })
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (savedInstanceState != null) {
selectedLang = savedInstanceState.getString(SELECTED_LANG_KEY);
} else {
Bundle args = getArguments();
if (args != null) {
selectedLang = args.getString(SELECTED_LANG_KEY);
}
}
final View mainView = inflate(R.layout.fragment_wikivoyage_article_dialog, container);
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
int appBarTextColor = nightMode ? R.color.wikivoyage_app_bar_text_dark : R.color.wikivoyage_app_bar_text_light;
articleToolbarText = (TextView) mainView.findViewById(R.id.article_toolbar_text);
articleToolbarText.setTextColor(ContextCompat.getColor(getContext(), appBarTextColor));
ColorStateList selectedLangColorStateList = AndroidUtils.createPressedColorStateList(getContext(), nightMode, R.color.icon_color_default_light, R.color.wikivoyage_active_light, R.color.icon_color_default_dark, R.color.wikivoyage_active_dark);
selectedLangTv = (TextView) mainView.findViewById(R.id.select_language_text_view);
selectedLangTv.setTextColor(selectedLangColorStateList);
selectedLangTv.setCompoundDrawablesWithIntrinsicBounds(getSelectedLangIcon(), null, null, null);
selectedLangTv.setBackgroundResource(nightMode ? R.drawable.wikipedia_select_lang_bg_dark_n : R.drawable.wikipedia_select_lang_bg_light_n);
selectedLangTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showPopupLangMenu(v, selectedLang);
}
});
TextView contentsBtn = (TextView) mainView.findViewById(R.id.contents_button);
contentsBtn.setCompoundDrawablesWithIntrinsicBounds(getActiveIcon(R.drawable.ic_action_contents), null, null, null);
contentsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fm = getFragmentManager();
if (article == null || fm == null) {
return;
}
Bundle args = new Bundle();
args.putString(WikivoyageArticleContentsFragment.CONTENTS_JSON_KEY, article.getContentsJson());
WikivoyageArticleContentsFragment fragment = new WikivoyageArticleContentsFragment();
fragment.setUsedOnMap(false);
fragment.setArguments(args);
fragment.setTargetFragment(WikivoyageArticleDialogFragment.this, WikivoyageArticleContentsFragment.SHOW_CONTENT_ITEM_REQUEST_CODE);
fragment.show(fm, WikivoyageArticleContentsFragment.TAG);
}
});
trackButton = (TextView) mainView.findViewById(R.id.gpx_button);
trackButton.setCompoundDrawablesWithIntrinsicBounds(getActiveIcon(R.drawable.ic_action_markers_dark), null, null, null);
trackButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentActivity activity = getActivity();
FragmentManager fm = getFragmentManager();
if (article == null || activity == null || fm == null) {
return;
}
if (activity instanceof WikivoyageExploreActivity) {
WikivoyageExploreActivity exploreActivity = (WikivoyageExploreActivity) activity;
exploreActivity.setArticle(article);
}
TravelHelper travelHelper = getMyApplication().getTravelHelper();
File file = travelHelper.createGpxFile(article);
openTrack(activity, new File(file.getAbsolutePath()), null, getString(R.string.icon_group_travel), TrackMenuType.POINTS);
}
});
trackButton.setVisibility(View.GONE);
gpxProgress = mainView.findViewById(R.id.gpx_progress);
gpxProgress.setVisibility(View.GONE);
saveBtn = (TextView) mainView.findViewById(R.id.save_button);
contentWebView = (WebView) mainView.findViewById(R.id.content_web_view);
WebSettings webSettings = contentWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setTextZoom((int) (getResources().getConfiguration().fontScale * 100f));
updateWebSettings();
contentWebView.addJavascriptInterface(new WikivoyageArticleWebAppInterface(), "Android");
FragmentActivity activity = requireActivity();
FragmentManager fragmentManager = requireFragmentManager();
webViewClient = new WikivoyageWebViewClient(activity, fragmentManager, nightMode);
contentWebView.setWebViewClient(webViewClient);
contentWebView.setBackgroundColor(ContextCompat.getColor(getMyApplication(), nightMode ? R.color.wiki_webview_background_dark : R.color.wiki_webview_background_light));
return mainView;
}
Aggregations