diff options
author | Sam Blitzstein <sblitz@google.com> | 2013-09-05 17:53:26 -0700 |
---|---|---|
committer | Sam Blitzstein <sblitz@google.com> | 2013-09-05 19:37:41 -0700 |
commit | 1f129e23db2dc5837a856f7734b15a5a8be6be94 (patch) | |
tree | 952caee82ca0ae6814f045a489d24f4fffdce7a6 | |
parent | a35f6b580aefd7bf1c7e92306e13dacd44316714 (diff) | |
download | android_frameworks_opt_datetimepicker-1f129e23db2dc5837a856f7734b15a5a8be6be94.tar.gz android_frameworks_opt_datetimepicker-1f129e23db2dc5837a856f7734b15a5a8be6be94.tar.bz2 android_frameworks_opt_datetimepicker-1f129e23db2dc5837a856f7734b15a5a8be6be94.zip |
Add setDarkTheme() to TimePicker.
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
-rw-r--r-- | res/color/done_text_color.xml | 2 | ||||
-rw-r--r-- | res/color/done_text_color_dark.xml | 21 | ||||
-rw-r--r-- | res/drawable-land/done_background_color.xml | 25 | ||||
-rw-r--r-- | res/drawable-land/done_background_color_dark.xml | 25 | ||||
-rw-r--r-- | res/drawable/done_background_color.xml | 25 | ||||
-rw-r--r-- | res/drawable/done_background_color_dark.xml | 25 | ||||
-rw-r--r-- | res/layout-land/time_picker_dialog.xml | 23 | ||||
-rw-r--r-- | res/layout/time_header_label.xml | 1 | ||||
-rw-r--r-- | res/layout/time_picker_dialog.xml | 26 | ||||
-rw-r--r-- | res/values/colors.xml | 23 | ||||
-rw-r--r-- | src/com/android/datetimepicker/Utils.java | 7 | ||||
-rw-r--r-- | src/com/android/datetimepicker/time/AmPmCirclesView.java | 53 | ||||
-rw-r--r-- | src/com/android/datetimepicker/time/CircleView.java | 23 | ||||
-rw-r--r-- | src/com/android/datetimepicker/time/RadialPickerLayout.java | 14 | ||||
-rw-r--r-- | src/com/android/datetimepicker/time/RadialSelectorView.java | 26 | ||||
-rw-r--r-- | src/com/android/datetimepicker/time/RadialTextsView.java | 11 | ||||
-rw-r--r-- | src/com/android/datetimepicker/time/TimePickerDialog.java | 59 |
17 files changed, 319 insertions, 70 deletions
diff --git a/res/color/done_text_color.xml b/res/color/done_text_color.xml index e6e55ed..85d0e9e 100644 --- a/res/color/done_text_color.xml +++ b/res/color/done_text_color.xml @@ -16,6 +16,6 @@ <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="false" android:color="@color/done_text_color_disabled"/> - <item android:state_enabled="true" android:color="@color/done_text_color_normal"/> + <item android:color="@color/done_text_color_normal"/> </selector>
\ No newline at end of file diff --git a/res/color/done_text_color_dark.xml b/res/color/done_text_color_dark.xml new file mode 100644 index 0000000..070baf2 --- /dev/null +++ b/res/color/done_text_color_dark.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2013 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. +--> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + + <item android:state_enabled="false" android:color="@color/done_text_color_dark_disabled"/> + <item android:color="@color/done_text_color_dark_normal"/> + +</selector>
\ No newline at end of file diff --git a/res/drawable-land/done_background_color.xml b/res/drawable-land/done_background_color.xml new file mode 100644 index 0000000..b2acf46 --- /dev/null +++ b/res/drawable-land/done_background_color.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2013 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. +--> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_focused="true" + android:state_pressed="false" + android:drawable="@color/blue_focused" /> + + <item android:state_pressed="true" + android:drawable="@color/blue" /> + + <item android:drawable="@color/white" /> +</selector>
\ No newline at end of file diff --git a/res/drawable-land/done_background_color_dark.xml b/res/drawable-land/done_background_color_dark.xml new file mode 100644 index 0000000..8e499e4 --- /dev/null +++ b/res/drawable-land/done_background_color_dark.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2013 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. +--> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_focused="true" + android:state_pressed="false" + android:drawable="@color/red_focused" /> + + <item android:state_pressed="true" + android:drawable="@color/red" /> + + <item android:drawable="@color/dark_gray" /> +</selector>
\ No newline at end of file diff --git a/res/drawable/done_background_color.xml b/res/drawable/done_background_color.xml new file mode 100644 index 0000000..19a3861 --- /dev/null +++ b/res/drawable/done_background_color.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2013 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. +--> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_focused="true" + android:state_pressed="false" + android:drawable="@color/blue_focused" /> + + <item android:state_pressed="true" + android:drawable="@color/blue" /> + + <item android:drawable="@color/circle_background" /> +</selector>
\ No newline at end of file diff --git a/res/drawable/done_background_color_dark.xml b/res/drawable/done_background_color_dark.xml new file mode 100644 index 0000000..1665eee --- /dev/null +++ b/res/drawable/done_background_color_dark.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2013 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. +--> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_focused="true" + android:state_pressed="false" + android:drawable="@color/red_focused" /> + + <item android:state_pressed="true" + android:drawable="@color/red" /> + + <item android:drawable="@color/light_gray" /> +</selector>
\ No newline at end of file diff --git a/res/layout-land/time_picker_dialog.xml b/res/layout-land/time_picker_dialog.xml index b24daf3..ed167af 100644 --- a/res/layout-land/time_picker_dialog.xml +++ b/res/layout-land/time_picker_dialog.xml @@ -29,6 +29,7 @@ android:layout_height="match_parent" android:orientation="vertical"> <FrameLayout + android:id="@+id/time_display_background" android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1" @@ -40,25 +41,19 @@ android:layout_gravity="center" /> </FrameLayout> <View + android:id="@+id/line" android:layout_width="match_parent" android:layout_height="1dip" android:background="@color/line_background" /> - <LinearLayout - style="?android:attr/buttonBarStyle" + <Button + android:id="@+id/done_button" + android:background="@drawable/done_background_color" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal" - android:background="@color/white" > - <Button - android:id="@+id/done_button" - style="?android:attr/buttonBarButtonStyle" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:minHeight="48dp" - android:text="@string/done_label" - android:textSize="@dimen/done_label_size" - android:textColor="@color/done_text_color" /> - </LinearLayout> + android:minHeight="48dp" + android:text="@string/done_label" + android:textSize="@dimen/done_label_size" + android:textColor="@color/done_text_color" /> </LinearLayout> <com.android.datetimepicker.time.RadialPickerLayout android:id="@+id/time_picker" diff --git a/res/layout/time_header_label.xml b/res/layout/time_header_label.xml index cd4a834..56776ad 100644 --- a/res/layout/time_header_label.xml +++ b/res/layout/time_header_label.xml @@ -15,6 +15,7 @@ ~ limitations under the License --> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/time_display" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" diff --git a/res/layout/time_picker_dialog.xml b/res/layout/time_picker_dialog.xml index b4d2d1c..24b18c9 100644 --- a/res/layout/time_picker_dialog.xml +++ b/res/layout/time_picker_dialog.xml @@ -15,13 +15,13 @@ ~ limitations under the License --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/time_picker_dialog" android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical" - android:background="@color/circle_background" - android:id="@+id/time_picker_dialog" android:focusable="true" > <FrameLayout + android:id="@+id/time_display_background" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white" > @@ -36,25 +36,21 @@ android:layout_height="@dimen/picker_dimen" android:layout_width="wrap_content" android:layout_gravity="center" + android:background="@color/circle_background" android:focusable="true" android:focusableInTouchMode="true" /> <View + android:id="@+id/line" android:layout_width="match_parent" android:layout_height="1dip" android:background="@color/line_background" /> - <LinearLayout - style="?android:attr/buttonBarStyle" + <Button + android:id="@+id/done_button" + android:background="@drawable/done_background_color" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal" > - <Button - android:id="@+id/done_button" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:minHeight="48dp" - android:text="@string/done_label" - android:textSize="@dimen/done_label_size" - android:textColor="@color/done_text_color" - style="?android:attr/buttonBarButtonStyle" /> - </LinearLayout> + android:minHeight="48dp" + android:text="@string/done_label" + android:textSize="@dimen/done_label_size" + android:textColor="@color/done_text_color" /> </LinearLayout> diff --git a/res/values/colors.xml b/res/values/colors.xml index ec1d495..8d92b47 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -20,16 +20,27 @@ <color name="circle_background">#f2f2f2</color> <color name="line_background">#cccccc</color> <color name="ampm_text_color">#8c8c8c</color> - <color name="done_text_color_normal">#333333</color> - <color name="done_text_color_disabled">#CCCCCC</color> + <color name="done_text_color_normal">#000000</color> + <color name="done_text_color_disabled">#cccccc</color> <color name="numbers_text_color">#8c8c8c</color> - <color name="transparent_black">#7F000000</color> + <color name="transparent_black">#7f000000</color> <color name="blue">#33b5e5</color> - <color name="darker_blue">#0099CC</color> - <color name="date_picker_text_normal">#FF999999</color> + <color name="blue_focused">#c1e8f7</color> + <color name="darker_blue">#0099cc</color> + <color name="date_picker_text_normal">#ff999999</color> <color name="calendar_header">#999999</color> <color name="date_picker_view_animator">#f2f2f2</color> - <color name="calendar_selected_date_text">#FFD1D2D4</color> + <color name="calendar_selected_date_text">#ffd1d2d4</color> + + <!-- Colors for red theme --> + <color name="red">#ff3333</color> + <color name="red_focused">#853333</color> + <color name="light_gray">#404040</color> + <color name="dark_gray">#363636</color> + <color name="line_dark">#808080</color> + <color name="done_text_color_dark_normal">#ffffff</color> + <color name="done_text_color_dark_disabled">#888888</color> + <color name="done_disabled_dark">#bfbfbf</color> </resources>
\ No newline at end of file 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]); } |