Skip to content

Commit

Permalink
[TimePicker] Use MaterialColors to correctly read CSLs with theme att…
Browse files Browse the repository at this point in the history
…ributes

PiperOrigin-RevId: 345068246
(cherry picked from commit 9f79157)
  • Loading branch information
ymarian authored and dsn5ft committed Dec 15, 2020
1 parent f7c4056 commit 9c9e6c4
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/java/com/google/android/material/timepicker/ClockFaceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import com.google.android.material.resources.MaterialResources;
import com.google.android.material.timepicker.ClockHandView.OnRotateListener;

/**
Expand Down Expand Up @@ -95,7 +96,9 @@ public ClockFaceView(@NonNull Context context, @Nullable AttributeSet attrs, int
defStyleAttr,
R.style.Widget_MaterialComponents_TimePicker_Clock);
Resources res = getResources();
textColor = a.getColorStateList(R.styleable.ClockFaceView_clockNumberTextColor);
textColor =
MaterialResources.getColorStateList(
context, a, R.styleable.ClockFaceView_clockNumberTextColor);
LayoutInflater.from(context).inflate(R.layout.material_clockface_view, this, true);
clockHandView = findViewById(R.id.material_clock_hand);
clockHandPadding = res.getDimensionPixelSize(R.dimen.material_clock_hand_padding);
Expand All @@ -106,12 +109,16 @@ public ClockFaceView(@NonNull Context context, @Nullable AttributeSet attrs, int
new int[] {clockHandTextColor, clockHandTextColor, textColor.getDefaultColor()};
clockHandView.addOnRotateListener(this);

int backgroundColor =
a.getColor(
R.styleable.ClockFaceView_clockFaceBackgroundColor,
AppCompatResources.getColorStateList(context, R.color.material_timepicker_clockface)
.getDefaultColor());
setBackgroundColor(backgroundColor);
int defaultBackgroundColor = AppCompatResources
.getColorStateList(context, R.color.material_timepicker_clockface)
.getDefaultColor();

ColorStateList backgroundColor =
MaterialResources.getColorStateList(
context, a, R.styleable.ClockFaceView_clockFaceBackgroundColor);

setBackgroundColor(
backgroundColor == null ? defaultBackgroundColor : backgroundColor.getDefaultColor());

getViewTreeObserver()
.addOnPreDrawListener(
Expand Down

0 comments on commit 9c9e6c4

Please sign in to comment.