Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Slider] Added LABEL_VISIBLE to label behavior and added a demo fragm…
…ent in catalog. Resolves #1316 PiperOrigin-RevId: 433570701
- Loading branch information
Showing
8 changed files
with
296 additions
and
53 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
63 changes: 63 additions & 0 deletions
63
catalog/java/io/material/catalog/slider/SliderLabelBehaviorDemoFragment.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,63 @@ | ||
/* | ||
* Copyright 2019 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.slider; | ||
|
||
import io.material.catalog.R; | ||
|
||
import android.os.Bundle; | ||
import androidx.appcompat.widget.SwitchCompat; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import androidx.annotation.IdRes; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import com.google.android.material.slider.RangeSlider; | ||
import com.google.android.material.slider.Slider; | ||
import io.material.catalog.feature.DemoFragment; | ||
|
||
/** | ||
* Fragment to display a few basic uses of the {@link Slider} widget with different label behaviors | ||
* for the Catalog app. | ||
*/ | ||
public class SliderLabelBehaviorDemoFragment extends DemoFragment { | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateDemoView( | ||
@NonNull LayoutInflater inflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) { | ||
View view = | ||
inflater.inflate( | ||
R.layout.cat_slider_demo_label_behavior, viewGroup, false /* attachToRoot */); | ||
|
||
setUpSlider(view, R.id.switch_button_1, R.id.slider_1); | ||
setUpSlider(view, R.id.switch_button_2, R.id.slider_2); | ||
setUpSlider(view, R.id.switch_button_3, R.id.slider_3); | ||
setUpSlider(view, R.id.switch_button_4, R.id.slider_4); | ||
|
||
return view; | ||
} | ||
|
||
private void setUpSlider( | ||
View view, @IdRes int switchId, @IdRes int sliderId) { | ||
final RangeSlider slider = view.findViewById(sliderId); | ||
SwitchCompat switchButton = view.findViewById(switchId); | ||
switchButton.setOnCheckedChangeListener( | ||
(buttonView, isChecked) -> slider.setEnabled(isChecked)); | ||
switchButton.setChecked(true); | ||
} | ||
} |
146 changes: 146 additions & 0 deletions
146
catalog/java/io/material/catalog/slider/res/layout/cat_slider_demo_label_behavior.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,146 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2019 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:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:paddingLeft="16dp" | ||
android:paddingRight="16dp" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:paddingTop="@dimen/cat_slider_title_top_padding" | ||
android:text="@string/cat_slider_label_floating"/> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_vertical"> | ||
|
||
<androidx.appcompat.widget.SwitchCompat | ||
android:id="@+id/switch_button_1" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> | ||
|
||
<com.google.android.material.slider.RangeSlider | ||
android:id="@+id/slider_1" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:layout_marginLeft="@dimen/cat_slider_left_margin" | ||
android:layout_marginStart="@dimen/cat_slider_left_margin" | ||
android:valueFrom="0" | ||
android:valueTo="10" | ||
app:values="@array/initial_slider_values" | ||
app:labelBehavior="floating"/> | ||
</LinearLayout> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:paddingTop="@dimen/cat_slider_title_top_padding" | ||
android:text="@string/cat_slider_label_within_bounds"/> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_vertical"> | ||
|
||
<androidx.appcompat.widget.SwitchCompat | ||
android:id="@+id/switch_button_2" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> | ||
|
||
<com.google.android.material.slider.RangeSlider | ||
android:id="@+id/slider_2" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:layout_marginLeft="@dimen/cat_slider_left_margin" | ||
android:layout_marginStart="@dimen/cat_slider_left_margin" | ||
android:valueFrom="0" | ||
android:valueTo="10" | ||
app:values="@array/initial_slider_values" | ||
app:labelBehavior="withinBounds"/> | ||
</LinearLayout> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:paddingTop="@dimen/cat_slider_title_top_padding" | ||
android:text="@string/cat_slider_label_gone"/> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_vertical"> | ||
|
||
<androidx.appcompat.widget.SwitchCompat | ||
android:id="@+id/switch_button_3" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> | ||
|
||
<com.google.android.material.slider.RangeSlider | ||
android:id="@+id/slider_3" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:layout_marginLeft="@dimen/cat_slider_left_margin" | ||
android:layout_marginStart="@dimen/cat_slider_left_margin" | ||
android:valueFrom="0" | ||
android:valueTo="10" | ||
app:values="@array/initial_slider_values" | ||
app:labelBehavior="gone"/> | ||
</LinearLayout> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:paddingTop="@dimen/cat_slider_title_top_padding" | ||
android:text="@string/cat_slider_label_visible"/> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_vertical"> | ||
|
||
<androidx.appcompat.widget.SwitchCompat | ||
android:id="@+id/switch_button_4" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> | ||
|
||
<com.google.android.material.slider.RangeSlider | ||
android:id="@+id/slider_4" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:layout_marginLeft="@dimen/cat_slider_left_margin" | ||
android:layout_marginStart="@dimen/cat_slider_left_margin" | ||
android:valueFrom="0" | ||
android:valueTo="10" | ||
app:values="@array/initial_slider_values" | ||
app:labelBehavior="visible"/> | ||
</LinearLayout> | ||
</LinearLayout> | ||
</ScrollView> |
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
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
Oops, something went wrong.