diff --git a/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java b/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java index 429251d0..abe0bf33 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java @@ -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 diff --git a/android-app/src/main/java/org/solovyev/android/calculator/Preferences.java b/android-app/src/main/java/org/solovyev/android/calculator/Preferences.java index e8a53990..5304b51d 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/Preferences.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/Preferences.java @@ -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 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), diff --git a/android-app/src/main/java/org/solovyev/android/calculator/preferences/BasePreferencesActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/preferences/BasePreferencesActivity.java index 3832097a..5feb35a0 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/preferences/BasePreferencesActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/preferences/BasePreferencesActivity.java @@ -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); } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/wizard/WizardActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/wizard/WizardActivity.java index 3d55222d..a8700784 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/wizard/WizardActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/wizard/WizardActivity.java @@ -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 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; diff --git a/android-app/src/main/java/org/solovyev/android/sherlock/AndroidSherlockUtils.java b/android-app/src/main/java/org/solovyev/android/sherlock/AndroidSherlockUtils.java index c35a574b..4d4a4ca3 100644 --- a/android-app/src/main/java/org/solovyev/android/sherlock/AndroidSherlockUtils.java +++ b/android-app/src/main/java/org/solovyev/android/sherlock/AndroidSherlockUtils.java @@ -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(); diff --git a/android-app/src/main/res/color/cpp_wizard_button_selector_light.xml b/android-app/src/main/res/color/cpp_wizard_button_selector_light.xml new file mode 100644 index 00000000..c08cab75 --- /dev/null +++ b/android-app/src/main/res/color/cpp_wizard_button_selector_light.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/android-app/src/main/res/drawable-v21/button_no_bg.xml b/android-app/src/main/res/drawable-v21/button_no_bg.xml new file mode 100644 index 00000000..baa1b0f2 --- /dev/null +++ b/android-app/src/main/res/drawable-v21/button_no_bg.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + diff --git a/android-app/src/main/res/drawable/button_no_bg.xml b/android-app/src/main/res/drawable/button_no_bg.xml new file mode 100644 index 00000000..8e86c067 --- /dev/null +++ b/android-app/src/main/res/drawable/button_no_bg.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android-app/src/main/res/drawable/button_no_bg_pressed.xml b/android-app/src/main/res/drawable/button_no_bg_pressed.xml new file mode 100644 index 00000000..d1ce8857 --- /dev/null +++ b/android-app/src/main/res/drawable/button_no_bg_pressed.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/android-app/src/main/res/drawable/material_blue_button.xml b/android-app/src/main/res/drawable/material_blue_button.xml index 7ed947d8..c3d22b2d 100644 --- a/android-app/src/main/res/drawable/material_blue_button.xml +++ b/android-app/src/main/res/drawable/material_blue_button.xml @@ -24,7 +24,11 @@ - + + + + + diff --git a/android-app/src/main/res/drawable/material_button_dark.xml b/android-app/src/main/res/drawable/material_button_dark.xml index bb98c45d..6a662dd2 100644 --- a/android-app/src/main/res/drawable/material_button_dark.xml +++ b/android-app/src/main/res/drawable/material_button_dark.xml @@ -24,7 +24,7 @@ - + diff --git a/android-app/src/main/res/drawable/material_button_light.xml b/android-app/src/main/res/drawable/material_button_light.xml index 569abf86..ea4ea224 100644 --- a/android-app/src/main/res/drawable/material_button_light.xml +++ b/android-app/src/main/res/drawable/material_button_light.xml @@ -23,7 +23,7 @@ --> - + diff --git a/android-app/src/main/res/drawable/material_button_light_primary.xml b/android-app/src/main/res/drawable/material_button_light_primary.xml index ff384506..7b88cf7c 100644 --- a/android-app/src/main/res/drawable/material_button_light_primary.xml +++ b/android-app/src/main/res/drawable/material_button_light_primary.xml @@ -24,7 +24,11 @@ - + + + + + diff --git a/android-app/src/main/res/drawable/material_button_pressed.xml b/android-app/src/main/res/drawable/material_button_pressed.xml new file mode 100644 index 00000000..7295c3f4 --- /dev/null +++ b/android-app/src/main/res/drawable/material_button_pressed.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/android-app/src/main/res/layout/cpp_activity_wizard.xml b/android-app/src/main/res/layout/cpp_activity_wizard.xml index 7f763b87..c71eb733 100644 --- a/android-app/src/main/res/layout/cpp_activity_wizard.xml +++ b/android-app/src/main/res/layout/cpp_activity_wizard.xml @@ -17,6 +17,7 @@ android:id="@+id/pager_indicator" android:layout_height="wrap_content" android:layout_width="match_parent" - my:radius="5dp" /> + my:radius="5dp" + my:fillColor="?attr/colorAccent"/> \ No newline at end of file diff --git a/android-app/src/main/res/layout/cpp_app_button_equals_no_bg.xml b/android-app/src/main/res/layout/cpp_app_button_equals_no_bg.xml new file mode 100644 index 00000000..6f7b84d7 --- /dev/null +++ b/android-app/src/main/res/layout/cpp_app_button_equals_no_bg.xml @@ -0,0 +1,34 @@ + + + + \ No newline at end of file diff --git a/android-app/src/main/res/layout/cpp_wizard_step_choose_mode.xml b/android-app/src/main/res/layout/cpp_wizard_step_choose_mode.xml index a2371790..a855d5e1 100644 --- a/android-app/src/main/res/layout/cpp_wizard_step_choose_mode.xml +++ b/android-app/src/main/res/layout/cpp_wizard_step_choose_mode.xml @@ -63,7 +63,7 @@ c:directionTextScale="0.5" a:layout_width="100dp" a:layout_height="100dp" - style="?attr/cpp_button_style_digit" /> + style="?attr/cpp_button_style_operation" /> + + + + + + + + + style="?attr/cpp_button_style_operation" /> diff --git a/android-app/src/main/res/layout/main_calculator.xml b/android-app/src/main/res/layout/main_calculator.xml index 58c14652..c855ee2e 100644 --- a/android-app/src/main/res/layout/main_calculator.xml +++ b/android-app/src/main/res/layout/main_calculator.xml @@ -43,7 +43,7 @@ a:baselineAligned="false"> diff --git a/android-app/src/main/res/values/attributes.xml b/android-app/src/main/res/values/attributes.xml index 1a74c798..4375e397 100644 --- a/android-app/src/main/res/values/attributes.xml +++ b/android-app/src/main/res/values/attributes.xml @@ -31,6 +31,7 @@ + diff --git a/android-app/src/main/res/values/colors.xml b/android-app/src/main/res/values/colors.xml index 9df54cf1..09d158a7 100644 --- a/android-app/src/main/res/values/colors.xml +++ b/android-app/src/main/res/values/colors.xml @@ -45,7 +45,10 @@ @color/cpp_material_grey_light #10648c #ff0d4663 - #2196F3 + #ff0d668d + #4285f4 + #ff3463bd + #c1d2ef #ff092c39 #088e3a #651456 diff --git a/android-app/src/main/res/values/styles.xml b/android-app/src/main/res/values/styles.xml index c2fbd64f..b4647bf4 100644 --- a/android-app/src/main/res/values/styles.xml +++ b/android-app/src/main/res/values/styles.xml @@ -37,6 +37,7 @@ @dimen/cpp_keyboard_button_text_size @color/cpp_button_text centerInside + @color/cpp_button_text diff --git a/android-app/src/main/res/values/theme.xml b/android-app/src/main/res/values/theme.xml index 99085e72..552a7172 100644 --- a/android-app/src/main/res/values/theme.xml +++ b/android-app/src/main/res/values/theme.xml @@ -108,21 +108,17 @@