Choose layout wizard step
This commit is contained in:
parent
20b408dc5c
commit
c380dc82e3
@ -78,13 +78,13 @@ public class OnScreenCalculatorWizardStepTest {
|
||||
|
||||
@Test
|
||||
public void testShouldRestoreStateOnRestart() throws Exception {
|
||||
fragment.getOnscreenCalculatorCheckbox().setChecked(true);
|
||||
fragment.getCheckbox().setChecked(true);
|
||||
controller.restart();
|
||||
assertTrue(fragment.getOnscreenCalculatorCheckbox().isChecked());
|
||||
assertTrue(fragment.getCheckbox().isChecked());
|
||||
|
||||
fragment.getOnscreenCalculatorCheckbox().setChecked(false);
|
||||
fragment.getCheckbox().setChecked(false);
|
||||
controller.restart();
|
||||
assertFalse(fragment.getOnscreenCalculatorCheckbox().isChecked());
|
||||
assertFalse(fragment.getCheckbox().isChecked());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -24,8 +24,10 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.preference.PreferenceManager;
|
||||
import org.solovyev.android.UiThreadExecutor;
|
||||
import org.solovyev.android.Views;
|
||||
import org.solovyev.android.calculator.ga.Ga;
|
||||
import org.solovyev.android.checkout.*;
|
||||
import org.solovyev.common.listeners.JEvent;
|
||||
@ -214,4 +216,8 @@ public final class App {
|
||||
public static Products getProducts() {
|
||||
return products;
|
||||
}
|
||||
|
||||
public static boolean isLargeScreen() {
|
||||
return Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, App.getApplication().getResources().getConfiguration());
|
||||
}
|
||||
}
|
||||
|
@ -92,8 +92,7 @@ public final class CalculatorButtons {
|
||||
@Nonnull Activity activity) {
|
||||
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences;
|
||||
|
||||
final boolean large = Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, activity.getResources().getConfiguration()) &&
|
||||
Preferences.Gui.getLayout(preferences).isOptimized();
|
||||
final boolean large = App.isLargeScreen() && Preferences.Gui.getLayout(preferences).isOptimized();
|
||||
|
||||
if (!large) {
|
||||
if (Views.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT
|
||||
|
@ -59,15 +59,17 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
|
||||
private final static String greekAlphabet = "αβγδεζηθικλμνξοπρστυφχψω";
|
||||
private final static List<Character> acceptableChars = Arrays.asList(Strings.toObjects(("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_" + greekAlphabet).toCharArray()));
|
||||
|
||||
@Nonnull
|
||||
private final Input input;
|
||||
private Input input;
|
||||
|
||||
public VarEditDialogFragment() {
|
||||
this(Input.newInstance());
|
||||
input = Input.newInstance();
|
||||
}
|
||||
|
||||
public VarEditDialogFragment(@Nonnull Input input) {
|
||||
this.input = input;
|
||||
@Nonnull
|
||||
public static VarEditDialogFragment create(@Nonnull Input input) {
|
||||
final VarEditDialogFragment fragment = new VarEditDialogFragment();
|
||||
fragment.input = input;
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -255,7 +257,7 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
|
||||
*/
|
||||
|
||||
public static void showDialog(@Nonnull Input input, @Nonnull FragmentManager fm) {
|
||||
AndroidSherlockUtils.showDialog(new VarEditDialogFragment(input), "constant-editor", fm);
|
||||
AndroidSherlockUtils.showDialog(create(input), "constant-editor", fm);
|
||||
}
|
||||
|
||||
public static class Input {
|
||||
|
@ -22,22 +22,14 @@
|
||||
|
||||
package org.solovyev.android.calculator.wizard;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.Views;
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.solovyev.android.calculator.CalculatorApplication.getPreferences;
|
||||
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;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 6/16/13
|
||||
@ -48,71 +40,14 @@ enum CalculatorWizardStep implements org.solovyev.android.wizard.WizardStep {
|
||||
welcome(WelcomeWizardStep.class, R.string.cpp_wizard_welcome_title, R.string.cpp_wizard_start),
|
||||
|
||||
choose_layout(ChooseLayoutWizardStep.class, R.string.cpp_wizard_layout_title) {
|
||||
@Override
|
||||
public boolean onNext(@Nonnull Fragment f) {
|
||||
final ChooseLayoutWizardStep fragment = (ChooseLayoutWizardStep) f;
|
||||
|
||||
final CalculatorLayout layout = fragment.getSelectedLayout();
|
||||
layout.apply(getPreferences());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Bundle getFragmentArgs() {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(LAYOUT, CalculatorLayout.fromGuiLayout(Preferences.Gui.layout.getPreference(getPreferences())));
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, App.getApplication().getResources().getConfiguration());
|
||||
return App.isLargeScreen();
|
||||
}
|
||||
},
|
||||
|
||||
choose_mode(ChooseModeWizardStep.class, R.string.cpp_wizard_mode_title) {
|
||||
@Override
|
||||
public boolean onNext(@Nonnull Fragment f) {
|
||||
final ChooseModeWizardStep fragment = (ChooseModeWizardStep) f;
|
||||
|
||||
final CalculatorMode mode = fragment.getSelectedMode();
|
||||
mode.apply(getPreferences());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Bundle getFragmentArgs() {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(MODE, CalculatorMode.fromGuiLayout(Preferences.Gui.layout.getPreference(getPreferences())));
|
||||
return bundle;
|
||||
}
|
||||
},
|
||||
|
||||
on_screen_calculator(OnScreenCalculatorWizardStep.class, R.string.cpp_wizard_onscreen_calculator_title) {
|
||||
@Override
|
||||
public boolean onNext(@Nonnull Fragment f) {
|
||||
final OnScreenCalculatorWizardStep fragment = (OnScreenCalculatorWizardStep) f;
|
||||
|
||||
Preferences.OnscreenCalculator.showAppIcon.putPreference(getPreferences(), fragment.isOnscreenCalculatorEnabled());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Bundle getFragmentArgs() {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(ONSCREEN_CALCULATOR_ENABLED, Preferences.OnscreenCalculator.showAppIcon.getPreference(getPreferences()));
|
||||
return bundle;
|
||||
}
|
||||
},
|
||||
|
||||
choose_mode(ChooseModeWizardStep.class, R.string.cpp_wizard_mode_title),
|
||||
on_screen_calculator(OnScreenCalculatorWizardStep.class, R.string.cpp_wizard_onscreen_calculator_title),
|
||||
drag_button(DragButtonWizardStep.class, R.string.cpp_wizard_dragbutton_title),
|
||||
|
||||
last(FinalWizardStep.class, R.string.cpp_wizard_final_title);
|
||||
|
||||
@Nonnull
|
||||
|
@ -23,106 +23,66 @@
|
||||
package org.solovyev.android.calculator.wizard;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorLayout.*;
|
||||
import static org.solovyev.android.calculator.CalculatorApplication.getPreferences;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorLayout.big_buttons;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorLayout.optimized;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 6/19/13
|
||||
* Time: 12:33 AM
|
||||
*/
|
||||
public class ChooseLayoutWizardStep extends Fragment {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTANTS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
static final String LAYOUT = "layout";
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@Nullable
|
||||
private RadioButton optimizedRadioButton;
|
||||
|
||||
@Nullable
|
||||
private RadioButton bigButtonsRadioButton;
|
||||
|
||||
private CalculatorLayout layout;
|
||||
public class ChooseLayoutWizardStep extends WizardFragment implements AdapterView.OnItemSelectedListener {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
layout = (CalculatorLayout) savedInstanceState.getSerializable(LAYOUT);
|
||||
protected int getViewResId() {
|
||||
return R.layout.cpp_wizard_step_choose_layout;
|
||||
}
|
||||
|
||||
if (layout == null) {
|
||||
layout = (CalculatorLayout) getArguments().getSerializable(LAYOUT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.cpp_wizard_step_choose_layout, null);
|
||||
}
|
||||
private ImageView image;
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
optimizedRadioButton = (RadioButton) root.findViewById(R.id.wizard_optimized_radiobutton);
|
||||
bigButtonsRadioButton = (RadioButton) root.findViewById(R.id.wizard_big_buttons_radiobutton);
|
||||
final CalculatorLayout layout = CalculatorLayout.fromGuiLayout(Preferences.Gui.layout.getPreference(getPreferences()));
|
||||
|
||||
switch (layout) {
|
||||
case big_buttons:
|
||||
bigButtonsRadioButton.setChecked(true);
|
||||
optimizedRadioButton.setChecked(false);
|
||||
break;
|
||||
case optimized:
|
||||
bigButtonsRadioButton.setChecked(false);
|
||||
optimizedRadioButton.setChecked(true);
|
||||
break;
|
||||
}
|
||||
image = (ImageView) root.findViewById(R.id.wizard_layout_image);
|
||||
final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_layout_spinner);
|
||||
spinner.setAdapter(new WizardArrayAdapter(getActivity(), R.array.cpp_layouts));
|
||||
spinner.setSelection(layout == big_buttons ? 0 : 1);
|
||||
spinner.setOnItemSelectedListener(this);
|
||||
|
||||
updateImage(layout);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
CalculatorLayout getSelectedLayout() {
|
||||
CalculatorLayout layout = getDefaultLayout();
|
||||
|
||||
if (bigButtonsRadioButton != null && bigButtonsRadioButton.isChecked()) {
|
||||
layout = big_buttons;
|
||||
} else if (optimizedRadioButton != null && optimizedRadioButton.isChecked()) {
|
||||
layout = optimized;
|
||||
}
|
||||
|
||||
return layout;
|
||||
private void updateImage(@Nonnull CalculatorLayout layout) {
|
||||
image.setImageResource(layout == big_buttons ? R.drawable.layout_big_buttons : R.drawable.layout_optimized);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
final CalculatorLayout layout = position == 0 ? big_buttons : optimized;
|
||||
layout.apply(getPreferences());
|
||||
updateImage(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
outState.putSerializable(LAYOUT, layout);
|
||||
}
|
||||
}
|
||||
|
@ -22,19 +22,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.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static org.solovyev.android.calculator.CalculatorApplication.getPreferences;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorMode.*;
|
||||
|
||||
/**
|
||||
@ -44,42 +42,8 @@ import static org.solovyev.android.calculator.wizard.CalculatorMode.*;
|
||||
*/
|
||||
public class ChooseModeWizardStep extends WizardFragment implements AdapterView.OnItemSelectedListener {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTANTS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
static final String MODE = "mode";
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private Spinner spinner;
|
||||
private TextView description;
|
||||
|
||||
private CalculatorMode mode;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mode = (CalculatorMode) savedInstanceState.getSerializable(MODE);
|
||||
}
|
||||
|
||||
if (mode == null) {
|
||||
mode = (CalculatorMode) getArguments().getSerializable(MODE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getViewResId() {
|
||||
return R.layout.cpp_wizard_step_choose_mode;
|
||||
@ -89,59 +53,28 @@ public class ChooseModeWizardStep extends WizardFragment implements AdapterView.
|
||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
spinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner);
|
||||
spinner.setAdapter(new MyArrayAdapter(getActivity()));
|
||||
final CalculatorMode mode = CalculatorMode.fromGuiLayout(Preferences.Gui.layout.getPreference(getPreferences()));
|
||||
final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner);
|
||||
spinner.setAdapter(new WizardArrayAdapter(getActivity(), R.array.cpp_modes));
|
||||
spinner.setSelection(mode == simple ? 0 : 1);
|
||||
spinner.setOnItemSelectedListener(this);
|
||||
|
||||
description = (TextView) root.findViewById(R.id.wizard_mode_description);
|
||||
updateDescription();
|
||||
updateDescription(mode);
|
||||
}
|
||||
|
||||
private void updateDescription() {
|
||||
private void updateDescription(@Nonnull CalculatorMode mode) {
|
||||
description.setText(mode == simple ? R.string.cpp_wizard_mode_simple_description : R.string.cpp_wizard_mode_engineer_description);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
CalculatorMode getSelectedMode() {
|
||||
if (spinner != null) {
|
||||
return mode;
|
||||
}
|
||||
|
||||
return getDefaultMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
||||
outState.putSerializable(MODE, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
mode = position == 0 ? simple : engineer;
|
||||
updateDescription();
|
||||
final CalculatorMode mode = position == 0 ? simple : engineer;
|
||||
mode.apply(getPreferences());
|
||||
updateDescription(mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
}
|
||||
|
||||
private static final class MyArrayAdapter extends ArrayAdapter<String> {
|
||||
|
||||
public MyArrayAdapter(Context context) {
|
||||
super(context, android.R.layout.simple_spinner_item, context.getResources().getStringArray(R.array.cpp_modes));
|
||||
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
final View view = super.getView(position, convertView, parent);
|
||||
if (view instanceof TextView) {
|
||||
((TextView) view).setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,48 +25,18 @@ package org.solovyev.android.calculator.wizard;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class OnScreenCalculatorWizardStep extends WizardFragment {
|
||||
import static org.solovyev.android.calculator.CalculatorApplication.getPreferences;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTANTS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
static final String ONSCREEN_CALCULATOR_ENABLED = "onscreen_calculator_enabled";
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
public class OnScreenCalculatorWizardStep extends WizardFragment implements CompoundButton.OnCheckedChangeListener {
|
||||
|
||||
@Nullable
|
||||
private CheckBox onscreenCalculatorCheckbox;
|
||||
|
||||
private Boolean onscreenCalculatorEnabled;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(ONSCREEN_CALCULATOR_ENABLED)) {
|
||||
onscreenCalculatorEnabled = savedInstanceState.getBoolean(ONSCREEN_CALCULATOR_ENABLED);
|
||||
}
|
||||
|
||||
if (onscreenCalculatorEnabled == null) {
|
||||
onscreenCalculatorEnabled = getArguments().getBoolean(ONSCREEN_CALCULATOR_ENABLED, Preferences.OnscreenCalculator.showAppIcon.getDefaultValue());
|
||||
}
|
||||
}
|
||||
private CheckBox checkbox;
|
||||
|
||||
@Override
|
||||
protected int getViewResId() {
|
||||
@ -77,31 +47,20 @@ public class OnScreenCalculatorWizardStep extends WizardFragment {
|
||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
onscreenCalculatorCheckbox = (CheckBox) root.findViewById(R.id.wizard_onscreen_app_enabled_checkbox);
|
||||
onscreenCalculatorCheckbox.setChecked(onscreenCalculatorEnabled);
|
||||
}
|
||||
|
||||
public Boolean isOnscreenCalculatorEnabled() {
|
||||
boolean enabled = Preferences.OnscreenCalculator.showAppIcon.getDefaultValue();
|
||||
|
||||
if (onscreenCalculatorCheckbox != null) {
|
||||
enabled = onscreenCalculatorCheckbox.isChecked();
|
||||
}
|
||||
|
||||
return enabled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
||||
outState.putBoolean(ONSCREEN_CALCULATOR_ENABLED, onscreenCalculatorEnabled);
|
||||
final Boolean enabled = Preferences.OnscreenCalculator.showAppIcon.getPreference(getPreferences());
|
||||
checkbox = (CheckBox) root.findViewById(R.id.wizard_onscreen_app_enabled_checkbox);
|
||||
checkbox.setChecked(enabled);
|
||||
checkbox.setOnCheckedChangeListener(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
CheckBox getOnscreenCalculatorCheckbox() {
|
||||
return onscreenCalculatorCheckbox;
|
||||
CheckBox getCheckbox() {
|
||||
return checkbox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
|
||||
Preferences.OnscreenCalculator.showAppIcon.putPreference(getPreferences(), checked);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import com.viewpagerindicator.PageIndicator;
|
||||
import org.solovyev.android.calculator.BaseActivity;
|
||||
@ -25,7 +24,7 @@ public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
private ViewPager pager;
|
||||
|
||||
@Nonnull
|
||||
private PagerAdapter pagerAdapter;
|
||||
private WizardPagerAdapter pagerAdapter;
|
||||
|
||||
@Nonnull
|
||||
private Wizards wizards = CalculatorApplication.getInstance().getWizards();
|
||||
@ -147,6 +146,8 @@ public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
public void goNext() {
|
||||
final int position = pager.getCurrentItem();
|
||||
if (position < pagerAdapter.getCount() - 1) {
|
||||
final WizardFragment fragment = (WizardFragment) pagerAdapter.getItem(position);
|
||||
fragment.onNext();
|
||||
pager.setCurrentItem(position + 1, true);
|
||||
}
|
||||
}
|
||||
@ -154,6 +155,8 @@ public class WizardActivity extends BaseActivity implements WizardsAware {
|
||||
public void goPrev() {
|
||||
final int position = pager.getCurrentItem();
|
||||
if (position > 0) {
|
||||
final WizardFragment fragment = (WizardFragment) pagerAdapter.getItem(position);
|
||||
fragment.onPrev();
|
||||
pager.setCurrentItem(position - 1, true);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package org.solovyev.android.calculator.wizard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
final class WizardArrayAdapter extends ArrayAdapter<String> {
|
||||
|
||||
public WizardArrayAdapter(Context context, int array) {
|
||||
super(context, android.R.layout.simple_spinner_item, context.getResources().getStringArray(array));
|
||||
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
final View view = super.getView(position, convertView, parent);
|
||||
if (view instanceof TextView) {
|
||||
((TextView) view).setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
}
|
@ -115,4 +115,19 @@ public abstract class WizardFragment extends Fragment implements View.OnClickLis
|
||||
private WizardActivity getWizardActivity() {
|
||||
return (WizardActivity) getActivity();
|
||||
}
|
||||
|
||||
public WizardStep getStep() {
|
||||
if (step == null) {
|
||||
step = findStepByClassName();
|
||||
}
|
||||
return step;
|
||||
}
|
||||
|
||||
public void onNext() {
|
||||
getStep().onNext(this);
|
||||
}
|
||||
|
||||
public void onPrev() {
|
||||
getStep().onPrev(this);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package org.solovyev.android.wizard;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
@ -75,29 +74,11 @@ public class WizardUi<A extends FragmentActivity> {
|
||||
activity.finish();
|
||||
}
|
||||
|
||||
protected final boolean tryGoPrev() {
|
||||
if (step == null) {
|
||||
return true;
|
||||
} else {
|
||||
final Fragment fragment = getFragmentManager().findFragmentByTag(step.getFragmentTag());
|
||||
return fragment == null || step.onPrev(fragment);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
protected final FragmentManager getFragmentManager() {
|
||||
return activity.getSupportFragmentManager();
|
||||
}
|
||||
|
||||
protected final boolean tryGoNext() {
|
||||
if (step == null) {
|
||||
return true;
|
||||
} else {
|
||||
final Fragment fragment = getFragmentManager().findFragmentByTag(step.getFragmentTag());
|
||||
return fragment == null || step.onNext(fragment);
|
||||
}
|
||||
}
|
||||
|
||||
public void onSaveInstanceState(@Nonnull Bundle out) {
|
||||
out.putString(FLOW, wizard.getName());
|
||||
out.putString(STEP, step.getName());
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
BIN
android-app/src/main/res/drawable-xhdpi/layout_big_buttons.png
Normal file
BIN
android-app/src/main/res/drawable-xhdpi/layout_big_buttons.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
BIN
android-app/src/main/res/drawable-xhdpi/layout_optimized.png
Normal file
BIN
android-app/src/main/res/drawable-xhdpi/layout_optimized.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
@ -25,51 +25,27 @@
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:orientation="vertical">
|
||||
a:orientation="vertical"
|
||||
a:gravity="center">
|
||||
|
||||
<RadioGroup
|
||||
a:orientation="horizontal"
|
||||
a:layout_width="match_parent"
|
||||
<TextView
|
||||
a:layout_width="wrap_content"
|
||||
a:layout_height="wrap_content"
|
||||
a:gravity="center_vertical|top">
|
||||
a:textAppearance="@android:style/TextAppearance.Large"
|
||||
style="@style/WizardLabel"
|
||||
a:text="Choose layout" />
|
||||
|
||||
<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"
|
||||
a:id="@+id/wizard_big_buttons_radiobutton"
|
||||
a:layout_weight="1"
|
||||
a:text="@string/cpp_wizard_layout_big_buttons"
|
||||
a:layout_height="wrap_content"/>
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<LinearLayout
|
||||
a:layout_width="match_parent"
|
||||
<Spinner
|
||||
a:id="@+id/wizard_layout_spinner"
|
||||
a:layout_width="wrap_content"
|
||||
a:layout_height="wrap_content"
|
||||
a:orientation="horizontal">
|
||||
style="@style/WizardLabel" />
|
||||
|
||||
<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"
|
||||
a:layout_weight="1"
|
||||
a:scaleType="centerInside"
|
||||
a:layout_height="match_parent"
|
||||
a:padding="10dp"
|
||||
a:src="@drawable/tablet_big_buttons"/>
|
||||
|
||||
</LinearLayout>
|
||||
a:id="@+id/wizard_layout_image"
|
||||
a:layout_width="wrap_content"
|
||||
a:layout_height="wrap_content"
|
||||
style="@style/WizardLabel.Last"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -138,4 +138,9 @@
|
||||
<item>@string/cpp_wizard_mode_simple</item>
|
||||
<item>@string/cpp_wizard_mode_engineer</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="cpp_layouts">
|
||||
<item>@string/cpp_wizard_layout_big_buttons</item>
|
||||
<item>@string/cpp_wizard_layout_optimized</item>
|
||||
</string-array>
|
||||
</resources>
|
@ -33,7 +33,7 @@
|
||||
<color name="cpp_wizard_button_normal">#424242</color>
|
||||
<color name="cpp_wizard_button_disabled">#616161</color>
|
||||
<color name="cpp_wizard_button_pressed">#757575</color>
|
||||
<color name="cpp_pane_background">#ff1f1f1f</color>
|
||||
<color name="cpp_pane_background">#212121</color>
|
||||
<color name="cpp_metro_button_dark">#ff000000</color>
|
||||
<color name="cpp_metro_button">#212121</color>
|
||||
<color name="cpp_metro_button_light">#393939</color>
|
||||
|
Loading…
Reference in New Issue
Block a user