Grey 'LED blink pattern' when LED Color is None
Add BooleanListPreference to allow pref_led_blink to depend on pref_led_color being non-None. Closes #6480
This commit is contained in:
parent
b0b1cdef35
commit
04153a3869
2 changed files with 60 additions and 2 deletions
|
@ -19,7 +19,7 @@
|
||||||
android:title="@string/preferences__vibrate"
|
android:title="@string/preferences__vibrate"
|
||||||
android:summary="@string/preferences__also_vibrate_when_notified" />
|
android:summary="@string/preferences__also_vibrate_when_notified" />
|
||||||
|
|
||||||
<ListPreference
|
<org.thoughtcrime.securesms.preferences.BooleanListPreference
|
||||||
android:key="pref_led_color"
|
android:key="pref_led_color"
|
||||||
android:defaultValue="blue"
|
android:defaultValue="blue"
|
||||||
android:title="@string/preferences__led_color"
|
android:title="@string/preferences__led_color"
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
android:key="pref_led_blink"
|
android:key="pref_led_blink"
|
||||||
android:defaultValue="500,2000"
|
android:defaultValue="500,2000"
|
||||||
android:title="@string/preferences__pref_led_blink_title"
|
android:title="@string/preferences__pref_led_blink_title"
|
||||||
android:dependency="pref_key_enable_notifications"
|
android:dependency="pref_led_color"
|
||||||
android:entries="@array/pref_led_blink_pattern_entries"
|
android:entries="@array/pref_led_blink_pattern_entries"
|
||||||
android:entryValues="@array/pref_led_blink_pattern_values" />
|
android:entryValues="@array/pref_led_blink_pattern_values" />
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/**
|
||||||
|
* Copyright (C) 2017 Whisper Systems
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.thoughtcrime.securesms.preferences;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.preference.ListPreference;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List preference that disables dependents when set to "none", similar to a CheckBoxPreference.
|
||||||
|
*
|
||||||
|
* @author Taylor Kline
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class BooleanListPreference extends ListPreference {
|
||||||
|
|
||||||
|
public BooleanListPreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BooleanListPreference(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(String value) {
|
||||||
|
CharSequence oldEntry = getEntry();
|
||||||
|
super.setValue(value);
|
||||||
|
CharSequence newEntry = getEntry();
|
||||||
|
if (oldEntry != newEntry) {
|
||||||
|
notifyDependencyChange(shouldDisableDependents());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldDisableDependents() {
|
||||||
|
CharSequence newEntry = getEntry();
|
||||||
|
String noneEntry = getContext().getString(R.string.preferences__none);
|
||||||
|
boolean shouldDisable = newEntry.equals(noneEntry);
|
||||||
|
return shouldDisable || super.shouldDisableDependents();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue