Material Light theme
This commit is contained in:
@@ -74,7 +74,7 @@ public class ActivityUi extends BaseUi {
|
||||
Locator.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener) activity);
|
||||
}
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
final SharedPreferences preferences = App.getPreferences();
|
||||
|
||||
theme = Preferences.Gui.getTheme(preferences);
|
||||
activity.setTheme(theme.getThemeId(activity));
|
||||
|
@@ -220,4 +220,9 @@ public final class App {
|
||||
public static boolean isLargeScreen() {
|
||||
return Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, App.getApplication().getResources().getConfiguration());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static SharedPreferences getPreferences() {
|
||||
return preferences;
|
||||
}
|
||||
}
|
||||
|
@@ -26,21 +26,14 @@ import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.*;
|
||||
import org.solovyev.android.menu.ActivityMenu;
|
||||
import org.solovyev.android.menu.AndroidMenuHelper;
|
||||
import org.solovyev.android.menu.ListActivityMenu;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.solovyev.android.menu.ActivityMenu;
|
||||
import org.solovyev.android.menu.ListActivityMenu;
|
||||
import org.solovyev.android.menu.AndroidMenuHelper;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
* Date: 25.09.12
|
||||
@@ -49,7 +42,7 @@ import org.solovyev.android.menu.AndroidMenuHelper;
|
||||
public class CalculatorEditorFragment extends Fragment {
|
||||
|
||||
@Nonnull
|
||||
private FragmentUi fragmentHelper;
|
||||
private FragmentUi fragmentUi;
|
||||
|
||||
@Nonnull
|
||||
private ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromEnum(CalculatorMenu.class, AndroidMenuHelper.getInstance());
|
||||
@@ -61,7 +54,7 @@ public class CalculatorEditorFragment extends Fragment {
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
fragmentHelper.onViewCreated(this, view);
|
||||
fragmentUi.onViewCreated(this, view);
|
||||
|
||||
((AndroidCalculator) Locator.getInstance().getCalculator()).setEditor(getActivity());
|
||||
}
|
||||
@@ -78,31 +71,29 @@ public class CalculatorEditorFragment extends Fragment {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
||||
final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(prefs);
|
||||
if (!layout.isOptimized()) {
|
||||
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_editor_mobile, R.string.editor);
|
||||
fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_editor_mobile, R.string.editor);
|
||||
} else {
|
||||
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_editor, R.string.editor);
|
||||
fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_editor, R.string.editor);
|
||||
}
|
||||
|
||||
fragmentHelper.onCreate(this);
|
||||
fragmentUi.onCreate(this);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return fragmentHelper.onCreateView(this, inflater, container);
|
||||
return fragmentUi.onCreateView(this, inflater, container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
this.fragmentHelper.onResume(this);
|
||||
this.fragmentUi.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
this.fragmentHelper.onPause(this);
|
||||
|
||||
this.fragmentUi.onPause(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@@ -113,7 +104,7 @@ public class CalculatorEditorFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
fragmentHelper.onDestroy(this);
|
||||
fragmentUi.onDestroy(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
@@ -24,10 +24,12 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.annotation.StyleRes;
|
||||
import jscl.AngleUnit;
|
||||
import jscl.NumeralBase;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.calculator.preferences.BasePreferencesActivity;
|
||||
import org.solovyev.android.calculator.wizard.WizardActivity;
|
||||
import org.solovyev.android.prefs.*;
|
||||
import org.solovyev.android.view.VibratorContainer;
|
||||
@@ -101,21 +103,27 @@ public final class Preferences {
|
||||
|
||||
public static enum Theme {
|
||||
|
||||
default_theme(R.style.Cpp_Theme_Gray, R.style.Cpp_Theme_Wizard),
|
||||
violet_theme(R.style.Cpp_Theme_Violet, R.style.Cpp_Theme_Wizard),
|
||||
light_blue_theme(R.style.Cpp_Theme_Blue, R.style.Cpp_Theme_Wizard),
|
||||
metro_blue_theme(R.style.cpp_metro_blue_theme, R.style.Cpp_Theme_Wizard),
|
||||
metro_purple_theme(R.style.cpp_metro_purple_theme, R.style.Cpp_Theme_Wizard),
|
||||
metro_green_theme(R.style.cpp_metro_green_theme, R.style.Cpp_Theme_Wizard),
|
||||
material_theme(R.style.Cpp_Theme_Material, R.style.Cpp_Theme_Wizard),
|
||||
default_theme(R.style.Cpp_Theme_Gray),
|
||||
violet_theme(R.style.Cpp_Theme_Violet),
|
||||
light_blue_theme(R.style.Cpp_Theme_Blue),
|
||||
metro_blue_theme(R.style.cpp_metro_blue_theme),
|
||||
metro_purple_theme(R.style.cpp_metro_purple_theme),
|
||||
metro_green_theme(R.style.cpp_metro_green_theme),
|
||||
material_theme(R.style.Cpp_Theme_Material),
|
||||
material_light_theme(R.style.Cpp_Theme_Material_Light, R.style.Cpp_Theme_Wizard_Light, R.style.Cpp_Theme_Settings_Light),
|
||||
;
|
||||
|
||||
private final int themeId;
|
||||
private final int wizardThemeId;
|
||||
private final int settingsThemeId;
|
||||
|
||||
Theme(int themeId, int wizardThemeId) {
|
||||
Theme(@StyleRes int themeId) {
|
||||
this(themeId, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Settings);
|
||||
}
|
||||
Theme(@StyleRes int themeId, @StyleRes int wizardThemeId, @StyleRes int settingsThemeId) {
|
||||
this.themeId = themeId;
|
||||
this.wizardThemeId = wizardThemeId;
|
||||
this.settingsThemeId = settingsThemeId;
|
||||
}
|
||||
|
||||
public int getThemeId() {
|
||||
@@ -126,6 +134,9 @@ public final class Preferences {
|
||||
if (activity instanceof WizardActivity) {
|
||||
return wizardThemeId;
|
||||
}
|
||||
if (activity instanceof BasePreferencesActivity) {
|
||||
return settingsThemeId;
|
||||
}
|
||||
return themeId;
|
||||
}
|
||||
}
|
||||
|
@@ -24,9 +24,8 @@ package org.solovyev.android.calculator.plot;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.solovyev.android.calculator.EmptyActivity;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.EmptyActivity;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package org.solovyev.android.calculator.preferences;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
@@ -10,10 +11,8 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import org.solovyev.android.calculator.ActivityUi;
|
||||
import org.solovyev.android.calculator.AdView;
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.Activities;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.checkout.ActivityCheckout;
|
||||
import org.solovyev.android.checkout.Checkout;
|
||||
import org.solovyev.android.checkout.Inventory;
|
||||
@@ -21,16 +20,23 @@ import org.solovyev.android.checkout.ProductTypes;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public abstract class BasePreferencesActivity extends PreferenceActivity {
|
||||
public abstract class BasePreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private static boolean SUPPORT_HEADERS = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
|
||||
private final ActivityCheckout checkout = Checkout.forActivity(this, App.getBilling(), App.getProducts());
|
||||
private Inventory inventory;
|
||||
private AdView adView;
|
||||
private Toolbar actionBar;
|
||||
private Preferences.Gui.Theme theme;
|
||||
private boolean paused = true;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
final SharedPreferences preferences = App.getPreferences();
|
||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||
theme = Preferences.Gui.getTheme(preferences);
|
||||
setTheme(theme.getThemeId(this));
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
actionBar.setTitle(getTitle());
|
||||
@@ -57,6 +63,15 @@ public abstract class BasePreferencesActivity extends PreferenceActivity {
|
||||
getWindow().setContentView(contentView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (!paused && Preferences.Gui.theme.isSameKey(key)) {
|
||||
final Preferences.Gui.Theme newTheme = Preferences.Gui.theme.getPreference(preferences);
|
||||
if (!theme.equals(newTheme)) {
|
||||
Activities.restartActivity(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class InventoryListener implements Inventory.Listener {
|
||||
@Override
|
||||
@@ -113,10 +128,16 @@ public abstract class BasePreferencesActivity extends PreferenceActivity {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
paused = false;
|
||||
if (adView != null) {
|
||||
adView.resume();
|
||||
}
|
||||
inventory.whenLoaded(new InventoryListener());
|
||||
|
||||
final Preferences.Gui.Theme newTheme = Preferences.Gui.theme.getPreference(App.getPreferences());
|
||||
if (!theme.equals(newTheme)) {
|
||||
Activities.restartActivity(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,6 +157,7 @@ public abstract class BasePreferencesActivity extends PreferenceActivity {
|
||||
if (adView != null) {
|
||||
adView.pause();
|
||||
}
|
||||
paused = true;
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@@ -145,6 +167,7 @@ public abstract class BasePreferencesActivity extends PreferenceActivity {
|
||||
adView.destroy();
|
||||
}
|
||||
checkout.stop();
|
||||
App.getPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
@@ -26,8 +26,8 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.SparseArray;
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.CalculatorApplication;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
@@ -42,7 +42,7 @@ import static org.solovyev.android.view.VibratorContainer.Preferences.hapticFeed
|
||||
import static org.solovyev.android.wizard.WizardUi.startWizard;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PreferencesActivity extends BasePreferencesActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public class PreferencesActivity extends BasePreferencesActivity {
|
||||
|
||||
@Nonnull
|
||||
private static final SparseArray<String> preferences = new SparseArray<String>();
|
||||
@@ -100,8 +100,7 @@ public class PreferencesActivity extends BasePreferencesActivity implements Shar
|
||||
setTitle(title);
|
||||
}
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||
final SharedPreferences preferences = App.getPreferences();
|
||||
onSharedPreferenceChanged(preferences, roundResult.getKey());
|
||||
onSharedPreferenceChanged(preferences, hapticFeedbackEnabled.getKey());
|
||||
}
|
||||
@@ -120,14 +119,9 @@ public class PreferencesActivity extends BasePreferencesActivity implements Shar
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
super.onSharedPreferenceChanged(preferences, key);
|
||||
if (roundResult.getKey().equals(key)) {
|
||||
final Preference preference = findPreference(precision.getKey());
|
||||
if (preference != null) {
|
||||
|
@@ -59,6 +59,7 @@ public class ChooseThemeWizardStep extends WizardFragment implements AdapterView
|
||||
final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_theme_spinner);
|
||||
themes.clear();
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.material_theme, R.string.p_material_theme));
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.material_light_theme, R.string.p_material_light_theme));
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.metro_blue_theme, R.string.p_metro_blue_theme));
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.metro_green_theme, R.string.p_metro_green_theme));
|
||||
themes.add(new ThemeUi(Preferences.Gui.Theme.metro_purple_theme, R.string.p_metro_purple_theme));
|
||||
|
Reference in New Issue
Block a user