Light Wizard theme
This commit is contained in:
@@ -96,6 +96,12 @@ public class ActivityUi extends BaseUi {
|
||||
public void onCreate(@Nonnull final ActionBarActivity activity) {
|
||||
onCreate((Activity) activity);
|
||||
final ActionBar actionBar = activity.getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
initActionBar(activity, actionBar);
|
||||
}
|
||||
}
|
||||
|
||||
private void initActionBar(@Nonnull Activity activity, @Nonnull ActionBar actionBar) {
|
||||
actionBar.setDisplayUseLogoEnabled(false);
|
||||
final boolean homeAsUp = !(activity instanceof CalculatorActivity);
|
||||
actionBar.setDisplayHomeAsUpEnabled(homeAsUp);
|
||||
@@ -103,7 +109,7 @@ public class ActivityUi extends BaseUi {
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
actionBar.setElevation(0);
|
||||
|
||||
toggleTitle(activity, true);
|
||||
toggleTitle(activity, actionBar, true);
|
||||
|
||||
if (!homeAsUp) {
|
||||
actionBar.setIcon(R.drawable.ab_icon);
|
||||
@@ -111,9 +117,7 @@ public class ActivityUi extends BaseUi {
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
}
|
||||
|
||||
private void toggleTitle(@Nonnull ActionBarActivity activity, boolean showTitle) {
|
||||
final ActionBar actionBar = activity.getSupportActionBar();
|
||||
|
||||
private void toggleTitle(@Nonnull Activity activity, @Nonnull ActionBar actionBar, boolean showTitle) {
|
||||
if (activity instanceof CalculatorActivity) {
|
||||
if (Views.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT) {
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
@@ -127,8 +131,10 @@ public class ActivityUi extends BaseUi {
|
||||
|
||||
public void restoreSavedTab(@Nonnull ActionBarActivity activity) {
|
||||
final ActionBar actionBar = activity.getSupportActionBar();
|
||||
if (selectedNavigationIndex >= 0 && selectedNavigationIndex < actionBar.getTabCount()) {
|
||||
actionBar.setSelectedNavigationItem(selectedNavigationIndex);
|
||||
if (actionBar != null) {
|
||||
if (selectedNavigationIndex >= 0 && selectedNavigationIndex < actionBar.getTabCount()) {
|
||||
actionBar.setSelectedNavigationItem(selectedNavigationIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,10 +146,14 @@ public class ActivityUi extends BaseUi {
|
||||
}
|
||||
|
||||
public void onResume(@Nonnull Activity activity) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
restartIfThemeChanged(activity, theme);
|
||||
}
|
||||
|
||||
final Preferences.Gui.Theme newTheme = Preferences.Gui.theme.getPreference(preferences);
|
||||
if (!theme.equals(newTheme)) {
|
||||
public static void restartIfThemeChanged(@Nonnull Activity activity, @Nonnull Preferences.Gui.Theme oldTheme) {
|
||||
final Preferences.Gui.Theme newTheme = Preferences.Gui.theme.getPreference(App.getPreferences());
|
||||
final int themeId = oldTheme.getThemeId(activity);
|
||||
final int newThemeId = newTheme.getThemeId(activity);
|
||||
if (themeId != newThemeId) {
|
||||
Activities.restartActivity(activity);
|
||||
}
|
||||
}
|
||||
@@ -154,14 +164,16 @@ public class ActivityUi extends BaseUi {
|
||||
public void onPause(@Nonnull ActionBarActivity activity) {
|
||||
onPause((Activity) activity);
|
||||
|
||||
final int selectedNavigationIndex = activity.getSupportActionBar().getSelectedNavigationIndex();
|
||||
if (selectedNavigationIndex >= 0) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
final SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putInt(getSavedTabPreferenceName(activity), selectedNavigationIndex);
|
||||
editor.apply();
|
||||
final ActionBar actionBar = activity.getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
final int selectedNavigationIndex = actionBar.getSelectedNavigationIndex();
|
||||
if (selectedNavigationIndex >= 0) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
final SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putInt(getSavedTabPreferenceName(activity), selectedNavigationIndex);
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
@@ -114,7 +114,7 @@ public final class Preferences {
|
||||
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, R.style.Cpp_Theme_Settings_Light),
|
||||
material_light_theme(R.style.Cpp_Theme_Material_Light, R.style.Cpp_Theme_Wizard_Light, R.style.Cpp_Theme_Settings_Light),
|
||||
;
|
||||
|
||||
private static final SparseArray<TextColor> textColors = new SparseArray<>();
|
||||
@@ -164,7 +164,7 @@ public final class Preferences {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class TextColor{
|
||||
public static final class TextColor {
|
||||
public final int normal;
|
||||
public final int error;
|
||||
|
||||
@@ -173,6 +173,7 @@ public final class Preferences {
|
||||
this.error = error;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Layout {
|
||||
main_calculator(R.layout.main_calculator, R.string.p_layout_calculator, true),
|
||||
main_calculator_mobile(R.layout.main_calculator_mobile, R.string.p_layout_calculator_mobile, false),
|
||||
|
@@ -66,10 +66,7 @@ public abstract class BasePreferencesActivity extends PreferenceActivity impleme
|
||||
@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);
|
||||
}
|
||||
ActivityUi.restartIfThemeChanged(this, theme);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,21 +2,20 @@ package org.solovyev.android.calculator.wizard;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import com.viewpagerindicator.PageIndicator;
|
||||
import org.solovyev.android.calculator.BaseActivity;
|
||||
import org.solovyev.android.calculator.CalculatorApplication;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.wizard.*;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
public class WizardActivity extends BaseActivity implements WizardsAware, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
@Nonnull
|
||||
private final WizardUi<WizardActivity> wizardUi = new WizardUi<>(this, this, 0);
|
||||
|
||||
@@ -43,7 +42,6 @@ public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
wizardUi.onCreate(savedInstanceState);
|
||||
getSupportActionBar().hide();
|
||||
final ListWizardFlow flow = (ListWizardFlow) wizardUi.getFlow();
|
||||
|
||||
pager = (ViewPager) findViewById(R.id.pager);
|
||||
@@ -51,23 +49,32 @@ public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
pager.setAdapter(pagerAdapter);
|
||||
final PageIndicator titleIndicator = (PageIndicator) findViewById(R.id.pager_indicator);
|
||||
titleIndicator.setViewPager(pager);
|
||||
final Wizard wizard = wizardUi.getWizard();
|
||||
titleIndicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
final WizardStep step = flow.getStepAt(position);
|
||||
wizardUi.setStep(step);
|
||||
wizardUi.getWizard().saveLastStep(step);
|
||||
wizard.saveLastStep(step);
|
||||
}
|
||||
});
|
||||
|
||||
final String lastSavedStepName = wizard.getLastSavedStepName();
|
||||
if (lastSavedStepName == null) {
|
||||
wizard.saveLastStep(wizardUi.getStep());
|
||||
} else {
|
||||
final WizardStep step = wizard.getFlow().getStepByName(lastSavedStepName);
|
||||
if (step != null) {
|
||||
wizardUi.setStep(step);
|
||||
}
|
||||
}
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
final int position = flow.getPositionFor(wizardUi.getStep());
|
||||
pager.setCurrentItem(position);
|
||||
}
|
||||
|
||||
if (wizardUi.getWizard().getLastSavedStepName() == null) {
|
||||
wizardUi.getWizard().saveLastStep(wizardUi.getStep());
|
||||
}
|
||||
App.getPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,6 +179,7 @@ public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
App.getPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||
dismissDialog();
|
||||
super.onDestroy();
|
||||
}
|
||||
@@ -183,6 +191,13 @@ public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (Preferences.Gui.theme.isSameKey(key)) {
|
||||
ActivityUi.restartIfThemeChanged(this, ui.getTheme());
|
||||
}
|
||||
}
|
||||
|
||||
private class WizardPagerAdapter extends FragmentStatePagerAdapter {
|
||||
@Nonnull
|
||||
private final ListWizardFlow flow;
|
||||
|
@@ -27,8 +27,6 @@ import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.view.MenuInflater;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -44,21 +42,6 @@ public final class AndroidSherlockUtils {
|
||||
throw new AssertionError("Not intended for instantiation!");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static ActionBar getSupportActionBar(@Nonnull Activity activity) {
|
||||
if (activity instanceof ActionBarActivity) {
|
||||
return ((ActionBarActivity) activity).getSupportActionBar();
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(activity.getClass() + " is not supported!");
|
||||
|
||||
}
|
||||
|
||||
public static ActionBar getSupportActionBar(@Nonnull Fragment fragment) {
|
||||
return ((ActionBarActivity) fragment.getActivity()).getSupportActionBar();
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
public static MenuInflater getSupportMenuInflater(@Nonnull Activity activity) {
|
||||
return activity.getMenuInflater();
|
||||
|
Reference in New Issue
Block a user