|
17 | 17 |
|
18 | 18 | import io.material.catalog.R; |
19 | 19 |
|
| 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 | + |
20 | 25 | import android.os.Bundle; |
21 | 26 | import android.view.LayoutInflater; |
22 | 27 | import android.view.View; |
23 | 28 | import android.view.ViewGroup; |
24 | | -import android.widget.Button; |
25 | | -import android.widget.EditText; |
26 | 29 | import androidx.annotation.NonNull; |
27 | 30 | import androidx.annotation.Nullable; |
28 | 31 | import com.google.android.material.materialswitch.MaterialSwitch; |
29 | 32 | import com.google.android.material.progressindicator.CircularProgressIndicator; |
30 | 33 | import com.google.android.material.progressindicator.LinearProgressIndicator; |
| 34 | +import com.google.android.material.slider.Slider; |
31 | 35 | import io.material.catalog.feature.DemoFragment; |
32 | 36 |
|
33 | 37 | /** |
@@ -55,27 +59,74 @@ public View onCreateDemoView( |
55 | 59 | public void initialize(@NonNull View view) { |
56 | 60 | LinearProgressIndicator linearIndicator = view.findViewById(R.id.linear_indicator); |
57 | 61 | 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); |
60 | 63 | MaterialSwitch determinateSwitch = view.findViewById(R.id.determinate_mode_switch); |
61 | 64 |
|
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); |
70 | 72 | } |
71 | | - linearIndicator.setProgressCompat(progress, true); |
72 | | - circularIndicator.setProgressCompat(progress, true); |
73 | | - determinateSwitch.setChecked(true); |
74 | 73 | }); |
75 | 74 | determinateSwitch.setOnCheckedChangeListener( |
76 | 75 | (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 | + } |
79 | 130 | }); |
80 | 131 | } |
81 | 132 | } |
0 commit comments