Skip to content

Commit

Permalink
Add DefaultButtonsAppearanceFragment for #18357
Browse files Browse the repository at this point in the history
  • Loading branch information
Chumva committed Dec 11, 2024
1 parent ba209c4 commit bd3e864
Show file tree
Hide file tree
Showing 19 changed files with 656 additions and 111 deletions.
1 change: 1 addition & 0 deletions OsmAnd/res/layout/card_multi_state.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
tools:text="Solid" />

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/drop_down_icon"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
Expand Down
1 change: 0 additions & 1 deletion OsmAnd/res/layout/map_button_appearance_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
android:id="@+id/cards_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/card_and_list_background_basic"
android:orientation="vertical" />

<include layout="@layout/card_bottom_divider" />
Expand Down
1 change: 1 addition & 0 deletions OsmAnd/res/layout/map_button_icons_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/card_and_list_background_basic"
android:orientation="vertical">

<LinearLayout
Expand Down
26 changes: 1 addition & 25 deletions OsmAnd/res/layout/map_button_opacity_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,6 @@
android:valueTo="1"
app:labelStyle="@style/TimeSlider" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingHorizontal="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding">

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/value_min"
style="@style/TitleStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="?android:textColorSecondary"
tools:text="0%" />

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/value_max"
style="@style/TitleStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
tools:text="100%" />

</LinearLayout>
<include layout="@layout/min_max_container" />

</LinearLayout>
29 changes: 29 additions & 0 deletions OsmAnd/res/layout/min_max_container.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/min_max_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingHorizontal="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding"
tools:showIn="@layout/map_button_opacity_card">

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/value_min"
style="@style/TitleStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="?android:textColorSecondary"
tools:text="0%" />

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/value_max"
style="@style/TitleStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
tools:text="100%" />

</LinearLayout>
82 changes: 41 additions & 41 deletions OsmAnd/res/layout/slider_with_buttons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,61 @@
android:orientation="vertical"
android:paddingBottom="@dimen/content_padding_half">

<include
android:id="@+id/header_container"
layout="@layout/card_multi_state" />

<LinearLayout
android:id="@+id/slider_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/content_padding"
android:paddingTop="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding_small">
android:orientation="vertical">

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
style="@style/TitleStyle.Medium"
android:layout_width="0dp"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:text="@string/shared_string_size" />
android:orientation="horizontal"
android:paddingHorizontal="@dimen/content_padding_round_medium">

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
style="@style/TitleStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
tools:text="40 dp" />
<ImageButton
android:id="@+id/decrease_button"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="@dimen/acceptable_touch_radius"
android:layout_height="@dimen/acceptable_touch_radius"
android:contentDescription="@string/shared_string_decrease"
tools:src="@drawable/ic_zoom_out"
tools:tint="?attr/secondary_icon_color" />

<com.google.android.material.slider.Slider
android:id="@+id/slider"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:saveEnabled="false"
app:labelStyle="@style/TimeSlider" />

<ImageButton
android:id="@+id/increase_button"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="@dimen/acceptable_touch_radius"
android:layout_height="@dimen/acceptable_touch_radius"
android:contentDescription="@string/shared_string_increase"
tools:src="@drawable/ic_zoom_in"
tools:tint="?attr/active_color_primary" />

</LinearLayout>

</LinearLayout>

<LinearLayout
android:id="@+id/description_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/content_padding_round_medium">

<ImageButton
android:id="@+id/decrease_button"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="@dimen/acceptable_touch_radius"
android:layout_height="@dimen/acceptable_touch_radius"
android:contentDescription="@string/shared_string_decrease"
tools:src="@drawable/ic_zoom_out"
tools:tint="?attr/secondary_icon_color" />
android:orientation="vertical">

<com.google.android.material.slider.Slider
android:id="@+id/slider"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:saveEnabled="false"
app:labelStyle="@style/TimeSlider" />
<include layout="@layout/list_item_divider_with_padding_basic" />

<ImageButton
android:id="@+id/increase_button"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="@dimen/acceptable_touch_radius"
android:layout_height="@dimen/acceptable_touch_radius"
android:contentDescription="@string/shared_string_increase"
tools:src="@drawable/ic_zoom_in"
tools:tint="?attr/active_color_primary" />
<include layout="@layout/card_description" />

</LinearLayout>

Expand Down
3 changes: 3 additions & 0 deletions OsmAnd/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
Thx - Hardy
-->

<string name="default_buttons_size_original_description">Each button would keep its own size.</string>
<string name="default_buttons_corners_original_description">Each button would keep its own corner radius.</string>
<string name="default_buttons_opacity_original_description">Each button would keep its own background opacity.</string>
<string name="selected_delayed_profile">Selected profile \"%s\"</string>
<string name="shared_string_interpolation">Interpolation</string>
<string name="location_interpolation_percent">Location interpolation percentage</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ data class ButtonAppearanceParams(

internal const val ROUND_RADIUS_DP = 36
internal const val RECTANGULAR_RADIUS_DP = 2

internal const val ORIGINAL_VALUE = -1
}
}
59 changes: 54 additions & 5 deletions OsmAnd/src/net/osmand/plus/quickaction/ButtonSizeCard.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package net.osmand.plus.quickaction;

import static com.google.android.material.slider.LabelFormatter.LABEL_FLOATING;
import static net.osmand.plus.quickaction.ButtonAppearanceParams.ORIGINAL_VALUE;

import android.view.View;

import androidx.annotation.NonNull;

import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.card.base.multistate.CardState;
import net.osmand.plus.utils.ColorUtilities;
import net.osmand.plus.utils.UiUtilities;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class ButtonSizeCard extends SliderButtonsCard {

public static final int MIN_BUTTON_SIZE = 40;
Expand All @@ -19,15 +26,22 @@ public class ButtonSizeCard extends SliderButtonsCard {

private final ButtonAppearanceParams appearanceParams;

public ButtonSizeCard(@NonNull MapActivity activity, @NonNull ButtonAppearanceParams appearanceParams) {
super(activity);
public ButtonSizeCard(@NonNull MapActivity activity,
@NonNull ButtonAppearanceParams appearanceParams, boolean showOriginal) {
super(activity, showOriginal);
this.appearanceParams = appearanceParams;
}

protected void setupHeader(@NonNull View view) {
super.setupHeader(view);
title.setText(R.string.shared_string_size);
description.setText(getFormattedValue(appearanceParams.getSize()));
valueTv.setText(getFormattedValue(appearanceParams.getSize()));
}

@Override
protected void setupDescription(@NonNull @NotNull View view) {
super.setupDescription(view);
description.setText(R.string.default_buttons_corners_original_description);
}

protected void setupSlider(@NonNull View view) {
Expand All @@ -37,22 +51,57 @@ protected void setupSlider(@NonNull View view) {
slider.setValueTo(MAX_BUTTON_SIZE);
slider.setValueFrom(MIN_BUTTON_SIZE);
slider.setStepSize(BUTTON_SIZE_STEP);
slider.setValue(appearanceParams.getSize());
slider.setLabelBehavior(LABEL_FLOATING);
slider.setLabelFormatter(ButtonSizeCard.this::getFormattedValue);

if (!isOriginalValue()) {
slider.setValue(appearanceParams.getSize());
}
}

protected void onValueSelected(float value) {
super.onValueSelected(value);

appearanceParams.setSize((int) value);
description.setText(getFormattedValue(appearanceParams.getSize()));
valueTv.setText(getFormattedValue(appearanceParams.getSize()));

notifyCardPressed();
}

@Override
protected boolean isOriginalValue() {
return appearanceParams.getSize() == ORIGINAL_VALUE;
}

@NonNull
protected String getFormattedValue(float value) {
if (value == ORIGINAL_VALUE) {
return getString(R.string.shared_string_original);
}
return getString(R.string.ltr_or_rtl_combine_via_space, (int) value, getString(R.string.shared_string_dp));
}

@NonNull
@Override
protected List<CardState> getCardStates() {
List<CardState> list = new ArrayList<>();

list.add(new CardState(R.string.shared_string_original).setTag(ORIGINAL_VALUE));

for (int i = MIN_BUTTON_SIZE; i <= MAX_BUTTON_SIZE; i += BUTTON_SIZE_STEP) {
list.add(new CardState(getFormattedValue(i))
.setShowTopDivider(i == MIN_BUTTON_SIZE)
.setTag(i));
}
return list;
}

@Override
protected void setSelectedState(@NonNull CardState cardState) {
if (cardState.getTag() instanceof Integer value) {
appearanceParams.setSize(value);
}
updateContent();
notifyCardPressed();
}
}
Loading

0 comments on commit bd3e864

Please sign in to comment.