Search in sources :

Example 1 with OsmAndFeature

use of net.osmand.plus.chooseplan.OsmAndFeature in project Osmand by osmandapp.

the class MappersPromoFragment method createFeaturesList.

private void createFeaturesList() {
    listContainer.removeAllViews();
    for (OsmAndFeature feature : allFeatures) {
        View view = createFeatureItemView(feature);
        listContainer.addView(view);
    }
}
Also used : OsmAndFeature(net.osmand.plus.chooseplan.OsmAndFeature) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 2 with OsmAndFeature

use of net.osmand.plus.chooseplan.OsmAndFeature in project Osmand by osmandapp.

the class PluginInfoFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    app = requireMyApplication();
    plugin = getPluginFromArgs();
    if (plugin == null) {
        return null;
    }
    Context context = requireContext();
    nightMode = !app.getSettings().isLightContent();
    LayoutInflater themedInflater = UiUtilities.getInflater(context, nightMode);
    mainView = themedInflater.inflate(R.layout.plugin, container, false);
    AndroidUtils.addStatusBarPadding21v(context, mainView);
    TextView toolbarTitle = mainView.findViewById(R.id.toolbar_title);
    toolbarTitle.setText(plugin.getName());
    ImageView closeButton = mainView.findViewById(R.id.close_button);
    closeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Activity activity = getMyActivity();
            if (activity != null) {
                activity.onBackPressed();
            }
        }
    });
    UiUtilities.rotateImageByLayoutDirection(closeButton);
    Drawable pluginImage = plugin.getAssetResourceImage();
    if (pluginImage != null) {
        ImageView img = mainView.findViewById(R.id.plugin_image);
        img.setImageDrawable(pluginImage);
    } else {
        mainView.findViewById(R.id.plugin_image_placeholder).setVisibility(View.VISIBLE);
    }
    TextView descriptionView = mainView.findViewById(R.id.plugin_description);
    descriptionView.setText(plugin.getDescription());
    int linkTextColorId = nightMode ? R.color.ctx_menu_bottom_view_url_color_dark : R.color.ctx_menu_bottom_view_url_color_light;
    int linkTextColor = ContextCompat.getColor(context, linkTextColorId);
    descriptionView.setLinkTextColor(linkTextColor);
    descriptionView.setMovementMethod(LinkMovementMethod.getInstance());
    AndroidUtils.removeLinkUnderline(descriptionView);
    Button settingsButton = mainView.findViewById(R.id.plugin_settings);
    settingsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            FragmentActivity activity = getActivity();
            if (activity != null) {
                SettingsScreenType settingsScreenType = plugin.getSettingsScreenType();
                if (settingsScreenType != null) {
                    Bundle args = new Bundle();
                    args.putBoolean(PLUGIN_INFO, true);
                    BaseSettingsFragment.showInstance(activity, settingsScreenType, null, args, null);
                }
            }
        }
    });
    CompoundButton enableDisableButton = mainView.findViewById(R.id.plugin_enable_disable);
    enableDisableButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (plugin.isEnabled() != isChecked) {
                if (OsmandPlugin.enablePlugin(getActivity(), app, plugin, isChecked)) {
                    updateState();
                    Fragment target = getTargetFragment();
                    if (target instanceof PluginStateListener) {
                        ((PluginStateListener) target).onPluginStateChanged(plugin);
                    }
                }
            }
        }
    });
    Button getButton = mainView.findViewById(R.id.plugin_get);
    getButton.setText(plugin.isPaid() ? R.string.get_plugin : R.string.shared_string_install);
    getButton.setOnClickListener(v -> {
        FragmentActivity activity = getActivity();
        if (activity != null) {
            OsmAndFeature feature = null;
            if (plugin instanceof SRTMPlugin) {
                feature = OsmAndFeature.TERRAIN;
            } else if (plugin instanceof WikipediaPlugin) {
                feature = OsmAndFeature.WIKIPEDIA;
            } else {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(plugin.getInstallURL()));
                AndroidUtils.startActivityIfSafe(activity, intent);
            }
            if (feature != null) {
                ChoosePlanFragment.showInstance(activity, feature);
            }
        }
    });
    updateState();
    return mainView;
}
Also used : Context(android.content.Context) SRTMPlugin(net.osmand.plus.plugins.srtm.SRTMPlugin) Bundle(android.os.Bundle) Drawable(android.graphics.drawable.Drawable) SettingsScreenType(net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType) FragmentActivity(androidx.fragment.app.FragmentActivity) Activity(android.app.Activity) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ChoosePlanFragment(net.osmand.plus.chooseplan.ChoosePlanFragment) Fragment(androidx.fragment.app.Fragment) BaseOsmAndFragment(net.osmand.plus.base.BaseOsmAndFragment) BaseSettingsFragment(net.osmand.plus.settings.fragments.BaseSettingsFragment) FragmentActivity(androidx.fragment.app.FragmentActivity) OsmAndFeature(net.osmand.plus.chooseplan.OsmAndFeature) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) PluginStateListener(net.osmand.plus.plugins.PluginInstalledBottomSheetDialog.PluginStateListener) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) WikipediaPlugin(net.osmand.plus.wikipedia.WikipediaPlugin) ImageView(android.widget.ImageView) CompoundButton(android.widget.CompoundButton)

Example 3 with OsmAndFeature

use of net.osmand.plus.chooseplan.OsmAndFeature in project Osmand by osmandapp.

the class PurchasingUtils method createPromoItem.

public static void createPromoItem(@NonNull ContextMenuAdapter adapter, @NonNull MapActivity mapActivity, @NonNull OsmAndFeature feature, @NonNull String id, @StringRes int titleId, @StringRes int descriptionId) {
    OsmandApplication app = mapActivity.getMyApplication();
    boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
    ItemClickListener listener = (adapter1, itemId, position, isChecked, viewCoordinates) -> {
        ChoosePlanFragment.showInstance(mapActivity, feature);
        return false;
    };
    adapter.addItem(new ContextMenuItem.ItemBuilder().setId(PROMO_PREFIX + id).setLayout(R.layout.list_item_promo).setTitleId(titleId, mapActivity).setDescription(app.getString(descriptionId)).setIcon(feature.getIconId(nightMode)).setSkipPaintingWithoutColor(true).setListener(listener).createItem());
}
Also used : ColorUtilities(net.osmand.plus.utils.ColorUtilities) Iterator(java.util.Iterator) NonNull(androidx.annotation.NonNull) Spannable(android.text.Spannable) Pair(android.util.Pair) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) InAppPurchase(net.osmand.plus.inapp.InAppPurchases.InAppPurchase) R(net.osmand.plus.R) ChoosePlanFragment(net.osmand.plus.chooseplan.ChoosePlanFragment) OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) StringRes(androidx.annotation.StringRes) List(java.util.List) Nullable(androidx.annotation.Nullable) InAppSubscriptionIntroductoryInfo(net.osmand.plus.inapp.InAppPurchases.InAppSubscriptionIntroductoryInfo) OsmAndFeature(net.osmand.plus.chooseplan.OsmAndFeature) InAppPurchaseHelper(net.osmand.plus.inapp.InAppPurchaseHelper) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ContextMenuItem(net.osmand.plus.ContextMenuItem) Algorithms(net.osmand.util.Algorithms) MapActivity(net.osmand.plus.activities.MapActivity) InAppSubscription(net.osmand.plus.inapp.InAppPurchases.InAppSubscription) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) OsmandApplication(net.osmand.plus.OsmandApplication) ContextMenuItem(net.osmand.plus.ContextMenuItem)

Example 4 with OsmAndFeature

use of net.osmand.plus.chooseplan.OsmAndFeature in project Osmand by osmandapp.

the class MenuBuilder method buildGetWikipediaBanner.

private void buildGetWikipediaBanner(ViewGroup viewGroup) {
    OsmAndFeature feature = OsmAndFeature.WIKIPEDIA;
    LinearLayout view = buildCollapsableContentView(app, false, true);
    View banner = UiUtilities.getInflater(app, !light).inflate(R.layout.get_wikipedia_context_menu_banner, view, false);
    ImageView ivIcon = banner.findViewById(R.id.icon);
    ivIcon.setImageResource(feature.getIconId(!light));
    View btnGet = banner.findViewById(R.id.button_get);
    UiUtilities.setupDialogButton(!light, btnGet, DialogButtonType.PRIMARY, R.string.get_plugin);
    btnGet.setOnClickListener(v -> {
        if (mapActivity != null) {
            ChoosePlanFragment.showInstance(mapActivity, feature);
        }
    });
    View row = createRowContainer(app, NEAREST_WIKI_KEY);
    view.addView(banner);
    String text = app.getString(R.string.wiki_around);
    CollapsableView collapsableView = new CollapsableView(view, this, false);
    buildRow(row, R.drawable.ic_action_wikipedia, null, text, 0, true, collapsableView, false, 0, false, null, false);
    viewGroup.addView(row);
}
Also used : OsmAndFeature(net.osmand.plus.chooseplan.OsmAndFeature) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 5 with OsmAndFeature

use of net.osmand.plus.chooseplan.OsmAndFeature in project Osmand by osmandapp.

the class IntentHelper method parseContentIntent.

public void parseContentIntent() {
    final Intent intent = mapActivity.getIntent();
    if (intent != null) {
        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            final Uri data = intent.getData();
            if (data != null) {
                final String scheme = data.getScheme();
                if ("file".equals(scheme)) {
                    final String path = data.getPath();
                    if (path != null) {
                        mapActivity.getImportHelper().handleFileImport(data, new File(path).getName(), intent.getExtras(), true);
                    }
                    clearIntent(intent);
                } else if ("content".equals(scheme)) {
                    mapActivity.getImportHelper().handleContentImport(data, intent.getExtras(), true);
                    clearIntent(intent);
                } else if ("google.navigation".equals(scheme) || "osmand.navigation".equals(scheme)) {
                    parseNavigationIntent(intent);
                } else if ("osmand.api".equals(scheme)) {
                    ExternalApiHelper apiHelper = new ExternalApiHelper(mapActivity);
                    Intent result = apiHelper.processApiRequest(intent);
                    mapActivity.setResult(apiHelper.getResultCode(), result);
                    result.setAction(null);
                    mapActivity.setIntent(result);
                    if (apiHelper.needFinish()) {
                        mapActivity.finish();
                    }
                } else if (LauncherShortcutsHelper.INTENT_SCHEME.equals(scheme)) {
                    app.getLauncherShortcutsHelper().parseIntent(mapActivity, intent);
                    clearIntent(intent);
                }
            }
        }
        if (intent.hasExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS)) {
            Bundle openMapMarkersGroupsExtra = intent.getBundleExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS);
            if (openMapMarkersGroupsExtra != null) {
                MapMarkersDialogFragment.showInstance(mapActivity, openMapMarkersGroupsExtra.getString(MapMarkersGroup.MARKERS_SYNC_GROUP_ID));
            }
            mapActivity.setIntent(null);
        }
        if (intent.hasExtra(BaseSettingsFragment.OPEN_SETTINGS)) {
            String appMode = intent.getStringExtra(BaseSettingsFragment.APP_MODE_KEY);
            String settingsTypeName = intent.getStringExtra(BaseSettingsFragment.OPEN_SETTINGS);
            if (!Algorithms.isEmpty(settingsTypeName)) {
                try {
                    SettingsScreenType screenType = SettingsScreenType.valueOf(settingsTypeName);
                    BaseSettingsFragment.showInstance(mapActivity, screenType, ApplicationMode.valueOfStringKey(appMode, null));
                } catch (IllegalArgumentException e) {
                    LOG.error("error", e);
                }
            }
            mapActivity.setIntent(null);
        }
        if (intent.hasExtra(PluginsFragment.OPEN_PLUGINS)) {
            boolean openPlugins = intent.getBooleanExtra(PluginsFragment.OPEN_PLUGINS, false);
            if (openPlugins) {
                PluginsFragment.showInstance(mapActivity.getSupportFragmentManager());
            }
            mapActivity.setIntent(null);
        }
        if (intent.hasExtra(BaseSettingsFragment.OPEN_CONFIG_ON_MAP)) {
            switch(intent.getStringExtra(BaseSettingsFragment.OPEN_CONFIG_ON_MAP)) {
                case BaseSettingsFragment.MAP_CONFIG:
                    mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_MAP, null);
                    break;
                case BaseSettingsFragment.SCREEN_CONFIG:
                    mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN, null);
                    break;
            }
            mapActivity.setIntent(null);
        }
        if (intent.hasExtra(TrackMenuFragment.OPEN_TRACK_MENU)) {
            String path = intent.getStringExtra(TRACK_FILE_NAME);
            String name = intent.getStringExtra(RETURN_SCREEN_NAME);
            String tabName = intent.getStringExtra(OPEN_TAB_NAME);
            boolean currentRecording = intent.getBooleanExtra(CURRENT_RECORDING, false);
            TrackMenuFragment.showInstance(mapActivity, path, currentRecording, name, null, tabName);
            mapActivity.setIntent(null);
        }
        if (intent.getExtras() != null) {
            Bundle extras = intent.getExtras();
            if (extras.containsKey(ChoosePlanFragment.OPEN_CHOOSE_PLAN)) {
                String featureValue = extras.getString(ChoosePlanFragment.CHOOSE_PLAN_FEATURE);
                if (!Algorithms.isEmpty(featureValue)) {
                    try {
                        OsmAndFeature feature = OsmAndFeature.valueOf(featureValue);
                        if (feature == OsmAndFeature.ANDROID_AUTO) {
                            if (!InAppPurchaseHelper.isAndroidAutoAvailable(app)) {
                                ChoosePlanFragment.showInstance(mapActivity, feature);
                            }
                        } else {
                            ChoosePlanFragment.showInstance(mapActivity, feature);
                        }
                    } catch (Exception e) {
                        LOG.error(e.getMessage(), e);
                    }
                }
            }
            clearIntent(intent);
        }
    }
}
Also used : OsmAndFeature(net.osmand.plus.chooseplan.OsmAndFeature) Bundle(android.os.Bundle) SettingsScreenType(net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType) Intent(android.content.Intent) Uri(android.net.Uri) File(java.io.File)

Aggregations

OsmAndFeature (net.osmand.plus.chooseplan.OsmAndFeature)5 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 ChoosePlanFragment (net.osmand.plus.chooseplan.ChoosePlanFragment)2 SettingsScreenType (net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 Spannable (android.text.Spannable)1 Pair (android.util.Pair)1 LayoutInflater (android.view.LayoutInflater)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1 LinearLayout (android.widget.LinearLayout)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1