Massive adapter clean up. Lots of stuff unfinished there yet. Don't mess around with it yet.

This commit is contained in:
Karim Abou Zeid 2015-07-13 02:16:26 +02:00
commit 0650df6250
35 changed files with 847 additions and 1438 deletions

View file

@ -68,6 +68,14 @@ public final class PreferenceUtil {
return sInstance;
}
public void registerOnSharedPreferenceChangedListener(SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener) {
mPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
public void unregisterOnSharedPreferenceChangedListener(SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener) {
mPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
public int getGeneralTheme() {
int value = Integer.parseInt(mPreferences.getString(GENERAL_THEME, "0"));
switch (value) {

View file

@ -2,9 +2,11 @@ package com.kabouzeid.gramophone.util;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.graphics.Bitmap;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.graphics.Palette;
import android.support.v7.internal.view.menu.ListMenuItemView;
import android.support.v7.internal.view.menu.MenuPopupHelper;
import android.view.View;
@ -26,6 +28,47 @@ import java.lang.reflect.Field;
public class ViewUtil {
public final static int DEFAULT_COLOR_ANIMATION_DURATION = 500;
public static void applyBackgroundColorFromBitmap(@Nullable Bitmap bitmap, final int defaultBgColor, @Nullable final View[] views, @Nullable final TextView[] textViews, final boolean animate) {
if (bitmap != null) {
Palette.from(bitmap)
.resizeBitmapSize(100)
.generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(@NonNull Palette palette) {
applyBackgroundColor(palette.getVibrantColor(defaultBgColor), views, textViews, animate);
}
});
} else {
applyBackgroundColor(defaultBgColor, views, textViews, animate);
}
}
public static void applyBackgroundColor(int bgColor, @Nullable final View[] views, @Nullable TextView[] textViews, final boolean animate) {
if (views != null) {
for (View view : views) {
if (view != null) {
if (animate) {
ViewUtil.animateViewColor(view, view.getDrawingCacheBackgroundColor(), bgColor);
} else {
view.setBackgroundColor(bgColor);
}
}
}
}
if (textViews != null) {
int textColor = ColorUtil.getTextColorForBackground(bgColor);
for (TextView textView : textViews) {
if (textView != null) {
if (animate) {
animateTextColor(textView, textView.getCurrentTextColor(), textColor);
} else {
textView.setTextColor(textColor);
}
}
}
}
}
public static void animateViewColor(final View v, final int startColor, final int endColor) {
animateViewColor(v, startColor, endColor, DEFAULT_COLOR_ANIMATION_DURATION);
}