Skip to content

Commit 5229b3f

Browse files
pekingmedsn5ft
authored andcommitted
[ProgressIndicator] Added standalone drawable demo with Chip in catalog.
PiperOrigin-RevId: 322692977
1 parent 88ca5c9 commit 5229b3f

File tree

4 files changed

+140
-0
lines changed

4 files changed

+140
-0
lines changed

catalog/java/io/material/catalog/progressindicator/ProgressIndicatorFragment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ public Fragment createFragment() {
7878
return new ProgressIndicatorCustomDemoFragment();
7979
}
8080
});
81+
additionalDemos.add(
82+
new Demo(R.string.cat_progress_indicator_demo_standalone_title) {
83+
@Override
84+
public Fragment createFragment() {
85+
return new ProgressIndicatorStandaloneDemoFragment();
86+
}
87+
});
8188
return additionalDemos;
8289
}
8390
/** The Dagger module for {@link ProgressIndicatorFragment} dependencies. */
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2020 The Android Open Source Project
3+
*
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+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.material.catalog.progressindicator;
17+
18+
import io.material.catalog.R;
19+
20+
import android.os.Bundle;
21+
import android.view.LayoutInflater;
22+
import android.view.View;
23+
import android.view.ViewGroup;
24+
import androidx.annotation.NonNull;
25+
import androidx.annotation.Nullable;
26+
import com.google.android.material.chip.Chip;
27+
import com.google.android.material.internal.ViewUtils;
28+
import com.google.android.material.progressindicator.CircularDrawingDelegate;
29+
import com.google.android.material.progressindicator.CircularIndeterminateAnimatorDelegate;
30+
import com.google.android.material.progressindicator.IndeterminateDrawable;
31+
import com.google.android.material.progressindicator.ProgressIndicatorSpec;
32+
import com.google.android.material.switchmaterial.SwitchMaterial;
33+
import io.material.catalog.feature.DemoFragment;
34+
35+
/**
36+
* The fragment demos progress indicator drawables used as standalone drawables in other components.
37+
*/
38+
public class ProgressIndicatorStandaloneDemoFragment extends DemoFragment {
39+
40+
@Override
41+
@NonNull
42+
public View onCreateDemoView(
43+
@NonNull LayoutInflater layoutInflater,
44+
@Nullable ViewGroup viewGroup,
45+
@Nullable Bundle bundle) {
46+
View view =
47+
layoutInflater.inflate(
48+
R.layout.cat_progress_indicator_standalone_fragment,
49+
viewGroup,
50+
/*attachToRoot=*/ false);
51+
52+
ProgressIndicatorSpec progressIndicatorSpec = new ProgressIndicatorSpec();
53+
progressIndicatorSpec.loadFromAttributes(
54+
getContext(),
55+
null,
56+
R.style.Widget_MaterialComponents_ProgressIndicator_Circular_Indeterminate);
57+
progressIndicatorSpec.circularInset = 0; // No inset.
58+
progressIndicatorSpec.circularRadius =
59+
(int) ViewUtils.dpToPx(getContext(), 10); // Circular radius is 10 dp.
60+
IndeterminateDrawable progressIndicatorDrawable =
61+
new IndeterminateDrawable(
62+
getContext(),
63+
progressIndicatorSpec,
64+
new CircularDrawingDelegate(),
65+
new CircularIndeterminateAnimatorDelegate());
66+
67+
Chip chip = view.findViewById(R.id.cat_progress_indicator_chip);
68+
chip.setChipIcon(progressIndicatorDrawable);
69+
70+
SwitchMaterial chipIconSwitch =
71+
view.findViewById(R.id.cat_progress_indicator_standalone_chip_switch);
72+
chipIconSwitch.setOnCheckedChangeListener(
73+
(buttonView, isChecked) -> {
74+
chip.setChipIconVisible(isChecked);
75+
});
76+
return view;
77+
}
78+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
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.
13+
-->
14+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
15+
xmlns:app="http://schemas.android.com/apk/res-auto"
16+
android:layout_width="match_parent"
17+
android:layout_height="match_parent"
18+
android:paddingTop="16dp"
19+
android:paddingLeft="16dp"
20+
android:paddingRight="16dp"
21+
android:clipChildren="false"
22+
android:clipToPadding="false"
23+
android:orientation="vertical"
24+
android:showDividers="middle"
25+
android:divider="@drawable/layout_divider">
26+
27+
<com.google.android.material.chip.Chip
28+
android:id="@+id/cat_progress_indicator_chip"
29+
style="@style/Widget.MaterialComponents.Chip.Action"
30+
android:layout_width="wrap_content"
31+
android:layout_height="wrap_content"
32+
android:ellipsize="end"
33+
android:text="@string/cat_progress_indicator_standalone_indeterminate_chip"/>
34+
35+
<com.google.android.material.switchmaterial.SwitchMaterial
36+
android:id="@+id/cat_progress_indicator_standalone_chip_switch"
37+
android:layout_width="wrap_content"
38+
android:layout_height="wrap_content"
39+
android:layout_marginTop="16dp"
40+
android:text="@string/cat_progress_indicator_standalone_switch_label"
41+
android:checked="true"/>
42+
43+
</LinearLayout>

catalog/java/io/material/catalog/progressindicator/res/values/strings.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
description="Title of demo for the progress indicators using custom drawables [CHAR LIMIT=NONE]">
2929
Custom Drawable Progress Indicator Demo
3030
</string>
31+
<string name="cat_progress_indicator_demo_standalone_title"
32+
description="Title of demo for other components using progress indicator standalone drawables [CHAR LIMIT=NONE]">
33+
Standalone Drawable Progress Indicator Demo
34+
</string>
3135
<string name="cat_progress_indicator_description"
3236
description="Body text describing the MaterialProgressIndicator widget within the design system [CHAR LIMIT=NONE]">
3337
ProgressIndicator shows the progress of an undergoing process.
@@ -128,4 +132,12 @@
128132
description="An example of the progress indicator in determinate mode using a custom drawable [CHAR LIMIT=NONE]">
129133
Custom (wavy) determinate progress indicator
130134
</string>
135+
<string name="cat_progress_indicator_standalone_indeterminate_chip"
136+
description="An example of using progress indicator drawable as chip icon [CHAR LIMIT=NONE]">
137+
Indeterminate Chip
138+
</string>
139+
<string name="cat_progress_indicator_standalone_switch_label"
140+
description="A material switch to toggle progress indicator drawable on chip [CHAR LIMIT=NONE]">
141+
Show Icon
142+
</string>
131143
</resources>

0 commit comments

Comments
 (0)