1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-09-20 23:09:36 +02:00
dandelion/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedColorPickerPreference.java

65 lines
2.1 KiB
Java
Raw Normal View History

2016-10-26 16:23:14 +02:00
package com.github.dfa.diaspora_android.ui.theme;
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;
/**
* 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
@SuppressWarnings("unused")
public ThemedColorPickerPreference(Context context) {
super(context);
}
2016-10-25 23:04:16 +02:00
@SuppressWarnings("unused")
public ThemedColorPickerPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
2016-10-25 23:04:16 +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();
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 {
color = appSettings.getColor(key, color, getSharedPreferences());
}
2016-10-25 23:04:16 +02:00
circle.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
}
}
}