Skip to content

Commit ba0b332

Browse files
pekingmehunterstich
authored andcommitted
[ProgressIndicator] Updated main demo in Catalog.
PiperOrigin-RevId: 592008643
1 parent 93b3010 commit ba0b332

File tree

4 files changed

+216
-118
lines changed

4 files changed

+216
-118
lines changed

catalog/java/io/material/catalog/progressindicator/ProgressIndicatorMainDemoFragment.java

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@
1717

1818
import io.material.catalog.R;
1919

20+
import static com.google.android.material.progressindicator.CircularProgressIndicator.INDICATOR_DIRECTION_CLOCKWISE;
21+
import static com.google.android.material.progressindicator.CircularProgressIndicator.INDICATOR_DIRECTION_COUNTERCLOCKWISE;
22+
import static com.google.android.material.progressindicator.LinearProgressIndicator.INDICATOR_DIRECTION_LEFT_TO_RIGHT;
23+
import static com.google.android.material.progressindicator.LinearProgressIndicator.INDICATOR_DIRECTION_RIGHT_TO_LEFT;
24+
2025
import android.os.Bundle;
2126
import android.view.LayoutInflater;
2227
import android.view.View;
2328
import android.view.ViewGroup;
24-
import android.widget.Button;
25-
import android.widget.EditText;
2629
import androidx.annotation.NonNull;
2730
import androidx.annotation.Nullable;
2831
import com.google.android.material.materialswitch.MaterialSwitch;
2932
import com.google.android.material.progressindicator.CircularProgressIndicator;
3033
import com.google.android.material.progressindicator.LinearProgressIndicator;
34+
import com.google.android.material.slider.Slider;
3135
import io.material.catalog.feature.DemoFragment;
3236

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

62-
updateButton.setOnClickListener(
63-
v -> {
64-
int progress;
65-
try {
66-
progress = Integer.parseInt(progressInput.getEditableText().toString());
67-
} catch (NumberFormatException e) {
68-
progress = 0;
69-
progressInput.setText("0");
65+
progressSlider.addOnChangeListener(
66+
(slider, value, fromUser) -> {
67+
if (!linearIndicator.isIndeterminate()) {
68+
linearIndicator.setProgressCompat((int) value, true);
69+
}
70+
if (!circularIndicator.isIndeterminate()) {
71+
circularIndicator.setProgressCompat((int) value, true);
7072
}
71-
linearIndicator.setProgressCompat(progress, true);
72-
circularIndicator.setProgressCompat(progress, true);
73-
determinateSwitch.setChecked(true);
7473
});
7574
determinateSwitch.setOnCheckedChangeListener(
7675
(v, isChecked) -> {
77-
linearIndicator.setIndeterminate(!isChecked);
78-
circularIndicator.setIndeterminate(!isChecked);
76+
if (isChecked) {
77+
float progress = progressSlider.getValue();
78+
linearIndicator.setProgressCompat((int) progress, true);
79+
circularIndicator.setProgressCompat((int) progress, true);
80+
} else {
81+
linearIndicator.setProgressCompat(0, false);
82+
circularIndicator.setProgressCompat(0, false);
83+
linearIndicator.setIndeterminate(true);
84+
circularIndicator.setIndeterminate(true);
85+
}
86+
});
87+
88+
float pixelsInDp = view.getResources().getDisplayMetrics().density;
89+
90+
Slider thicknessSlider = view.findViewById(R.id.thicknessSlider);
91+
thicknessSlider.addOnChangeListener(
92+
(slider, value, fromUser) -> {
93+
int newThickness = (int) (value * pixelsInDp);
94+
if (linearIndicator.getTrackThickness() != newThickness) {
95+
linearIndicator.setTrackThickness(newThickness);
96+
}
97+
if (circularIndicator.getTrackThickness() != newThickness) {
98+
circularIndicator.setTrackThickness(newThickness);
99+
}
100+
});
101+
102+
Slider cornerSlider = view.findViewById(R.id.cornerSlider);
103+
cornerSlider.addOnChangeListener(
104+
(slider, value, fromUser) -> {
105+
int newCornerRadius = (int) (value * pixelsInDp);
106+
if (linearIndicator.getTrackCornerRadius() != newCornerRadius) {
107+
linearIndicator.setTrackCornerRadius(newCornerRadius);
108+
}
109+
if (circularIndicator.getTrackCornerRadius() != newCornerRadius) {
110+
circularIndicator.setTrackCornerRadius(newCornerRadius);
111+
}
112+
});
113+
114+
MaterialSwitch reverseSwitch = view.findViewById(R.id.reverseSwitch);
115+
reverseSwitch.setOnCheckedChangeListener(
116+
(buttonView, isChecked) -> {
117+
linearIndicator.setIndicatorDirection(
118+
isChecked ? INDICATOR_DIRECTION_RIGHT_TO_LEFT : INDICATOR_DIRECTION_LEFT_TO_RIGHT);
119+
circularIndicator.setIndicatorDirection(
120+
isChecked ? INDICATOR_DIRECTION_COUNTERCLOCKWISE : INDICATOR_DIRECTION_CLOCKWISE);
121+
});
122+
123+
Slider circularSizeSlider = view.findViewById(R.id.circularSizeSlider);
124+
circularSizeSlider.addOnChangeListener(
125+
(slider, value, fromUser) -> {
126+
int newCornerRadius = (int) (value * pixelsInDp);
127+
if (circularIndicator.getIndicatorSize() != newCornerRadius) {
128+
circularIndicator.setIndicatorSize(newCornerRadius);
129+
}
79130
});
80131
}
81132
}
Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!--
3-
Copyright 2020 The Android Open Source Project
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
http://www.apache.org/licenses/LICENSE-2.0
8-
Unless required by applicable law or agreed to in writing, software
9-
distributed under the License is distributed on an "AS IS" BASIS,
10-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11-
See the License for the specific language governing permissions and
12-
limitations under the License.
3+
~ Copyright (C) 2020 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
1316
-->
1417

15-
<ScrollView
16-
xmlns:android="http://schemas.android.com/apk/res/android"
17-
xmlns:tools="http://schemas.android.com/tools"
18-
android:layout_width="match_parent"
19-
android:layout_height="match_parent">
20-
<LinearLayout
21-
android:id="@+id/content"
18+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:tools="http://schemas.android.com/tools"
2220
android:layout_width="match_parent"
23-
android:layout_height="wrap_content"
24-
android:paddingTop="16dp"
25-
android:paddingLeft="16dp"
26-
android:paddingRight="16dp"
27-
android:clipChildren="false"
28-
android:clipToPadding="false"
29-
android:orientation="vertical">
21+
android:layout_height="match_parent">
22+
<LinearLayout
23+
android:id="@+id/content"
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:paddingTop="16dp"
27+
android:paddingLeft="16dp"
28+
android:paddingRight="16dp"
29+
android:clipChildren="false"
30+
android:clipToPadding="false"
31+
android:orientation="vertical">
3032

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

@@ -54,28 +56,28 @@
5456
</LinearLayout>
5557

5658
<TextView
57-
android:layout_width="match_parent"
58-
android:layout_height="wrap_content"
59-
android:text="@string/cat_progress_indicator_indeterminate_to_determinate_explanation"/>
59+
android:layout_width="match_parent"
60+
android:layout_height="wrap_content"
61+
android:text="@string/cat_progress_indicator_indeterminate_to_determinate_explanation"/>
6062

6163
<LinearLayout
62-
android:layout_width="match_parent"
63-
android:layout_height="wrap_content">
64+
android:layout_width="match_parent"
65+
android:layout_height="wrap_content">
6466
<EditText
65-
android:id="@+id/progress_input"
66-
android:layout_width="0dp"
67-
android:layout_height="wrap_content"
68-
android:layout_weight="1"
69-
android:layout_margin="1dp"
70-
android:hint="@string/cat_progress_indicator_deteriminate_progress_hint"
71-
android:inputType="number"
72-
tools:ignore="Autofill"/>
67+
android:id="@+id/progress_input"
68+
android:layout_width="0dp"
69+
android:layout_height="wrap_content"
70+
android:layout_weight="1"
71+
android:layout_margin="1dp"
72+
android:hint="@string/cat_progress_indicator_determinate_progress"
73+
android:inputType="number"
74+
tools:ignore="Autofill"/>
7375
<Button
74-
android:id="@+id/update_button"
75-
android:layout_width="wrap_content"
76-
android:layout_height="wrap_content"
77-
android:layout_margin="1dp"
78-
android:text="@string/cat_progress_indicator_update"/>
76+
android:id="@+id/update_button"
77+
android:layout_width="wrap_content"
78+
android:layout_height="wrap_content"
79+
android:layout_margin="1dp"
80+
android:text="@string/cat_progress_indicator_update"/>
7981
</LinearLayout>
8082
</LinearLayout>
8183
</ScrollView>

catalog/java/io/material/catalog/progressindicator/res/layout/cat_progress_indicator_main_fragment.xml

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!--
3-
Copyright 2020 The Android Open Source Project
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
http://www.apache.org/licenses/LICENSE-2.0
8-
Unless required by applicable law or agreed to in writing, software
9-
distributed under the License is distributed on an "AS IS" BASIS,
10-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11-
See the License for the specific language governing permissions and
12-
limitations under the License.
3+
~ Copyright (C) 2020 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
1316
-->
1417
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
15-
xmlns:tools="http://schemas.android.com/tools"
1618
android:layout_width="match_parent"
1719
android:layout_height="match_parent"
1820
android:clipChildren="false"
@@ -50,24 +52,53 @@
5052
<TextView
5153
android:layout_width="wrap_content"
5254
android:layout_height="wrap_content"
53-
android:text="@string/cat_progress_indicator_determinate_progress_prompt"/>
54-
<LinearLayout
55+
android:text="@string/cat_progress_indicator_determinate_progress"/>
56+
<com.google.android.material.slider.Slider
57+
android:id="@+id/progress_slider"
5558
android:layout_width="match_parent"
56-
android:layout_height="wrap_content">
57-
<EditText
58-
android:id="@+id/progress_input"
59-
android:layout_width="0dp"
60-
android:layout_height="wrap_content"
61-
android:layout_weight="1"
62-
android:hint="@string/cat_progress_indicator_deteriminate_progress_hint"
63-
android:inputType="number"
64-
tools:ignore="Autofill"/>
65-
<Button
66-
android:id="@+id/update_button"
67-
android:layout_width="wrap_content"
68-
android:layout_height="wrap_content"
69-
android:layout_margin="1dp"
70-
android:text="@string/cat_progress_indicator_update"/>
71-
</LinearLayout>
59+
android:layout_height="wrap_content"
60+
android:valueFrom="0"
61+
android:valueTo="100"
62+
android:stepSize="1"/>
63+
64+
<TextView
65+
android:layout_width="wrap_content"
66+
android:layout_height="wrap_content"
67+
android:text="@string/cat_progress_indicator_track_thickness"/>
68+
<com.google.android.material.slider.Slider
69+
android:id="@+id/thicknessSlider"
70+
android:layout_width="match_parent"
71+
android:layout_height="wrap_content"
72+
android:valueFrom="1"
73+
android:valueTo="15"
74+
android:stepSize="1"/>
75+
<TextView
76+
android:layout_width="wrap_content"
77+
android:layout_height="wrap_content"
78+
android:text="@string/cat_progress_indicator_corner_size"/>
79+
<com.google.android.material.slider.Slider
80+
android:id="@+id/cornerSlider"
81+
android:layout_width="match_parent"
82+
android:layout_height="wrap_content"
83+
android:valueFrom="0"
84+
android:valueTo="5"
85+
android:stepSize="1"/>
86+
<com.google.android.material.materialswitch.MaterialSwitch
87+
android:id="@+id/reverseSwitch"
88+
android:layout_width="match_parent"
89+
android:layout_height="wrap_content"
90+
android:text="@string/cat_progress_indicator_reverse_direction"/>
91+
92+
<TextView
93+
android:layout_width="wrap_content"
94+
android:layout_height="wrap_content"
95+
android:text="@string/cat_progress_indicator_circular_indicator_size"/>
96+
<com.google.android.material.slider.Slider
97+
android:id="@+id/circularSizeSlider"
98+
android:layout_width="match_parent"
99+
android:layout_height="wrap_content"
100+
android:valueFrom="20"
101+
android:valueTo="200"
102+
android:stepSize="5"/>
72103
</LinearLayout>
73104

0 commit comments

Comments
 (0)