tests added
This commit is contained in:
@@ -242,6 +242,11 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static SharedPreferences getPreferences() {
|
||||
return PreferenceManager.getDefaultSharedPreferences(getInstance());
|
||||
}
|
||||
|
||||
public static boolean isMonkeyRunner(@Nonnull Context context) {
|
||||
// NOTE: this code is only for monkeyrunner
|
||||
return context.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) == PackageManager.PERMISSION_GRANTED;
|
||||
|
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.wizard;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.solovyev.android.calculator.wizard.WizardStep.last;
|
||||
import static org.solovyev.android.calculator.wizard.Wizards.DEFAULT_WIZARD_FLOW;
|
||||
import static org.solovyev.android.calculator.wizard.Wizards.FIRST_TIME_WIZARD;
|
||||
import static org.solovyev.android.calculator.wizard.WizardStep.welcome;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 6/16/13
|
||||
* Time: 9:25 PM
|
||||
*/
|
||||
final class AppWizardFlow implements WizardFlow {
|
||||
|
||||
@Nonnull
|
||||
private final ListWizardFlow listWizardFlow;
|
||||
|
||||
private AppWizardFlow(@Nonnull String name, @Nonnull List<WizardStep> wizardSteps) {
|
||||
this.listWizardFlow = new ListWizardFlow(name, wizardSteps);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
static AppWizardFlow newDefaultWizardFlow() {
|
||||
final List<WizardStep> wizardSteps = new ArrayList<WizardStep>();
|
||||
for (WizardStep wizardStep : WizardStep.values()) {
|
||||
if (wizardStep != welcome && wizardStep != last && wizardStep.isVisible()) {
|
||||
wizardSteps.add(wizardStep);
|
||||
}
|
||||
}
|
||||
return new AppWizardFlow(DEFAULT_WIZARD_FLOW, wizardSteps);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
static AppWizardFlow newFirstTimeWizardFlow() {
|
||||
final List<WizardStep> wizardSteps = new ArrayList<WizardStep>();
|
||||
for (WizardStep wizardStep : WizardStep.values()) {
|
||||
if (wizardStep.isVisible()) {
|
||||
wizardSteps.add(wizardStep);
|
||||
}
|
||||
}
|
||||
return new AppWizardFlow(FIRST_TIME_WIZARD, wizardSteps);
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return listWizardFlow.getName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public WizardStep getStep(@Nonnull String name) {
|
||||
return listWizardFlow.getStep(name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public WizardStep getNextStep(@Nonnull WizardStep step) {
|
||||
return listWizardFlow.getNextStep(step);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public WizardStep getPrevStep(@Nonnull WizardStep step) {
|
||||
return listWizardFlow.getPrevStep(step);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public WizardStep getFirstStep() {
|
||||
return listWizardFlow.getFirstStep();
|
||||
}
|
||||
}
|
@@ -1,20 +1,13 @@
|
||||
package org.solovyev.android.calculator.wizard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import net.robotmedia.billing.BillingController;
|
||||
|
||||
import org.solovyev.android.ads.AdsController;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.preferences.CalculatorPurchaseDialogActivity;
|
||||
|
||||
|
@@ -22,21 +22,18 @@
|
||||
|
||||
package org.solovyev.android.calculator.wizard;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import org.solovyev.android.App;
|
||||
import org.solovyev.android.Views;
|
||||
import org.solovyev.android.calculator.CalculatorApplication;
|
||||
import org.solovyev.android.calculator.CalculatorPreferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.solovyev.android.calculator.CalculatorApplication.getPreferences;
|
||||
import static org.solovyev.android.calculator.wizard.ChooseLayoutWizardStep.LAYOUT;
|
||||
import static org.solovyev.android.calculator.wizard.ChooseModeWizardStep.MODE;
|
||||
import static org.solovyev.android.calculator.wizard.OnScreenCalculatorWizardStep.ONSCREEN_CALCULATOR_ENABLED;
|
||||
@@ -55,10 +52,8 @@ enum WizardStep {
|
||||
boolean onNext(@Nonnull Fragment f) {
|
||||
final ChooseLayoutWizardStep fragment = (ChooseLayoutWizardStep) f;
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(f.getActivity());
|
||||
|
||||
final CalculatorLayout layout = fragment.getSelectedLayout();
|
||||
layout.apply(preferences);
|
||||
layout.apply(getPreferences());
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -66,10 +61,8 @@ enum WizardStep {
|
||||
@Nullable
|
||||
@Override
|
||||
Bundle getFragmentArgs() {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(LAYOUT, CalculatorLayout.fromGuiLayout(CalculatorPreferences.Gui.layout.getPreference(preferences)));
|
||||
bundle.putSerializable(LAYOUT, CalculatorLayout.fromGuiLayout(CalculatorPreferences.Gui.layout.getPreference(getPreferences())));
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@@ -84,10 +77,8 @@ enum WizardStep {
|
||||
boolean onNext(@Nonnull Fragment f) {
|
||||
final ChooseModeWizardStep fragment = (ChooseModeWizardStep) f;
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(f.getActivity());
|
||||
|
||||
final CalculatorMode mode = fragment.getSelectedMode();
|
||||
mode.apply(preferences);
|
||||
mode.apply(getPreferences());
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -95,10 +86,8 @@ enum WizardStep {
|
||||
@Nullable
|
||||
@Override
|
||||
Bundle getFragmentArgs() {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(MODE, CalculatorMode.fromGuiLayout(CalculatorPreferences.Gui.layout.getPreference(preferences)));
|
||||
bundle.putSerializable(MODE, CalculatorMode.fromGuiLayout(CalculatorPreferences.Gui.layout.getPreference(getPreferences())));
|
||||
return bundle;
|
||||
}
|
||||
},
|
||||
@@ -108,9 +97,7 @@ enum WizardStep {
|
||||
boolean onNext(@Nonnull Fragment f) {
|
||||
final OnScreenCalculatorWizardStep fragment = (OnScreenCalculatorWizardStep) f;
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(f.getActivity());
|
||||
|
||||
CalculatorPreferences.OnscreenCalculator.showAppIcon.putPreference(preferences, fragment.isOnscreenCalculatorEnabled());
|
||||
CalculatorPreferences.OnscreenCalculator.showAppIcon.putPreference(getPreferences(), fragment.isOnscreenCalculatorEnabled());
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -118,10 +105,8 @@ enum WizardStep {
|
||||
@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));
|
||||
bundle.putSerializable(ONSCREEN_CALCULATOR_ENABLED, CalculatorPreferences.OnscreenCalculator.showAppIcon.getPreference(getPreferences()));
|
||||
return bundle;
|
||||
}
|
||||
},
|
||||
@@ -136,8 +121,6 @@ enum WizardStep {
|
||||
private final int titleResId;
|
||||
private final int nextButtonTitleResId;
|
||||
|
||||
|
||||
|
||||
WizardStep(@Nonnull Class<? extends Fragment> fragmentClass, int titleResId) {
|
||||
this(fragmentClass, titleResId, R.string.cpp_wizard_next);
|
||||
}
|
||||
|
@@ -30,8 +30,11 @@ import org.solovyev.android.calculator.CalculatorApplication;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.solovyev.android.calculator.wizard.AppWizardFlow.newDefaultWizardFlow;
|
||||
import static org.solovyev.android.calculator.wizard.AppWizardFlow.newFirstTimeWizardFlow;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.solovyev.android.calculator.wizard.WizardStep.last;
|
||||
import static org.solovyev.android.calculator.wizard.WizardStep.welcome;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@@ -114,4 +117,26 @@ public final class Wizards {
|
||||
private static String makeLastStepPreferenceKey(@Nonnull String flowName) {
|
||||
return FLOW + ":" + flowName;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
static WizardFlow newDefaultWizardFlow() {
|
||||
final List<WizardStep> wizardSteps = new ArrayList<WizardStep>();
|
||||
for (WizardStep wizardStep : WizardStep.values()) {
|
||||
if (wizardStep != welcome && wizardStep != last && wizardStep.isVisible()) {
|
||||
wizardSteps.add(wizardStep);
|
||||
}
|
||||
}
|
||||
return new ListWizardFlow(DEFAULT_WIZARD_FLOW, wizardSteps);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
static WizardFlow newFirstTimeWizardFlow() {
|
||||
final List<WizardStep> wizardSteps = new ArrayList<WizardStep>();
|
||||
for (WizardStep wizardStep : WizardStep.values()) {
|
||||
if (wizardStep.isVisible()) {
|
||||
wizardSteps.add(wizardStep);
|
||||
}
|
||||
}
|
||||
return new ListWizardFlow(FIRST_TIME_WIZARD, wizardSteps);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user