Search in sources :

Example 21 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class ConfigureMapMenu method createBooleanRenderingProperty.

public static ContextMenuItem createBooleanRenderingProperty(@NonNull MapActivity activity, @NonNull String attrName, @NonNull String name, @NonNull String id, @Nullable RenderingRuleProperty property, @DrawableRes int icon, boolean nightMode, @Nullable CallbackWithObject<Boolean> callback) {
    OsmandApplication app = activity.getMyApplication();
    OsmandSettings settings = app.getSettings();
    CommonPreference<Boolean> pref = settings.getCustomRenderBooleanProperty(attrName);
    return ContextMenuItem.createBuilder(name).setId(id).setListener(new ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            if (property != null) {
                pref.set(isChecked);
                activity.refreshMap();
                activity.updateLayers();
            } else {
                isChecked = pref.get();
            }
            if (callback != null) {
                callback.processResult(isChecked);
            }
            ContextMenuItem item = adapter.getItem(pos);
            if (item != null) {
                item.setSelected(pref.get());
                item.setColor(activity, isChecked ? R.color.osmand_orange : INVALID_ID);
                item.setDescription(app.getString(isChecked ? R.string.shared_string_enabled : R.string.shared_string_disabled));
                adapter.notifyDataSetChanged();
            }
            return false;
        }
    }).setSelected(pref.get()).setColor(pref.get() ? settings.getApplicationMode().getProfileColor(nightMode) : null).setDescription(app.getString(pref.get() ? R.string.shared_string_enabled : R.string.shared_string_disabled)).setIcon(icon).createItem();
}
Also used : ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) OsmandApplication(net.osmand.plus.OsmandApplication) ContextMenuItem(net.osmand.plus.ContextMenuItem) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) ArrayAdapter(android.widget.ArrayAdapter)

Example 22 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class ConfigureMapMenu method createCycleRoutesItem.

private ContextMenuItem createCycleRoutesItem(@NonNull MapActivity activity, @NonNull String attrName, @Nullable RenderingRuleProperty property, boolean nightMode) {
    OsmandApplication app = activity.getMyApplication();
    OsmandSettings settings = app.getSettings();
    CommonPreference<Boolean> pref = settings.getCustomRenderBooleanProperty(attrName);
    return new ContextMenuItem.ItemBuilder().setId(ROUTES_ID + attrName).setTitle(AndroidUtils.getRenderingStringPropertyName(app, attrName, property != null ? property.getName() : attrName)).setIcon(getIconIdForAttr(attrName)).setSecondaryIcon(R.drawable.ic_action_additional_option).setSelected(pref.get()).setColor(pref.get() ? settings.getApplicationMode().getProfileColor(nightMode) : null).setDescription(app.getString(pref.get() ? R.string.shared_string_enabled : R.string.shared_string_disabled)).setListener(new OnRowItemClick() {

        @Override
        public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
            if (property != null) {
                activity.getDashboard().setDashboardVisibility(true, DashboardType.CYCLE_ROUTES, AndroidUtils.getCenterViewCoordinates(view));
            } else {
                showRendererSnackbarForAttr(activity, attrName, nightMode, null);
            }
            return false;
        }

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
            pref.set(isChecked);
            ContextMenuItem item = adapter.getItem(position);
            if (item != null) {
                item.setColor(activity, isChecked ? R.color.osmand_orange : INVALID_ID);
                item.setDescription(app.getString(isChecked ? R.string.shared_string_enabled : R.string.shared_string_disabled));
                adapter.notifyDataSetChanged();
            }
            if (property != null) {
                activity.refreshMap();
                activity.updateLayers();
            } else {
                showRendererSnackbarForAttr(activity, attrName, nightMode, null);
            }
            return false;
        }
    }).createItem();
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ContextMenuItem(net.osmand.plus.ContextMenuItem) OnRowItemClick(net.osmand.plus.ContextMenuAdapter.OnRowItemClick) View(android.view.View) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) ArrayAdapter(android.widget.ArrayAdapter)

Example 23 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class DashboardOnMap method removeFragment.

private void removeFragment(String tag) {
    FragmentManager manager = mapActivity.getSupportFragmentManager();
    Fragment fragment = manager.findFragmentByTag(tag);
    if (fragment != null) {
        OsmandSettings settings = getMyApplication().getSettings();
        TransactionBuilder builder = new TransactionBuilder(manager, settings, mapActivity);
        builder.getFragmentTransaction().remove(fragment).commitAllowingStateLoss();
    }
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) TransactionBuilder(net.osmand.plus.dashboard.tools.TransactionBuilder) TerrainFragment(net.osmand.plus.plugins.srtm.TerrainFragment) TravelRoutesFragment(net.osmand.plus.dialogs.TravelRoutesFragment) Fragment(androidx.fragment.app.Fragment) HikingRoutesFragment(net.osmand.plus.dialogs.HikingRoutesFragment) DashboardSettingsDialogFragment(net.osmand.plus.dashboard.tools.DashboardSettingsDialogFragment) MapillaryFiltersFragment(net.osmand.plus.plugins.mapillary.MapillaryFiltersFragment) MapillaryFirstDialogFragment(net.osmand.plus.plugins.mapillary.MapillaryFirstDialogFragment) CycleRoutesFragment(net.osmand.plus.dialogs.CycleRoutesFragment) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

Example 24 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class DashDashboardOrDrawerFragment method initView.

@Override
public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = getActivity().getLayoutInflater().inflate(R.layout.dash_dashboard_or_drawer_fragment, container, false);
    view.findViewById(R.id.useDashboardButton).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final OsmandSettings settings = getMyApplication().getSettings();
            settings.SHOW_DASHBOARD_ON_START.set(true);
            settings.SHOW_DASHBOARD_ON_MAP_SCREEN.set(true);
            settings.SHOW_CARD_TO_CHOOSE_DRAWER.set(false);
            dashboard.hideFragmentByTag(TAG);
        }
    });
    view.findViewById(R.id.useDrawerButton).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final OsmandSettings settings = getMyApplication().getSettings();
            settings.SHOW_DASHBOARD_ON_START.set(false);
            settings.SHOW_DASHBOARD_ON_MAP_SCREEN.set(false);
            settings.SHOW_CARD_TO_CHOOSE_DRAWER.set(false);
            dashboard.hideDashboard();
        }
    });
    return view;
}
Also used : View(android.view.View) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

Example 25 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class AvailableGPXFragment method showGpxOnMap.

private void showGpxOnMap(GpxInfo info) {
    info.setGpx(GPXUtilities.loadGPXFile(info.file));
    boolean e = true;
    if (info.gpx != null) {
        WptPt loc = info.gpx.findPointToShow();
        OsmandApplication app = requireMyApplication();
        OsmandSettings settings = app.getSettings();
        if (loc != null) {
            settings.setMapLocationToShow(loc.lat, loc.lon, settings.getLastKnownMapZoom());
            e = false;
            app.getSelectedGpxHelper().setGpxFileToDisplay(info.gpx);
            MapActivity.launchMapActivityMoveToTop(getActivity(), storeState());
        }
    }
    if (e) {
        app.showToastMessage(app.getString(R.string.gpx_file_is_empty));
    }
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) OsmandApplication(net.osmand.plus.OsmandApplication) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

Aggregations

OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)154 OsmandApplication (net.osmand.plus.OsmandApplication)52 View (android.view.View)25 ArrayList (java.util.ArrayList)23 LatLon (net.osmand.data.LatLon)17 MapActivity (net.osmand.plus.activities.MapActivity)17 TextView (android.widget.TextView)16 NonNull (androidx.annotation.NonNull)16 AlertDialog (androidx.appcompat.app.AlertDialog)15 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)15 ArrayAdapter (android.widget.ArrayAdapter)13 ContextMenuItem (net.osmand.plus.ContextMenuItem)13 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)12 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)12 Context (android.content.Context)11 ImageView (android.widget.ImageView)11 Intent (android.content.Intent)8 List (java.util.List)8 PointDescription (net.osmand.data.PointDescription)8 DialogInterface (android.content.DialogInterface)7