From a2a3cf8aa8c777d6edfd5a51afa44e7a72d4c499 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Tue, 22 Oct 2019 22:24:17 +0200 Subject: [PATCH] show led-color standardized in the value row right-aligned settings look a bit odd on newer android versions, the default is a second row with the value. also, the led is subject to change as it probably won't be directly editable in the notification channels - so, do not continue to maintain an explicit class for that. --- res/xml/preferences_notifications.xml | 2 +- .../widgets/LEDColorListPreference.java | 108 ------------------ 2 files changed, 1 insertion(+), 109 deletions(-) delete mode 100644 src/org/thoughtcrime/securesms/preferences/widgets/LEDColorListPreference.java diff --git a/res/xml/preferences_notifications.xml b/res/xml/preferences_notifications.xml index 5b34ec673..bd757cf08 100644 --- a/res/xml/preferences_notifications.xml +++ b/res/xml/preferences_notifications.xml @@ -20,7 +20,7 @@ android:defaultValue="true" android:title="@string/pref_vibrate"/> - . - */ -package org.thoughtcrime.securesms.preferences.widgets; - -import android.content.Context; -import android.graphics.drawable.GradientDrawable; -import android.support.annotation.NonNull; -import android.support.v7.preference.ListPreference; -import android.support.v7.preference.PreferenceViewHolder; -import android.util.AttributeSet; -import android.widget.ImageView; - -import org.thoughtcrime.securesms.R; - -/** - * List preference that disables dependents when set to "none", similar to a CheckBoxPreference. - * - * @author Taylor Kline - */ - -public class LEDColorListPreference extends ListPreference { - - private static final String TAG = LEDColorListPreference.class.getSimpleName(); - - private ImageView colorImageView; - - public LEDColorListPreference(Context context, AttributeSet attrs) { - super(context, attrs); - setWidgetLayoutResource(R.layout.led_color_preference_widget); - } - - public LEDColorListPreference(Context context) { - super(context); - setWidgetLayoutResource(R.layout.led_color_preference_widget); - } - - @Override - public void setValue(String value) { - CharSequence oldEntry = getEntry(); - super.setValue(value); - CharSequence newEntry = getEntry(); - if (oldEntry != newEntry) { - notifyDependencyChange(shouldDisableDependents()); - } - - if (value != null) setPreviewColor(value); - } - - @Override - public boolean shouldDisableDependents() { - CharSequence newEntry = getValue(); - boolean shouldDisable = newEntry.equals("none"); - return shouldDisable || super.shouldDisableDependents(); - } - - @Override - public void onBindViewHolder(PreferenceViewHolder view) { - super.onBindViewHolder(view); - this.colorImageView = (ImageView)view.findViewById(R.id.color_view); - setPreviewColor(getValue()); - } - - @Override - public void setSummary(CharSequence summary) { - super.setSummary(null); - } - - private void setPreviewColor(@NonNull String value) { - int color; - - switch (value) { - case "purple": color = getContext().getResources().getColor(R.color.purple_led); break; - case "green": color = getContext().getResources().getColor(R.color.green_500); break; - case "red": color = getContext().getResources().getColor(R.color.red_500); break; - case "blue": color = getContext().getResources().getColor(R.color.blue_500); break; - case "yellow": color = getContext().getResources().getColor(R.color.yellow_500); break; - case "cyan": color = getContext().getResources().getColor(R.color.cyan_500); break; - case "magenta": color = getContext().getResources().getColor(R.color.pink_500); break; - case "white": color = getContext().getResources().getColor(R.color.white); break; - default: color = getContext().getResources().getColor(R.color.transparent); break; - } - - if (colorImageView != null) { - GradientDrawable drawable = new GradientDrawable(); - drawable.setShape(GradientDrawable.OVAL); - drawable.setColor(color); - - colorImageView.setImageDrawable(drawable); - } - } - - - -}