Skip to content

Commit 72d9025

Browse files
committed
MDC-Android 1.12.0
Fragment 1.7.0. Rework slider to support latest design. Implement circular and linear progress indicators. Update layouts and recycler view frame accordingly.
1 parent 162d5ac commit 72d9025

24 files changed

+788
-45
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ buildscript {
2222
'buildTools' : '35.0.0',
2323
'multidex' : '2.0.1',
2424
'dynamic' : '4.5.1',
25-
'fragment' : '1.6.0',
25+
'fragment' : '1.7.0',
2626
'flexbox' : '3.0.0',
2727
'kotlin' : '1.9.24',
2828
'locale' : '2.4.0',
29-
'material' : '1.11.0-alpha01',
29+
'material' : '1.12.0',
3030
'preferences' : '2.3.1',
3131
'swiperefresh': '1.1.0',
3232
'theme' : '4.5.1',

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/recyclerview/DynamicRecyclerViewFrame.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2022 Pranav Pandey
2+
* Copyright 2018-2024 Pranav Pandey
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,13 +22,13 @@
2222
import android.util.AttributeSet;
2323
import android.view.View;
2424
import android.widget.FrameLayout;
25+
import android.widget.ProgressBar;
2526

2627
import androidx.annotation.AttrRes;
2728
import androidx.annotation.CallSuper;
2829
import androidx.annotation.LayoutRes;
2930
import androidx.annotation.NonNull;
3031
import androidx.annotation.Nullable;
31-
import androidx.core.widget.ContentLoadingProgressBar;
3232
import androidx.recyclerview.widget.LinearLayoutManager;
3333
import androidx.recyclerview.widget.RecyclerView;
3434
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
@@ -91,7 +91,7 @@ public abstract class DynamicRecyclerViewFrame extends FrameLayout {
9191
* @see #showProgress()
9292
* @see #hideProgress()
9393
*/
94-
private ContentLoadingProgressBar mProgressBar;
94+
private ProgressBar mProgressBar;
9595

9696
public DynamicRecyclerViewFrame(@NonNull Context context) {
9797
this(context, null);
@@ -416,7 +416,7 @@ public void hideEmptyView() {
416416
*
417417
* @return The progress bar that can be shown while the data is loading in the background.
418418
*/
419-
public @Nullable ContentLoadingProgressBar getProgressBar() {
419+
public @Nullable ProgressBar getProgressBar() {
420420
return mProgressBar;
421421
}
422422

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/theme/inflater/DynamicLayoutInflater.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2022 Pranav Pandey
2+
* Copyright 2018-2024 Pranav Pandey
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@
3434
import com.pranavpandey.android.dynamic.support.widget.DynamicButton;
3535
import com.pranavpandey.android.dynamic.support.widget.DynamicCardView;
3636
import com.pranavpandey.android.dynamic.support.widget.DynamicCheckBox;
37+
import com.pranavpandey.android.dynamic.support.widget.DynamicCircularProgressIndicator;
3738
import com.pranavpandey.android.dynamic.support.widget.DynamicCollapsingToolbarLayout;
3839
import com.pranavpandey.android.dynamic.support.widget.DynamicCoordinatorLayout;
3940
import com.pranavpandey.android.dynamic.support.widget.DynamicDrawerLayout;
@@ -48,6 +49,7 @@
4849
import com.pranavpandey.android.dynamic.support.widget.DynamicImageView;
4950
import com.pranavpandey.android.dynamic.support.widget.DynamicLinearLayout;
5051
import com.pranavpandey.android.dynamic.support.widget.DynamicLinearLayoutCompat;
52+
import com.pranavpandey.android.dynamic.support.widget.DynamicLinearProgressIndicator;
5153
import com.pranavpandey.android.dynamic.support.widget.DynamicListView;
5254
import com.pranavpandey.android.dynamic.support.widget.DynamicMaterialCardView;
5355
import com.pranavpandey.android.dynamic.support.widget.DynamicMaterialSwitch;
@@ -199,6 +201,14 @@ public class DynamicLayoutInflater implements LayoutInflater.Factory2 {
199201
case "com.pranavpandey.android.dynamic.support.widget.DynamicProgressBar":
200202
view = new DynamicProgressBar(context, attrs);
201203
break;
204+
case "com.google.android.material.progressindicator.CircularProgressIndicator":
205+
case "com.pranavpandey.android.dynamic.support.widget.DynamicCircularProgressIndicator":
206+
view = new DynamicCircularProgressIndicator(context, attrs);
207+
break;
208+
case "com.google.android.material.progressindicator.LinearProgressIndicator":
209+
case "com.pranavpandey.android.dynamic.support.widget.DynamicLinearProgressIndicator":
210+
view = new DynamicLinearProgressIndicator(context, attrs);
211+
break;
202212
case "android.support.v4.widget.SwipeRefreshLayout":
203213
case "androidx.SwipeRefreshLayout.widget.SwipeRefreshLayout":
204214
case "com.pranavpandey.android.dynamic.support.widget.DynamicSwipeRefreshLayout":

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/util/DynamicShapeUtils.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2022 Pranav Pandey
2+
* Copyright 2018-2024 Pranav Pandey
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,6 +36,21 @@
3636
*/
3737
public class DynamicShapeUtils {
3838

39+
/**
40+
* Returns the corner size for the slider according to the supplied corner size.
41+
*
42+
* @param cornerSize The corner size to be considered in dips.
43+
*
44+
* @return The corner size for the slider according to the supplied corner size.
45+
*/
46+
public static @DrawableRes int getSlideCornerSize(float cornerSize) {
47+
if (cornerSize < Theme.Corner.MIN_ROUND) {
48+
return 0;
49+
} else {
50+
return DynamicUnitUtils.convertDpToPixels(Theme.Corner.DEFAULT);
51+
}
52+
}
53+
3954
/**
4055
* Returns the overlay resource according to the supplied corner size.
4156
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
/*
2+
* Copyright 2018-2024 Pranav Pandey
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+
17+
package com.pranavpandey.android.dynamic.support.widget;
18+
19+
import android.annotation.TargetApi;
20+
import android.content.Context;
21+
import android.content.res.TypedArray;
22+
import android.os.Build;
23+
import android.util.AttributeSet;
24+
25+
import androidx.annotation.ColorInt;
26+
import androidx.annotation.NonNull;
27+
import androidx.annotation.Nullable;
28+
29+
import com.google.android.material.progressindicator.CircularProgressIndicator;
30+
import com.pranavpandey.android.dynamic.support.Defaults;
31+
import com.pranavpandey.android.dynamic.support.Dynamic;
32+
import com.pranavpandey.android.dynamic.support.R;
33+
import com.pranavpandey.android.dynamic.support.theme.DynamicTheme;
34+
import com.pranavpandey.android.dynamic.support.util.DynamicShapeUtils;
35+
import com.pranavpandey.android.dynamic.support.widget.base.DynamicWidget;
36+
import com.pranavpandey.android.dynamic.theme.Theme;
37+
import com.pranavpandey.android.dynamic.util.DynamicColorUtils;
38+
39+
/**
40+
* A {@link CircularProgressIndicator} to apply {@link DynamicTheme} according to the
41+
* supplied parameters.
42+
*/
43+
public class DynamicCircularProgressIndicator extends CircularProgressIndicator
44+
implements DynamicWidget {
45+
46+
/**
47+
* Color type applied to this view.
48+
*
49+
* @see Theme.ColorType
50+
*/
51+
protected @Theme.ColorType int mColorType;
52+
53+
/**
54+
* Background color type for this view so that it will remain in contrast with this
55+
* color type.
56+
*/
57+
protected @Theme.ColorType int mContrastWithColorType;
58+
59+
/**
60+
* Color applied to this view.
61+
*/
62+
protected @ColorInt int mColor;
63+
64+
/**
65+
* Color applied to this view after considering the background aware properties.
66+
*/
67+
protected @ColorInt int mAppliedColor;
68+
69+
/**
70+
* Background color for this view so that it will remain in contrast with this color.
71+
*/
72+
protected @ColorInt int mContrastWithColor;
73+
74+
/**
75+
* The background aware functionality to change this view color according to the background.
76+
* It was introduced to provide better legibility for colored views and to avoid dark view
77+
* on dark background like situations.
78+
*
79+
* <p>If this is enabled then, it will check for the contrast color and do color
80+
* calculations according to that color so that this text view will always be visible on
81+
* that background. If no contrast color is found then, it will take the default
82+
* background color.
83+
*
84+
* @see Theme.BackgroundAware
85+
* @see #mContrastWithColor
86+
*/
87+
protected @Theme.BackgroundAware int mBackgroundAware;
88+
89+
/**
90+
* Minimum contrast value to generate contrast color for the background aware functionality.
91+
*/
92+
protected int mContrast;
93+
94+
public DynamicCircularProgressIndicator(@NonNull Context context) {
95+
this(context, null);
96+
}
97+
98+
public DynamicCircularProgressIndicator(@NonNull Context context, @Nullable AttributeSet attrs) {
99+
super(context, attrs);
100+
101+
loadFromAttributes(attrs);
102+
}
103+
104+
@Override
105+
public void loadFromAttributes(@Nullable AttributeSet attrs) {
106+
TypedArray a = getContext().obtainStyledAttributes(attrs,
107+
R.styleable.DynamicCircularProgressIndicator);
108+
109+
try {
110+
mColorType = a.getInt(
111+
R.styleable.DynamicCircularProgressIndicator_adt_colorType,
112+
Theme.ColorType.ACCENT);
113+
mContrastWithColorType = a.getInt(
114+
R.styleable.DynamicCircularProgressIndicator_adt_contrastWithColorType,
115+
Theme.ColorType.BACKGROUND);
116+
mColor = a.getColor(
117+
R.styleable.DynamicCircularProgressIndicator_adt_color,
118+
Theme.Color.UNKNOWN);
119+
mContrastWithColor = a.getColor(
120+
R.styleable.DynamicCircularProgressIndicator_adt_contrastWithColor,
121+
Defaults.getContrastWithColor(getContext()));
122+
mBackgroundAware = a.getInteger(
123+
R.styleable.DynamicCircularProgressIndicator_adt_backgroundAware,
124+
Defaults.getBackgroundAware());
125+
mContrast = a.getInteger(
126+
R.styleable.DynamicCircularProgressIndicator_adt_contrast,
127+
Theme.Contrast.AUTO);
128+
} finally {
129+
a.recycle();
130+
}
131+
132+
initialize();
133+
}
134+
135+
@Override
136+
public void initialize() {
137+
if (mColorType != Theme.ColorType.NONE
138+
&& mColorType != Theme.ColorType.CUSTOM) {
139+
mColor = DynamicTheme.getInstance().resolveColorType(mColorType);
140+
}
141+
142+
if (mContrastWithColorType != Theme.ColorType.NONE
143+
&& mContrastWithColorType != Theme.ColorType.CUSTOM) {
144+
mContrastWithColor = DynamicTheme.getInstance()
145+
.resolveColorType(mContrastWithColorType);
146+
}
147+
148+
setColor();
149+
}
150+
151+
@Override
152+
public @Theme.ColorType int getColorType() {
153+
return mColorType;
154+
}
155+
156+
@Override
157+
public void setColorType(@Theme.ColorType int colorType) {
158+
this.mColorType = colorType;
159+
160+
initialize();
161+
}
162+
163+
@Override
164+
public @Theme.ColorType int getContrastWithColorType() {
165+
return mContrastWithColorType;
166+
}
167+
168+
@Override
169+
public void setContrastWithColorType(@Theme.ColorType int contrastWithColorType) {
170+
this.mContrastWithColorType = contrastWithColorType;
171+
172+
initialize();
173+
}
174+
175+
@Override
176+
public @ColorInt int getColor(boolean resolve) {
177+
return resolve ? mAppliedColor : mColor;
178+
}
179+
180+
@Override
181+
public @ColorInt int getColor() {
182+
return getColor(true);
183+
}
184+
185+
@Override
186+
public void setColor(@ColorInt int color) {
187+
this.mColorType = Theme.ColorType.CUSTOM;
188+
this.mColor = color;
189+
190+
setColor();
191+
}
192+
193+
@Override
194+
public @ColorInt int getContrastWithColor() {
195+
return mContrastWithColor;
196+
}
197+
198+
@Override
199+
public void setContrastWithColor(@ColorInt int contrastWithColor) {
200+
this.mContrastWithColorType = Theme.ColorType.CUSTOM;
201+
this.mContrastWithColor = contrastWithColor;
202+
203+
setColor();
204+
}
205+
206+
@Override
207+
public @Theme.BackgroundAware int getBackgroundAware() {
208+
return mBackgroundAware;
209+
}
210+
211+
@Override
212+
public boolean isBackgroundAware() {
213+
return Dynamic.isBackgroundAware(this);
214+
}
215+
216+
@Override
217+
public void setBackgroundAware(@Theme.BackgroundAware int backgroundAware) {
218+
this.mBackgroundAware = backgroundAware;
219+
220+
setColor();
221+
}
222+
223+
@Override
224+
public int getContrast(boolean resolve) {
225+
if (resolve) {
226+
return Dynamic.getContrast(this);
227+
}
228+
229+
return mContrast;
230+
}
231+
232+
@Override
233+
public int getContrast() {
234+
return getContrast(true);
235+
}
236+
237+
@Override
238+
public float getContrastRatio() {
239+
return getContrast() / (float) Theme.Contrast.MAX;
240+
}
241+
242+
@Override
243+
public void setContrast(int contrast) {
244+
this.mContrast = contrast;
245+
246+
setBackgroundAware(getBackgroundAware());
247+
}
248+
249+
@Override
250+
public void setEnabled(boolean enabled) {
251+
super.setEnabled(enabled);
252+
253+
setAlpha(enabled ? Defaults.ADS_ALPHA_ENABLED : Defaults.ADS_ALPHA_DISABLED);
254+
}
255+
256+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
257+
@Override
258+
public void setColor() {
259+
setTrackCornerRadius(DynamicShapeUtils.getSlideCornerSize(
260+
DynamicTheme.getInstance().get().getCornerSize()));
261+
262+
if (mColor != Theme.Color.UNKNOWN) {
263+
mAppliedColor = mColor;
264+
if (isBackgroundAware() && mContrastWithColor != Theme.Color.UNKNOWN) {
265+
mAppliedColor = Dynamic.withContrastRatio(mColor, mContrastWithColor, this);
266+
}
267+
268+
setIndicatorColor(mAppliedColor);
269+
setTrackColor(DynamicColorUtils.adjustAlpha(
270+
mAppliedColor, Defaults.ADS_ALPHA_PRESSED));
271+
}
272+
}
273+
}

0 commit comments

Comments
 (0)