Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ef62c1a9 authored by Dave Kover's avatar Dave Kover Committed by Dave Kover
Browse files

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
parent e6065f84
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
<?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>
+45 −0
Original line number Diff line number Diff line
<?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>
+2 −2
Original line number Diff line number Diff line
@@ -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()));
        }


+3 −3
Original line number Diff line number Diff line
@@ -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
+16 −31
Original line number Diff line number Diff line
@@ -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);
    }

    /**
Loading