Android: Adjust theme prefs for future selections

This commit is contained in:
Ender's Games 2018-09-26 00:11:46 -04:00
parent 93319c6c6c
commit 4b0d1092c1
21 changed files with 69 additions and 67 deletions

View File

@ -153,8 +153,9 @@ public class AboutFragment extends Fragment {
ListView list = (ListView) ref.get().getView().findViewById(R.id.list);
SharedPreferences mPrefs = PreferenceManager
.getDefaultSharedPreferences(ref.get().getActivity());
if (mPrefs.getBoolean("lightTheme", false)) {
list.setSelector(R.drawable.list_selector);
int app_theme = mPrefs.getInt(Config.pref_app_theme, 0);
if (app_theme == 7) {
list.setSelector(R.drawable.list_selector_dream);
} else {
list.setSelector(R.drawable.list_selector_dark);
}

View File

@ -5,7 +5,6 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
@ -17,14 +16,11 @@ import android.support.constraint.ConstraintLayout;
import android.support.design.widget.Snackbar;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
@ -52,7 +48,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@ -188,7 +183,7 @@ public class FileBrowser extends Fragment {
private void installButtons() {
try {
File buttons = null;
String theme = mPrefs.getString(Config.pref_theme, null);
String theme = mPrefs.getString(Config.pref_button_theme, null);
if (theme != null) {
buttons = new File(theme);
}
@ -452,9 +447,10 @@ public class FileBrowser extends Fragment {
final View childview = browser.get().getActivity().getLayoutInflater().inflate(
R.layout.browser_fragment_item, null, false);
if (browser.get().mPrefs.getBoolean("lightTheme", false)) {
int app_theme = browser.get().mPrefs.getInt(Config.pref_app_theme, 0);
if (app_theme == 7) {
childview.findViewById(R.id.childview)
.setBackgroundResource(R.drawable.game_selector);
.setBackgroundResource(R.drawable.game_selector_dream);
} else {
childview.findViewById(R.id.childview)
.setBackgroundResource(R.drawable.game_selector_dark);

View File

@ -57,8 +57,12 @@ public class MainActivity extends AppCompatActivity implements
@Override
public void onCreate(Bundle savedInstanceState) {
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
setTheme(mPrefs.getBoolean("lightTheme", false)
? R.style.AppTheme_Light : R.style.AppTheme);
int app_theme = mPrefs.getInt(Config.pref_app_theme, 0);
if (app_theme == 7) {
setTheme(R.style.AppTheme_Dream);
} else {
setTheme(R.style.AppTheme);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@ -536,11 +540,12 @@ public class MainActivity extends AppCompatActivity implements
drawer.closeDrawer(GravityCompat.START);
return true;
case R.id.theme_menu:
if (mPrefs.getBoolean("lightTheme", false)) {
mPrefs.edit().putBoolean("lightTheme", false).apply();
int app_theme = mPrefs.getInt(Config.pref_app_theme, 0);
if (app_theme == 7) {
mPrefs.edit().putInt(Config.pref_app_theme, 0).apply();
restartActivity();
} else {
mPrefs.edit().putBoolean("lightTheme", true).apply();
mPrefs.edit().putInt(Config.pref_app_theme, 7).apply();
restartActivity();
}
drawer.closeDrawer(GravityCompat.START);

View File

@ -8,7 +8,9 @@ public class Config {
public static final String pref_home = "home_directory";
public static final String pref_games = "game_directory";
public static final String pref_theme = "button_theme";
public static final String pref_button_theme = "button_theme";
public static final String pref_app_theme = "app_theme";
public static final String pref_gamedetails = "game_details";

View File

@ -427,7 +427,7 @@ public class InputModFragment extends Fragment {
try {
File buttons = null;
InputStream bitmap;
String theme = mPrefs.getString(Config.pref_theme, null);
String theme = mPrefs.getString(Config.pref_button_theme, null);
if (theme != null) {
buttons = new File(theme);
}

View File

@ -53,7 +53,6 @@ import java.io.OutputStream;
import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
public class OptionsFragment extends Fragment {
@ -608,10 +607,10 @@ public class OptionsFragment extends Fragment {
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
String theme = String.valueOf(parentView.getItemAtPosition(position));
if (theme.equals("None")) {
options.get().mPrefs.edit().remove(Config.pref_theme).apply();
options.get().mPrefs.edit().remove(Config.pref_button_theme).apply();
} else {
String theme_path = options.get().home_directory + "/themes/" + theme;
options.get().mPrefs.edit().putString(Config.pref_theme, theme_path).apply();
options.get().mPrefs.edit().putString(Config.pref_button_theme, theme_path).apply();
}
}
@Override
@ -705,7 +704,7 @@ public class OptionsFragment extends Fragment {
mPrefs.edit().remove(Config.pref_rendertype).apply();
mPrefs.edit().remove(Emulator.pref_nosound).apply();
mPrefs.edit().remove(Config.pref_renderdepth).apply();
mPrefs.edit().remove(Config.pref_theme).apply();
mPrefs.edit().remove(Config.pref_button_theme).apply();
getActivity().finish();
}

View File

@ -30,6 +30,7 @@ import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.reicast.emulator.R;
import com.reicast.emulator.config.Config;
import java.util.ArrayList;
import java.util.HashMap;
@ -74,8 +75,9 @@ public class GitAdapter extends BaseAdapter {
if (convertView == null)
vi = this.inflater.inflate(R.layout.change_item, null);
if (mPrefs.getBoolean("lightTheme", false)) {
vi.setBackgroundResource(R.drawable.list_selector);
int app_theme = mPrefs.getInt(Config.pref_app_theme, 0);
if (app_theme == 7) {
vi.setBackgroundResource(R.drawable.list_selector_dream);
} else {
vi.setBackgroundResource(R.drawable.list_selector_dark);
}
@ -99,7 +101,7 @@ public class GitAdapter extends BaseAdapter {
RelativeLayout item = (RelativeLayout) vi.findViewById(R.id.change);
if (current != null && current.equals(sha.substring(0, 7))) {
item.getBackground().setColorFilter(0xFF00FF00,
PorterDuff.Mode.MULTIPLY);
PorterDuff.Mode.OVERLAY);
} else {
item.getBackground().setColorFilter(null);
}

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selector style for listrow -->
<item android:drawable="@android:color/transparent" android:state_pressed="false" android:state_selected="false" android:state_focused="false"/>
<item android:drawable="@drawable/gradient_bg_hover" android:state_pressed="true"/>
<item android:drawable="@drawable/gradient_bg_hover" android:state_focused="true"/>
<item android:drawable="@drawable/gradient_bg_hover" android:state_pressed="false" android:state_selected="true"/>
</selector>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selector style for listrow -->
<item android:drawable="@android:color/transparent" android:state_pressed="false" android:state_selected="false" android:state_focused="false"/>
<item android:drawable="@drawable/gradient_bg_hover_dream" android:state_pressed="true"/>
<item android:drawable="@drawable/gradient_bg_hover_dream" android:state_focused="true"/>
<item android:drawable="@drawable/gradient_bg_hover_dream" android:state_pressed="false" android:state_selected="true"/>
</selector>

View File

@ -5,8 +5,8 @@
<!-- Gradient BgColor for listrow Selected -->
<gradient
android:angle="270"
android:centerColor="@color/colorLightAccentDark"
android:endColor="@color/colorLightAccent"
android:startColor="@color/colorLightAccent" />
android:centerColor="@color/colorDreamAccentDark"
android:endColor="@color/colorDreamAccent"
android:startColor="@color/colorDreamAccent" />
</shape>

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selector style for listrow -->
<item android:drawable="@drawable/gradient_bg" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="@drawable/gradient_bg_hover" android:state_pressed="true"/>
<item android:drawable="@drawable/gradient_bg_hover" android:state_pressed="false" android:state_selected="true"/>
</selector>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selector style for listrow -->
<item android:drawable="@drawable/gradient_bg_dream" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="@drawable/gradient_bg_hover_dream" android:state_pressed="true"/>
<item android:drawable="@drawable/gradient_bg_hover_dream" android:state_pressed="false" android:state_selected="true"/>
</selector>

View File

@ -13,7 +13,7 @@
android:orientation="horizontal"
android:clickable="true"
android:focusable="true"
android:background="@drawable/game_selector" >
android:background="@drawable/game_selector_dream" >
<ImageView
android:id="@+id/item_icon"

View File

@ -13,7 +13,7 @@
android:orientation="horizontal"
android:clickable="true"
android:focusable="true"
android:background="@drawable/game_selector" >
android:background="@drawable/game_selector_dream" >
<ImageView
android:id="@+id/item_icon"

View File

@ -14,7 +14,7 @@
android:layout_centerInParent="true"
android:clickable="true"
android:focusable="true"
android:background="@drawable/game_selector" >
android:background="@drawable/game_selector_dream" >
<ImageView
android:id="@+id/item_icon"

View File

@ -4,7 +4,7 @@
android:id="@+id/change"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_selector"
android:background="@drawable/list_selector_dream"
android:orientation="horizontal"
android:padding="5dip" >

View File

@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_selector"
android:background="@drawable/list_selector_dream"
android:orientation="horizontal"
android:padding="5dip" >

View File

@ -7,11 +7,12 @@
<color name="colorDarkText">#e0e0e0</color>
<color name="colorDarkTint">#e0e0e0</color>
<color name="colorLightPrimary">#6e6b66</color>
<color name="colorLightPrimaryDark">#534e4b</color>
<color name="colorLightAccent">#5787c7</color>
<color name="colorLightAccentDark">#42a5f5</color>
<color name="colorLightText">#3d3533</color>
<color name="colorDreamPrimary">#6e6b66</color>
<color name="colorDreamPrimaryDark">#534e4b</color>
<color name="colorDreamAccent">#5787c7</color>
<color name="colorDreamAccentDark">#42a5f5</color>
<color name="colorDreamText">#3d3533</color>
<color name="colorDreamTint">#534e4b</color>
<color name="colorLink">#42a5f5</color>
</resources>

View File

@ -8,25 +8,21 @@
<item name="colorPrimaryDark">@color/colorDarkPrimaryDark</item>
<item name="colorAccent">@color/colorDarkAccent</item>
<item name="android:windowBackground">@drawable/background_dark</item>
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textColorSecondary">@color/colorDarkText</item>
<item name="android:textColorTertiary">@android:color/white</item>
<item name="android:tint">@color/colorDarkTint</item>
</style>
<style name="AppTheme.Light" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorLightPrimary</item>
<item name="colorPrimaryDark">@color/colorLightPrimaryDark</item>
<item name="colorAccent">@color/colorLightAccent</item>
<item name="android:windowBackground">@drawable/background_light</item>
<style name="AppTheme.Dream" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorDreamPrimary</item>
<item name="colorPrimaryDark">@color/colorDreamPrimaryDark</item>
<item name="colorAccent">@color/colorDreamAccent</item>
<item name="android:windowBackground">@drawable/background_dream</item>
<item name="android:textColorPrimary">@android:color/black</item>
<item name="android:textColorSecondary">@color/colorLightText</item>
<item name="android:textColorSecondary">@color/colorDreamText</item>
<item name="android:textColorTertiary">@android:color/black</item>
<item name="android:tint">@color/colorLightPrimaryDark</item>
<item name="android:tint">@color/colorDreamTint</item>
</style>
<style name="AppTheme.NoActionBar">