Skip to content

Commit 1d4c076

Browse files
pekingmeimhappi
authored andcommitted
[LoadingIndicator] Added a new component.
PiperOrigin-RevId: 663371718
1 parent 21ba18a commit 1d4c076

File tree

28 files changed

+1583
-4
lines changed

28 files changed

+1583
-4
lines changed

catalog/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def srcDirs = [
7777
'feature',
7878
'font',
7979
'internal',
80+
'loadingindicator',
8081
'main',
8182
'materialswitch',
8283
'menu',
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2024 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.loadingindicator;
17+
18+
import io.material.catalog.R;
19+
20+
import androidx.fragment.app.Fragment;
21+
import androidx.annotation.NonNull;
22+
import dagger.Provides;
23+
import dagger.android.ContributesAndroidInjector;
24+
import dagger.multibindings.IntoSet;
25+
import io.material.catalog.application.scope.ActivityScope;
26+
import io.material.catalog.application.scope.FragmentScope;
27+
import io.material.catalog.feature.Demo;
28+
import io.material.catalog.feature.DemoLandingFragment;
29+
import io.material.catalog.feature.FeatureDemo;
30+
31+
/** A fragment that displays loading indicator demos for the Catalog app. */
32+
public class LoadingIndicatorFragment extends DemoLandingFragment {
33+
@Override
34+
public int getTitleResId() {
35+
return R.string.cat_loading_indicator_title;
36+
}
37+
38+
@Override
39+
public int getDescriptionResId() {
40+
return R.string.cat_loading_indicator_description;
41+
}
42+
43+
@Override
44+
@NonNull
45+
public Demo getMainDemo() {
46+
return new Demo() {
47+
@Override
48+
public Fragment createFragment() {
49+
return new LoadingIndicatorMainDemoFragment();
50+
}
51+
};
52+
}
53+
54+
/** The Dagger module for {@link LoadingIndicatorFragment} dependencies. */
55+
@dagger.Module
56+
public abstract static class Module {
57+
@FragmentScope
58+
@ContributesAndroidInjector
59+
abstract LoadingIndicatorFragment contributeInjector();
60+
61+
@IntoSet
62+
@Provides
63+
@ActivityScope
64+
static FeatureDemo provideFeatureDemo() {
65+
return new FeatureDemo(
66+
R.string.cat_loading_indicator_title, R.drawable.ic_progress_activity_24px) {
67+
@Override
68+
public Fragment createFragment() {
69+
return new LoadingIndicatorFragment();
70+
}
71+
};
72+
}
73+
}
74+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.loadingindicator;
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.button.MaterialButton;
27+
import com.google.android.material.loadingindicator.LoadingIndicator;
28+
import com.google.android.material.loadingindicator.LoadingIndicatorDrawable;
29+
import com.google.android.material.loadingindicator.LoadingIndicatorSpec;
30+
import io.material.catalog.feature.DemoFragment;
31+
32+
/** This is the fragment to demo simple use cases of {@link LoadingIndicator}. */
33+
public class LoadingIndicatorMainDemoFragment extends DemoFragment {
34+
35+
@NonNull
36+
@Override
37+
public View onCreateDemoView(
38+
@NonNull LayoutInflater layoutInflater,
39+
@Nullable ViewGroup viewGroup,
40+
@Nullable Bundle bundle) {
41+
View view =
42+
layoutInflater.inflate(
43+
R.layout.cat_loading_indicator_fragment, viewGroup, false /* attachToRoot */);
44+
45+
LoadingIndicatorSpec spec =
46+
new LoadingIndicatorSpec(getContext(), null, 0, R.style.Widget_Material3_LoadingIndicator);
47+
spec.setScaleToFit(true);
48+
LoadingIndicatorDrawable loadingIndicatorDrawable =
49+
LoadingIndicatorDrawable.create(getContext(), spec);
50+
MaterialButton loadingButton = view.findViewById(R.id.loading_btn);
51+
loadingButton.setIcon(loadingIndicatorDrawable);
52+
53+
return view;
54+
}
55+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
15+
<size
16+
android:height="5dp"
17+
android:width="0dp"/>
18+
</shape>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2024 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.
16+
-->
17+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:app="http://schemas.android.com/apk/res-auto"
19+
android:layout_width="match_parent"
20+
android:layout_height="match_parent">
21+
22+
<LinearLayout
23+
android:layout_width="match_parent"
24+
android:layout_height="wrap_content"
25+
android:clipChildren="false"
26+
android:clipToPadding="false"
27+
android:divider="@drawable/cat_loading_indicator_layout_divider"
28+
android:orientation="vertical"
29+
android:padding="16dp"
30+
android:showDividers="middle">
31+
32+
<TextView
33+
android:layout_width="wrap_content"
34+
android:layout_height="wrap_content"
35+
android:text="@string/cat_loading_indicator_default" />
36+
37+
<com.google.android.material.loadingindicator.LoadingIndicator
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content" />
40+
41+
<TextView
42+
android:layout_width="wrap_content"
43+
android:layout_height="wrap_content"
44+
android:text="@string/cat_loading_indicator_with_container" />
45+
46+
<com.google.android.material.loadingindicator.LoadingIndicator
47+
style="@style/Widget.Material3.LoadingIndicator.Contained"
48+
android:layout_width="wrap_content"
49+
android:layout_height="wrap_content" />
50+
51+
<TextView
52+
android:layout_width="wrap_content"
53+
android:layout_height="wrap_content"
54+
android:text="@string/cat_loading_indicator_with_multiple_colors" />
55+
56+
<com.google.android.material.loadingindicator.LoadingIndicator
57+
android:layout_width="wrap_content"
58+
android:layout_height="wrap_content"
59+
app:indicatorColor="@array/cat_custom_indicator_colors" />
60+
61+
<TextView
62+
android:layout_width="wrap_content"
63+
android:layout_height="wrap_content"
64+
android:text="@string/cat_loading_indicator_in_a_button" />
65+
66+
<Button
67+
android:id="@+id/loading_btn"
68+
style="?attr/materialIconButtonOutlinedStyle"
69+
android:layout_width="wrap_content"
70+
android:layout_height="wrap_content"/>
71+
</LinearLayout>
72+
</ScrollView>
73+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2024 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.
16+
-->
17+
<resources>
18+
<color name="cat_custom_indicator_colors_yellow_500">#ffde03</color>
19+
<color name="cat_custom_indicator_colors_blue_700">#0336ff</color>
20+
<color name="cat_custom_indicator_colors_red_500">#ff0266</color>
21+
<integer-array name="cat_custom_indicator_colors">
22+
<item>@color/cat_custom_indicator_colors_yellow_500</item>
23+
<item>@color/cat_custom_indicator_colors_blue_700</item>
24+
<item>@color/cat_custom_indicator_colors_red_500</item>
25+
</integer-array>
26+
</resources>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2024 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.
16+
-->
17+
<resources>
18+
<string name="cat_loading_indicator_title"
19+
description="Title for the screen that showcases demonstrative usages of the Loading Indicator widget [CHAR LIMIT=NONE]">
20+
Loading Indicator
21+
</string>
22+
<string name="cat_loading_indicator_description"
23+
description="Body text describing the LoadingIndicator widget within the design system [CHAR LIMIT=NONE]">
24+
LoadingIndicator shows an indeterminate undergoing process.
25+
</string>
26+
<string name="cat_loading_indicator_default"
27+
description="Text label above a default loading indicator. [CHAR LIMIT=NONE]">
28+
Loading indicator
29+
</string>
30+
<string name="cat_loading_indicator_with_container"
31+
description="Text label above a loading indicator with a container [CHAR LIMIT=NONE]">
32+
Loading indicator with container
33+
</string>
34+
<string name="cat_loading_indicator_with_multiple_colors"
35+
description="Text label above a loading indicator with multiple colors [CHAR LIMIT=NONE]">
36+
Loading indicator with multiple colors
37+
</string>
38+
<string name="cat_loading_indicator_in_a_button"
39+
description="Text label above a button with a loading indicator icon [CHAR LIMIT=NONE]">
40+
Loading indicator in a button
41+
</string>
42+
</resources>

catalog/java/io/material/catalog/tableofcontents/TocModule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import io.material.catalog.fab.FabFragment;
3737
import io.material.catalog.font.FontFragment;
3838
import io.material.catalog.imageview.ShapeableImageViewFragment;
39+
import io.material.catalog.loadingindicator.LoadingIndicatorFragment;
3940
import io.material.catalog.materialswitch.SwitchFragment;
4041
import io.material.catalog.menu.MenuFragment;
4142
import io.material.catalog.navigationdrawer.NavigationDrawerFragment;
@@ -72,6 +73,7 @@
7273
ElevationFragment.Module.class,
7374
FabFragment.Module.class,
7475
FontFragment.Module.class,
76+
LoadingIndicatorFragment.Module.class,
7577
MenuFragment.Module.class,
7678
NavigationDrawerFragment.Module.class,
7779
NavigationRailFragment.Module.class,

0 commit comments

Comments
 (0)