wizard changes
This commit is contained in:
@@ -26,6 +26,9 @@ import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple;
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple_mobile;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/28/12
|
||||
@@ -149,7 +152,7 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
|
||||
roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences));
|
||||
}
|
||||
|
||||
if (layout == CalculatorPreferences.Gui.Layout.simple) {
|
||||
if (layout == simple || layout == simple_mobile) {
|
||||
toggleButtonDirectionText(root, R.id.cpp_button_1, false, DragDirection.up, DragDirection.down);
|
||||
toggleButtonDirectionText(root, R.id.cpp_button_2, false, DragDirection.up, DragDirection.down);
|
||||
toggleButtonDirectionText(root, R.id.cpp_button_3, false, DragDirection.up, DragDirection.down);
|
||||
|
@@ -43,7 +43,22 @@ enum CalculatorLayout {
|
||||
protected abstract void apply(@Nonnull SharedPreferences preferences);
|
||||
|
||||
@Nonnull
|
||||
static CalculatorLayout getDefaultMode(){
|
||||
static CalculatorLayout getDefaultLayout(){
|
||||
return big_buttons;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
static CalculatorLayout fromGuiLayout(@Nonnull CalculatorPreferences.Gui.Layout layout) {
|
||||
switch (layout) {
|
||||
case main_calculator:
|
||||
case main_cellphone:
|
||||
case simple:
|
||||
return optimized;
|
||||
case main_calculator_mobile:
|
||||
case simple_mobile:
|
||||
return big_buttons;
|
||||
default:
|
||||
return getDefaultLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.main_calculator;
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.main_calculator_mobile;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@@ -20,7 +21,12 @@ enum CalculatorMode {
|
||||
simple(R.string.cpp_wizard_mode_simple) {
|
||||
@Override
|
||||
protected void apply(@Nonnull SharedPreferences preferences) {
|
||||
CalculatorPreferences.Gui.layout.putPreference(preferences, CalculatorPreferences.Gui.Layout.simple);
|
||||
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreference(preferences);
|
||||
if (layout.isOptimized()) {
|
||||
CalculatorPreferences.Gui.layout.putPreference(preferences, CalculatorPreferences.Gui.Layout.simple);
|
||||
} else {
|
||||
CalculatorPreferences.Gui.layout.putPreference(preferences, CalculatorPreferences.Gui.Layout.simple_mobile);
|
||||
}
|
||||
CalculatorPreferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.deg);
|
||||
AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, AngleUnit.deg);
|
||||
AndroidCalculatorEngine.Preferences.scienceNotation.putPreference(preferences, false);
|
||||
@@ -31,7 +37,12 @@ enum CalculatorMode {
|
||||
engineer(R.string.cpp_wizard_mode_engineer) {
|
||||
@Override
|
||||
protected void apply(@Nonnull SharedPreferences preferences) {
|
||||
CalculatorPreferences.Gui.layout.putPreference(preferences, main_calculator);
|
||||
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreference(preferences);
|
||||
if (layout.isOptimized()) {
|
||||
CalculatorPreferences.Gui.layout.putPreference(preferences, main_calculator);
|
||||
} else {
|
||||
CalculatorPreferences.Gui.layout.putPreference(preferences, main_calculator_mobile);
|
||||
}
|
||||
CalculatorPreferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.rad);
|
||||
AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, AngleUnit.rad);
|
||||
AndroidCalculatorEngine.Preferences.scienceNotation.putPreference(preferences, true);
|
||||
@@ -55,4 +66,19 @@ enum CalculatorMode {
|
||||
static CalculatorMode getDefaultMode(){
|
||||
return engineer;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
static CalculatorMode fromGuiLayout(@Nonnull CalculatorPreferences.Gui.Layout layout) {
|
||||
switch (layout) {
|
||||
case main_calculator:
|
||||
case main_cellphone:
|
||||
case main_calculator_mobile:
|
||||
return engineer;
|
||||
case simple:
|
||||
case simple_mobile:
|
||||
return simple;
|
||||
default:
|
||||
return getDefaultMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,111 @@
|
||||
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;
|
||||
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorLayout.big_buttons;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorLayout.getDefaultLayout;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorLayout.optimized;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 6/19/13
|
||||
* Time: 12:33 AM
|
||||
*/
|
||||
public class ChooseLayoutWizardStep extends SherlockFragment {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTANTS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
static final String LAYOUT = "layout";
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@Nullable
|
||||
private RadioButton optimizedRadioButton;
|
||||
|
||||
@Nullable
|
||||
private RadioButton bigButtonsRadioButton;
|
||||
|
||||
private CalculatorLayout layout;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if(savedInstanceState != null) {
|
||||
layout = (CalculatorLayout) savedInstanceState.getSerializable(LAYOUT);
|
||||
}
|
||||
|
||||
if (layout == null) {
|
||||
layout = (CalculatorLayout) getArguments().getSerializable(LAYOUT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.cpp_wizard_step_tablet, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
optimizedRadioButton = (RadioButton) root.findViewById(R.id.wizard_optimized_radiobutton);
|
||||
bigButtonsRadioButton = (RadioButton) root.findViewById(R.id.wizard_big_buttons_radiobutton);
|
||||
|
||||
switch (layout) {
|
||||
case big_buttons:
|
||||
bigButtonsRadioButton.setChecked(true);
|
||||
optimizedRadioButton.setChecked(false);
|
||||
break;
|
||||
case optimized:
|
||||
bigButtonsRadioButton.setChecked(false);
|
||||
optimizedRadioButton.setChecked(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
CalculatorLayout getSelectedLayout() {
|
||||
CalculatorLayout layout = getDefaultLayout();
|
||||
|
||||
if (bigButtonsRadioButton != null && bigButtonsRadioButton.isChecked()) {
|
||||
layout = big_buttons;
|
||||
} else if (optimizedRadioButton != null && optimizedRadioButton.isChecked()) {
|
||||
layout = optimized;
|
||||
}
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
||||
outState.putSerializable(LAYOUT, layout);
|
||||
}
|
||||
}
|
@@ -25,7 +25,7 @@ import static org.solovyev.android.calculator.wizard.CalculatorMode.getDefaultMo
|
||||
* Date: 6/16/13
|
||||
* Time: 9:59 PM
|
||||
*/
|
||||
public final class ChooseModeWizardStep extends SherlockFragment {
|
||||
public class ChooseModeWizardStep extends SherlockFragment {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
|
@@ -1,156 +0,0 @@
|
||||
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.Spinner;
|
||||
import android.widget.TextView;
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.list.ListItem;
|
||||
import org.solovyev.android.list.ListItemAdapter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorLayout.getDefaultMode;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 6/19/13
|
||||
* Time: 12:33 AM
|
||||
*/
|
||||
final class TabletWizardStep extends SherlockFragment {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTANTS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
static final String LAYOUT = "layout";
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@Nullable
|
||||
private Spinner layoutSpinner;
|
||||
|
||||
private CalculatorLayout layout;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if(savedInstanceState != null) {
|
||||
layout = (CalculatorLayout) savedInstanceState.getSerializable(LAYOUT);
|
||||
}
|
||||
|
||||
if (layout == null) {
|
||||
layout = (CalculatorLayout) getArguments().getSerializable(LAYOUT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.cpp_wizard_step_tablet, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
layoutSpinner = (Spinner) root.findViewById(R.id.wizard_layout_spinner);
|
||||
|
||||
final List<LayoutListItem> listItems = new ArrayList<LayoutListItem>();
|
||||
for (CalculatorLayout layout : CalculatorLayout.values()) {
|
||||
listItems.add(new LayoutListItem(layout));
|
||||
}
|
||||
layoutSpinner.setAdapter(ListItemAdapter.newInstance(getActivity(), listItems));
|
||||
|
||||
final int position = Arrays.binarySearch(CalculatorMode.values(), layout);
|
||||
if (position >= 0) {
|
||||
layoutSpinner.setSelection(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
CalculatorLayout getSelectedLayout() {
|
||||
CalculatorLayout layout = getDefaultMode();
|
||||
|
||||
if (layoutSpinner != null) {
|
||||
final int position = layoutSpinner.getSelectedItemPosition();
|
||||
|
||||
if (position >= 0 && position < CalculatorLayout.values().length) {
|
||||
layout = CalculatorLayout.values()[position];
|
||||
}
|
||||
}
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
||||
outState.putSerializable(LAYOUT, layout);
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC/INNER
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private static final class LayoutListItem implements ListItem {
|
||||
|
||||
@Nonnull
|
||||
private final CalculatorLayout layout;
|
||||
|
||||
private LayoutListItem(@Nonnull CalculatorLayout layout) {
|
||||
this.layout = layout;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public OnClickAction getOnClickAction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public OnClickAction getOnLongClickAction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public View updateView(@Nonnull Context context, @Nonnull View view) {
|
||||
return build(context);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public View build(@Nonnull Context context) {
|
||||
final TextView textView = new TextView(context);
|
||||
textView.setText(layout.getNameResId());
|
||||
return textView;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -32,17 +32,4 @@ public final class Wizard {
|
||||
throw new IllegalArgumentException("Wizard flow " + name + " is not supported");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC/INNER
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
static final class Preferences {
|
||||
static final Preference<CalculatorMode> mode = ofEnum("mode", CalculatorMode.getDefaultMode(), CalculatorMode.class);
|
||||
static final Preference<CalculatorLayout> layout = ofEnum("layout", CalculatorLayout.getDefaultMode(), CalculatorLayout.class);
|
||||
}
|
||||
}
|
||||
|
@@ -1,17 +1,22 @@
|
||||
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.CalculatorLocator;
|
||||
import org.solovyev.android.calculator.CalculatorPreferences;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.solovyev.android.calculator.wizard.ChooseModeWizardStep.MODE;
|
||||
import static org.solovyev.android.calculator.wizard.TabletWizardStep.LAYOUT;
|
||||
import static org.solovyev.android.calculator.wizard.Wizard.Preferences;
|
||||
import static org.solovyev.android.calculator.wizard.ChooseLayoutWizardStep.LAYOUT;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@@ -38,6 +43,40 @@ enum WizardStep {
|
||||
}
|
||||
},
|
||||
|
||||
choose_layout(ChooseLayoutWizardStep.class) {
|
||||
@Override
|
||||
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);
|
||||
|
||||
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(LAYOUT, CalculatorLayout.fromGuiLayout(CalculatorPreferences.Gui.layout.getPreference(preferences)));
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, App.getApplication().getResources().getConfiguration());
|
||||
}
|
||||
},
|
||||
|
||||
choose_mode(ChooseModeWizardStep.class) {
|
||||
@Override
|
||||
boolean onNext(@Nonnull Fragment f) {
|
||||
@@ -47,7 +86,6 @@ enum WizardStep {
|
||||
|
||||
final CalculatorMode mode = fragment.getSelectedMode();
|
||||
mode.apply(preferences);
|
||||
Preferences.mode.putPreference(preferences, mode);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -63,37 +101,7 @@ enum WizardStep {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(MODE, Preferences.mode.getPreference(preferences));
|
||||
return bundle;
|
||||
}
|
||||
},
|
||||
|
||||
tablet(TabletWizardStep.class) {
|
||||
@Override
|
||||
boolean onNext(@Nonnull Fragment f) {
|
||||
final TabletWizardStep fragment = (TabletWizardStep) f;
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(f.getActivity());
|
||||
|
||||
final CalculatorLayout layout = fragment.getSelectedLayout();
|
||||
layout.apply(preferences);
|
||||
Preferences.layout.putPreference(preferences, layout);
|
||||
|
||||
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(LAYOUT, Preferences.layout.getPreference(preferences));
|
||||
bundle.putSerializable(MODE, CalculatorMode.fromGuiLayout(CalculatorPreferences.Gui.layout.getPreference(preferences)));
|
||||
return bundle;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user