Wizard improved
This commit is contained in:
parent
097840688c
commit
723fd1a461
@ -17,9 +17,15 @@
|
||||
Result is is not rounded and is presented in engineer notation.</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_up">Drag from the center of the button up to use function in the upper right corner</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_down">Drag from the center of the button down to use function in the bottom right corner</string>
|
||||
<string name="cpp_wizard_dragbutton_action_end">Excellent! Tap button one more time to try again</string>
|
||||
<string name="cpp_wizard_dragbutton_action_center">Tap button once to use 9</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_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>
|
@ -5,26 +5,21 @@
|
||||
a:layout_height="match_parent"
|
||||
a:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
a:text="Do you want to use optimized layout for large screens or just big buttons?"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"/>
|
||||
|
||||
<LinearLayout a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:orientation="vertical">
|
||||
|
||||
<RadioGroup a:orientation="horizontal"
|
||||
<RadioGroup
|
||||
a:orientation="horizontal"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content">
|
||||
a:layout_height="wrap_content"
|
||||
a:gravity="center_vertical|top">
|
||||
|
||||
<RadioButton a:layout_width="0dp"
|
||||
<RadioButton
|
||||
a:layout_width="0dp"
|
||||
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"
|
||||
<RadioButton
|
||||
a:layout_width="0dp"
|
||||
a:id="@+id/wizard_big_buttons_radiobutton"
|
||||
a:layout_weight="1"
|
||||
a:text="@string/cpp_wizard_layout_big_buttons"
|
||||
@ -32,18 +27,21 @@
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<LinearLayout a:layout_width="match_parent"
|
||||
<LinearLayout
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"
|
||||
a:orientation="horizontal">
|
||||
|
||||
<ImageView a:layout_width="0dp"
|
||||
<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" />
|
||||
|
||||
<ImageView a:layout_width="0dp"
|
||||
<ImageView
|
||||
a:layout_width="0dp"
|
||||
a:layout_weight="1"
|
||||
a:scaleType="centerInside"
|
||||
a:layout_height="match_parent"
|
||||
@ -53,5 +51,3 @@
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -10,9 +10,51 @@
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent" />
|
||||
|
||||
<Spinner
|
||||
a:id="@+id/wizard_mode_spinner"
|
||||
<LinearLayout
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:orientation="vertical">
|
||||
|
||||
<RadioGroup
|
||||
a:orientation="horizontal"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent" />
|
||||
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>
|
||||
|
@ -13,6 +13,8 @@
|
||||
|
||||
<TextView
|
||||
a:id="@+id/wizard_dragbutton_action_textview"
|
||||
a:layout_marginTop="10dp"
|
||||
a:textStyle="bold"
|
||||
a:text="@string/cpp_wizard_dragbutton_action_center"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent" />
|
||||
@ -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"
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<ModeListItem> listItems = new ArrayList<ModeListItem>();
|
||||
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 (position >= 0 && position < CalculatorMode.values().length) {
|
||||
mode = CalculatorMode.values()[position];
|
||||
if (simpleModeRadioButton != null && simpleModeRadioButton.isChecked()) {
|
||||
mode = simple;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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<? 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.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);
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user