Search in sources :

Example 1 with WikivoyageExploreActivity

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;
}
Also used : Bundle(android.os.Bundle) ColorStateList(android.content.res.ColorStateList) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) FragmentManager(androidx.fragment.app.FragmentManager) FragmentActivity(androidx.fragment.app.FragmentActivity) WikivoyageWebViewClient(net.osmand.plus.wikivoyage.WikivoyageWebViewClient) WikivoyageExploreActivity(net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity) WebSettings(android.webkit.WebSettings) TextView(android.widget.TextView) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) TravelHelper(net.osmand.plus.wikivoyage.data.TravelHelper) SuppressLint(android.annotation.SuppressLint) Nullable(androidx.annotation.Nullable)

Example 2 with WikivoyageExploreActivity

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;
}
Also used : LatLon(net.osmand.data.LatLon) WptPt(net.osmand.GPXUtilities.WptPt) WikivoyageExploreActivity(net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity) PointDescription(net.osmand.data.PointDescription) List(java.util.List) Intent(android.content.Intent) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

Example 3 with WikivoyageExploreActivity

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);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) WikivoyageExploreActivity(net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity) Intent(android.content.Intent)

Aggregations

WikivoyageExploreActivity (net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity)3 Intent (android.content.Intent)2 File (java.io.File)2 GPXFile (net.osmand.GPXUtilities.GPXFile)2 SuppressLint (android.annotation.SuppressLint)1 ColorStateList (android.content.res.ColorStateList)1 Bundle (android.os.Bundle)1 View (android.view.View)1 WebSettings (android.webkit.WebSettings)1 WebView (android.webkit.WebView)1 TextView (android.widget.TextView)1 Nullable (androidx.annotation.Nullable)1 FragmentActivity (androidx.fragment.app.FragmentActivity)1 FragmentManager (androidx.fragment.app.FragmentManager)1 List (java.util.List)1 WptPt (net.osmand.GPXUtilities.WptPt)1 LatLon (net.osmand.data.LatLon)1 PointDescription (net.osmand.data.PointDescription)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)1