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

Commit b386427c authored by Marek Walczak's avatar Marek Walczak Committed by Paul Beeler
Browse files

Add option to hide AlarmClock Icon in StatusBar



If somebody does not need to be reminded by an icon in the status bar
of an enabled alarm. You can switch it off.

Patch Set 4: Use default preferences instead of AlarmClock.PREFERENCES

Patch Set 5: Use PreferenceManager instead of static variable +
cosmetic changes

Patch Set 6: Fix strings and address code review comments

Patch Set 7: Implement settings set/read per Nebkat's suggestion

Patch Set 8: Fix minor nitpick

Patch Set 9: Fix NPE

Patch Set 12: Fix Wrong Patch Set 11
		- Use correct DefaultPreferences instead of unused
AlarmClock.PREFERENCES

Patch Set 13: Removed obsolete null-check

Change-Id: I1de4d2b084e00118d6036e05ce7dc171f73ff438

Forward Port to cm-10.1

Signed-off-by: default avatarPaul Beeler <sparksco@gmail.com>
parent 11edfd80
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -172,6 +172,12 @@
    <!-- Label for the Settings activity displayed on-screen when that activity must be represented to the user. -->
    <!-- Label for the Settings activity displayed on-screen when that activity must be represented to the user. -->
    <string name="settings">Settings</string>
    <string name="settings">Settings</string>


    <!-- Setting title for showing/hiding the alarm status bar icon -->
    <string name="show_status_bar_icon_title">Show icon</string>

    <!-- Setting summary for showing/hiding the alarm statusbar icon -->
    <string name="show_status_bar_icon_summary">Show an icon in the status bar when an alarm is set</string>

    <!-- Setting title for changing the snooze duration. -->
    <!-- Setting title for changing the snooze duration. -->
    <string name="snooze_duration_title">Snooze length</string>
    <string name="snooze_duration_title">Snooze length</string>


+6 −0
Original line number Original line Diff line number Diff line
@@ -65,5 +65,11 @@
            android:entries="@array/volume_button_setting_entries"
            android:entries="@array/volume_button_setting_entries"
            android:entryValues="@array/volume_button_setting_values"
            android:entryValues="@array/volume_button_setting_values"
            android:defaultValue="1" />
            android:defaultValue="1" />

        <CheckBoxPreference
            android:key="show_status_bar_icon"
            android:title="@string/show_status_bar_icon_title"
            android:summary="@string/show_status_bar_icon_summary"
            android:defaultValue="true"  />
    </PreferenceCategory>
    </PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>
+20 −1
Original line number Original line Diff line number Diff line
@@ -29,7 +29,9 @@ import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.Cursor;
import android.net.Uri;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcel;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.text.format.DateFormat;


import java.util.Calendar;
import java.util.Calendar;
@@ -448,7 +450,11 @@ public class Alarms {


        am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender);
        am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender);


        setStatusBarIcon(context, true);
        // Read the icon state preference before showing the icon, default to visible
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        boolean showIcon = prefs.getBoolean(SettingsActivity.KEY_SHOW_STATUS_BAR_ICON, true);

        setStatusBarIcon(context, showIcon);


        Calendar c = Calendar.getInstance();
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(atTimeInMillis);
        c.setTimeInMillis(atTimeInMillis);
@@ -573,6 +579,13 @@ public class Alarms {
        return true;
        return true;
    }
    }


    public static void updateStatusBarIcon(Context context, boolean enabled) {
        String nextAlarm = getNextAlarm(context);
        if (!TextUtils.isEmpty(nextAlarm)) {
            setStatusBarIcon(context, enabled);
        }
    }

    /**
    /**
     * Tells the StatusBar whether the alarm is enabled or disabled
     * Tells the StatusBar whether the alarm is enabled or disabled
     */
     */
@@ -646,6 +659,12 @@ public class Alarms {
                                  timeString);
                                  timeString);
    }
    }


    private static String getNextAlarm(final Context context) {
        String nextAlarm = Settings.System.getString(context.getContentResolver(),
                                  Settings.System.NEXT_ALARM_FORMATTED);
        return nextAlarm;
    }

    /**
    /**
     * @return true if clock is set to 24-hour mode
     * @return true if clock is set to 24-hour mode
     */
     */
+9 −0
Original line number Original line Diff line number Diff line
@@ -43,6 +43,8 @@ public class SettingsActivity extends PreferenceActivity


    static final String KEY_ALARM_IN_SILENT_MODE =
    static final String KEY_ALARM_IN_SILENT_MODE =
            "alarm_in_silent_mode";
            "alarm_in_silent_mode";
    static final String KEY_SHOW_STATUS_BAR_ICON =
            "show_status_bar_icon";
    static final String KEY_ALARM_SNOOZE =
    static final String KEY_ALARM_SNOOZE =
            "snooze_duration";
            "snooze_duration";
    static final String KEY_VOLUME_BEHAVIOR =
    static final String KEY_VOLUME_BEHAVIOR =
@@ -164,6 +166,10 @@ public class SettingsActivity extends PreferenceActivity
            final ListPreference listPref = (ListPreference) pref;
            final ListPreference listPref = (ListPreference) pref;
            final int idx = listPref.findIndexOfValue((String) newValue);
            final int idx = listPref.findIndexOfValue((String) newValue);
            listPref.setSummary(listPref.getEntries()[idx]);
            listPref.setSummary(listPref.getEntries()[idx]);
        } else if (KEY_SHOW_STATUS_BAR_ICON.equals(pref.getKey())) {
            // Check if any alarms are active. If yes and
            // we allow showing the alarm icon, the icon will be shown.
            Alarms.updateStatusBarIcon(getApplicationContext(), (Boolean) newValue);
        }
        }
        return true;
        return true;
    }
    }
@@ -200,6 +206,9 @@ public class SettingsActivity extends PreferenceActivity
        listPref.setSummary(listPref.getEntry());
        listPref.setSummary(listPref.getEntry());
        listPref.setOnPreferenceChangeListener(this);
        listPref.setOnPreferenceChangeListener(this);


        CheckBoxPreference hideStatusbarIcon = (CheckBoxPreference) findPreference(KEY_SHOW_STATUS_BAR_ICON);
        hideStatusbarIcon.setOnPreferenceChangeListener(this);

        SnoozeLengthDialog snoozePref = (SnoozeLengthDialog) findPreference(KEY_ALARM_SNOOZE);
        SnoozeLengthDialog snoozePref = (SnoozeLengthDialog) findPreference(KEY_ALARM_SNOOZE);
        snoozePref.setSummary();
        snoozePref.setSummary();
    }
    }