2016-10-26 16:23:14 +02:00
|
|
|
package com.github.dfa.diaspora_android.ui.theme;
|
2016-10-25 17:04:32 +02:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.preference.Preference;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
2016-10-25 23:04:16 +02:00
|
|
|
import com.github.dfa.diaspora_android.R;
|
2016-10-26 16:23:14 +02:00
|
|
|
import com.github.dfa.diaspora_android.util.AppSettings;
|
2016-10-25 23:04:16 +02:00
|
|
|
import com.github.dfa.diaspora_android.util.Helpers;
|
2016-10-25 17:04:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Preference that shows selected Color in a circle
|
|
|
|
* Created by vanitas on 25.10.16.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class ThemedColorPickerPreference extends Preference implements Themeable {
|
|
|
|
protected ImageView colorPreview;
|
2016-10-25 23:04:16 +02:00
|
|
|
|
2016-10-25 17:04:32 +02:00
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public ThemedColorPickerPreference(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
2016-10-25 23:04:16 +02:00
|
|
|
|
2016-10-25 17:04:32 +02:00
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public ThemedColorPickerPreference(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
2016-10-25 23:04:16 +02:00
|
|
|
|
2016-10-25 17:04:32 +02:00
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public ThemedColorPickerPreference(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
super(context, attrs, defStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onBindView(View view) {
|
|
|
|
super.onBindView(view);
|
|
|
|
colorPreview = (ImageView) view.findViewById(android.R.id.icon);
|
|
|
|
setColors();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setColors() {
|
2016-10-25 23:04:16 +02:00
|
|
|
Drawable circle;
|
|
|
|
if (colorPreview != null && (circle = colorPreview.getDrawable()) != null) {
|
|
|
|
Context c = getContext();
|
2017-05-20 02:08:04 +02:00
|
|
|
AppSettings appSettings = AppSettings.get();
|
2016-10-25 23:04:16 +02:00
|
|
|
String key = getKey();
|
|
|
|
|
2017-05-29 19:05:37 +02:00
|
|
|
int color = Helpers.get().color(R.color.primary);
|
2016-10-25 23:04:16 +02:00
|
|
|
if ((appSettings.isKeyEqual(key, R.string.pref_key__primary_color_shade))) {
|
|
|
|
color = appSettings.getPrimaryColor();
|
|
|
|
} else if ((appSettings.isKeyEqual(key, R.string.pref_key__accent_color_shade))) {
|
|
|
|
color = appSettings.getAccentColor();
|
|
|
|
} else {
|
2017-08-29 14:44:43 +02:00
|
|
|
color = appSettings.getColor(key, color, getSharedPreferences());
|
2016-10-25 17:04:32 +02:00
|
|
|
}
|
2016-10-25 23:04:16 +02:00
|
|
|
circle.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
2016-10-25 17:04:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|