use of net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity 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;
}
use of net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity in project Osmand by osmandapp.
the class WikivoyageWebViewClient method shouldOverrideUrlLoading.
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
url = WikiArticleHelper.normalizeFileUrl(url);
boolean isWebPage = url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS);
if (url.contains(WIKIVOYAGE_DOMAIN) && isWebPage) {
WikivoyageUtils.processWikivoyageDomain(activity, url, nightMode);
return true;
} else if (url.contains(WIKI_DOMAIN) && isWebPage && article != null) {
LatLon defaultCoordinates = new LatLon(article.getLat(), article.getLon());
WikivoyageUtils.processWikipediaDomain(wikiArticleHelper, defaultCoordinates, url);
} else if (isWebPage) {
WikiArticleHelper.warnAboutExternalLoad(url, activity, nightMode);
} else if (url.startsWith(PREFIX_GEO)) {
if (article != null && article.getGpxFile() != null) {
GPXFile gpxFile = article.getGpxFile();
List<WptPt> points = gpxFile.getPoints();
String coordinates = url.replace(PREFIX_GEO, "");
WptPt gpxPoint = WikivoyageUtils.findNearestPoint(points, coordinates);
if (gpxPoint != null) {
OsmandSettings settings = app.getSettings();
settings.setMapLocationToShow(gpxPoint.getLatitude(), gpxPoint.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_WPT, gpxPoint.name), false, gpxPoint);
if (activity instanceof WikivoyageExploreActivity) {
WikivoyageExploreActivity exploreActivity = (WikivoyageExploreActivity) activity;
exploreActivity.setArticle(article);
}
fragmentManager.popBackStackImmediate();
File path = app.getTravelHelper().createGpxFile(article);
gpxFile.path = path.getAbsolutePath();
app.getSelectedGpxHelper().setGpxFileToDisplay(gpxFile);
MapActivity.launchMapActivityMoveToTop(activity);
}
}
} else {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
AndroidUtils.startActivityIfSafe(activity, intent);
}
return true;
}
use of net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity in project Osmand by osmandapp.
the class WikivoyageUtils method openWikivoyageArticle.
public static void openWikivoyageArticle(@NonNull FragmentActivity activity, @NonNull TravelArticleIdentifier articleId, @NonNull String lang) {
OsmandApplication app = (OsmandApplication) activity.getApplicationContext();
if (activity instanceof WikivoyageExploreActivity) {
WikivoyageArticleDialogFragment.showInstance(app, activity.getSupportFragmentManager(), articleId, lang);
} else {
Intent intent = new Intent(activity, WikivoyageExploreActivity.class);
intent.putExtra(ARTICLE_ID_KEY, articleId);
intent.putExtra(SELECTED_LANG_KEY, lang);
activity.startActivity(intent);
}
}
Aggregations