summaryrefslogtreecommitdiff
path: root/src/com
diff options
context:
space:
mode:
authorSam Blitzstein <sblitz@google.com>2013-09-05 17:53:26 -0700
committerSam Blitzstein <sblitz@google.com>2013-09-05 19:37:41 -0700
commit1f129e23db2dc5837a856f7734b15a5a8be6be94 (patch)
tree952caee82ca0ae6814f045a489d24f4fffdce7a6 /src/com
parenta35f6b580aefd7bf1c7e92306e13dacd44316714 (diff)
downloaddatetimepicker-1f129e23db2dc5837a856f7734b15a5a8be6be94.tar.gz
Add setDarkTheme() to TimePicker.android-4.4_r0.7
This is just a temporary solution for the clock app. When the pickers are framework-ready they will use the correct system-level factory methods for setting dark themes. Bug: 10516092 Change-Id: I0574de6f79f0d2973a80ea91bcc885e207f2fcf8
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/datetimepicker/Utils.java7
-rw-r--r--src/com/android/datetimepicker/time/AmPmCirclesView.java53
-rw-r--r--src/com/android/datetimepicker/time/CircleView.java23
-rw-r--r--src/com/android/datetimepicker/time/RadialPickerLayout.java14
-rw-r--r--src/com/android/datetimepicker/time/RadialSelectorView.java26
-rw-r--r--src/com/android/datetimepicker/time/RadialTextsView.java11
-rw-r--r--src/com/android/datetimepicker/time/TimePickerDialog.java59
7 files changed, 159 insertions, 34 deletions
diff --git a/src/com/android/datetimepicker/Utils.java b/src/com/android/datetimepicker/Utils.java
index ac603bc..4a3110c 100644
--- a/src/com/android/datetimepicker/Utils.java
+++ b/src/com/android/datetimepicker/Utils.java
@@ -34,6 +34,13 @@ public class Utils {
public static final int MONDAY_BEFORE_JULIAN_EPOCH = Time.EPOCH_JULIAN_DAY - 3;
public static final int PULSE_ANIMATOR_DURATION = 544;
+ // Alpha level for time picker selection.
+ public static final int SELECTED_ALPHA = 51;
+ public static final int SELECTED_ALPHA_THEME_DARK = 102;
+ // Alpha level for fully opaque.
+ public static final int FULL_ALPHA = 255;
+
+
static final String SHARED_PREFS_NAME = "com.android.calendar_preferences";
public static boolean isJellybeanOrLater() {
diff --git a/src/com/android/datetimepicker/time/AmPmCirclesView.java b/src/com/android/datetimepicker/time/AmPmCirclesView.java
index 8221365..c62aebf 100644
--- a/src/com/android/datetimepicker/time/AmPmCirclesView.java
+++ b/src/com/android/datetimepicker/time/AmPmCirclesView.java
@@ -26,6 +26,7 @@ import android.util.Log;
import android.view.View;
import com.android.datetimepicker.R;
+import com.android.datetimepicker.Utils;
import java.text.DateFormatSymbols;
@@ -35,15 +36,15 @@ import java.text.DateFormatSymbols;
public class AmPmCirclesView extends View {
private static final String TAG = "AmPmCirclesView";
- // Alpha level of blue color for selected circle.
- private static final int SELECTED_ALPHA = 51;
- // Alpha level of blue color for pressed circle.
- private static final int PRESSED_ALPHA = 175;
+ // Alpha level for selected circle.
+ private static final int SELECTED_ALPHA = Utils.SELECTED_ALPHA;
+ private static final int SELECTED_ALPHA_THEME_DARK = Utils.SELECTED_ALPHA_THEME_DARK;
private final Paint mPaint = new Paint();
- private int mWhite;
+ private int mSelectedAlpha;
+ private int mUnselectedColor;
private int mAmPmTextColor;
- private int mBlue;
+ private int mSelectedColor;
private float mCircleRadiusMultiplier;
private float mAmPmCircleRadiusMultiplier;
private String mAmText;
@@ -73,9 +74,10 @@ public class AmPmCirclesView extends View {
}
Resources res = context.getResources();
- mWhite = res.getColor(R.color.white);
+ mUnselectedColor = res.getColor(R.color.white);
+ mSelectedColor = res.getColor(R.color.blue);
mAmPmTextColor = res.getColor(R.color.ampm_text_color);
- mBlue = res.getColor(R.color.blue);
+ mSelectedAlpha = SELECTED_ALPHA;
String typefaceFamily = res.getString(R.string.sans_serif);
Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL);
mPaint.setTypeface(tf);
@@ -96,6 +98,21 @@ public class AmPmCirclesView extends View {
mIsInitialized = true;
}
+ /* package */ void setTheme(Context context, boolean themeDark) {
+ Resources res = context.getResources();
+ if (themeDark) {
+ mUnselectedColor = res.getColor(R.color.dark_gray);
+ mSelectedColor = res.getColor(R.color.red);
+ mAmPmTextColor = res.getColor(R.color.white);
+ mSelectedAlpha = SELECTED_ALPHA_THEME_DARK;
+ } else {
+ mUnselectedColor = res.getColor(R.color.white);
+ mSelectedColor = res.getColor(R.color.blue);
+ mAmPmTextColor = res.getColor(R.color.ampm_text_color);
+ mSelectedAlpha = SELECTED_ALPHA;
+ }
+ }
+
public void setAmOrPm(int amOrPm) {
mAmOrPm = amOrPm;
}
@@ -158,23 +175,23 @@ public class AmPmCirclesView extends View {
// We'll need to draw either a lighter blue (for selection), a darker blue (for touching)
// or white (for not selected).
- int amColor = mWhite;
+ int amColor = mUnselectedColor;
int amAlpha = 255;
- int pmColor = mWhite;
+ int pmColor = mUnselectedColor;
int pmAlpha = 255;
if (mAmOrPm == AM) {
- amColor = mBlue;
- amAlpha = SELECTED_ALPHA;
+ amColor = mSelectedColor;
+ amAlpha = mSelectedAlpha;
} else if (mAmOrPm == PM) {
- pmColor = mBlue;
- pmAlpha = SELECTED_ALPHA;
+ pmColor = mSelectedColor;
+ pmAlpha = mSelectedAlpha;
}
if (mAmOrPmPressed == AM) {
- amColor = mBlue;
- amAlpha = PRESSED_ALPHA;
+ amColor = mSelectedColor;
+ amAlpha = mSelectedAlpha;
} else if (mAmOrPmPressed == PM) {
- pmColor = mBlue;
- pmAlpha = PRESSED_ALPHA;
+ pmColor = mSelectedColor;
+ pmAlpha = mSelectedAlpha;
}
// Draw the two circles.
diff --git a/src/com/android/datetimepicker/time/CircleView.java b/src/com/android/datetimepicker/time/CircleView.java
index 89b577a..549db42 100644
--- a/src/com/android/datetimepicker/time/CircleView.java
+++ b/src/com/android/datetimepicker/time/CircleView.java
@@ -33,8 +33,8 @@ public class CircleView extends View {
private final Paint mPaint = new Paint();
private boolean mIs24HourMode;
- private int mWhite;
- private int mBlack;
+ private int mCircleColor;
+ private int mDotColor;
private float mCircleRadiusMultiplier;
private float mAmPmCircleRadiusMultiplier;
private boolean mIsInitialized;
@@ -48,8 +48,8 @@ public class CircleView extends View {
super(context);
Resources res = context.getResources();
- mWhite = res.getColor(R.color.white);
- mBlack = res.getColor(R.color.numbers_text_color);
+ mCircleColor = res.getColor(R.color.white);
+ mDotColor = res.getColor(R.color.numbers_text_color);
mPaint.setAntiAlias(true);
mIsInitialized = false;
@@ -76,6 +76,17 @@ public class CircleView extends View {
mIsInitialized = true;
}
+ /* package */ void setTheme(Context context, boolean dark) {
+ Resources res = context.getResources();
+ if (dark) {
+ mCircleColor = res.getColor(R.color.dark_gray);
+ mDotColor = res.getColor(R.color.light_gray);
+ } else {
+ mCircleColor = res.getColor(R.color.white);
+ mDotColor = res.getColor(R.color.numbers_text_color);
+ }
+ }
+
@Override
public void onDraw(Canvas canvas) {
@@ -101,11 +112,11 @@ public class CircleView extends View {
}
// Draw the white circle.
- mPaint.setColor(mWhite);
+ mPaint.setColor(mCircleColor);
canvas.drawCircle(mXCenter, mYCenter, mCircleRadius, mPaint);
// Draw a small black circle in the center.
- mPaint.setColor(mBlack);
+ mPaint.setColor(mDotColor);
canvas.drawCircle(mXCenter, mYCenter, 2, mPaint);
}
}
diff --git a/src/com/android/datetimepicker/time/RadialPickerLayout.java b/src/com/android/datetimepicker/time/RadialPickerLayout.java
index 71b1740..0f53bc4 100644
--- a/src/com/android/datetimepicker/time/RadialPickerLayout.java
+++ b/src/com/android/datetimepicker/time/RadialPickerLayout.java
@@ -41,6 +41,11 @@ import android.widget.FrameLayout;
import com.android.datetimepicker.HapticFeedbackController;
import com.android.datetimepicker.R;
+/**
+ * The primary layout to hold the circular picker, and the am/pm buttons. This view well measure
+ * itself to end up as a square. It also handles touches to be passed in to views that need to know
+ * when they'd been touched.
+ */
public class RadialPickerLayout extends FrameLayout implements OnTouchListener {
private static final String TAG = "RadialPickerLayout";
@@ -214,6 +219,15 @@ public class RadialPickerLayout extends FrameLayout implements OnTouchListener {
mTimeInitialized = true;
}
+ /* package */ void setTheme(Context context, boolean themeDark) {
+ mCircleView.setTheme(context, themeDark);
+ mAmPmCirclesView.setTheme(context, themeDark);
+ mHourRadialTextsView.setTheme(context, themeDark);
+ mMinuteRadialTextsView.setTheme(context, themeDark);
+ mHourRadialSelectorView.setTheme(context, themeDark);
+ mMinuteRadialSelectorView.setTheme(context, themeDark);
+ }
+
public void setTime(int hours, int minutes) {
setItem(HOUR_INDEX, hours);
setItem(MINUTE_INDEX, minutes);
diff --git a/src/com/android/datetimepicker/time/RadialSelectorView.java b/src/com/android/datetimepicker/time/RadialSelectorView.java
index d987e7b..0339dcd 100644
--- a/src/com/android/datetimepicker/time/RadialSelectorView.java
+++ b/src/com/android/datetimepicker/time/RadialSelectorView.java
@@ -29,6 +29,7 @@ import android.util.Log;
import android.view.View;
import com.android.datetimepicker.R;
+import com.android.datetimepicker.Utils;
/**
* View to show what number is selected. This will draw a blue circle over the number, with a blue
@@ -37,6 +38,12 @@ import com.android.datetimepicker.R;
public class RadialSelectorView extends View {
private static final String TAG = "RadialSelectorView";
+ // Alpha level for selected circle.
+ private static final int SELECTED_ALPHA = Utils.SELECTED_ALPHA;
+ private static final int SELECTED_ALPHA_THEME_DARK = Utils.SELECTED_ALPHA_THEME_DARK;
+ // Alpha level for the line.
+ private static final int FULL_ALPHA = Utils.FULL_ALPHA;
+
private final Paint mPaint = new Paint();
private boolean mIsInitialized;
@@ -51,6 +58,7 @@ public class RadialSelectorView extends View {
private float mAnimationRadiusMultiplier;
private boolean mIs24HourMode;
private boolean mHasInnerCircle;
+ private int mSelectionAlpha;
private int mXCenter;
private int mYCenter;
@@ -95,6 +103,7 @@ public class RadialSelectorView extends View {
int blue = res.getColor(R.color.blue);
mPaint.setColor(blue);
mPaint.setAntiAlias(true);
+ mSelectionAlpha = SELECTED_ALPHA;
// Calculate values for the circle radius size.
mIs24HourMode = is24HourMode;
@@ -132,6 +141,19 @@ public class RadialSelectorView extends View {
mIsInitialized = true;
}
+ /* package */ void setTheme(Context context, boolean themeDark) {
+ Resources res = context.getResources();
+ int color;
+ if (themeDark) {
+ color = res.getColor(R.color.red);
+ mSelectionAlpha = SELECTED_ALPHA_THEME_DARK;
+ } else {
+ color = res.getColor(R.color.blue);
+ mSelectionAlpha = SELECTED_ALPHA;
+ }
+ mPaint.setColor(color);
+ }
+
/**
* Set the selection.
* @param selectionDegrees The degrees to be selected.
@@ -277,12 +299,12 @@ public class RadialSelectorView extends View {
int pointY = mYCenter - (int) (mLineLength * Math.cos(mSelectionRadians));
// Draw the selection circle.
- mPaint.setAlpha(51);
+ mPaint.setAlpha(mSelectionAlpha);
canvas.drawCircle(pointX, pointY, mSelectionRadius, mPaint);
if (mForceDrawDot | mSelectionDegrees % 30 != 0) {
// We're not on a direct tick (or we've been told to draw the dot anyway).
- mPaint.setAlpha(255);
+ mPaint.setAlpha(FULL_ALPHA);
canvas.drawCircle(pointX, pointY, (mSelectionRadius * 2 / 7), mPaint);
} else {
// We're not drawing the dot, so shorten the line to only go as far as the edge of the
diff --git a/src/com/android/datetimepicker/time/RadialTextsView.java b/src/com/android/datetimepicker/time/RadialTextsView.java
index ea59ec6..9acc8c5 100644
--- a/src/com/android/datetimepicker/time/RadialTextsView.java
+++ b/src/com/android/datetimepicker/time/RadialTextsView.java
@@ -143,6 +143,17 @@ public class RadialTextsView extends View {
mIsInitialized = true;
}
+ /* package */ void setTheme(Context context, boolean themeDark) {
+ Resources res = context.getResources();
+ int textColor;
+ if (themeDark) {
+ textColor = res.getColor(R.color.white);
+ } else {
+ textColor = res.getColor(R.color.numbers_text_color);
+ }
+ mPaint.setColor(textColor);
+ }
+
/**
* Allows for smoother animation.
*/
diff --git a/src/com/android/datetimepicker/time/TimePickerDialog.java b/src/com/android/datetimepicker/time/TimePickerDialog.java
index 953f03d..6e585b5 100644
--- a/src/com/android/datetimepicker/time/TimePickerDialog.java
+++ b/src/com/android/datetimepicker/time/TimePickerDialog.java
@@ -20,6 +20,8 @@ import android.animation.ObjectAnimator;
import android.app.ActionBar.LayoutParams;
import android.app.DialogFragment;
import android.content.Context;
+import android.content.res.ColorStateList;
+import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
@@ -55,6 +57,7 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL
private static final String KEY_CURRENT_ITEM_SHOWING = "current_item_showing";
private static final String KEY_IN_KB_MODE = "in_kb_mode";
private static final String KEY_TYPED_TIMES = "typed_times";
+ private static final String KEY_DARK_THEME = "dark_theme";
public static final int HOUR_INDEX = 0;
public static final int MINUTE_INDEX = 1;
@@ -81,8 +84,8 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL
private View mAmPmHitspace;
private RadialPickerLayout mTimePicker;
- private int mBlue;
- private int mBlack;
+ private int mSelectedColor;
+ private int mUnselectedColor;
private String mAmText;
private String mPmText;
@@ -90,6 +93,7 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL
private int mInitialHourOfDay;
private int mInitialMinute;
private boolean mIs24HourMode;
+ private boolean mThemeDark;
// For hardware IME input.
private char mPlaceholderText;
@@ -145,6 +149,18 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL
mInitialMinute = minute;
mIs24HourMode = is24HourMode;
mInKbMode = false;
+ mThemeDark = false;
+ }
+
+ /**
+ * Set a dark or light theme. NOTE: this will only take effect for the next onCreateView.
+ */
+ public void setThemeDark(boolean dark) {
+ mThemeDark = dark;
+ }
+
+ public boolean isThemeDark() {
+ return mThemeDark;
}
public void setOnTimeSetListener(OnTimeSetListener callback) {
@@ -167,6 +183,7 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL
mInitialMinute = savedInstanceState.getInt(KEY_MINUTE);
mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW);
mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE);
+ mThemeDark = savedInstanceState.getBoolean(KEY_DARK_THEME);
}
}
@@ -184,8 +201,8 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL
mSelectHours = res.getString(R.string.select_hours);
mMinutePickerDescription = res.getString(R.string.minute_picker_description);
mSelectMinutes = res.getString(R.string.select_minutes);
- mBlue = res.getColor(R.color.blue);
- mBlack = res.getColor(R.color.numbers_text_color);
+ mSelectedColor = res.getColor(mThemeDark? R.color.red : R.color.blue);
+ mUnselectedColor = res.getColor(mThemeDark? R.color.white : R.color.numbers_text_color);
mHourView = (TextView) view.findViewById(R.id.hours);
mHourView.setOnKeyListener(keyboardListener);
@@ -295,6 +312,31 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL
mTypedTimes = new ArrayList<Integer>();
}
+ // Set the theme at the end so that the initialize()s above don't counteract the theme.
+ mTimePicker.setTheme(getActivity().getApplicationContext(), mThemeDark);
+ // Prepare some colors to use.
+ int white = res.getColor(R.color.white);
+ int circleBackground = res.getColor(R.color.circle_background);
+ int line = res.getColor(R.color.line_background);
+ int timeDisplay = res.getColor(R.color.numbers_text_color);
+ ColorStateList doneTextColor = res.getColorStateList(R.color.done_text_color);
+ int doneBackground = R.drawable.done_background_color;
+
+ int darkGray = res.getColor(R.color.dark_gray);
+ int lightGray = res.getColor(R.color.light_gray);
+ int darkLine = res.getColor(R.color.line_dark);
+ ColorStateList darkDoneTextColor = res.getColorStateList(R.color.done_text_color_dark);
+ int darkDoneBackground = R.drawable.done_background_color_dark;
+
+ // Set the colors for each view based on the theme.
+ view.findViewById(R.id.time_display_background).setBackgroundColor(mThemeDark? darkGray : white);
+ view.findViewById(R.id.time_display).setBackgroundColor(mThemeDark? darkGray : white);
+ ((TextView) view.findViewById(R.id.separator)).setTextColor(mThemeDark? white : timeDisplay);
+ ((TextView) view.findViewById(R.id.ampm_label)).setTextColor(mThemeDark? white : timeDisplay);
+ view.findViewById(R.id.line).setBackgroundColor(mThemeDark? darkLine : line);
+ mDoneButton.setTextColor(mThemeDark? darkDoneTextColor : doneTextColor);
+ mTimePicker.setBackgroundColor(mThemeDark? lightGray : circleBackground);
+ mDoneButton.setBackgroundResource(mThemeDark? darkDoneBackground : doneBackground);
return view;
}
@@ -339,6 +381,7 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL
if (mInKbMode) {
outState.putIntegerArrayList(KEY_TYPED_TIMES, mTypedTimes);
}
+ outState.putBoolean(KEY_DARK_THEME, mThemeDark);
}
}
@@ -426,8 +469,8 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL
labelToAnimate = mMinuteView;
}
- int hourColor = (index == HOUR_INDEX)? mBlue : mBlack;
- int minuteColor = (index == MINUTE_INDEX)? mBlue : mBlack;
+ int hourColor = (index == HOUR_INDEX)? mSelectedColor : mUnselectedColor;
+ int minuteColor = (index == MINUTE_INDEX)? mSelectedColor : mUnselectedColor;
mHourView.setTextColor(hourColor);
mMinuteView.setTextColor(minuteColor);
@@ -643,10 +686,10 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL
String.format(minuteFormat, values[1]).replace(' ', mPlaceholderText);
mHourView.setText(hourStr);
mHourSpaceView.setText(hourStr);
- mHourView.setTextColor(mBlack);
+ mHourView.setTextColor(mUnselectedColor);
mMinuteView.setText(minuteStr);
mMinuteSpaceView.setText(minuteStr);
- mMinuteView.setTextColor(mBlack);
+ mMinuteView.setTextColor(mUnselectedColor);
if (!mIs24HourMode) {
updateAmPmDisplay(values[2]);
}