@@ -0,0 +1,2687 @@
+package com.maxiee.heartbeat.common;%0A%0Aimport android.content.Context;%0Aimport android.content.DialogInterface;%0Aimport android.content.SharedPreferences;%0Aimport android.support.v7.app.AlertDialog;%0Aimport android.util.TypedValue;%0A%0Aimport com.maxiee.heartbeat.R;%0Aimport com.maxiee.heartbeat.ui.common.BaseActivity;%0A%0A/**%0A * Created by maxiee on 15/10/22.%0A */%0Apublic class ThemeUtils %7B%0A    private static final String CURRENT_THEME = %22current_theme%22;%0A%0A    private static final int%5B%5D THEME_TITLES_RES = new int%5B%5D %7B%0A            R.string.theme_heartbeat,%0A            R.string.theme_test%0A    %7D;%0A%0A    private static final int%5B%5D THEME_ACTIVITY_RES = new int%5B%5D %7B%0A            R.style.AppTheme,%0A            R.style.AppTheme_test%0A    %7D;%0A%0A    public static void chooseThemeDialog(final Context context) %7B%0A        AlertDialog.Builder builder = new AlertDialog.Builder(context);%0A        builder.setTitle(context.getString(R.string.change_theme));%0A        builder.setItems(getThemeTitles(context), new DialogInterface.OnClickListener() %7B%0A            @Override%0A            public void onClick(DialogInterface dialog, int which) %7B%0A                setCurrentActivityTheme(context, which);%0A                ((BaseActivity) context).recreate();%0A            %7D%0A        %7D);%0A        builder.show();%0A    %7D%0A%0A    private static CharSequence%5B%5D getThemeTitles(Context context) %7B%0A        CharSequence%5B%5D titles = new String%5BTHEME_TITLES_RES.length%5D;%0A        for (int i=0; i%3CTHEME_TITLES_RES.length; i++) %7B%0A            titles%5Bi%5D = context.getString(THEME_TITLES_RES%5Bi%5D);%0A        %7D%0A        return titles;%0A    %7D%0A%0A    public static int getCurrentActivityTheme(Context context) %7B%0A        SharedPreferences sp = getSharedPreference(context);%0A        int index = sp.getInt(CURRENT_THEME, 0);%0A        return THEME_ACTIVITY_RES%5Bindex%5D;%0A    %7D%0A%0A    private static void setCurrentActivityTheme(Context context, int index) %7B%0A        SharedPreferences.Editor editor = getSharedPreference(context).edit();%0A        editor.putInt(CURRENT_THEME, index);%0A        editor.apply();%0A    %7D%0A%0A    private static SharedPreferences getSharedPreference(Context context) %7B%0A        return context.getSharedPreferences(%22hb%22, Context.MODE_PRIVATE);%0A    %7D%0A%0A    public static int getAttributeColor(Context context, int resId) %7B%0A        TypedValue typedValue = new TypedValue();%0A        context.getTheme().resolveAttribute(resId, typedValue, true);%0A        int color = 0x000000;%0A        if (typedValue.type %3E= TypedValue.TYPE_FIRST_COLOR_INT && typedValue.type %3C= TypedValue.TYPE_LAST_COLOR_INT) %7B%0A            // resId is a color%0A            color = typedValue.data;%0A        %7D else %7B%0A            // resId is not a color%0A        %7D%0A        return color;%0A    %7D%0A%7D%0A

manage themes.