on screen calculator wizard step

This commit is contained in:
Sergey Solovyev 2013-06-24 15:50:27 +04:00
parent 8084bd7683
commit 83dce53d15
9 changed files with 235 additions and 5 deletions

View File

@ -15,4 +15,5 @@
<string name="cpp_wizard_mode_engineer">Engineer</string>
<string name="cpp_wizard_mode_engineer_description">In engineer mode special functions will be used on the main screen.
Result is is not rounded and is presented in engineer notation.</string>
<string name="cpp_restart_wizard">Start wizard</string>
</resources>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:orientation="vertical">
<TextView
a:text="Calculator in separate window allows you to do calculations while using other apps on your device"
a:layout_height="wrap_content"
a:layout_width="match_parent" />
<CheckBox
a:id="@+id/wizard_onscreen_app_enabled_checkbox"
a:layout_height="wrap_content"
a:layout_width="match_parent"
a:text="Enable calculator in separate window (second icon will appear in the apps list)"/>
</LinearLayout>

View File

@ -23,6 +23,10 @@
a:summary="@string/c_clear_billing_info_summary"
a:title="@string/c_clear_billing_info_title" />
<Preference
a:key="restart_wizard"
a:title="@string/cpp_restart_wizard" />
</PreferenceScreen>
</PreferenceScreen>

View File

@ -26,6 +26,8 @@ import org.solovyev.android.App;
import org.solovyev.android.ads.AdsController;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import org.solovyev.android.calculator.wizard.CalculatorWizardActivity;
import org.solovyev.android.calculator.wizard.Wizard;
import org.solovyev.android.msg.AndroidMessage;
import org.solovyev.android.view.VibratorContainer;
import org.solovyev.common.msg.Message;
@ -38,7 +40,8 @@ import org.solovyev.common.msg.MessageType;
*/
public class CalculatorPreferencesActivity extends SherlockPreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener, IBillingObserver {
public static final String CLEAR_BILLING_INFO = "clear_billing_info";
public static final String PREFERENCE_CLEAR_BILLING_INFO = "clear_billing_info";
public static final String PREFERENCE_RESTART_WIZARD = "restart_wizard";
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -53,6 +56,15 @@ public class CalculatorPreferencesActivity extends SherlockPreferenceActivity im
addPreferencesFromResource(R.xml.preferences_other);
addPreferencesFromResource(R.xml.preferences_onscreen);
final Preference restartWizardPreference = findPreference(PREFERENCE_RESTART_WIZARD);
restartWizardPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
CalculatorWizardActivity.startWizard(Wizard.DEFAULT_WIZARD_FLOW, CalculatorPreferencesActivity.this);
return true;
}
});
final Preference adFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY);
adFreePreference.setEnabled(false);
@ -66,7 +78,7 @@ public class CalculatorPreferencesActivity extends SherlockPreferenceActivity im
onSharedPreferenceChanged(preferences, AndroidCalculatorEngine.Preferences.roundResult.getKey());
onSharedPreferenceChanged(preferences, VibratorContainer.Preferences.hapticFeedbackEnabled.getKey());
final Preference clearBillingInfoPreference = findPreference(CLEAR_BILLING_INFO);
final Preference clearBillingInfoPreference = findPreference(PREFERENCE_CLEAR_BILLING_INFO);
if (clearBillingInfoPreference != null) {
clearBillingInfoPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override

View File

@ -1,12 +1,10 @@
package org.solovyev.android.calculator.wizard;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.TextView;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -67,7 +65,7 @@ public class ChooseLayoutWizardStep extends SherlockFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.cpp_wizard_step_tablet, null);
return inflater.inflate(R.layout.cpp_wizard_step_choose_layout, null);
}
@Override

View File

@ -0,0 +1,90 @@
package org.solovyev.android.calculator.wizard;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import javax.annotation.Nullable;
import org.solovyev.android.calculator.CalculatorPreferences;
import org.solovyev.android.calculator.R;
import com.actionbarsherlock.app.SherlockFragment;
public class OnScreenCalculatorWizardStep extends SherlockFragment {
/*
**********************************************************************
*
* CONSTANTS
*
**********************************************************************
*/
static final String ONSCREEN_CALCULATOR_ENABLED = "onscreen_calculator_enabled";
/*
**********************************************************************
*
* FIELDS
*
**********************************************************************
*/
@Nullable
private CheckBox onscreenCalculatorCheckbox;
private Boolean onscreenCalculatorEnabled;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(savedInstanceState != null && savedInstanceState.containsKey(ONSCREEN_CALCULATOR_ENABLED)) {
onscreenCalculatorEnabled = savedInstanceState.getBoolean(ONSCREEN_CALCULATOR_ENABLED);
}
if (onscreenCalculatorEnabled == null) {
onscreenCalculatorEnabled = getArguments().getBoolean(ONSCREEN_CALCULATOR_ENABLED, CalculatorPreferences.OnscreenCalculator.showAppIcon.getDefaultValue());
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.cpp_wizard_step_onscreen, null);
}
@Override
public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
onscreenCalculatorCheckbox = (CheckBox) root.findViewById(R.id.wizard_onscreen_app_enabled_checkbox);
onscreenCalculatorCheckbox.setChecked(onscreenCalculatorEnabled);
}
public Boolean isOnscreenCalculatorEnabled() {
boolean enabled = CalculatorPreferences.OnscreenCalculator.showAppIcon.getDefaultValue();
if (onscreenCalculatorCheckbox != null) {
enabled = onscreenCalculatorCheckbox.isChecked();
}
return enabled;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(ONSCREEN_CALCULATOR_ENABLED, onscreenCalculatorEnabled);
}
@Nullable
CheckBox getOnscreenCalculatorCheckbox() {
return onscreenCalculatorCheckbox;
}
}

View File

@ -17,6 +17,7 @@ import javax.annotation.Nullable;
import static org.solovyev.android.calculator.wizard.ChooseModeWizardStep.MODE;
import static org.solovyev.android.calculator.wizard.ChooseLayoutWizardStep.LAYOUT;
import static org.solovyev.android.calculator.wizard.OnScreenCalculatorWizardStep.ONSCREEN_CALCULATOR_ENABLED;
/**
* User: serso
@ -104,6 +105,34 @@ enum WizardStep {
bundle.putSerializable(MODE, CalculatorMode.fromGuiLayout(CalculatorPreferences.Gui.layout.getPreference(preferences)));
return bundle;
}
},
on_screen_calculator(OnScreenCalculatorWizardStep.class) {
@Override
boolean onNext(@Nonnull Fragment f) {
final OnScreenCalculatorWizardStep fragment = (OnScreenCalculatorWizardStep) f;
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(f.getActivity());
CalculatorPreferences.OnscreenCalculator.showAppIcon.putPreference(preferences, fragment.isOnscreenCalculatorEnabled());
return true;
}
@Override
boolean onPrev(@Nonnull Fragment fragment) {
return true;
}
@Nullable
@Override
Bundle getFragmentArgs() {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
final Bundle bundle = new Bundle();
bundle.putSerializable(ONSCREEN_CALCULATOR_ENABLED, CalculatorPreferences.OnscreenCalculator.showAppIcon.getPreference(preferences));
return bundle;
}
};
@Nonnull

View File

@ -0,0 +1,77 @@
package org.solovyev.android.calculator.wizard;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import javax.annotation.Nonnull;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.util.ActivityController;
import org.solovyev.android.calculator.CalculatorPreferences;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@RunWith(RobolectricTestRunner.class)
public class OnScreenCalculatorWizardStepTest {
@Nonnull
private OnScreenCalculatorWizardStep fragment;
@Nonnull
private CalculatorWizardActivity activity;
@Nonnull
private ActivityController<CalculatorWizardActivity> controller;
@Before
public void setUp() throws Exception {
createActivity();
setFragment();
}
private void createActivity() {
controller = Robolectric.buildActivity(CalculatorWizardActivity.class).create().start().resume();
activity = controller.get();
}
private void setFragment() {
activity.setStep(WizardStep.on_screen_calculator);
activity.getSupportFragmentManager().executePendingTransactions();
fragment = (OnScreenCalculatorWizardStep) activity.getSupportFragmentManager().findFragmentByTag(WizardStep.on_screen_calculator.getFragmentTag());
}
@Test
public void testShouldRestoreStateOnRestart() throws Exception {
fragment.getOnscreenCalculatorCheckbox().setChecked(true);
controller.restart();
assertTrue(fragment.getOnscreenCalculatorCheckbox().isChecked());
fragment.getOnscreenCalculatorCheckbox().setChecked(false);
controller.restart();
assertFalse(fragment.getOnscreenCalculatorCheckbox().isChecked());
}
@Test
public void testShouldBeEnabledIfIconIsShown() throws Exception {
testShouldBeEqualsToIconState(true);
}
@Test
public void testShouldBeDisabledIfIconIsNotShown() throws Exception {
testShouldBeEqualsToIconState(false);
}
private void testShouldBeEqualsToIconState(boolean iconEnabled) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(Robolectric.application);
CalculatorPreferences.OnscreenCalculator.showAppIcon.putPreference(preferences, iconEnabled);
createActivity();
setFragment();
assertEquals(iconEnabled, fragment.isOnscreenCalculatorEnabled());
}
}