Search in sources :

Example 1 with Slider

use of com.google.android.material.slider.Slider in project Osmand by osmandapp.

the class SliderCard method updateContent.

@Override
protected void updateContent() {
    final TextView thresholdDistanceValue = view.findViewById(R.id.value);
    thresholdDistanceValue.setText(getStringValueWithMetric(initValue));
    TextView thresholdDistance = view.findViewById(R.id.title);
    thresholdDistance.setText(R.string.threshold_distance);
    Slider slider = view.findViewById(R.id.slider);
    slider.setValueFrom(0);
    slider.setValue(initValue);
    slider.setValueTo(100);
    slider.setStepSize(5);
    UiUtilities.setupSlider(slider, nightMode, ContextCompat.getColor(view.getContext(), R.color.profile_icon_color_blue_light));
    slider.addOnChangeListener(new Slider.OnChangeListener() {

        @Override
        public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
            if (fromUser) {
                String valueStr = getStringValueWithMetric((int) value);
                thresholdDistanceValue.setText(valueStr);
            }
        }
    });
    slider.addOnSliderTouchListener(new Slider.OnSliderTouchListener() {

        @Override
        public void onStartTrackingTouch(@NonNull Slider slider) {
        }

        @Override
        public void onStopTrackingTouch(@NonNull Slider slider) {
            if (listener != null) {
                listener.onSliderChange((int) slider.getValue());
            }
        }
    });
}
Also used : Slider(com.google.android.material.slider.Slider) TextView(android.widget.TextView)

Example 2 with Slider

use of com.google.android.material.slider.Slider in project Osmand by osmandapp.

the class RouteLineWidthCard method updateCustomWidthSlider.

private void updateCustomWidthSlider() {
    if (selectedMode == WidthMode.CUSTOM) {
        Slider slider = view.findViewById(R.id.width_slider);
        final TextView tvCustomWidth = view.findViewById(R.id.width_value_tv);
        slider.setValueTo(CUSTOM_WIDTH_MAX);
        slider.setValueFrom(CUSTOM_WIDTH_MIN);
        ((TextView) view.findViewById(R.id.width_value_min)).setText(String.valueOf(CUSTOM_WIDTH_MIN));
        ((TextView) view.findViewById(R.id.width_value_max)).setText(String.valueOf(CUSTOM_WIDTH_MAX));
        String widthKey = getRouteLineWidth();
        int width = Algorithms.parseIntSilently(widthKey, 1);
        widthKey = String.valueOf(width);
        setRouteLineWidth(widthKey);
        tvCustomWidth.setText(widthKey);
        slider.setValue(width);
        slider.addOnChangeListener(new Slider.OnChangeListener() {

            @Override
            public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
                if (fromUser) {
                    String newWidth = String.valueOf((int) value);
                    setRouteLineWidth(newWidth);
                    tvCustomWidth.setText(newWidth);
                }
            }
        });
        UiUtilities.setupSlider(slider, nightMode, null, true);
        ScrollUtils.addOnGlobalLayoutListener(sliderContainer, new Runnable() {

            @Override
            public void run() {
                if (sliderContainer.getVisibility() == View.VISIBLE) {
                    onNeedScrollListener.onVerticalScrollNeeded(sliderContainer.getBottom());
                }
            }
        });
        AndroidUiHelper.updateVisibility(sliderContainer, true);
    } else {
        AndroidUiHelper.updateVisibility(sliderContainer, false);
    }
}
Also used : Slider(com.google.android.material.slider.Slider) TextView(android.widget.TextView)

Example 3 with Slider

use of com.google.android.material.slider.Slider in project Osmand by osmandapp.

the class OsmAndLocationSimulation method startStopRouteAnimation.

// public void startStopRouteAnimationRoute(final MapActivity ma) {
// if (!isRouteAnimating()) {
// List<Location> currentRoute = app.getRoutingHelper().getCurrentRoute();
// if (currentRoute.isEmpty()) {
// Toast.makeText(app, R.string.animate_routing_route_not_calculated, Toast.LENGTH_LONG).show();
// } else {
// startAnimationThread(app.getRoutingHelper(), ma, new ArrayList<Location>(currentRoute), false, 1);
// }
// } else {
// stop();
// }
// }
public void startStopRouteAnimation(@Nullable Activity activity, boolean useGpx, final Runnable runnable) {
    if (!isRouteAnimating()) {
        if (useGpx) {
            if (activity == null) {
                stop();
                if (runnable != null) {
                    runnable.run();
                }
                return;
            }
            boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
            int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
            ApplicationMode appMode = app.getSettings().getApplicationMode();
            int selectedModeColor = appMode.getProfileColor(nightMode);
            AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(activity, themeRes));
            builder.setTitle(R.string.animate_route);
            final View view = activity.getLayoutInflater().inflate(R.layout.animate_route, null);
            // $NON-NLS-1$
            ((TextView) view.findViewById(R.id.MinSpeedup)).setText("1");
            // $NON-NLS-1$
            ((TextView) view.findViewById(R.id.MaxSpeedup)).setText("4");
            final Slider speedup = view.findViewById(R.id.Speedup);
            speedup.setValueTo(3);
            UiUtilities.setupSlider(speedup, nightMode, selectedModeColor, true);
            builder.setView(view);
            builder.setPositiveButton(R.string.shared_string_ok, (dialog, which) -> {
                boolean nightMode1 = activity instanceof MapActivity ? app.getDaynightHelper().isNightModeForMapControls() : !app.getSettings().isLightContent();
                GpxUiHelper.selectGPXFile(activity, false, false, result -> {
                    GPXRouteParamsBuilder gpxParamsBuilder = new GPXRouteParamsBuilder(result[0], app.getSettings());
                    startAnimationThread(app, gpxParamsBuilder.getPoints(app), true, speedup.getValue() + 1);
                    if (runnable != null) {
                        runnable.run();
                    }
                    return true;
                }, nightMode1);
            });
            builder.setNegativeButton(R.string.shared_string_cancel, null);
            builder.show();
        } else {
            List<Location> currentRoute = app.getRoutingHelper().getCurrentCalculatedRoute();
            if (currentRoute.isEmpty()) {
                Toast.makeText(app, R.string.animate_routing_route_not_calculated, Toast.LENGTH_LONG).show();
            } else {
                startAnimationThread(app, new ArrayList<Location>(currentRoute), false, 1);
                if (runnable != null) {
                    runnable.run();
                }
            }
        }
    } else {
        stop();
        if (runnable != null) {
            runnable.run();
        }
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Slider(com.google.android.material.slider.Slider) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) TextView(android.widget.TextView) View(android.view.View) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) TextView(android.widget.TextView) MapActivity(net.osmand.plus.activities.MapActivity) Location(net.osmand.Location)

Example 4 with Slider

use of com.google.android.material.slider.Slider in project Osmand by osmandapp.

the class AllocatedRoutingMemoryBottomSheet method setupSliderView.

private void setupSliderView(View container) {
    TextView title = container.findViewById(android.R.id.title);
    TextView summary = container.findViewById(android.R.id.summary);
    TextView from = container.findViewById(R.id.from_value);
    TextView to = container.findViewById(R.id.to_value);
    title.setText(getString(R.string.shared_string_memory));
    summary.setText(getFormattedMb(currentValue));
    from.setText(getFormattedMb(minValue));
    to.setText(getFormattedMb(maxValue));
    Slider slider = container.findViewById(R.id.slider);
    int activeColor = ColorUtilities.getActiveColor(app, nightMode);
    UiUtilities.setupSlider(slider, nightMode, activeColor, true);
    slider.setValueFrom(0);
    slider.setValueTo(range.length - 1);
    slider.setStepSize(1);
    slider.setValue(getRangeIndex(currentValue));
    slider.addOnChangeListener((slider1, value, fromUser) -> {
        if (fromUser) {
            currentValue = range[(int) slider1.getValue()];
            summary.setText(getFormattedMb(currentValue));
        }
    });
}
Also used : Slider(com.google.android.material.slider.Slider) TextView(android.widget.TextView)

Example 5 with Slider

use of com.google.android.material.slider.Slider in project Osmand by osmandapp.

the class AllocatedRoutingMemoryBottomSheet method updateSliderView.

private void updateSliderView(View container) {
    TextView summary = container.findViewById(android.R.id.summary);
    summary.setText(getFormattedMb(currentValue));
    Slider slider = container.findViewById(R.id.slider);
    slider.setValue(getRangeIndex(currentValue));
}
Also used : Slider(com.google.android.material.slider.Slider) TextView(android.widget.TextView)

Aggregations

Slider (com.google.android.material.slider.Slider)14 TextView (android.widget.TextView)12 View (android.view.View)7 Context (android.content.Context)2 ImageView (android.widget.ImageView)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 BaseBottomSheetItem (net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem)2 BottomSheetItemWithCompoundButton (net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton)2 DividerSpaceItem (net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem)2 TitleItem (net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem)2 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)2 InputFilter (android.text.InputFilter)1 OnClickListener (android.view.View.OnClickListener)1 ViewGroup (android.view.ViewGroup)1 EditText (android.widget.EditText)1 LinearLayout (android.widget.LinearLayout)1 LayoutParams (android.widget.LinearLayout.LayoutParams)1 ContextThemeWrapper (androidx.appcompat.view.ContextThemeWrapper)1 AppCompatCheckBox (androidx.appcompat.widget.AppCompatCheckBox)1 Fragment (androidx.fragment.app.Fragment)1