From 723fd1a46116df36ca19712af302f648ad750d1a Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Tue, 25 Jun 2013 00:46:37 +0400 Subject: [PATCH] Wizard improved --- android-app-core/res/values/text_wizard.xml | 14 ++- .../layout/cpp_wizard_step_choose_layout.xml | 82 ++++++++--------- .../layout/cpp_wizard_step_choose_mode.xml | 50 +++++++++- .../layout/cpp_wizard_step_drag_button.xml | 4 + .../calculator/CalculatorActivity.java | 2 +- .../wizard/CalculatorWizardActivity.java | 46 ++++++---- .../wizard/ChooseModeWizardStep.java | 92 +++++-------------- .../wizard/DragButtonWizardStep.java | 16 ++-- .../android/calculator/wizard/WizardStep.java | 23 +++-- .../wizard/CalculatorWizardActivityTest.java | 6 ++ 10 files changed, 179 insertions(+), 156 deletions(-) diff --git a/android-app-core/res/values/text_wizard.xml b/android-app-core/res/values/text_wizard.xml index 7b7a620c..2debb5dd 100644 --- a/android-app-core/res/values/text_wizard.xml +++ b/android-app-core/res/values/text_wizard.xml @@ -17,9 +17,15 @@ Result is is not rounded and is presented in engineer notation. Start wizard - Tap button once to use value located in the center - Drag from the center of the button up to use function in the upper right corner - Drag from the center of the button to the left to use function to the left - Drag from the center of the button down to use function in the bottom right corner + Excellent! Tap button one more time to try again + Tap button once to use 9 + Drag from the center of the button up to use % + Drag from the center of the button to the left to use sin + Drag from the center of the button down to use ^2 + Welcome + Choose layout + Choose mode + Calculator in separate window + Drag button basics \ No newline at end of file diff --git a/android-app/res/layout/cpp_wizard_step_choose_layout.xml b/android-app/res/layout/cpp_wizard_step_choose_layout.xml index b2d3ff06..43d38bec 100644 --- a/android-app/res/layout/cpp_wizard_step_choose_layout.xml +++ b/android-app/res/layout/cpp_wizard_step_choose_layout.xml @@ -1,56 +1,52 @@ + a:layout_width="match_parent" + a:layout_height="match_parent" + a:orientation="vertical"> - + - + - + - + - + - + - - - - - - - + diff --git a/android-app/res/layout/cpp_wizard_step_choose_mode.xml b/android-app/res/layout/cpp_wizard_step_choose_mode.xml index 1d36d4e6..879bd099 100644 --- a/android-app/res/layout/cpp_wizard_step_choose_mode.xml +++ b/android-app/res/layout/cpp_wizard_step_choose_mode.xml @@ -10,9 +10,51 @@ a:layout_height="wrap_content" a:layout_width="match_parent" /> - + + + + + + + + + + + + + + + + + + + diff --git a/android-app/res/layout/cpp_wizard_step_drag_button.xml b/android-app/res/layout/cpp_wizard_step_drag_button.xml index 65a5f19e..104a7741 100644 --- a/android-app/res/layout/cpp_wizard_step_drag_button.xml +++ b/android-app/res/layout/cpp_wizard_step_drag_button.xml @@ -13,6 +13,8 @@ @@ -21,6 +23,8 @@ a:layout_margin="30dp" a:layout_height="100dp" a:layout_width="100dp" + a:minWidth="100dp" + a:minHeight="100dp" a:layout_gravity="center" a:id="@+id/wizard_dragbutton" a:text="9" diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index d2da2478..4518fb24 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -153,7 +153,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar //Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!"); if (!dialogShown) { - if (appOpenedCounter != null && appOpenedCounter > 10) { + if (appOpenedCounter != null && appOpenedCounter > 100) { dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.feedbackWindowShown, R.layout.feedback, R.id.feedbackText, context); } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/wizard/CalculatorWizardActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/wizard/CalculatorWizardActivity.java index 6bf76c01..eb51c86a 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/wizard/CalculatorWizardActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/wizard/CalculatorWizardActivity.java @@ -75,22 +75,20 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity { void setStep(@Nonnull WizardStep step) { if (this.step == null || !this.step.equals(step)) { - final FragmentManager fm = getSupportFragmentManager(); - final FragmentTransaction ft = fm.beginTransaction(); - - hideFragment(fm, ft); - + hideFragment(); this.step = step; + showFragment(); - showFragment(fm, ft); - - ft.commit(); - + initTitle(); initNextButton(); initPrevButton(); } } + private void initTitle() { + setTitle(step.getTitleResId()); + } + private void initPrevButton() { final WizardStep prevStep = flow.getPrevStep(step); if (prevStep == null) { @@ -167,25 +165,39 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity { } @Nonnull - private Fragment showFragment(@Nonnull FragmentManager fm, @Nonnull FragmentTransaction ft) { + private Fragment showFragment() { + final FragmentManager fm = getSupportFragmentManager(); + final FragmentTransaction ft = fm.beginTransaction(); + Fragment newFragment = fm.findFragmentByTag(this.step.getFragmentTag()); if (newFragment == null) { newFragment = Fragment.instantiate(this, this.step.getFragmentClass().getName(), this.step.getFragmentArgs()); ft.add(R.id.wizard_content, newFragment, this.step.getFragmentTag()); - } else { - ft.show(newFragment); } + ft.commit(); + fm.executePendingTransactions(); + return newFragment; } - private void hideFragment(@Nonnull FragmentManager fm, @Nonnull FragmentTransaction ft) { + private void hideFragment() { + final FragmentManager fm = getSupportFragmentManager(); + final FragmentTransaction ft = fm.beginTransaction(); + if (this.step != null) { - final Fragment oldFragment = fm.findFragmentByTag(this.step.getFragmentTag()); - if (oldFragment != null) { - ft.hide(oldFragment); - } + hideFragmentByTag(fm, ft, this.step.getFragmentTag()); + } + + ft.commit(); + fm.executePendingTransactions(); + } + + private void hideFragmentByTag(@Nonnull FragmentManager fm, @Nonnull FragmentTransaction ft, @Nonnull String fragmentTag) { + final Fragment oldFragment = fm.findFragmentByTag(fragmentTag); + if (oldFragment != null) { + ft.remove(oldFragment); } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/wizard/ChooseModeWizardStep.java b/android-app/src/main/java/org/solovyev/android/calculator/wizard/ChooseModeWizardStep.java index 538a40da..b28d883d 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/wizard/ChooseModeWizardStep.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/wizard/ChooseModeWizardStep.java @@ -1,24 +1,17 @@ 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 android.widget.RadioButton; 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.CalculatorMode.getDefaultMode; +import static org.solovyev.android.calculator.wizard.CalculatorMode.*; /** * User: serso @@ -46,7 +39,10 @@ public class ChooseModeWizardStep extends SherlockFragment { */ @Nullable - private Spinner modeSpinner; + private RadioButton simpleModeRadioButton; + + @Nullable + private RadioButton engineerModeRadioButton; private CalculatorMode mode; @@ -72,17 +68,18 @@ public class ChooseModeWizardStep extends SherlockFragment { public void onViewCreated(View root, Bundle savedInstanceState) { super.onViewCreated(root, savedInstanceState); - modeSpinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner); + simpleModeRadioButton = (RadioButton) root.findViewById(R.id.wizard_simple_mode_radiobutton); + engineerModeRadioButton = (RadioButton) root.findViewById(R.id.wizard_engineer_mode_radiobutton); - final List listItems = new ArrayList(); - for (CalculatorMode mode : CalculatorMode.values()) { - listItems.add(new ModeListItem(mode)); - } - modeSpinner.setAdapter(ListItemAdapter.newInstance(getActivity(), listItems)); - - final int position = Arrays.binarySearch(CalculatorMode.values(), mode); - if (position >= 0) { - modeSpinner.setSelection(position); + switch (mode) { + case simple: + simpleModeRadioButton.setChecked(true); + engineerModeRadioButton.setChecked(false); + break; + case engineer: + simpleModeRadioButton.setChecked(false); + engineerModeRadioButton.setChecked(true); + break; } } @@ -90,12 +87,12 @@ public class ChooseModeWizardStep extends SherlockFragment { CalculatorMode getSelectedMode() { CalculatorMode mode = getDefaultMode(); - if (modeSpinner != null) { - final int position = modeSpinner.getSelectedItemPosition(); + if (simpleModeRadioButton != null && simpleModeRadioButton.isChecked()) { + mode = simple; + } - if (position >= 0 && position < CalculatorMode.values().length) { - mode = CalculatorMode.values()[position]; - } + if (engineerModeRadioButton != null && engineerModeRadioButton.isChecked()) { + mode = engineer; } return mode; @@ -107,49 +104,4 @@ public class ChooseModeWizardStep extends SherlockFragment { outState.putSerializable(MODE, mode); } - - /* - ********************************************************************** - * - * STATIC/INNER - * - ********************************************************************** - */ - - private static final class ModeListItem implements ListItem { - - @Nonnull - private final CalculatorMode mode; - - private ModeListItem(@Nonnull CalculatorMode mode) { - this.mode = mode; - } - - @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(mode.getNameResId()); - return textView; - } - } - } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/wizard/DragButtonWizardStep.java b/android-app/src/main/java/org/solovyev/android/calculator/wizard/DragButtonWizardStep.java index 17e79ee8..a1a4045d 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/wizard/DragButtonWizardStep.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/wizard/DragButtonWizardStep.java @@ -6,12 +6,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; - -import java.util.Arrays; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - +import com.actionbarsherlock.app.SherlockFragment; import org.solovyev.android.calculator.R; import org.solovyev.android.view.drag.DirectionDragButton; import org.solovyev.android.view.drag.DragButton; @@ -19,7 +14,9 @@ import org.solovyev.android.view.drag.DragDirection; import org.solovyev.android.view.drag.SimpleOnDragListener; import org.solovyev.common.math.Point2d; -import com.actionbarsherlock.app.SherlockFragment; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.Arrays; public class DragButtonWizardStep extends SherlockFragment { @@ -94,7 +91,8 @@ public class DragButtonWizardStep extends SherlockFragment { center(R.string.cpp_wizard_dragbutton_action_center, null), up(R.string.cpp_wizard_dragbutton_action_up, DragDirection.up), left(R.string.cpp_wizard_dragbutton_action_left, DragDirection.left), - down(R.string.cpp_wizard_dragbutton_action_down, DragDirection.down); + down(R.string.cpp_wizard_dragbutton_action_down, DragDirection.down), + end(R.string.cpp_wizard_dragbutton_action_end, null); private final int actionTextResId; @@ -121,7 +119,7 @@ public class DragButtonWizardStep extends SherlockFragment { private class DragButtonOnClickListener implements View.OnClickListener { @Override public void onClick(View v) { - if(action == DragButtonAction.center) { + if(action == DragButtonAction.center || action == DragButtonAction.end) { setNextAction(); } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/wizard/WizardStep.java b/android-app/src/main/java/org/solovyev/android/calculator/wizard/WizardStep.java index ce24a171..88820919 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/wizard/WizardStep.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/wizard/WizardStep.java @@ -5,17 +5,17 @@ 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.wizard.ChooseModeWizardStep.MODE; 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; /** @@ -25,7 +25,7 @@ import static org.solovyev.android.calculator.wizard.OnScreenCalculatorWizardSte */ enum WizardStep { - welcome(WelcomeWizardStep.class) { + welcome(WelcomeWizardStep.class, R.string.cpp_wizard_welcome_title) { @Override boolean onNext(@Nonnull Fragment fragment) { return true; @@ -43,7 +43,7 @@ enum WizardStep { } }, - choose_layout(ChooseLayoutWizardStep.class) { + choose_layout(ChooseLayoutWizardStep.class, R.string.cpp_wizard_layout_title) { @Override boolean onNext(@Nonnull Fragment f) { final ChooseLayoutWizardStep fragment = (ChooseLayoutWizardStep) f; @@ -77,7 +77,7 @@ enum WizardStep { } }, - choose_mode(ChooseModeWizardStep.class) { + choose_mode(ChooseModeWizardStep.class, R.string.cpp_wizard_mode_title) { @Override boolean onNext(@Nonnull Fragment f) { final ChooseModeWizardStep fragment = (ChooseModeWizardStep) f; @@ -106,7 +106,7 @@ enum WizardStep { } }, - on_screen_calculator(OnScreenCalculatorWizardStep.class) { + on_screen_calculator(OnScreenCalculatorWizardStep.class, R.string.cpp_wizard_onscreen_calculator_title) { @Override boolean onNext(@Nonnull Fragment f) { final OnScreenCalculatorWizardStep fragment = (OnScreenCalculatorWizardStep) f; @@ -134,7 +134,7 @@ enum WizardStep { } }, - drag_button_step(DragButtonWizardStep.class) { + drag_button_step(DragButtonWizardStep.class, R.string.cpp_wizard_dragbutton_title) { @Override boolean onNext(@Nonnull Fragment fragment) { return true; @@ -155,8 +155,11 @@ enum WizardStep { @Nonnull private final Class fragmentClass; - WizardStep(@Nonnull Class fragmentClass) { + private final int titleResId; + + WizardStep(@Nonnull Class fragmentClass, int titleResId) { this.fragmentClass = fragmentClass; + this.titleResId = titleResId; } public String getFragmentTag() { @@ -168,6 +171,10 @@ enum WizardStep { return fragmentClass; } + int getTitleResId() { + return titleResId; + } + abstract boolean onNext(@Nonnull Fragment fragment); abstract boolean onPrev(@Nonnull Fragment fragment); diff --git a/android-app/src/test/java/org/solovyev/android/calculator/wizard/CalculatorWizardActivityTest.java b/android-app/src/test/java/org/solovyev/android/calculator/wizard/CalculatorWizardActivityTest.java index 7693e8b2..2058410b 100644 --- a/android-app/src/test/java/org/solovyev/android/calculator/wizard/CalculatorWizardActivityTest.java +++ b/android-app/src/test/java/org/solovyev/android/calculator/wizard/CalculatorWizardActivityTest.java @@ -119,4 +119,10 @@ public class CalculatorWizardActivityTest { startWizard(Wizard.DEFAULT_WIZARD_FLOW, shadowActivity.getApplicationContext()); assertNotNull(shadowActivity.getNextStartedActivity()); } + + @Test + public void testTitleShouldBeSet() throws Exception { + activity.setStep(choose_mode); + assertEquals(activity.getString(choose_mode.getTitleResId()), activity.getTitle().toString()); + } }