2015-08-23 01:44:21 -04:00
|
|
|
package com.virtualapplications.play;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.os.Build;
|
2021-05-31 19:23:24 -04:00
|
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
2021-05-31 18:30:41 -04:00
|
|
|
import androidx.preference.PreferenceManager;
|
2020-08-25 14:39:41 -04:00
|
|
|
import androidx.appcompat.widget.Toolbar;
|
2016-01-25 18:23:42 +00:00
|
|
|
import android.util.TypedValue;
|
2015-08-23 01:44:21 -04:00
|
|
|
import android.view.WindowManager;
|
|
|
|
|
2021-05-31 16:36:10 -04:00
|
|
|
import static com.virtualapplications.play.Constants.PREF_UI_THEME_SELECTION;
|
|
|
|
|
2015-08-23 01:44:21 -04:00
|
|
|
public class ThemeManager
|
|
|
|
{
|
2021-05-31 19:23:24 -04:00
|
|
|
public static void applyTheme(Activity activity, final @Nullable Toolbar toolbar)
|
2015-08-23 01:44:21 -04:00
|
|
|
{
|
2021-05-31 16:36:10 -04:00
|
|
|
String positionString = PreferenceManager.getDefaultSharedPreferences(activity)
|
|
|
|
.getString(PREF_UI_THEME_SELECTION, "1");
|
2021-07-06 12:57:48 -04:00
|
|
|
int position = Integer.parseInt(positionString);
|
2015-08-23 01:44:21 -04:00
|
|
|
int theme;
|
2017-06-19 04:47:56 +01:00
|
|
|
switch(position)
|
2015-08-23 01:44:21 -04:00
|
|
|
{
|
|
|
|
case 0:
|
2017-06-19 04:20:22 +01:00
|
|
|
theme = R.style.Amber;
|
2015-08-23 01:44:21 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 1:
|
|
|
|
theme = R.style.Blue;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
theme = R.style.Pink;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
theme = R.style.Purple;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
theme = R.style.Teal;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
theme = R.style.Dark_Purple;
|
|
|
|
break;
|
2017-06-19 04:40:24 +01:00
|
|
|
case 6:
|
|
|
|
theme = R.style.Green;
|
|
|
|
break;
|
2015-08-23 01:44:21 -04:00
|
|
|
}
|
2017-06-19 04:47:56 +01:00
|
|
|
activity.getTheme().applyStyle(theme, true);
|
2015-08-23 01:44:21 -04:00
|
|
|
if(toolbar != null)
|
|
|
|
{
|
2017-06-19 04:47:56 +01:00
|
|
|
int color = getThemeColor(activity, R.attr.colorPrimary);
|
|
|
|
toolbar.setBackgroundColor(color);
|
2015-08-23 01:44:21 -04:00
|
|
|
}
|
2017-06-19 04:47:56 +01:00
|
|
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
2015-08-23 01:44:21 -04:00
|
|
|
{
|
|
|
|
int color = getThemeColor(activity, R.attr.colorPrimaryDark);
|
|
|
|
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
|
|
|
activity.getWindow().setStatusBarColor(color);
|
|
|
|
}
|
|
|
|
}
|
2016-01-25 18:23:42 +00:00
|
|
|
|
2015-08-23 01:44:21 -04:00
|
|
|
static int getThemeColor(Activity activity, int attribute)
|
|
|
|
{
|
2016-01-25 18:23:42 +00:00
|
|
|
TypedValue typedValue = new TypedValue();
|
|
|
|
activity.getTheme().resolveAttribute(attribute, typedValue, true);
|
2021-07-06 12:57:48 -04:00
|
|
|
return typedValue.data;
|
2015-08-23 01:44:21 -04:00
|
|
|
}
|
|
|
|
}
|