drag button wizard step

This commit is contained in:
Sergey Solovyev 2013-06-24 17:38:53 +04:00
parent 83dce53d15
commit 0139d1e87c
6 changed files with 230 additions and 9 deletions

View File

@ -16,4 +16,10 @@
<string name="cpp_wizard_mode_engineer_description">In engineer mode special functions will be used on the main screen. <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> 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_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>
</resources> </resources>

View File

@ -55,4 +55,13 @@
<item name="android:actionBarStyle">@style/metro_blue_actionbar_style</item>--> <item name="android:actionBarStyle">@style/metro_blue_actionbar_style</item>-->
</style> </style>
<style name="cpp_metro_blue_dialog_theme" parent="cpp_gray_dialog_theme">
<item name="cpp_digit_button_style">@style/metro_digit_button_style</item>
<item name="cpp_control_button_style">@style/metro_control_button_style</item>
<item name="cpp_control_image_button_style">@style/metro_control_image_button_style</item>
<item name="cpp_operation_button_style">@style/metro_blue_operation_button_style</item>
<item name="cpp_fragment_list_view_item_style">@style/metro_blue_fragment_list_view_item_style</item>
</style>
</resources> </resources>

View File

@ -40,7 +40,7 @@
<activity android:label="@string/c_history" android:name=".history.CalculatorHistoryActivity"/> <activity android:label="@string/c_history" android:name=".history.CalculatorHistoryActivity"/>
<activity android:excludeFromRecents="true" android:finishOnTaskLaunch="true" android:label="@string/calculation_messages_dialog_title" android:launchMode="singleTask" android:name=".FixableMessagesDialog" android:theme="@style/cpp_gray_dialog_theme"/> <activity android:excludeFromRecents="true" android:finishOnTaskLaunch="true" android:label="@string/calculation_messages_dialog_title" android:launchMode="singleTask" android:name=".FixableMessagesDialog" android:theme="@style/cpp_metro_blue_dialog_theme"/>
<activity android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/> <activity android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/>
@ -52,20 +52,20 @@
<activity android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsActivity"/> <activity android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsActivity"/>
<activity android:name=".CalculatorWikiActivity"/> <activity android:name=".CalculatorWikiActivity"/>
<activity android:name=".wizard.CalculatorWizardActivity" android:theme="@style/cpp_gray_dialog_theme"> <activity android:name=".wizard.CalculatorWizardActivity" android:theme="@style/cpp_metro_blue_dialog_theme">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/> <activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/>
<activity android:label="@string/cpp_plot_functions" android:name=".plot.CalculatorPlotFunctionsActivity" android:theme="@style/cpp_gray_dialog_theme"/> <activity android:label="@string/cpp_plot_functions" android:name=".plot.CalculatorPlotFunctionsActivity" android:theme="@style/cpp_metro_blue_dialog_theme"/>
<activity android:label="@string/cpp_plot_function_settings" android:name=".plot.CalculatorPlotFunctionSettingsActivity" android:theme="@style/cpp_gray_dialog_theme"/> <activity android:label="@string/cpp_plot_function_settings" android:name=".plot.CalculatorPlotFunctionSettingsActivity" android:theme="@style/cpp_metro_blue_dialog_theme"/>
<activity android:label="@string/cpp_plot_range" android:name=".plot.CalculatorPlotRangeActivity" android:theme="@style/cpp_gray_dialog_theme"/> <activity android:label="@string/cpp_plot_range" android:name=".plot.CalculatorPlotRangeActivity" android:theme="@style/cpp_metro_blue_dialog_theme"/>
<activity android:label="@string/cpp_purchase_title" android:name=".preferences.CalculatorPurchaseDialogActivity" android:theme="@style/cpp_gray_dialog_theme"/> <activity android:label="@string/cpp_purchase_title" android:name=".preferences.CalculatorPurchaseDialogActivity" android:theme="@style/cpp_metro_blue_dialog_theme"/>
<activity android:name=".CalculatorDialogActivity" android:theme="@style/cpp_gray_dialog_theme"/> <activity android:name=".CalculatorDialogActivity" android:theme="@style/cpp_metro_blue_dialog_theme"/>
<!-- todo serso: strings--> <!-- todo serso: strings-->
<activity android:label="@string/c_plot_graph" android:name=".matrix.CalculatorMatrixActivity"/> <activity android:label="@string/c_plot_graph" android:name=".matrix.CalculatorMatrixActivity"/>
@ -81,7 +81,7 @@
<!-- ONSCREEN CONFIG --> <!-- ONSCREEN CONFIG -->
<activity android:icon="@drawable/icon_onscreen" android:label="@string/c_app_name_on_screen" android:launchMode="singleInstance" android:name=".onscreen.CalculatorOnscreenStartActivity" android:theme="@style/cpp_gray_dialog_theme"> <activity android:icon="@drawable/icon_onscreen" android:label="@string/c_app_name_on_screen" android:launchMode="singleInstance" android:name=".onscreen.CalculatorOnscreenStartActivity" android:theme="@style/cpp_metro_blue_dialog_theme">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:orientation="vertical">
<TextView
a:text="Drag button is an exclusive feature of Calculator++ which provides fast access to the secondary functions"
a:layout_height="wrap_content"
a:layout_width="match_parent" />
<TextView
a:id="@+id/wizard_dragbutton_action_textview"
a:text="@string/cpp_wizard_dragbutton_action_center"
a:layout_height="wrap_content"
a:layout_width="match_parent" />
<org.solovyev.android.view.drag.DirectionDragButton
a:layout_margin="30dp"
a:layout_height="100dp"
a:layout_width="100dp"
a:layout_gravity="center"
a:id="@+id/wizard_dragbutton"
a:text="9"
c:textDown="^2"
c:textLeft="sin"
c:textUp="%"
c:directionTextScale="0.5;0.5;0.5;0.33"
style="?cpp_operation_button_style"/>
</LinearLayout>

View File

@ -0,0 +1,156 @@
package org.solovyev.android.calculator.wizard;
import android.os.Bundle;
import android.view.LayoutInflater;
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 org.solovyev.android.calculator.R;
import org.solovyev.android.view.drag.DirectionDragButton;
import org.solovyev.android.view.drag.DragButton;
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;
public class DragButtonWizardStep extends SherlockFragment {
/*
**********************************************************************
*
* CONSTANTS
*
**********************************************************************
*/
private static final String ACTION = "action";
/*
**********************************************************************
*
* FIELDS
*
**********************************************************************
*/
@Nullable
private DirectionDragButton dragButton;
@Nullable
private TextView actionTextView;
private DragButtonAction action = DragButtonAction.center;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
action = (DragButtonAction) savedInstanceState.getSerializable(ACTION);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.cpp_wizard_step_drag_button, null);
}
@Override
public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
dragButton = (DirectionDragButton) root.findViewById(R.id.wizard_dragbutton);
dragButton.setOnClickListener(new DragButtonOnClickListener());
dragButton.setOnDragListener(new SimpleOnDragListener(new DragButtonProcessor(), SimpleOnDragListener.getDefaultPreferences(getActivity())));
actionTextView = (TextView) root.findViewById(R.id.wizard_dragbutton_action_textview);
actionTextView.setText(action.actionTextResId);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(ACTION, action);
}
/*
**********************************************************************
*
* STATIC/INNER
*
**********************************************************************
*/
private static enum DragButtonAction {
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);
private final int actionTextResId;
@Nullable
private final DragDirection dragDirection;
DragButtonAction(int actionTextResId, @Nullable DragDirection dragDirection) {
this.actionTextResId = actionTextResId;
this.dragDirection = dragDirection;
}
@Nullable
DragButtonAction getNextAction() {
final DragButtonAction[] values = values();
final int position = Arrays.binarySearch(values, this);
if (position < values.length - 1) {
return values[position + 1];
} else {
return values[0];
}
}
}
private class DragButtonOnClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
if(action == DragButtonAction.center) {
setNextAction();
}
}
}
private void setNextAction() {
setAction(action.getNextAction());
}
private class DragButtonProcessor implements SimpleOnDragListener.DragProcessor {
@Override
public boolean processDragEvent(@Nonnull DragDirection dragDirection,
@Nonnull DragButton dragButton,
@Nonnull Point2d startPoint2d,
@Nonnull MotionEvent motionEvent) {
if(action.dragDirection == dragDirection) {
setNextAction();
return true;
}
return false;
}
}
private void setAction(DragButtonAction action) {
if (this.action != action) {
this.action = action;
if (actionTextView != null) {
actionTextView.setText(this.action.actionTextResId);
}
}
}
}

View File

@ -9,7 +9,6 @@ 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.CalculatorLocator;
import org.solovyev.android.calculator.CalculatorPreferences; import org.solovyev.android.calculator.CalculatorPreferences;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -133,6 +132,24 @@ enum WizardStep {
bundle.putSerializable(ONSCREEN_CALCULATOR_ENABLED, CalculatorPreferences.OnscreenCalculator.showAppIcon.getPreference(preferences)); bundle.putSerializable(ONSCREEN_CALCULATOR_ENABLED, CalculatorPreferences.OnscreenCalculator.showAppIcon.getPreference(preferences));
return bundle; return bundle;
} }
},
drag_button_step(DragButtonWizardStep.class) {
@Override
boolean onNext(@Nonnull Fragment fragment) {
return true;
}
@Override
boolean onPrev(@Nonnull Fragment fragment) {
return true;
}
@Nullable
@Override
Bundle getFragmentArgs() {
return null;
}
}; };
@Nonnull @Nonnull