-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ProgressIndicator] Added demo for visibility control.
PiperOrigin-RevId: 592008983
- Loading branch information
1 parent
ba0b332
commit 5d62e9e
Showing
4 changed files
with
314 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
...g/java/io/material/catalog/progressindicator/ProgressIndicatorVisibilityDemoFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
* Copyright 2023 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. | ||
*/ | ||
package io.material.catalog.progressindicator; | ||
|
||
import io.material.catalog.R; | ||
|
||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.AutoCompleteTextView; | ||
import android.widget.Button; | ||
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; | ||
import java.util.HashMap; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
/** | ||
* This is the fragment to demo different visibility change behaviors of {@link | ||
* LinearProgressIndicator} and {@link CircularProgressIndicator}. | ||
*/ | ||
public class ProgressIndicatorVisibilityDemoFragment extends DemoFragment { | ||
|
||
public static final int SHOW_NONE = 0; | ||
public static final int SHOW_OUTWARD = 1; | ||
public static final int SHOW_INWARD = 2; | ||
public static final int HIDE_NONE = 0; | ||
public static final int HIDE_OUTWARD = 1; | ||
public static final int HIDE_INWARD = 2; | ||
public static final int HIDE_ESCAPE = 3; | ||
|
||
private static final Map<String, Integer> showBehaviorCodes = new HashMap<>(); | ||
private static final Map<String, Integer> hideBehaviorCodes = new HashMap<>(); | ||
|
||
static { | ||
showBehaviorCodes.put("none", SHOW_NONE); | ||
showBehaviorCodes.put("outward", SHOW_OUTWARD); | ||
showBehaviorCodes.put("inward", SHOW_INWARD); | ||
hideBehaviorCodes.put("none", HIDE_NONE); | ||
hideBehaviorCodes.put("outward", HIDE_OUTWARD); | ||
hideBehaviorCodes.put("inward", HIDE_INWARD); | ||
hideBehaviorCodes.put("escape", HIDE_ESCAPE); | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public View onCreateDemoView( | ||
@NonNull LayoutInflater layoutInflater, | ||
@Nullable ViewGroup viewGroup, | ||
@Nullable Bundle bundle) { | ||
|
||
View view = | ||
layoutInflater.inflate( | ||
R.layout.cat_progress_indicator_visibility_fragment, | ||
viewGroup, | ||
false /* attachToRoot */); | ||
|
||
initialize(view); | ||
|
||
return view; | ||
} | ||
|
||
public void initialize(@NonNull View view) { | ||
LinearProgressIndicator linearIndicator = view.findViewById(R.id.linear_indicator); | ||
CircularProgressIndicator circularIndicator = view.findViewById(R.id.circular_indicator); | ||
Slider progressSlider = view.findViewById(R.id.progress_slider); | ||
MaterialSwitch determinateSwitch = view.findViewById(R.id.determinate_mode_switch); | ||
|
||
progressSlider.addOnChangeListener( | ||
(slider, value, fromUser) -> { | ||
if (!linearIndicator.isIndeterminate()) { | ||
linearIndicator.setProgressCompat((int) value, true); | ||
} | ||
if (!circularIndicator.isIndeterminate()) { | ||
circularIndicator.setProgressCompat((int) value, true); | ||
} | ||
}); | ||
determinateSwitch.setOnCheckedChangeListener( | ||
(v, 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); | ||
} | ||
}); | ||
|
||
AutoCompleteTextView showBehaviorInput = view.findViewById(R.id.showBehaviorDropdown); | ||
showBehaviorInput.setOnItemClickListener( | ||
(parent, view12, position, id) -> { | ||
String selected = (String) showBehaviorInput.getAdapter().getItem(position); | ||
int showBehaviorCode = showBehaviorCodes.get(selected.toLowerCase(Locale.US)); | ||
linearIndicator.setShowAnimationBehavior(showBehaviorCode); | ||
circularIndicator.setShowAnimationBehavior(showBehaviorCode); | ||
}); | ||
AutoCompleteTextView hideBehaviorInput = view.findViewById(R.id.hideBehaviorDropdown); | ||
hideBehaviorInput.setOnItemClickListener( | ||
(parent, view1, position, id) -> { | ||
String selected = (String) hideBehaviorInput.getAdapter().getItem(position); | ||
int hideBehaviorCode = hideBehaviorCodes.get(selected.toLowerCase(Locale.US)); | ||
linearIndicator.setHideAnimationBehavior(hideBehaviorCode); | ||
circularIndicator.setHideAnimationBehavior(hideBehaviorCode); | ||
}); | ||
|
||
Button showButton = view.findViewById(R.id.showButton); | ||
showButton.setOnClickListener( | ||
v -> { | ||
if (linearIndicator.getVisibility() != View.VISIBLE) { | ||
linearIndicator.show(); | ||
} | ||
if (circularIndicator.getVisibility() != View.VISIBLE) { | ||
circularIndicator.show(); | ||
} | ||
}); | ||
Button hideButton = view.findViewById(R.id.hideButton); | ||
hideButton.setOnClickListener( | ||
v -> { | ||
if (linearIndicator.getVisibility() == View.VISIBLE) { | ||
linearIndicator.hide(); | ||
} | ||
if (circularIndicator.getVisibility() == View.VISIBLE) { | ||
circularIndicator.hide(); | ||
} | ||
}); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
...erial/catalog/progressindicator/res/layout/cat_progress_indicator_visibility_fragment.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright (C) 2023 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:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:clipChildren="false" | ||
android:clipToPadding="false" | ||
android:orientation="vertical" | ||
android:padding="16dp" | ||
android:showDividers="middle" | ||
android:divider="@drawable/layout_divider"> | ||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/cat_progress_indicator_linear" /> | ||
<com.google.android.material.progressindicator.LinearProgressIndicator | ||
android:id="@+id/linear_indicator" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:indeterminate="true"/> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/cat_progress_indicator_circular" /> | ||
<com.google.android.material.progressindicator.CircularProgressIndicator | ||
android:id="@+id/circular_indicator" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:indeterminate="true"/> | ||
|
||
<com.google.android.material.materialswitch.MaterialSwitch | ||
android:id="@+id/determinate_mode_switch" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/cat_progress_indicator_set_to_determinate_mode"/> | ||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
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" | ||
android:valueFrom="0" | ||
android:valueTo="100" | ||
android:stepSize="1"/> | ||
|
||
<com.google.android.material.textfield.TextInputLayout | ||
style="?attr/textInputOutlinedExposedDropdownMenuStyle" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:hint="@string/cat_progress_indicator_show_behavior"> | ||
<AutoCompleteTextView | ||
android:id="@+id/showBehaviorDropdown" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:inputType="none" | ||
android:text="@string/cat_progress_indicator_initial_behavior" | ||
android:hint="@string/cat_progress_indicator_show_behavior" | ||
app:simpleItems="@array/show_behaviors_array"/> | ||
</com.google.android.material.textfield.TextInputLayout> | ||
|
||
<com.google.android.material.textfield.TextInputLayout | ||
style="?attr/textInputOutlinedExposedDropdownMenuStyle" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:hint="@string/cat_progress_indicator_hide_behavior"> | ||
<AutoCompleteTextView | ||
android:id="@+id/hideBehaviorDropdown" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:inputType="none" | ||
android:text="@string/cat_progress_indicator_initial_behavior" | ||
android:hint="@string/cat_progress_indicator_hide_behavior" | ||
app:simpleItems="@array/hide_behaviors_array"/> | ||
</com.google.android.material.textfield.TextInputLayout> | ||
|
||
<androidx.appcompat.widget.LinearLayoutCompat | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal"> | ||
<Button | ||
android:id="@+id/showButton" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:layout_margin="2dp" | ||
android:text="@string/cat_progress_indicator_show"/> | ||
<Button | ||
android:id="@+id/hideButton" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:layout_margin="2dp" | ||
android:text="@string/cat_progress_indicator_hide"/> | ||
</androidx.appcompat.widget.LinearLayoutCompat> | ||
|
||
</LinearLayout> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters