Wizard improved

This commit is contained in:
Sergey Solovyev 2013-06-25 00:46:37 +04:00
parent 097840688c
commit 723fd1a461
10 changed files with 179 additions and 156 deletions

View File

@ -17,9 +17,15 @@
Result is is not rounded and is presented in engineer notation.</string> Result is is not rounded and is presented in engineer notation.</string>
<string name="cpp_restart_wizard">Start wizard</string> <string name="cpp_restart_wizard">Start wizard</string>
<string name="cpp_wizard_dragbutton_action_center">Tap button once to use value located in the center</string> <string name="cpp_wizard_dragbutton_action_end">Excellent! Tap button one more time to try again</string>
<string name="cpp_wizard_dragbutton_action_up">Drag from the center of the button up to use function in the upper right corner</string> <string name="cpp_wizard_dragbutton_action_center">Tap button once to use 9</string>
<string name="cpp_wizard_dragbutton_action_left">Drag from the center of the button to the left to use function to the left</string> <string name="cpp_wizard_dragbutton_action_up">Drag from the center of the button up to use %</string>
<string name="cpp_wizard_dragbutton_action_down">Drag from the center of the button down to use function in the bottom right corner</string> <string name="cpp_wizard_dragbutton_action_left">Drag from the center of the button to the left to use sin</string>
<string name="cpp_wizard_dragbutton_action_down">Drag from the center of the button down to use ^2</string>
<string name="cpp_wizard_welcome_title">Welcome</string>
<string name="cpp_wizard_layout_title">Choose layout</string>
<string name="cpp_wizard_mode_title">Choose mode</string>
<string name="cpp_wizard_onscreen_calculator_title">Calculator in separate window</string>
<string name="cpp_wizard_dragbutton_title">Drag button basics</string>
</resources> </resources>

View File

@ -1,56 +1,52 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="match_parent" a:layout_height="match_parent"
a:orientation="vertical"> a:orientation="vertical">
<TextView <RadioGroup
a:text="Do you want to use optimized layout for large screens or just big buttons?" a:orientation="horizontal"
a:layout_height="wrap_content" a:layout_width="match_parent"
a:layout_width="match_parent"/> a:layout_height="wrap_content"
a:gravity="center_vertical|top">
<LinearLayout a:layout_width="match_parent" <RadioButton
a:layout_height="match_parent" a:layout_width="0dp"
a:orientation="vertical"> a:id="@+id/wizard_optimized_radiobutton"
a:layout_weight="1"
a:text="@string/cpp_wizard_layout_optimized"
a:layout_height="wrap_content" />
<RadioGroup a:orientation="horizontal" <RadioButton
a:layout_width="match_parent" a:layout_width="0dp"
a:layout_height="wrap_content"> a:id="@+id/wizard_big_buttons_radiobutton"
a:layout_weight="1"
a:text="@string/cpp_wizard_layout_big_buttons"
a:layout_height="wrap_content" />
<RadioButton a:layout_width="0dp" </RadioGroup>
a:id="@+id/wizard_optimized_radiobutton"
a:layout_weight="1"
a:text="@string/cpp_wizard_layout_optimized"
a:layout_height="wrap_content"/>
<RadioButton a:layout_width="0dp" <LinearLayout
a:id="@+id/wizard_big_buttons_radiobutton" a:layout_width="match_parent"
a:layout_weight="1" a:layout_height="wrap_content"
a:text="@string/cpp_wizard_layout_big_buttons" a:orientation="horizontal">
a:layout_height="wrap_content"/>
</RadioGroup> <ImageView
a:layout_width="0dp"
a:layout_weight="1"
a:scaleType="centerInside"
a:layout_height="match_parent"
a:padding="10dp"
a:src="@drawable/tablet_optimized" />
<LinearLayout a:layout_width="match_parent" <ImageView
a:layout_height="wrap_content" a:layout_width="0dp"
a:orientation="horizontal"> a:layout_weight="1"
a:scaleType="centerInside"
<ImageView a:layout_width="0dp" a:layout_height="match_parent"
a:layout_weight="1" a:padding="10dp"
a:scaleType="centerInside" a:src="@drawable/tablet_big_buttons" />
a:layout_height="match_parent"
a:padding="10dp"
a:src="@drawable/tablet_optimized"/>
<ImageView a:layout_width="0dp"
a:layout_weight="1"
a:scaleType="centerInside"
a:layout_height="match_parent"
a:padding="10dp"
a:src="@drawable/tablet_big_buttons"/>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -10,9 +10,51 @@
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="match_parent" /> a:layout_width="match_parent" />
<Spinner <LinearLayout
a:id="@+id/wizard_mode_spinner" a:layout_width="match_parent"
a:layout_height="wrap_content" a:layout_height="match_parent"
a:layout_width="match_parent" /> a:orientation="vertical">
<RadioGroup
a:orientation="horizontal"
a:layout_width="match_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical|top">
<RadioButton a:layout_width="0dp"
a:id="@+id/wizard_simple_mode_radiobutton"
a:layout_weight="1"
a:text="@string/cpp_wizard_mode_simple"
a:layout_height="wrap_content"/>
<RadioButton a:layout_width="0dp"
a:id="@+id/wizard_engineer_mode_radiobutton"
a:layout_weight="1"
a:text="@string/cpp_wizard_mode_engineer"
a:layout_height="wrap_content"/>
</RadioGroup>
<LinearLayout a:layout_width="match_parent"
a:layout_height="wrap_content"
a:orientation="horizontal">
<TextView
a:layout_width="0dp"
a:layout_weight="1"
a:layout_height="match_parent"
a:text="@string/cpp_wizard_mode_simple_description"
a:padding="10dp"/>
<TextView
a:layout_width="0dp"
a:layout_weight="1"
a:layout_height="match_parent"
a:text="@string/cpp_wizard_mode_engineer_description"
a:padding="10dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -13,6 +13,8 @@
<TextView <TextView
a:id="@+id/wizard_dragbutton_action_textview" a:id="@+id/wizard_dragbutton_action_textview"
a:layout_marginTop="10dp"
a:textStyle="bold"
a:text="@string/cpp_wizard_dragbutton_action_center" a:text="@string/cpp_wizard_dragbutton_action_center"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="match_parent" /> a:layout_width="match_parent" />
@ -21,6 +23,8 @@
a:layout_margin="30dp" a:layout_margin="30dp"
a:layout_height="100dp" a:layout_height="100dp"
a:layout_width="100dp" a:layout_width="100dp"
a:minWidth="100dp"
a:minHeight="100dp"
a:layout_gravity="center" a:layout_gravity="center"
a:id="@+id/wizard_dragbutton" a:id="@+id/wizard_dragbutton"
a:text="9" a:text="9"

View File

@ -153,7 +153,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
//Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!"); //Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!");
if (!dialogShown) { 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); dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.feedbackWindowShown, R.layout.feedback, R.id.feedbackText, context);
} }
} }

View File

@ -75,22 +75,20 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
void setStep(@Nonnull WizardStep step) { void setStep(@Nonnull WizardStep step) {
if (this.step == null || !this.step.equals(step)) { if (this.step == null || !this.step.equals(step)) {
final FragmentManager fm = getSupportFragmentManager(); hideFragment();
final FragmentTransaction ft = fm.beginTransaction();
hideFragment(fm, ft);
this.step = step; this.step = step;
showFragment();
showFragment(fm, ft); initTitle();
ft.commit();
initNextButton(); initNextButton();
initPrevButton(); initPrevButton();
} }
} }
private void initTitle() {
setTitle(step.getTitleResId());
}
private void initPrevButton() { private void initPrevButton() {
final WizardStep prevStep = flow.getPrevStep(step); final WizardStep prevStep = flow.getPrevStep(step);
if (prevStep == null) { if (prevStep == null) {
@ -167,25 +165,39 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
} }
@Nonnull @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()); Fragment newFragment = fm.findFragmentByTag(this.step.getFragmentTag());
if (newFragment == null) { if (newFragment == null) {
newFragment = Fragment.instantiate(this, this.step.getFragmentClass().getName(), this.step.getFragmentArgs()); newFragment = Fragment.instantiate(this, this.step.getFragmentClass().getName(), this.step.getFragmentArgs());
ft.add(R.id.wizard_content, newFragment, this.step.getFragmentTag()); ft.add(R.id.wizard_content, newFragment, this.step.getFragmentTag());
} else {
ft.show(newFragment);
} }
ft.commit();
fm.executePendingTransactions();
return newFragment; 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) { if (this.step != null) {
final Fragment oldFragment = fm.findFragmentByTag(this.step.getFragmentTag()); hideFragmentByTag(fm, ft, this.step.getFragmentTag());
if (oldFragment != null) { }
ft.hide(oldFragment);
} 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);
} }
} }

View File

@ -1,24 +1,17 @@
package org.solovyev.android.calculator.wizard; package org.solovyev.android.calculator.wizard;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Spinner; import android.widget.RadioButton;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.app.SherlockFragment;
import org.solovyev.android.calculator.R; 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.Nonnull;
import javax.annotation.Nullable; 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 * User: serso
@ -46,7 +39,10 @@ public class ChooseModeWizardStep extends SherlockFragment {
*/ */
@Nullable @Nullable
private Spinner modeSpinner; private RadioButton simpleModeRadioButton;
@Nullable
private RadioButton engineerModeRadioButton;
private CalculatorMode mode; private CalculatorMode mode;
@ -72,17 +68,18 @@ public class ChooseModeWizardStep extends SherlockFragment {
public void onViewCreated(View root, Bundle savedInstanceState) { public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, 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<ModeListItem> listItems = new ArrayList<ModeListItem>(); switch (mode) {
for (CalculatorMode mode : CalculatorMode.values()) { case simple:
listItems.add(new ModeListItem(mode)); simpleModeRadioButton.setChecked(true);
} engineerModeRadioButton.setChecked(false);
modeSpinner.setAdapter(ListItemAdapter.newInstance(getActivity(), listItems)); break;
case engineer:
final int position = Arrays.binarySearch(CalculatorMode.values(), mode); simpleModeRadioButton.setChecked(false);
if (position >= 0) { engineerModeRadioButton.setChecked(true);
modeSpinner.setSelection(position); break;
} }
} }
@ -90,12 +87,12 @@ public class ChooseModeWizardStep extends SherlockFragment {
CalculatorMode getSelectedMode() { CalculatorMode getSelectedMode() {
CalculatorMode mode = getDefaultMode(); CalculatorMode mode = getDefaultMode();
if (modeSpinner != null) { if (simpleModeRadioButton != null && simpleModeRadioButton.isChecked()) {
final int position = modeSpinner.getSelectedItemPosition(); mode = simple;
}
if (position >= 0 && position < CalculatorMode.values().length) { if (engineerModeRadioButton != null && engineerModeRadioButton.isChecked()) {
mode = CalculatorMode.values()[position]; mode = engineer;
}
} }
return mode; return mode;
@ -107,49 +104,4 @@ public class ChooseModeWizardStep extends SherlockFragment {
outState.putSerializable(MODE, mode); 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;
}
}
} }

View File

@ -6,12 +6,7 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
import java.util.Arrays;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.view.drag.DirectionDragButton; import org.solovyev.android.view.drag.DirectionDragButton;
import org.solovyev.android.view.drag.DragButton; 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.android.view.drag.SimpleOnDragListener;
import org.solovyev.common.math.Point2d; 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 { public class DragButtonWizardStep extends SherlockFragment {
@ -94,7 +91,8 @@ public class DragButtonWizardStep extends SherlockFragment {
center(R.string.cpp_wizard_dragbutton_action_center, null), center(R.string.cpp_wizard_dragbutton_action_center, null),
up(R.string.cpp_wizard_dragbutton_action_up, DragDirection.up), up(R.string.cpp_wizard_dragbutton_action_up, DragDirection.up),
left(R.string.cpp_wizard_dragbutton_action_left, DragDirection.left), 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; private final int actionTextResId;
@ -121,7 +119,7 @@ public class DragButtonWizardStep extends SherlockFragment {
private class DragButtonOnClickListener implements View.OnClickListener { private class DragButtonOnClickListener implements View.OnClickListener {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if(action == DragButtonAction.center) { if(action == DragButtonAction.center || action == DragButtonAction.end) {
setNextAction(); setNextAction();
} }
} }

View File

@ -5,17 +5,17 @@ import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import org.solovyev.android.App; import org.solovyev.android.App;
import org.solovyev.android.Views; import org.solovyev.android.Views;
import org.solovyev.android.calculator.CalculatorApplication; import org.solovyev.android.calculator.CalculatorApplication;
import org.solovyev.android.calculator.CalculatorPreferences; import org.solovyev.android.calculator.CalculatorPreferences;
import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; 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.ChooseLayoutWizardStep.LAYOUT;
import static org.solovyev.android.calculator.wizard.ChooseModeWizardStep.MODE;
import static org.solovyev.android.calculator.wizard.OnScreenCalculatorWizardStep.ONSCREEN_CALCULATOR_ENABLED; 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 { enum WizardStep {
welcome(WelcomeWizardStep.class) { welcome(WelcomeWizardStep.class, R.string.cpp_wizard_welcome_title) {
@Override @Override
boolean onNext(@Nonnull Fragment fragment) { boolean onNext(@Nonnull Fragment fragment) {
return true; return true;
@ -43,7 +43,7 @@ enum WizardStep {
} }
}, },
choose_layout(ChooseLayoutWizardStep.class) { choose_layout(ChooseLayoutWizardStep.class, R.string.cpp_wizard_layout_title) {
@Override @Override
boolean onNext(@Nonnull Fragment f) { boolean onNext(@Nonnull Fragment f) {
final ChooseLayoutWizardStep fragment = (ChooseLayoutWizardStep) 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 @Override
boolean onNext(@Nonnull Fragment f) { boolean onNext(@Nonnull Fragment f) {
final ChooseModeWizardStep fragment = (ChooseModeWizardStep) 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 @Override
boolean onNext(@Nonnull Fragment f) { boolean onNext(@Nonnull Fragment f) {
final OnScreenCalculatorWizardStep fragment = (OnScreenCalculatorWizardStep) 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 @Override
boolean onNext(@Nonnull Fragment fragment) { boolean onNext(@Nonnull Fragment fragment) {
return true; return true;
@ -155,8 +155,11 @@ enum WizardStep {
@Nonnull @Nonnull
private final Class<? extends Fragment> fragmentClass; private final Class<? extends Fragment> fragmentClass;
WizardStep(@Nonnull Class<? extends Fragment> fragmentClass) { private final int titleResId;
WizardStep(@Nonnull Class<? extends Fragment> fragmentClass, int titleResId) {
this.fragmentClass = fragmentClass; this.fragmentClass = fragmentClass;
this.titleResId = titleResId;
} }
public String getFragmentTag() { public String getFragmentTag() {
@ -168,6 +171,10 @@ enum WizardStep {
return fragmentClass; return fragmentClass;
} }
int getTitleResId() {
return titleResId;
}
abstract boolean onNext(@Nonnull Fragment fragment); abstract boolean onNext(@Nonnull Fragment fragment);
abstract boolean onPrev(@Nonnull Fragment fragment); abstract boolean onPrev(@Nonnull Fragment fragment);

View File

@ -119,4 +119,10 @@ public class CalculatorWizardActivityTest {
startWizard(Wizard.DEFAULT_WIZARD_FLOW, shadowActivity.getApplicationContext()); startWizard(Wizard.DEFAULT_WIZARD_FLOW, shadowActivity.getApplicationContext());
assertNotNull(shadowActivity.getNextStartedActivity()); assertNotNull(shadowActivity.getNextStartedActivity());
} }
@Test
public void testTitleShouldBeSet() throws Exception {
activity.setStep(choose_mode);
assertEquals(activity.getString(choose_mode.getTitleResId()), activity.getTitle().toString());
}
} }