package net.somethingdreadful.MAL;

import android.app.Application;
import android.content.res.Configuration;
import android.content.res.Resources;

import com.crashlytics.android.Crashlytics;

import net.somethingdreadful.MAL.account.AccountService;

import java.util.Locale;

public class Theme extends Application {

    Locale locale;
    Configuration config;

    @Override
    public void onCreate() {
        super.onCreate();
        Crashlytics.start(this);
        PrefManager.create(getApplicationContext());
        AccountService.create(getApplicationContext());
        
        locale = PrefManager.getLocale();
        config = new Configuration();
        config.locale = locale;
        setLanguage(); //Change language when it is started
        Crashlytics.setString("Language", locale.toString());
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        setLanguage(); //Change language after orientation.
    }

    public void setLanguage() {
        Resources res = getBaseContext().getResources();
        res.updateConfiguration(config, res.getDisplayMetrics());
    }
}

@@ -49,26 +49,87 @@
 id.app.A
-pplication
+ctivity;%0Aimport android.app.Application;%0Aimport android.content.Context
 ;%0Aimport
@@ -201,16 +201,42 @@
 sources;
+%0Aimport android.view.View;
 %0A%0Aimport
@@ -400,16 +400,53 @@
 tion %7B%0A%0A
+    public static boolean darkTheme;%0A
     Loca
@@ -698,17 +698,9 @@
 ));%0A
-        
 %0A
+
     
@@ -733,24 +733,72 @@
 etLocale();%0A
+        darkTheme = PrefManager.getDarkTheme();%0A
         conf
@@ -1265,24 +1265,24 @@
 esources();%0A
-
         res.
@@ -1340,11 +1340,1880 @@
 );%0A    %7D
+%0A%0A    /**%0A     * This will apply the right theme and background.%0A     *%0A     * @param activity The activity which should be themed%0A     * @param view     The main view id%0A     * @param card     If the contents contains a card%0A     */%0A    public static void setTheme(Activity activity, int view, boolean card) %7B%0A        if (view != 0)%0A            activity.setContentView(view);%0A        if (darkTheme) %7B%0A            activity.setTheme(R.style.AtarashiiDarkBg);%0A            activity.getWindow().getDecorView().setBackgroundColor(activity.getResources().getColor(card ? R.color.bg_dark_card : R.color.bg_dark));%0A        %7D else %7B%0A            activity.getWindow().getDecorView().setBackgroundColor(activity.getResources().getColor(card ? R.color.bg_light_card : R.color.bg_light));%0A        %7D%0A    %7D%0A%0A    /**%0A     * Set a background with the default card theme.%0A     *%0A     * @param c    The context%0A     * @param view The view which should use this drawable%0A     */%0A    public static void setBackground(Context c, View view) %7B%0A        setBackground(c, view, getDrawable());%0A    %7D%0A%0A    /**%0A     * Set the background of a view.%0A     *%0A     * @param c The context%0A     * @param view The view which should use this drawable%0A     * @param id The drawable/color id of the wanted color/drawable%0A     */%0A    public static void setBackground(Context c, View view, int id) %7B%0A        if (android.os.Build.VERSION.SDK_INT %3C android.os.Build.VERSION_CODES.JELLY_BEAN) %7B%0A            view.setBackgroundDrawable(c.getResources().getDrawable(id));%0A        %7D else %7B%0A            view.setBackground(c.getResources().getDrawable(id));%0A        %7D%0A    %7D%0A%0A    /**%0A     * Get the default drawable.%0A     *%0A     * @return int The id of the default card drawable%0A     */%0A    private static int getDrawable() %7B%0A        return darkTheme ? R.drawable.highlite_details_dark : R.drawable.highlite_details;%0A    %7D
 %0A%7D%0A

Create theme methods to change a theme (Theme)