Wizard improved
This commit is contained in:
@@ -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 (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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user