wizard
This commit is contained in:
parent
7e945fb487
commit
6ef4354f2c
16
android-app-core/res/values/text_wizard.xml
Normal file
16
android-app-core/res/values/text_wizard.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
~ For more information, please, contact se.solovyev@gmail.com
|
||||
~ or visit http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<string name="cpp_wizard_mode_simple">Simple</string>
|
||||
<string name="cpp_wizard_mode_simple_description">In simple mode only basic functionality will be available from the main screen.
|
||||
Result is rounded up to 5 digits.</string>
|
||||
<string name="cpp_wizard_mode_engineer">Engineer</string>
|
||||
<string name="cpp_wizard_mode_engineer_description">In engineer mode special functions will be used on the main screen.
|
||||
Result is is not rounded and is presented in engineer notation.</string>
|
||||
</resources>
|
@ -133,10 +133,6 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
|
||||
if (Objects.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
|
||||
// new start
|
||||
context.startActivity(new Intent(context, CalculatorWizardActivity.class));
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(R.string.c_first_start_text);
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
builder.setTitle(R.string.c_first_start_text_title);
|
||||
builder.create().show();
|
||||
dialogShown = true;
|
||||
} else {
|
||||
if (savedVersion < appVersion) {
|
||||
|
@ -7,22 +7,25 @@ import android.preference.PreferenceManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
import org.solovyev.android.calculator.CalculatorPreferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.list.ListItem;
|
||||
import org.solovyev.android.list.ListItemAdapter;
|
||||
import jscl.AngleUnit;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorPreferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.list.ListItem;
|
||||
import org.solovyev.android.list.ListItemAdapter;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.main_calculator;
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.main_calculator_mobile;
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple;
|
||||
|
||||
/**
|
||||
@ -30,7 +33,10 @@ import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.s
|
||||
* Date: 6/16/13
|
||||
* Time: 9:59 PM
|
||||
*/
|
||||
public final class ChooseModeWizardStep extends SherlockFragment {
|
||||
public final class ChooseModeWizardStep extends SherlockFragment implements WizardStepFragment {
|
||||
|
||||
@Nullable
|
||||
private Spinner layoutSpinner;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
@ -41,27 +47,35 @@ public final class ChooseModeWizardStep extends SherlockFragment {
|
||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
final Spinner layoutSpinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner);
|
||||
layoutSpinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner);
|
||||
final List<ModeListItem> listItems = new ArrayList<ModeListItem>();
|
||||
listItems.add(new ModeListItem(main_calculator));
|
||||
listItems.add(new ModeListItem(main_calculator_mobile));
|
||||
listItems.add(new ModeListItem(simple));
|
||||
final ListItemAdapter<ModeListItem> adapter = ListItemAdapter.newInstance(getActivity(), listItems);
|
||||
layoutSpinner.setAdapter(adapter);
|
||||
layoutSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
for (Mode mode : Mode.values()) {
|
||||
listItems.add(new ModeListItem(mode));
|
||||
}
|
||||
layoutSpinner.setAdapter(ListItemAdapter.newInstance(getActivity(), listItems));
|
||||
}
|
||||
|
||||
final ModeListItem item = adapter.getItem(position);
|
||||
CalculatorPreferences.Gui.layout.putPreference(preferences, item.layout);
|
||||
@Override
|
||||
public boolean onNext() {
|
||||
if (layoutSpinner != null) {
|
||||
final int position = layoutSpinner.getSelectedItemPosition();
|
||||
|
||||
final Mode mode;
|
||||
if (position >= 0 && position < Mode.values().length) {
|
||||
mode = Mode.values()[position];
|
||||
} else {
|
||||
mode = Mode.Simple;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
mode.apply(PreferenceManager.getDefaultSharedPreferences(getActivity()));
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrev() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -75,10 +89,10 @@ public final class ChooseModeWizardStep extends SherlockFragment {
|
||||
private static final class ModeListItem implements ListItem {
|
||||
|
||||
@Nonnull
|
||||
private final CalculatorPreferences.Gui.Layout layout;
|
||||
private final Mode mode;
|
||||
|
||||
private ModeListItem(@Nonnull CalculatorPreferences.Gui.Layout layout) {
|
||||
this.layout = layout;
|
||||
private ModeListItem(@Nonnull Mode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -103,8 +117,42 @@ public final class ChooseModeWizardStep extends SherlockFragment {
|
||||
@Override
|
||||
public View build(@Nonnull Context context) {
|
||||
final TextView textView = new TextView(context);
|
||||
textView.setText(layout.getNameResId());
|
||||
textView.setText(mode.getNameResId());
|
||||
return textView;
|
||||
}
|
||||
}
|
||||
|
||||
private static enum Mode {
|
||||
Simple(R.string.cpp_wizard_mode_simple) {
|
||||
@Override
|
||||
protected void apply(@Nonnull SharedPreferences preferences) {
|
||||
CalculatorPreferences.Gui.layout.putPreference(preferences, simple);
|
||||
CalculatorPreferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.deg);
|
||||
AndroidCalculatorEngine.Preferences.scienceNotation.putPreference(preferences, false);
|
||||
AndroidCalculatorEngine.Preferences.roundResult.putPreference(preferences, true);
|
||||
}
|
||||
},
|
||||
|
||||
Engineer(R.string.cpp_wizard_mode_engineer) {
|
||||
@Override
|
||||
protected void apply(@Nonnull SharedPreferences preferences) {
|
||||
CalculatorPreferences.Gui.layout.putPreference(preferences, main_calculator);
|
||||
CalculatorPreferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.rad);
|
||||
AndroidCalculatorEngine.Preferences.scienceNotation.putPreference(preferences, true);
|
||||
AndroidCalculatorEngine.Preferences.roundResult.putPreference(preferences, false);
|
||||
}
|
||||
};
|
||||
|
||||
private final int nameResId;
|
||||
|
||||
Mode(int nameResId) {
|
||||
this.nameResId = nameResId;
|
||||
}
|
||||
|
||||
private int getNameResId() {
|
||||
return nameResId;
|
||||
}
|
||||
|
||||
protected abstract void apply(@Nonnull SharedPreferences preferences);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.solovyev.android.calculator.wizard.WizardStep.choose_mode;
|
||||
import static org.solovyev.android.calculator.wizard.WizardStep.welcome;
|
||||
|
||||
/**
|
||||
@ -22,7 +23,7 @@ final class FirstTimeWizardFlow implements WizardFlow {
|
||||
FirstTimeWizardFlow() {
|
||||
final List<WizardStep> wizardSteps = new ArrayList<WizardStep>();
|
||||
wizardSteps.add(welcome);
|
||||
//wizardSteps.add(choose_mode);
|
||||
wizardSteps.add(choose_mode);
|
||||
this.listWizardFlow = new ListWizardFlow(NAME, wizardSteps);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
package org.solovyev.android.calculator.wizard;
|
||||
|
||||
public interface WizardStepFragment {
|
||||
|
||||
public boolean onNext();
|
||||
|
||||
public boolean onPrev();
|
||||
}
|
Loading…
Reference in New Issue
Block a user