Search in sources :

Example 51 with OsmandSettings

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

the class DirectionIndicationDialogFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final OsmandSettings settings = getSettings();
    helpImgHeight = getResources().getDimensionPixelSize(R.dimen.action_bar_image_height);
    mainView = inflater.inflate(R.layout.fragment_direction_indication_dialog, container);
    Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(getIconsCache().getIcon(R.drawable.ic_arrow_back));
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            dismiss();
        }
    });
    TextView appModeTv = (TextView) mainView.findViewById(R.id.app_mode_text_view);
    ApplicationMode appMode = settings.APPLICATION_MODE.get();
    appModeTv.setText(appMode.getStringResource());
    appModeTv.setCompoundDrawablesWithIntrinsicBounds(null, null, getIconsCache().getIcon(appMode.getSmallIconDark()), null);
    if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
        ((ObservableScrollView) mainView.findViewById(R.id.scroll_view)).setScrollViewCallbacks(new ObservableScrollViewCallbacks() {

            @Override
            public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
                if (scrollY >= helpImgHeight) {
                    if (!shadowVisible) {
                        mainView.findViewById(R.id.app_bar_shadow).setVisibility(View.VISIBLE);
                        shadowVisible = true;
                    }
                } else if (shadowVisible) {
                    mainView.findViewById(R.id.app_bar_shadow).setVisibility(View.GONE);
                    shadowVisible = false;
                }
            }

            @Override
            public void onDownMotionEvent() {
            }

            @Override
            public void onUpOrCancelMotionEvent(ScrollState scrollState) {
            }
        });
    }
    updateHelpImage();
    final TextView menuTv = (TextView) mainView.findViewById(R.id.active_markers_text_view);
    menuTv.setText(settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 1 ? R.string.shared_string_one : R.string.shared_string_two);
    menuTv.setCompoundDrawablesWithIntrinsicBounds(null, null, getContentIcon(R.drawable.ic_action_arrow_drop_down), null);
    menuTv.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            CharSequence[] titles = getMenuTitles();
            Paint paint = new Paint();
            paint.setTextSize(getResources().getDimensionPixelSize(R.dimen.default_list_text_size));
            float titleTextWidth = Math.max(paint.measureText(titles[0].toString()), paint.measureText(titles[1].toString()));
            float itemWidth = titleTextWidth + AndroidUtils.dpToPx(getActivity(), 32);
            float minWidth = AndroidUtils.dpToPx(getActivity(), 100);
            final ListPopupWindow listPopupWindow = new ListPopupWindow(getActivity());
            listPopupWindow.setAnchorView(menuTv);
            listPopupWindow.setContentWidth((int) (Math.max(itemWidth, minWidth)));
            listPopupWindow.setDropDownGravity(Gravity.END | Gravity.TOP);
            listPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(getActivity(), 8));
            listPopupWindow.setVerticalOffset(-menuTv.getHeight());
            listPopupWindow.setModal(true);
            listPopupWindow.setAdapter(new ArrayAdapter<>(getActivity(), R.layout.popup_list_text_item, titles));
            listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    updateDisplayedMarkersCount(position == 0 ? 1 : 2);
                    listPopupWindow.dismiss();
                }
            });
            listPopupWindow.show();
        }
    });
    final CompoundButton distanceIndicationToggle = (CompoundButton) mainView.findViewById(R.id.distance_indication_switch);
    distanceIndicationToggle.setChecked(settings.MARKERS_DISTANCE_INDICATION_ENABLED.get());
    mainView.findViewById(R.id.distance_indication_row).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            updateChecked(settings.MARKERS_DISTANCE_INDICATION_ENABLED, distanceIndicationToggle);
            updateSelection(true);
        }
    });
    mainView.findViewById(R.id.top_bar_row).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            settings.MAP_MARKERS_MODE.set(MapMarkersMode.TOOLBAR);
            updateSelection(true);
        }
    });
    mainView.findViewById(R.id.widget_row).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            settings.MAP_MARKERS_MODE.set(MapMarkersMode.WIDGETS);
            updateSelection(true);
        }
    });
    updateSelection(false);
    final CompoundButton showArrowsToggle = (CompoundButton) mainView.findViewById(R.id.show_arrows_switch);
    showArrowsToggle.setChecked(settings.SHOW_ARROWS_TO_FIRST_MARKERS.get());
    mainView.findViewById(R.id.show_arrows_row).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            updateChecked(settings.SHOW_ARROWS_TO_FIRST_MARKERS, showArrowsToggle);
        }
    });
    final CompoundButton showLinesToggle = (CompoundButton) mainView.findViewById(R.id.show_guide_line_switch);
    showLinesToggle.setChecked(settings.SHOW_LINES_TO_FIRST_MARKERS.get());
    mainView.findViewById(R.id.show_guide_line_row).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            updateChecked(settings.SHOW_LINES_TO_FIRST_MARKERS, showLinesToggle);
        }
    });
    final CompoundButton oneTapActiveToggle = (CompoundButton) mainView.findViewById(R.id.one_tap_active_switch);
    oneTapActiveToggle.setChecked(settings.SELECT_MARKER_ON_SINGLE_TAP.get());
    mainView.findViewById(R.id.one_tap_active_row).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            updateChecked(settings.SELECT_MARKER_ON_SINGLE_TAP, oneTapActiveToggle);
        }
    });
    return mainView;
}
Also used : ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) ObservableScrollViewCallbacks(com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks) ApplicationMode(net.osmand.plus.ApplicationMode) Paint(android.graphics.Paint) ImageView(android.widget.ImageView) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) OsmandSettings(net.osmand.plus.OsmandSettings) Paint(android.graphics.Paint) ListPopupWindow(android.support.v7.widget.ListPopupWindow) ScrollState(com.github.ksoichiro.android.observablescrollview.ScrollState) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter) CompoundButton(android.widget.CompoundButton) Toolbar(android.support.v7.widget.Toolbar) Nullable(android.support.annotation.Nullable)

Example 52 with OsmandSettings

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

the class DestinationReachedMenuFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.dest_reached_menu_fragment, container, false);
    view.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismissMenu();
        }
    });
    IconsCache iconsCache = getMapActivity().getMyApplication().getIconsCache();
    ImageButton closeImageButton = (ImageButton) view.findViewById(R.id.closeImageButton);
    closeImageButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark, menu.isLight()));
    closeImageButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismissMenu();
        }
    });
    Button removeDestButton = (Button) view.findViewById(R.id.removeDestButton);
    removeDestButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_done, menu.isLight()), null, null, null);
    AndroidUtils.setTextPrimaryColor(view.getContext(), removeDestButton, !menu.isLight());
    removeDestButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getMapActivity().getMyApplication().getTargetPointsHelper().removeWayPoint(true, -1);
            Object contextMenuObj = getMapActivity().getContextMenu().getObject();
            if (getMapActivity().getContextMenu().isActive() && contextMenuObj != null && contextMenuObj instanceof TargetPoint) {
                TargetPoint targetPoint = (TargetPoint) contextMenuObj;
                if (!targetPoint.start && !targetPoint.intermediate) {
                    getMapActivity().getContextMenu().close();
                }
            }
            OsmandSettings settings = getMapActivity().getMyApplication().getSettings();
            settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get());
            getMapActivity().getMapActions().stopNavigationWithoutConfirm();
            dismissMenu();
        }
    });
    Button recalcDestButton = (Button) view.findViewById(R.id.recalcDestButton);
    recalcDestButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_gdirections_dark, menu.isLight()), null, null, null);
    AndroidUtils.setTextPrimaryColor(view.getContext(), recalcDestButton, !menu.isLight());
    recalcDestButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TargetPointsHelper helper = getMapActivity().getMyApplication().getTargetPointsHelper();
            TargetPoint target = helper.getPointToNavigate();
            dismissMenu();
            if (target != null) {
                helper.navigateToPoint(new LatLon(target.getLatitude(), target.getLongitude()), true, -1, target.getOriginalPointDescription());
                getMapActivity().getMapActions().recalculateRoute(false);
                getMapActivity().getMapLayers().getMapControlsLayer().startNavigation();
            }
        }
    });
    Button findParkingButton = (Button) view.findViewById(R.id.findParkingButton);
    ApplicationMode appMode = getMapActivity().getMyApplication().getRoutingHelper().getAppMode();
    if (!appMode.isDerivedRoutingFrom(appMode.CAR)) {
        findParkingButton.setVisibility(View.GONE);
    }
    findParkingButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_parking_dark, menu.isLight()), null, null, null);
    AndroidUtils.setTextPrimaryColor(view.getContext(), findParkingButton, !menu.isLight());
    findParkingButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PoiFiltersHelper helper = getMapActivity().getMyApplication().getPoiFilters();
            // PoiType place = getMapActivity().getMyApplication().getPoiTypes().getPoiTypeByKey("parking");
            PoiUIFilter parkingFilter = helper.getFilterById(PoiUIFilter.STD_PREFIX + "parking");
            if (parkingFilter != null) {
                final Intent newIntent = new Intent(getActivity(), SearchPOIActivity.class);
                newIntent.putExtra(SearchPOIActivity.AMENITY_FILTER, parkingFilter.getFilterId());
                newIntent.putExtra(SearchActivity.SEARCH_NEARBY, true);
                startActivityForResult(newIntent, 0);
            }
            dismissMenu();
        }
    });
    View mainView = view.findViewById(R.id.main_view);
    if (menu.isLandscapeLayout()) {
        AndroidUtils.setBackground(view.getContext(), mainView, !menu.isLight(), R.drawable.bg_left_menu_light, R.drawable.bg_left_menu_dark);
    } else {
        AndroidUtils.setBackground(view.getContext(), mainView, !menu.isLight(), R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
    }
    TextView title = (TextView) view.findViewById(R.id.titleTextView);
    AndroidUtils.setTextPrimaryColor(view.getContext(), title, !menu.isLight());
    return view;
}
Also used : Intent(android.content.Intent) ApplicationMode(net.osmand.plus.ApplicationMode) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TextView(android.widget.TextView) View(android.view.View) OsmandSettings(net.osmand.plus.OsmandSettings) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) ImageButton(android.widget.ImageButton) Button(android.widget.Button) SearchPOIActivity(net.osmand.plus.activities.search.SearchPOIActivity) TextView(android.widget.TextView) IconsCache(net.osmand.plus.IconsCache) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) Nullable(android.support.annotation.Nullable)

Example 53 with OsmandSettings

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

the class FirstUsageWizardFragment method updateStorageView.

private void updateStorageView(View storageView) {
    if (storageView != null) {
        TextView title = (TextView) storageView.findViewById(R.id.storage_title);
        OsmandSettings settings = getMyApplication().getSettings();
        int type;
        if (settings.getExternalStorageDirectoryTypeV19() >= 0) {
            type = settings.getExternalStorageDirectoryTypeV19();
        } else {
            ValueHolder<Integer> vh = new ValueHolder<>();
            settings.getExternalStorageDirectory(vh);
            if (vh.value != null && vh.value >= 0) {
                type = vh.value;
            } else {
                type = 0;
            }
        }
        title.setText(getString(R.string.storage_place_description, getStorageName(type)));
        TextView freeSpace = (TextView) storageView.findViewById(R.id.storage_free_space);
        TextView freeSpaceValue = (TextView) storageView.findViewById(R.id.storage_free_space_value);
        String freeSpaceStr = getString(R.string.storage_free_space) + ": ";
        freeSpace.setText(freeSpaceStr);
        freeSpaceValue.setText(getFreeSpace(settings.getExternalStorageDirectory()));
        AppCompatButton changeStorageButton = (AppCompatButton) storageView.findViewById(R.id.storage_change_button);
        if (wizardType == WizardType.MAP_DOWNLOAD) {
            changeStorageButton.setEnabled(false);
            changeStorageButton.setTextColor(getMyApplication().getResources().getColor(R.color.disabled_btn_text_color));
        } else {
            changeStorageButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (!DownloadActivity.hasPermissionToWriteExternalStorage(getContext())) {
                        ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, FIRST_USAGE_REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION);
                    } else {
                        DataStoragePlaceDialogFragment.showInstance(getActivity().getSupportFragmentManager(), false);
                    }
                }
            });
        }
    }
}
Also used : TextView(android.widget.TextView) ValueHolder(net.osmand.ValueHolder) View(android.view.View) TextView(android.widget.TextView) OsmandSettings(net.osmand.plus.OsmandSettings) AppCompatButton(android.support.v7.widget.AppCompatButton)

Example 54 with OsmandSettings

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

the class ConfigureMapMenu method createLayersItems.

private void createLayersItems(List<RenderingRuleProperty> customRules, ContextMenuAdapter adapter, final MapActivity activity) {
    final OsmandApplication app = activity.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    LayerMenuListener l = new LayerMenuListener(activity, adapter);
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_show, activity).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
    // String appMode = " [" + settings.getApplicationMode().toHumanString(view.getApplication()) +"] ";
    boolean selected = settings.SHOW_FAVORITES.get();
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_favorites, activity).setSelected(settings.SHOW_FAVORITES.get()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_fav_dark).setListener(l).createItem());
    selected = app.getPoiFilters().isShowingAnyPoi();
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_poi, activity).setSelected(selected).setDescription(app.getPoiFilters().getSelectedPoiFiltersName()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_info_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(l).createItem());
    selected = settings.SHOW_POI_LABEL.get();
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_amenity_label, activity).setSelected(settings.SHOW_POI_LABEL.get()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_text_dark).setListener(l).createItem());
    /*
		ContextMenuItem item = createProperties(customRules, null, R.string.rendering_category_transport, R.drawable.ic_action_bus_dark,
				"transport", settings.TRANSPORT_DEFAULT_SETTINGS, adapter, activity, false);
		if (item != null) {
			adapter.addItem(item);
		}
		*/
    final List<RenderingRuleProperty> transportRules = new ArrayList<>();
    final List<OsmandSettings.CommonPreference<Boolean>> transportPrefs = new ArrayList<>();
    Iterator<RenderingRuleProperty> it = customRules.iterator();
    while (it.hasNext()) {
        RenderingRuleProperty p = it.next();
        if ("transport".equals(p.getCategory()) && p.isBoolean()) {
            transportRules.add(p);
            final OsmandSettings.CommonPreference<Boolean> pref = activity.getMyApplication().getSettings().getCustomRenderBooleanProperty(p.getAttrName());
            transportPrefs.add(pref);
            it.remove();
        }
    }
    selected = false;
    for (OsmandSettings.CommonPreference<Boolean> p : transportPrefs) {
        if (p.get()) {
            selected = true;
            break;
        }
    }
    final boolean transportSelected = selected;
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.rendering_category_transport, activity).setIcon(R.drawable.ic_action_bus_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setSelected(transportSelected).setColor(transportSelected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setListener(new ContextMenuAdapter.OnRowItemClick() {

        ArrayAdapter<CharSequence> adapter;

        boolean transportSelectedInner = transportSelected;

        @Override
        public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
            if (transportSelectedInner) {
                showTransportDialog(adapter, position);
                return false;
            } else {
                CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
                if (btn != null && btn.getVisibility() == View.VISIBLE) {
                    btn.setChecked(!btn.isChecked());
                    adapter.getItem(position).setColorRes(btn.isChecked() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
                    adapter.notifyDataSetChanged();
                    return false;
                } else {
                    return onContextMenuClick(adapter, itemId, position, false, null);
                }
            }
        }

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            if (transportSelectedInner) {
                for (int i = 0; i < transportPrefs.size(); i++) {
                    transportPrefs.get(i).set(false);
                }
                transportSelectedInner = false;
                ad.getItem(pos).setColorRes(ContextMenuItem.INVALID_ID);
                refreshMapComplete(activity);
                activity.getMapLayers().updateLayers(activity.getMapView());
            } else {
                ad.getItem(pos).setColorRes(R.color.osmand_orange);
                showTransportDialog(ad, pos);
            }
            ad.notifyDataSetChanged();
            return false;
        }

        private void showTransportDialog(final ArrayAdapter<ContextMenuItem> ad, final int pos) {
            final AlertDialog.Builder b = new AlertDialog.Builder(activity);
            b.setTitle(activity.getString(R.string.rendering_category_transport));
            final int[] iconIds = new int[transportPrefs.size()];
            final boolean[] checkedItems = new boolean[transportPrefs.size()];
            for (int i = 0; i < transportPrefs.size(); i++) {
                checkedItems[i] = transportPrefs.get(i).get();
            }
            final String[] vals = new String[transportRules.size()];
            for (int i = 0; i < transportRules.size(); i++) {
                RenderingRuleProperty p = transportRules.get(i);
                String propertyName = SettingsActivity.getStringPropertyName(activity, p.getAttrName(), p.getName());
                vals[i] = propertyName;
                if ("transportStops".equals(p.getAttrName())) {
                    iconIds[i] = R.drawable.ic_action_transport_stop;
                } else if ("publicTransportMode".equals(p.getAttrName())) {
                    iconIds[i] = R.drawable.ic_action_bus_dark;
                } else if ("tramTrainRoutes".equals(p.getAttrName())) {
                    iconIds[i] = R.drawable.ic_action_transport_tram;
                } else if ("subwayMode".equals(p.getAttrName())) {
                    iconIds[i] = R.drawable.ic_action_transport_subway;
                } else {
                    iconIds[i] = R.drawable.ic_action_bus_dark;
                }
            }
            adapter = new ArrayAdapter<CharSequence>(activity, R.layout.popup_list_item_icon24_and_menu, R.id.title, vals) {

                @NonNull
                @Override
                public View getView(final int position, View convertView, ViewGroup parent) {
                    View v = super.getView(position, convertView, parent);
                    final ImageView icon = (ImageView) v.findViewById(R.id.icon);
                    if (checkedItems[position]) {
                        icon.setImageDrawable(app.getIconsCache().getIcon(iconIds[position], R.color.osmand_orange));
                    } else {
                        icon.setImageDrawable(app.getIconsCache().getThemedIcon(iconIds[position]));
                    }
                    v.findViewById(R.id.divider).setVisibility(View.GONE);
                    v.findViewById(R.id.description).setVisibility(View.GONE);
                    v.findViewById(R.id.secondary_icon).setVisibility(View.GONE);
                    final SwitchCompat check = (SwitchCompat) v.findViewById(R.id.toggle_item);
                    check.setOnCheckedChangeListener(null);
                    check.setChecked(checkedItems[position]);
                    check.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            checkedItems[position] = isChecked;
                            if (checkedItems[position]) {
                                icon.setImageDrawable(app.getIconsCache().getIcon(iconIds[position], R.color.osmand_orange));
                            } else {
                                icon.setImageDrawable(app.getIconsCache().getThemedIcon(iconIds[position]));
                            }
                        }
                    });
                    return v;
                }
            };
            final ListView listView = new ListView(activity);
            listView.setDivider(null);
            listView.setClickable(true);
            listView.setAdapter(adapter);
            listView.setOnItemClickListener(new ListView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    checkedItems[position] = !checkedItems[position];
                    adapter.notifyDataSetChanged();
                }
            });
            b.setView(listView);
            b.setOnDismissListener(new DialogInterface.OnDismissListener() {

                @Override
                public void onDismiss(DialogInterface dialog) {
                    ContextMenuItem item = ad.getItem(pos);
                    if (item != null) {
                        item.setSelected(transportSelectedInner);
                        item.setColorRes(transportSelectedInner ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
                        ad.notifyDataSetChanged();
                    }
                }
            });
            b.setNegativeButton(R.string.shared_string_cancel, null);
            b.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    transportSelectedInner = false;
                    for (int i = 0; i < transportPrefs.size(); i++) {
                        transportPrefs.get(i).set(checkedItems[i]);
                        if (!transportSelectedInner && checkedItems[i]) {
                            transportSelectedInner = true;
                        }
                    }
                    refreshMapComplete(activity);
                    activity.getMapLayers().updateLayers(activity.getMapView());
                }
            });
            b.show();
        }
    }).createItem());
    selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_gpx_layer, activity).setSelected(app.getSelectedGpxHelper().isShowingAnyGpxFiles()).setDescription(app.getSelectedGpxHelper().getGpxDescription()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_polygom_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(l).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_map, activity).setIcon(R.drawable.ic_world_globe_dark).setDescription(settings.MAP_ONLINE_DATA.get() ? settings.MAP_TILE_SOURCES.get() : null).setListener(l).createItem());
    OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity);
    app.getAppCustomization().prepareLayerContextMenu(activity, adapter);
    boolean srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
    if (srtmDisabled) {
        SRTMPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
        if (srtmPlugin != null) {
            srtmPlugin.registerLayerContextMenuActions(activity.getMapView(), adapter, activity);
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) ListView(android.widget.ListView) ImageView(android.widget.ImageView) SRTMPlugin(net.osmand.plus.srtmplugin.SRTMPlugin) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) CommonPreference(net.osmand.plus.OsmandSettings.CommonPreference) ViewGroup(android.view.ViewGroup) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) OnRowItemClick(net.osmand.plus.ContextMenuAdapter.OnRowItemClick) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) OsmandSettings(net.osmand.plus.OsmandSettings) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) ArrayAdapter(android.widget.ArrayAdapter) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 55 with OsmandSettings

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

the class GpxUiHelper method createGPXElevationDataSet.

public static OrderedLineDataSet createGPXElevationDataSet(OsmandApplication ctx, LineChart mChart, GPXTrackAnalysis analysis, GPXDataSetAxisType axisType, boolean useRightAxis, boolean drawFilled) {
    OsmandSettings settings = ctx.getSettings();
    OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get();
    boolean useFeet = (mc == OsmandSettings.MetricsConstants.MILES_AND_FEET) || (mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS);
    boolean light = settings.isLightContent();
    final float convEle = useFeet ? 3.28084f : 1.0f;
    float divX;
    XAxis xAxis = mChart.getXAxis();
    if (axisType == GPXDataSetAxisType.TIME && analysis.isTimeSpecified()) {
        divX = setupXAxisTime(xAxis, analysis.timeSpan);
    } else {
        divX = setupXAxisDistance(ctx, xAxis, analysis.totalDistance);
    }
    final String mainUnitY = useFeet ? ctx.getString(R.string.foot) : ctx.getString(R.string.m);
    YAxis yAxis;
    if (useRightAxis) {
        yAxis = mChart.getAxisRight();
        yAxis.setEnabled(true);
    } else {
        yAxis = mChart.getAxisLeft();
    }
    yAxis.setTextColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_blue_label));
    yAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_blue_grid));
    yAxis.setGranularity(1f);
    yAxis.resetAxisMinimum();
    yAxis.setValueFormatter(new IAxisValueFormatter() {

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return (int) value + " " + mainUnitY;
        }
    });
    List<Entry> values = calculateElevationArray(analysis, axisType, divX, convEle);
    OrderedLineDataSet dataSet = new OrderedLineDataSet(values, "", GPXDataSetType.ALTITUDE, axisType);
    dataSet.priority = (float) (analysis.avgElevation - analysis.minElevation) * convEle;
    dataSet.divX = divX;
    dataSet.mulY = convEle;
    dataSet.divY = Float.NaN;
    dataSet.units = mainUnitY;
    dataSet.setColor(ContextCompat.getColor(mChart.getContext(), R.color.gpx_chart_blue));
    dataSet.setLineWidth(1f);
    if (drawFilled) {
        dataSet.setFillAlpha(128);
        dataSet.setFillColor(ContextCompat.getColor(mChart.getContext(), R.color.gpx_chart_blue));
        dataSet.setDrawFilled(true);
    } else {
        dataSet.setDrawFilled(false);
    }
    dataSet.setDrawValues(false);
    dataSet.setValueTextSize(9f);
    dataSet.setFormLineWidth(1f);
    dataSet.setFormSize(15.f);
    dataSet.setDrawCircles(false);
    dataSet.setDrawCircleHole(false);
    dataSet.setHighlightEnabled(true);
    dataSet.setDrawVerticalHighlightIndicator(true);
    dataSet.setDrawHorizontalHighlightIndicator(false);
    dataSet.setHighLightColor(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));
    // dataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    dataSet.setFillFormatter(new IFillFormatter() {

        @Override
        public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
            return dataProvider.getYChartMin();
        }
    });
    if (useRightAxis) {
        dataSet.setAxisDependency(YAxis.AxisDependency.RIGHT);
    }
    return dataSet;
}
Also used : IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) SpannableString(android.text.SpannableString) AxisBase(com.github.mikephil.charting.components.AxisBase) IFillFormatter(com.github.mikephil.charting.formatter.IFillFormatter) OsmandSettings(net.osmand.plus.OsmandSettings) XAxis(com.github.mikephil.charting.components.XAxis) Entry(com.github.mikephil.charting.data.Entry) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) LineDataProvider(com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider) YAxis(com.github.mikephil.charting.components.YAxis)

Aggregations

OsmandSettings (net.osmand.plus.OsmandSettings)91 View (android.view.View)27 OsmandApplication (net.osmand.plus.OsmandApplication)25 ArrayList (java.util.ArrayList)20 LatLon (net.osmand.data.LatLon)17 DialogInterface (android.content.DialogInterface)14 ArrayAdapter (android.widget.ArrayAdapter)14 TextView (android.widget.TextView)14 AlertDialog (android.support.v7.app.AlertDialog)11 ImageView (android.widget.ImageView)11 PointDescription (net.osmand.data.PointDescription)10 AdapterView (android.widget.AdapterView)9 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)8 ContextMenuItem (net.osmand.plus.ContextMenuItem)8 ApplicationMode (net.osmand.plus.ApplicationMode)7 Paint (android.graphics.Paint)6 Pair (android.support.v4.util.Pair)6 ListView (android.widget.ListView)6 SpannableString (android.text.SpannableString)5 CompoundButton (android.widget.CompoundButton)5