summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Kover <dkover@cyngn.com>2015-05-07 17:31:19 -0700
committerClark Scheff <clark@cyngn.com>2016-01-18 15:48:45 -0800
commit03244050a316335e06cad0e6df339b6bcbf772df (patch)
tree547acba28b7d36811c013c14cc080629999c96d1
parente6065f8409b59b18707cf5e80ec117688021e175 (diff)
downloadandroid_packages_apps_DeskClock-03244050a316335e06cad0e6df339b6bcbf772df.tar.gz
android_packages_apps_DeskClock-03244050a316335e06cad0e6df339b6bcbf772df.tar.bz2
android_packages_apps_DeskClock-03244050a316335e06cad0e6df339b6bcbf772df.zip
Expose background colors for theming.
The background colors are currently defined as a hard coded array in Utils.java. This patch moves this array to cm_arrays.xml and exposes the colors of the array in cm_colors.xml for theming Ticket: KOV-14 Change-Id: Id72867ee82edd28bc120223be96c34448d79f1ae (cherry picked from commit ef62c1a92eb6f02e78f8501ddca25ce0ed613132)
-rw-r--r--res/values/cm_arrays.xml30
-rw-r--r--res/values/cm_colors.xml45
-rw-r--r--src/com/android/deskclock/AlarmClockFragment.java4
-rw-r--r--src/com/android/deskclock/BaseActivity.java6
-rw-r--r--src/com/android/deskclock/Utils.java47
-rw-r--r--src/com/android/deskclock/alarms/AlarmActivity.java2
6 files changed, 96 insertions, 38 deletions
diff --git a/res/values/cm_arrays.xml b/res/values/cm_arrays.xml
index e0e92a42f..af32189b8 100644
--- a/res/values/cm_arrays.xml
+++ b/res/values/cm_arrays.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- Copyright (C) 2012-2015 The CyanogenMod Project
+ Copyright (C) 2012-2016 The CyanogenMod Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -22,4 +22,32 @@
<item>@string/action_summary_dismiss</item>
<item>@string/action_summary_do_nothing</item>
</string-array>
+
+ <array name="background_color_by_hour">
+ <item>@color/hour_00</item>
+ <item>@color/hour_01</item>
+ <item>@color/hour_02</item>
+ <item>@color/hour_03</item>
+ <item>@color/hour_04</item>
+ <item>@color/hour_05</item>
+ <item>@color/hour_06</item>
+ <item>@color/hour_07</item>
+ <item>@color/hour_08</item>
+ <item>@color/hour_09</item>
+ <item>@color/hour_10</item>
+ <item>@color/hour_11</item>
+ <item>@color/hour_12</item>
+ <item>@color/hour_13</item>
+ <item>@color/hour_14</item>
+ <item>@color/hour_15</item>
+ <item>@color/hour_16</item>
+ <item>@color/hour_17</item>
+ <item>@color/hour_18</item>
+ <item>@color/hour_19</item>
+ <item>@color/hour_20</item>
+ <item>@color/hour_21</item>
+ <item>@color/hour_22</item>
+ <item>@color/hour_23</item>
+ </array>
+
</resources>
diff --git a/res/values/cm_colors.xml b/res/values/cm_colors.xml
new file mode 100644
index 000000000..b318bdfe2
--- /dev/null
+++ b/res/values/cm_colors.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2015 The CyanogenMod 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.
+-->
+<resources>
+
+ <!--- Colors modify the background of the clock and change hourly -->
+ <color name="hour_00">#212121</color><!-- Midnight -->
+ <color name="hour_01">#27232e</color>
+ <color name="hour_02">#2d253a</color>
+ <color name="hour_03">#332847</color>
+ <color name="hour_04">#382a53</color>
+ <color name="hour_05">#3e2c5f</color>
+ <color name="hour_06">#442e6c</color>
+ <color name="hour_07">#393a7a</color>
+ <color name="hour_08">#2e4687</color>
+ <color name="hour_09">#235395</color>
+ <color name="hour_10">#185fa2</color>
+ <color name="hour_11">#0d6baf</color>
+ <color name="hour_12">#0277bd</color><!-- Noon -->
+ <color name="hour_13">#0d6cb1</color>
+ <color name="hour_14">#1861a6</color>
+ <color name="hour_15">#23569b</color>
+ <color name="hour_16">#2d4a8f</color>
+ <color name="hour_17">#383f84</color>
+ <color name="hour_18">#433478</color>
+ <color name="hour_19">#3d3169</color>
+ <color name="hour_20">#382e5b</color>
+ <color name="hour_21">#322b4d</color>
+ <color name="hour_22">#2c273e</color>
+ <color name="hour_23">#272430</color>
+
+</resources>
diff --git a/src/com/android/deskclock/AlarmClockFragment.java b/src/com/android/deskclock/AlarmClockFragment.java
index 29d5cec8d..aa6a55618 100644
--- a/src/com/android/deskclock/AlarmClockFragment.java
+++ b/src/com/android/deskclock/AlarmClockFragment.java
@@ -980,7 +980,7 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements
}
private int getTintedBackgroundColor() {
- final int c = Utils.getCurrentHourColor();
+ final int c = Utils.getCurrentHourColor(getActivity());
final int red = Color.red(c) + (int) (TINTED_LEVEL * (255 - Color.red(c)));
final int green = Color.green(c) + (int) (TINTED_LEVEL * (255 - Color.green(c)));
final int blue = Color.blue(c) + (int) (TINTED_LEVEL * (255 - Color.blue(c)));
@@ -1193,7 +1193,7 @@ public abstract class AlarmClockFragment extends DeskClockFragment implements
final CompoundButton dayButton = holder.dayButtons[dayIndex];
dayButton.setActivated(true);
dayButton.setChecked(true);
- dayButton.setTextColor(Utils.getCurrentHourColor());
+ dayButton.setTextColor(Utils.getCurrentHourColor(getActivity()));
}
diff --git a/src/com/android/deskclock/BaseActivity.java b/src/com/android/deskclock/BaseActivity.java
index 4b72d80f8..58a0a3637 100644
--- a/src/com/android/deskclock/BaseActivity.java
+++ b/src/com/android/deskclock/BaseActivity.java
@@ -55,7 +55,7 @@ public class BaseActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- final int currentColor = Utils.getCurrentHourColor();
+ final int currentColor = Utils.getCurrentHourColor(this);
final int backgroundColor = savedInstanceState == null ? currentColor
: savedInstanceState.getInt(KEY_BACKGROUND_COLOR, currentColor);
setBackgroundColor(backgroundColor, false /* animate */);
@@ -74,13 +74,13 @@ public class BaseActivity extends AppCompatActivity {
registerReceiver(mOnTimeChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- setBackgroundColor(Utils.getCurrentHourColor(), true /* animate */);
+ setBackgroundColor(Utils.getCurrentHourColor(BaseActivity.this), true /* animate */);
}
}, filter);
}
// Ensure the background color is up-to-date.
- setBackgroundColor(Utils.getCurrentHourColor(), true /* animate */);
+ setBackgroundColor(Utils.getCurrentHourColor(this), true /* animate */);
}
@Override
diff --git a/src/com/android/deskclock/Utils.java b/src/com/android/deskclock/Utils.java
index 046df5444..6d0f7251c 100644
--- a/src/com/android/deskclock/Utils.java
+++ b/src/com/android/deskclock/Utils.java
@@ -106,35 +106,10 @@ public class Utils {
*/
private static final int[] TEMP_ARRAY = new int[1];
- /**
- * The background colors of the app - it changes throughout out the day to mimic the sky.
- */
- private static final int[] BACKGROUND_SPECTRUM = {
- 0xFF212121 /* 12 AM */,
- 0xFF20222A /* 1 AM */,
- 0xFF202233 /* 2 AM */,
- 0xFF1F2242 /* 3 AM */,
- 0xFF1E224F /* 4 AM */,
- 0xFF1D225C /* 5 AM */,
- 0xFF1B236B /* 6 AM */,
- 0xFF1A237E /* 7 AM */,
- 0xFF1D2783 /* 8 AM */,
- 0xFF232E8B /* 9 AM */,
- 0xFF283593 /* 10 AM */,
- 0xFF2C3998 /* 11 AM */,
- 0xFF303F9F /* 12 PM */,
- 0xFF2C3998 /* 1 PM */,
- 0xFF283593 /* 2 PM */,
- 0xFF232E8B /* 3 PM */,
- 0xFF1D2783 /* 4 PM */,
- 0xFF1A237E /* 5 PM */,
- 0xFF1B236B /* 6 PM */,
- 0xFF1D225C /* 7 PM */,
- 0xFF1E224F /* 8 PM */,
- 0xFF1F2242 /* 9 PM */,
- 0xFF202233 /* 10 PM */,
- 0xFF20222A /* 11 PM */
- };
+
+ /** The background colors of the app, it changes thru out the day to mimic the sky. **/
+ public static TypedArray sBackgroundSpectrum;
+ private static int sDefaultBackgroundSpectrumColor;
/**
* Returns whether the SDK is KitKat or later
@@ -732,11 +707,21 @@ public class Utils {
}
}
+ private static void loadBackgroundSpectrum(Context context) {
+ Resources res = context.getResources();
+ sBackgroundSpectrum = res.obtainTypedArray(R.array.background_color_by_hour);
+ sDefaultBackgroundSpectrumColor = res.getColor(R.color.hour_12);
+ }
+
/**
* Returns the background color to use based on the current time.
*/
- public static int getCurrentHourColor() {
- return BACKGROUND_SPECTRUM[Calendar.getInstance().get(Calendar.HOUR_OF_DAY)];
+ public static int getCurrentHourColor(Context context) {
+ if (sBackgroundSpectrum == null) {
+ loadBackgroundSpectrum(context);
+ }
+ final int hourOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
+ return sBackgroundSpectrum.getColor(hourOfDay, sDefaultBackgroundSpectrumColor);
}
/**
diff --git a/src/com/android/deskclock/alarms/AlarmActivity.java b/src/com/android/deskclock/alarms/AlarmActivity.java
index 69abb56c3..f31381db8 100644
--- a/src/com/android/deskclock/alarms/AlarmActivity.java
+++ b/src/com/android/deskclock/alarms/AlarmActivity.java
@@ -284,7 +284,7 @@ public class AlarmActivity extends AppCompatActivity
Utils.setTimeFormat(this, digitalClock,
getResources().getDimensionPixelSize(R.dimen.main_ampm_font_size));
- mCurrentHourColor = Utils.getCurrentHourColor();
+ mCurrentHourColor = Utils.getCurrentHourColor(this);
getWindow().setBackgroundDrawable(new ColorDrawable(mCurrentHourColor));
mAlarmButton.setOnTouchListener(this);