Search in sources :

Example 71 with OsmandSettings

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

the class SearchPOIActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
    final Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position);
    final OsmandSettings settings = app.getSettings();
    String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(amenity, app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get());
    PointDescription name = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
    int z = Math.max(16, settings.getLastKnownMapZoom());
    LatLon location = amenity.getLocation();
    settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), z, name, true, // $NON-NLS-1$
    amenity);
    MapActivity.launchMapActivityMoveToTop(this);
}
Also used : Amenity(net.osmand.data.Amenity) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

Example 72 with OsmandSettings

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

the class ConfigureMapDialogs method showMapModeDialog.

protected static void showMapModeDialog(@NonNull MapActivity activity, int themeRes, boolean nightMode) {
    OsmandApplication app = activity.getMyApplication();
    OsmandSettings settings = app.getSettings();
    int selectedProfileColor = settings.APPLICATION_MODE.get().getProfileColor(nightMode);
    final OsmandMapTileView view = activity.getMapView();
    AlertDialog.Builder bld = new AlertDialog.Builder(new ContextThemeWrapper(activity, themeRes));
    bld.setTitle(R.string.daynight);
    final String[] items = new String[DayNightMode.values().length];
    for (int i = 0; i < items.length; i++) {
        items[i] = DayNightMode.values()[i].toHumanString(app);
    }
    int i = view.getSettings().DAYNIGHT_MODE.get().ordinal();
    bld.setNegativeButton(R.string.shared_string_dismiss, null);
    DialogListItemAdapter dialogAdapter = DialogListItemAdapter.createSingleChoiceAdapter(items, nightMode, i, app, selectedProfileColor, themeRes, new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            int which = (int) v.getTag();
            view.getSettings().DAYNIGHT_MODE.set(DayNightMode.values()[which]);
            activity.refreshMapComplete();
            activity.getDashboard().refreshContent(true);
        }
    });
    bld.setAdapter(dialogAdapter, null);
    dialogAdapter.setDialog(bld.show());
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) AppCompatCheckedTextView(androidx.appcompat.widget.AppCompatCheckedTextView) TextView(android.widget.TextView) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) DialogListItemAdapter(net.osmand.plus.DialogListItemAdapter)

Example 73 with OsmandSettings

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

the class ConfigureMapDialogs method showMapMagnifierDialog.

protected static void showMapMagnifierDialog(MapActivity activity, ContextMenuAdapter adapter, int themeRes, boolean nightMode, int pos, ArrayAdapter<ContextMenuItem> ad) {
    OsmandApplication app = activity.getMyApplication();
    OsmandSettings settings = app.getSettings();
    int selectedProfileColor = settings.APPLICATION_MODE.get().getProfileColor(nightMode);
    final OsmandMapTileView view = activity.getMapView();
    final OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
    AlertDialog.Builder bld = new AlertDialog.Builder(new ContextThemeWrapper(activity, themeRes));
    int p = (int) (mapDensity.get() * 100);
    final TIntArrayList tlist = new TIntArrayList(new int[] { 25, 33, 50, 75, 100, 125, 150, 200, 300, 400 });
    final List<String> values = new ArrayList<>();
    int i = -1;
    for (int k = 0; k <= tlist.size(); k++) {
        final boolean end = k == tlist.size();
        if (i == -1) {
            if ((end || p < tlist.get(k))) {
                values.add(p + " %");
                i = k;
            } else if (p == tlist.get(k)) {
                i = k;
            }
        }
        if (k < tlist.size()) {
            values.add(tlist.get(k) + " %");
        }
    }
    if (values.size() != tlist.size()) {
        tlist.insert(i, p);
    }
    bld.setTitle(R.string.map_magnifier);
    bld.setNegativeButton(R.string.shared_string_dismiss, null);
    DialogListItemAdapter dialogAdapter = DialogListItemAdapter.createSingleChoiceAdapter(values.toArray(new String[0]), nightMode, i, app, selectedProfileColor, themeRes, new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            int which = (int) v.getTag();
            int p = tlist.get(which);
            mapDensity.set(p / 100.0f);
            view.setComplexZoom(view.getZoom(), view.getSettingsMapDensity());
            MapRendererContext mapContext = NativeCoreContext.getMapRendererContext();
            if (mapContext != null) {
                mapContext.updateMapSettings();
            }
            adapter.getItem(pos).setDescription(String.format(Locale.UK, "%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %");
            ad.notifyDataSetInvalidated();
        }
    });
    bld.setAdapter(dialogAdapter, null);
    dialogAdapter.setDialog(bld.show());
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) AppCompatCheckedTextView(androidx.appcompat.widget.AppCompatCheckedTextView) TextView(android.widget.TextView) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) TIntArrayList(gnu.trove.list.array.TIntArrayList) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) DialogListItemAdapter(net.osmand.plus.DialogListItemAdapter) MapRendererContext(net.osmand.core.android.MapRendererContext)

Example 74 with OsmandSettings

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

the class DashboardOnMap method addOrUpdateDashboardFragments.

private void addOrUpdateDashboardFragments() {
    OsmandSettings settings = getMyApplication().getSettings();
    TransactionBuilder builder = new TransactionBuilder(mapActivity.getSupportFragmentManager(), settings, mapActivity);
    builder.addFragmentsData(fragmentsData).addFragmentsData(OsmandPlugin.getPluginsCardsList()).getFragmentTransaction().commitAllowingStateLoss();
}
Also used : TransactionBuilder(net.osmand.plus.dashboard.tools.TransactionBuilder) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

Example 75 with OsmandSettings

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

the class DashboardSettingsDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    TypedValue typedValue = new TypedValue();
    FragmentActivity activity = requireActivity();
    boolean nightMode = isNightMode();
    context = new ContextThemeWrapper(activity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
    Theme theme = context.getTheme();
    theme.resolveAttribute(android.R.attr.textColorPrimary, typedValue, true);
    textColorPrimary = typedValue.data;
    theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true);
    textColorSecondary = typedValue.data;
    final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
    final View showDashboardOnStart = createCheckboxItem(settings.SHOW_DASHBOARD_ON_START, R.string.show_on_start, R.string.show_on_start_description);
    final View accessFromMap = createCheckboxItem(settings.SHOW_DASHBOARD_ON_MAP_SCREEN, R.string.access_from_map, R.string.access_from_map_description);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    if (savedInstanceState != null && savedInstanceState.containsKey(CHECKED_ITEMS)) {
        mAdapter = new DashFragmentAdapter(context, mFragmentsData, savedInstanceState.getBooleanArray(CHECKED_ITEMS), savedInstanceState.getIntArray(NUMBER_OF_ROWS_ARRAY));
    } else {
        mAdapter = new DashFragmentAdapter(context, mFragmentsData, settings);
    }
    builder.setTitle(R.string.dahboard_options_dialog_title).setAdapter(mAdapter, null).setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int type) {
            boolean[] shouldShow = mAdapter.getCheckedItems();
            int[] numberOfRows = mAdapter.getNumbersOfRows();
            for (int i = 0; i < shouldShow.length; i++) {
                final DashFragmentData fragmentData = mFragmentsData.get(i);
                settings.registerBooleanPreference(DashboardOnMap.SHOULD_SHOW + fragmentData.tag, true).makeGlobal().set(shouldShow[i]);
                if (fragmentData.rowNumberTag != null) {
                    settings.registerIntPreference(fragmentData.rowNumberTag, DEFAULT_NUMBER_OF_ROWS).makeGlobal().set(numberOfRows[i]);
                }
            }
            mapActivity.getDashboard().refreshDashboardFragments();
            settings.SHOW_DASHBOARD_ON_START.set(((CompoundButton) showDashboardOnStart.findViewById(R.id.toggle_item)).isChecked());
            settings.SHOW_DASHBOARD_ON_MAP_SCREEN.set(((CompoundButton) accessFromMap.findViewById(R.id.toggle_item)).isChecked());
            mapActivity.getMapLayers().getMapControlsLayer().initDasboardRelatedControls();
        }
    }).setNegativeButton(R.string.shared_string_cancel, null);
    final AlertDialog dialog = builder.create();
    ListView listView = dialog.getListView();
    listView.addHeaderView(showDashboardOnStart);
    listView.addHeaderView(accessFromMap);
    return dialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) DialogInterface(android.content.DialogInterface) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) FragmentActivity(androidx.fragment.app.FragmentActivity) ListView(android.widget.ListView) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) Theme(android.content.res.Resources.Theme) TypedValue(android.util.TypedValue) NonNull(androidx.annotation.NonNull)

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