Light Wizard theme

This commit is contained in:
serso 2015-02-09 13:00:19 +01:00
parent 3b0d16aa68
commit bc0e6d2344
24 changed files with 262 additions and 72 deletions

View File

@ -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,10 +131,12 @@ public class ActivityUi extends BaseUi {
public void restoreSavedTab(@Nonnull ActionBarActivity activity) {
final ActionBar actionBar = activity.getSupportActionBar();
if (actionBar != null) {
if (selectedNavigationIndex >= 0 && selectedNavigationIndex < actionBar.getTabCount()) {
actionBar.setSelectedNavigationItem(selectedNavigationIndex);
}
}
}
public void onSaveInstanceState(@Nonnull ActionBarActivity activity, @Nonnull Bundle outState) {
onSaveInstanceState((Activity) activity, outState);
@ -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();
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

View File

@ -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),

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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();

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/cpp_material_light_darker" android:state_enabled="true" android:state_pressed="true" />
<item android:color="@color/cpp_material_light_disabled" android:state_enabled="false" />
<item android:color="@color/cpp_material_light" />
</selector>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2013 serso aka se.solovyev
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Contact details
~
~ Email: se.solovyev@gmail.com
~ Site: http://se.solovyev.org
-->
<ripple xmlns:a="http://schemas.android.com/apk/res/android"
a:color="?attr/colorControlHighlight">
<item>
<shape>
<solid a:color="?attr/cpp_main_bg" />
</shape>
</item>
</ripple>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2013 serso aka se.solovyev
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Contact details
~
~ Email: se.solovyev@gmail.com
~ Site: http://se.solovyev.org
-->
<selector xmlns:a="http://schemas.android.com/apk/res/android">
<item a:state_pressed="true" a:drawable="@drawable/button_no_bg_pressed" />
<item>
<shape>
<solid a:color="@android:color/transparent" />
</shape>
</item>
</selector>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2013 serso aka se.solovyev
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Contact details
~
~ Email: se.solovyev@gmail.com
~ Site: http://se.solovyev.org
-->
<shape xmlns:a="http://schemas.android.com/apk/res/android">
<solid a:color="#664d4d4d" />
</shape>

View File

@ -24,7 +24,11 @@
<selector xmlns:a="http://schemas.android.com/apk/res/android">
<item a:state_pressed="true" a:drawable="@drawable/metro_button_pressed" />
<item a:state_pressed="true">
<shape>
<solid a:color="@color/cpp_material_blue_lighter" />
</shape>
</item>
<item>
<shape>

View File

@ -24,7 +24,7 @@
<selector xmlns:a="http://schemas.android.com/apk/res/android">
<item a:state_pressed="true" a:drawable="@drawable/metro_button_pressed" />
<item a:state_pressed="true" a:drawable="@drawable/material_button_pressed" />
<item>
<shape>

View File

@ -23,7 +23,7 @@
-->
<selector xmlns:a="http://schemas.android.com/apk/res/android">
<item a:state_pressed="true" a:drawable="@drawable/metro_button_pressed" />
<item a:state_pressed="true" a:drawable="@drawable/material_button_pressed" />
<item>
<shape>

View File

@ -24,7 +24,11 @@
<selector xmlns:a="http://schemas.android.com/apk/res/android">
<item a:state_pressed="true" a:drawable="@drawable/metro_button_pressed" />
<item a:state_pressed="true">
<shape>
<solid a:color="@color/cpp_material_light_darker" />
</shape>
</item>
<item>
<shape>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2013 serso aka se.solovyev
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Contact details
~
~ Email: se.solovyev@gmail.com
~ Site: http://se.solovyev.org
-->
<shape xmlns:a="http://schemas.android.com/apk/res/android">
<solid a:color="#ff4d4d4d" />
</shape>

View File

@ -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"/>
</LinearLayout>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2013 serso aka se.solovyev
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Contact details
~
~ Email: se.solovyev@gmail.com
~ Site: http://se.solovyev.org
-->
<org.solovyev.android.calculator.drag.DirectionDragButton a:id="@id/cpp_button_equals"
style="?attr/cpp_button_style_control"
xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res-auto"
a:text="="
a:textColor="?android:attr/textColorPrimary"
c:directionTextColor="?android:attr/textColorPrimary"
c:directionTextScale="0.5;0.5;0.33;0.5"
c:textDown="@string/cpp_plot_button_text"
a:background="@drawable/button_no_bg"
c:textUp="≡" />

View File

@ -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" />
</FrameLayout>
<TextView

View File

@ -30,6 +30,22 @@
a:padding="3dp"
a:background="?attr/cpp_main_bg">
<LinearLayout
a:layout_width="match_parent"
a:layout_height="wrap_content"
a:orientation="horizontal">
<include layout="@layout/cpp_app_button_equals_no_bg" />
<TextView
a:layout_width="0dp"
a:layout_height="match_parent"
style="@style/CppText.Display"
a:text="3.1415"
a:layout_weight="2"/>
</LinearLayout>
<LinearLayout
a:layout_width="match_parent"
a:layout_height="wrap_content"

View File

@ -51,11 +51,10 @@
a:layout_weight="0"
a:layout_gravity="center"
a:id="@+id/wizard_dragbutton"
a:background="@drawable/cpp_wizard_button_selector"
a:text="9"
c:textDown="^2"
c:textUp="%"
c:directionTextScale="0.5;0.5;0.5;0.33"
style="?attr/cpp_button_style_control" />
style="?attr/cpp_button_style_operation" />
</LinearLayout>

View File

@ -43,7 +43,7 @@
a:baselineAligned="false">
<include
layout="@layout/cpp_app_button_equals"
layout="@layout/cpp_app_button_equals_no_bg"
a:layout_width="0dp"
a:layout_height="match_parent"
a:layout_weight="1" />

View File

@ -31,6 +31,7 @@
<attr name="cpp_pane_bg" format="reference"/>
<attr name="cpp_fab_bg" format="reference"/>
<attr name="cpp_toolbar_theme" format="reference"/>
<attr name="cpp_wizard_button_bg" format="reference"/>
<attr name="cpp_text_color" format="reference"/>
<attr name="cpp_text_error_color" format="reference"/>

View File

@ -45,7 +45,10 @@
<color name="cpp_metro_button_light">@color/cpp_material_grey_light</color>
<color name="cpp_metro_blue">#10648c</color>
<color name="cpp_material_blue">#ff0d4663</color>
<color name="cpp_material_light">#2196F3</color>
<color name="cpp_material_blue_lighter">#ff0d668d</color>
<color name="cpp_material_light">#4285f4</color>
<color name="cpp_material_light_darker">#ff3463bd</color>
<color name="cpp_material_light_disabled">#c1d2ef</color>
<color name="cpp_metro_blue_dark">#ff092c39</color>
<color name="cpp_metro_green">#088e3a</color>
<color name="cpp_metro_purple">#651456</color>

View File

@ -37,6 +37,7 @@
<item name="android:textSize">@dimen/cpp_keyboard_button_text_size</item>
<item name="android:textColor">@color/cpp_button_text</item>
<item name="android:scaleType">centerInside</item>
<item name="directionTextColor">@color/cpp_button_text</item>
</style>
<style name="cpp_onscreen_editor_style" parent="CppText.Editor">
@ -173,8 +174,8 @@
</style>
<style name="MaterialButton.Wizard" parent="MaterialButton">
<item name="android:textColor">@color/cpp_text</item>
<item name="materialColor">@color/cpp_wizard_button_selector</item>
<item name="android:textColor">@color/cpp_button_text</item>
<item name="materialColor">?attr/cpp_wizard_button_bg</item>
<item name="android:textAppearance">@android:style/TextAppearance.Medium</item>
</style>

View File

@ -108,21 +108,17 @@
</style>
<style name="Cpp.Theme.Wizard" parent="Cpp.Theme.Material">
<item name="android:windowBackground">@color/cpp_material_grey</item>
<item name="android:colorEdgeEffect">@color/cpp_wizard_overscroll</item>
<item name="colorAccent">@color/cpp_wizard_primary</item>
<item name="android:colorAccent">@color/cpp_wizard_primary</item>
<item name="android:textColorSecondary">@color/cpp_wizard_secondary</item>
<item name="android:textColorPrimary">@color/cpp_wizard_primary</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowActionBar">false</item>
<item name="cpp_wizard_button_bg">@color/cpp_wizard_button_selector</item>
</style>
<style name="Cpp.Theme.Wizard.Light" parent="Cpp.Theme.Material.Light">
<item name="android:windowBackground">@color/cpp_material_grey</item>
<item name="android:colorEdgeEffect">@color/cpp_wizard_overscroll</item>
<item name="colorAccent">@color/cpp_wizard_primary</item>
<item name="android:colorAccent">@color/cpp_wizard_primary</item>
<item name="android:textColorSecondary">@color/cpp_wizard_secondary</item>
<item name="android:textColorPrimary">@color/cpp_wizard_primary</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowActionBar">false</item>
<item name="cpp_wizard_button_bg">@color/cpp_wizard_button_selector_light</item>
</style>
<style name="Cpp.Theme.Settings" parent="Cpp.Theme">