Skip to content

Commit

Permalink
[ProgressIndicator] Updated main demo in Catalog.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 592008643
  • Loading branch information
pekingme authored and hunterstich committed Dec 19, 2023
1 parent 93b3010 commit ba0b332
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@

import io.material.catalog.R;

import static com.google.android.material.progressindicator.CircularProgressIndicator.INDICATOR_DIRECTION_CLOCKWISE;
import static com.google.android.material.progressindicator.CircularProgressIndicator.INDICATOR_DIRECTION_COUNTERCLOCKWISE;
import static com.google.android.material.progressindicator.LinearProgressIndicator.INDICATOR_DIRECTION_LEFT_TO_RIGHT;
import static com.google.android.material.progressindicator.LinearProgressIndicator.INDICATOR_DIRECTION_RIGHT_TO_LEFT;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.materialswitch.MaterialSwitch;
import com.google.android.material.progressindicator.CircularProgressIndicator;
import com.google.android.material.progressindicator.LinearProgressIndicator;
import com.google.android.material.slider.Slider;
import io.material.catalog.feature.DemoFragment;

/**
Expand Down Expand Up @@ -55,27 +59,74 @@ public View onCreateDemoView(
public void initialize(@NonNull View view) {
LinearProgressIndicator linearIndicator = view.findViewById(R.id.linear_indicator);
CircularProgressIndicator circularIndicator = view.findViewById(R.id.circular_indicator);
EditText progressInput = view.findViewById(R.id.progress_input);
Button updateButton = view.findViewById(R.id.update_button);
Slider progressSlider = view.findViewById(R.id.progress_slider);
MaterialSwitch determinateSwitch = view.findViewById(R.id.determinate_mode_switch);

updateButton.setOnClickListener(
v -> {
int progress;
try {
progress = Integer.parseInt(progressInput.getEditableText().toString());
} catch (NumberFormatException e) {
progress = 0;
progressInput.setText("0");
progressSlider.addOnChangeListener(
(slider, value, fromUser) -> {
if (!linearIndicator.isIndeterminate()) {
linearIndicator.setProgressCompat((int) value, true);
}
if (!circularIndicator.isIndeterminate()) {
circularIndicator.setProgressCompat((int) value, true);
}
linearIndicator.setProgressCompat(progress, true);
circularIndicator.setProgressCompat(progress, true);
determinateSwitch.setChecked(true);
});
determinateSwitch.setOnCheckedChangeListener(
(v, isChecked) -> {
linearIndicator.setIndeterminate(!isChecked);
circularIndicator.setIndeterminate(!isChecked);
if (isChecked) {
float progress = progressSlider.getValue();
linearIndicator.setProgressCompat((int) progress, true);
circularIndicator.setProgressCompat((int) progress, true);
} else {
linearIndicator.setProgressCompat(0, false);
circularIndicator.setProgressCompat(0, false);
linearIndicator.setIndeterminate(true);
circularIndicator.setIndeterminate(true);
}
});

float pixelsInDp = view.getResources().getDisplayMetrics().density;

Slider thicknessSlider = view.findViewById(R.id.thicknessSlider);
thicknessSlider.addOnChangeListener(
(slider, value, fromUser) -> {
int newThickness = (int) (value * pixelsInDp);
if (linearIndicator.getTrackThickness() != newThickness) {
linearIndicator.setTrackThickness(newThickness);
}
if (circularIndicator.getTrackThickness() != newThickness) {
circularIndicator.setTrackThickness(newThickness);
}
});

Slider cornerSlider = view.findViewById(R.id.cornerSlider);
cornerSlider.addOnChangeListener(
(slider, value, fromUser) -> {
int newCornerRadius = (int) (value * pixelsInDp);
if (linearIndicator.getTrackCornerRadius() != newCornerRadius) {
linearIndicator.setTrackCornerRadius(newCornerRadius);
}
if (circularIndicator.getTrackCornerRadius() != newCornerRadius) {
circularIndicator.setTrackCornerRadius(newCornerRadius);
}
});

MaterialSwitch reverseSwitch = view.findViewById(R.id.reverseSwitch);
reverseSwitch.setOnCheckedChangeListener(
(buttonView, isChecked) -> {
linearIndicator.setIndicatorDirection(
isChecked ? INDICATOR_DIRECTION_RIGHT_TO_LEFT : INDICATOR_DIRECTION_LEFT_TO_RIGHT);
circularIndicator.setIndicatorDirection(
isChecked ? INDICATOR_DIRECTION_COUNTERCLOCKWISE : INDICATOR_DIRECTION_CLOCKWISE);
});

Slider circularSizeSlider = view.findViewById(R.id.circularSizeSlider);
circularSizeSlider.addOnChangeListener(
(slider, value, fromUser) -> {
int newCornerRadius = (int) (value * pixelsInDp);
if (circularIndicator.getIndicatorSize() != newCornerRadius) {
circularIndicator.setIndicatorSize(newCornerRadius);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
~ Copyright (C) 2020 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/content"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical">
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical">

<!-- Indeterminate indicators will be added here. -->

Expand Down Expand Up @@ -54,28 +56,28 @@
</LinearLayout>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/cat_progress_indicator_indeterminate_to_determinate_explanation"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/cat_progress_indicator_indeterminate_to_determinate_explanation"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/progress_input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="1dp"
android:hint="@string/cat_progress_indicator_deteriminate_progress_hint"
android:inputType="number"
tools:ignore="Autofill"/>
android:id="@+id/progress_input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="1dp"
android:hint="@string/cat_progress_indicator_determinate_progress"
android:inputType="number"
tools:ignore="Autofill"/>
<Button
android:id="@+id/update_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="@string/cat_progress_indicator_update"/>
android:id="@+id/update_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="@string/cat_progress_indicator_update"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
~ Copyright (C) 2020 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
Expand Down Expand Up @@ -50,24 +52,53 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cat_progress_indicator_determinate_progress_prompt"/>
<LinearLayout
android:text="@string/cat_progress_indicator_determinate_progress"/>
<com.google.android.material.slider.Slider
android:id="@+id/progress_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/progress_input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/cat_progress_indicator_deteriminate_progress_hint"
android:inputType="number"
tools:ignore="Autofill"/>
<Button
android:id="@+id/update_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="@string/cat_progress_indicator_update"/>
</LinearLayout>
android:layout_height="wrap_content"
android:valueFrom="0"
android:valueTo="100"
android:stepSize="1"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cat_progress_indicator_track_thickness"/>
<com.google.android.material.slider.Slider
android:id="@+id/thicknessSlider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:valueFrom="1"
android:valueTo="15"
android:stepSize="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cat_progress_indicator_corner_size"/>
<com.google.android.material.slider.Slider
android:id="@+id/cornerSlider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:valueFrom="0"
android:valueTo="5"
android:stepSize="1"/>
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/reverseSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/cat_progress_indicator_reverse_direction"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cat_progress_indicator_circular_indicator_size"/>
<com.google.android.material.slider.Slider
android:id="@+id/circularSizeSlider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:valueFrom="20"
android:valueTo="200"
android:stepSize="5"/>
</LinearLayout>

Loading

0 comments on commit ba0b332

Please sign in to comment.