Widget implementation

This commit is contained in:
serso 2012-10-19 18:20:03 +04:00
parent 5607c3bb7d
commit 42acacee32
48 changed files with 1599 additions and 959 deletions

View File

@ -0,0 +1,25 @@
package org.solovyev.android.calculator;
/**
* User: Solovyev_S
* Date: 19.10.12
* Time: 17:31
*/
public final class CalculatorButtonActions {
public static final String ERASE = "erase";
public static final String PASTE = "paste";
public static final String COPY = "copy";
public static final String CLEAR = "clear";
public static final String SHOW_FUNCTIONS = "functions";
public static final String SHOW_VARS = "vars";
public static final String SHOW_OPERATORS = "operators";
private CalculatorButtonActions() {
throw new AssertionError();
}
public static final String SHOW_HISTORY = "history";
public static final String MOVE_CURSOR_RIGHT = "";
public static final String MOVE_CURSOR_LEFT = "";
}

View File

@ -88,6 +88,8 @@ public enum CalculatorEventType {
clear_history_requested,
show_history,
/*
**********************************************************************
*
@ -112,7 +114,19 @@ public enum CalculatorEventType {
constant_changed,
// @NotNull IConstant
constant_removed;
constant_removed,
/*
**********************************************************************
*
* OTHER
*
**********************************************************************
*/
show_functions,
show_vars,
show_operators;
public boolean isOfType(@NotNull CalculatorEventType... types) {
for (CalculatorEventType type : types) {

View File

@ -409,17 +409,17 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
case use_constant:
final IConstant constant = (IConstant)data;
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(constant.getName());
CalculatorLocatorImpl.getInstance().getKeyboard().buttonPressed(constant.getName());
break;
case use_operator:
final Operator operator = (Operator)data;
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(operator.getName());
CalculatorLocatorImpl.getInstance().getKeyboard().buttonPressed(operator.getName());
break;
case use_function:
final Function function = (Function)data;
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(function.getName());
CalculatorLocatorImpl.getInstance().getKeyboard().buttonPressed(function.getName());
break;
}

View File

@ -9,7 +9,7 @@ import org.jetbrains.annotations.Nullable;
*/
public interface CalculatorKeyboard {
void digitButtonPressed(@Nullable String text);
void buttonPressed(@Nullable String text);
void roundBracketsButtonPressed();

View File

@ -20,11 +20,15 @@ public class CalculatorKeyboardImpl implements CalculatorKeyboard {
}
@Override
public void digitButtonPressed(@Nullable final String text) {
public void buttonPressed(@Nullable final String text) {
if (!StringUtils.isEmpty(text)) {
assert text != null;
// process special buttons
boolean processed = processSpecialButtons(text);
if (!processed) {
int cursorPositionOffset = 0;
final StringBuilder textToBeInserted = new StringBuilder(text);
@ -53,6 +57,37 @@ public class CalculatorKeyboardImpl implements CalculatorKeyboard {
editor.insert(textToBeInserted.toString(), cursorPositionOffset);
}
}
}
private boolean processSpecialButtons(@NotNull String text) {
boolean result = false;
if (CalculatorButtonActions.MOVE_CURSOR_LEFT.equals(text)) {
this.moveCursorLeft();
result = true;
} else if (CalculatorButtonActions.MOVE_CURSOR_RIGHT.equals(text)) {
this.moveCursorRight();
result = true;
} else if (CalculatorButtonActions.SHOW_HISTORY.equals(text)) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_history, null);
} else if (CalculatorButtonActions.ERASE.equals(text)) {
CalculatorLocatorImpl.getInstance().getEditor().erase();
} else if (CalculatorButtonActions.COPY.equals(text)) {
copyButtonPressed();
} else if (CalculatorButtonActions.PASTE.equals(text)) {
pasteButtonPressed();
} else if (CalculatorButtonActions.CLEAR.equals(text)) {
clearButtonPressed();
} else if (CalculatorButtonActions.SHOW_FUNCTIONS.equals(text)) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_functions, null);
} else if (CalculatorButtonActions.SHOW_OPERATORS.equals(text)) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null);
} else if (CalculatorButtonActions.SHOW_VARS.equals(text)) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_vars, null);
}
return result;
}
@Override
public void roundBracketsButtonPressed() {

View File

@ -37,9 +37,29 @@
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/>
<activity android:name=".widget.CalculatorWidgetConfigurationActivity" android:theme="@style/metro_blue_theme">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>
<!-- settings must use action bar icon-->
<activity android:icon="@drawable/icon_action_bar" android:label="@string/c_settings" android:name=".plot.CalculatorPlotPreferenceActivity"/>
<receiver
android:icon="@drawable/icon"
android:label="Example Widget"
android:name=".widget.CalculatorWidgetProvider">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/calculator_widget_info"/>
</receiver>
<activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:name="com.google.ads.AdActivity"/>
<service android:name="net.robotmedia.billing.BillingService"/>

View File

@ -13,4 +13,4 @@
a:text="◀"
c:directionTextScale="0.5"
style="?controlButtonStyle"
a:onClick="moveLeftButtonClickHandler"/>
a:onClick="digitButtonClickHandler"/>

View File

@ -13,4 +13,4 @@
a:text="▶"
c:directionTextScale="0.5"
style="?controlButtonStyle"
a:onClick="moveRightButtonClickHandler"/>
a:onClick="digitButtonClickHandler"/>

View File

@ -0,0 +1,13 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/clearButton"
a:text="@string/c_clear"
a:textStyle="bold"
style="@style/metro_control_image_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/pasteButton"
a:drawableTop="@drawable/kb_copy"
style="@style/metro_control_image_button_style"/>

View File

@ -0,0 +1,17 @@
<?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
-->
<TextView
xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/calculatorDisplay"
style="@style/display_style"
a:padding="@dimen/display_padding"
a:inputType="textMultiLine"
a:maxLines="3"
a:scrollHorizontally="false"
a:scrollbars="none"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/divisionButton"
a:text="/"
style="@style/metro_blue_operation_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/squareBracketsButton"
a:text="."
style="@style/metro_digit_button_style"/>

View File

@ -0,0 +1,24 @@
<?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
-->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/main_fragment_layout"
style="@style/default_fragment_layout_style"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:padding="@dimen/editor_padding">
<TextView
a:id="@+id/calculatorEditor"
style="@style/editor_style"
a:textIsSelectable="true"
a:singleLine="false"
a:scrollbars="vertical"
a:hint="@string/c_calc_editor_hint"/>
</LinearLayout>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/eightDigitButton"
a:text="8"
style="@style/metro_digit_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button
xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/equalsButton"
a:text="="
style="@style/metro_control_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/eraseButton"
a:drawableTop="@drawable/kb_delete"
style="@style/metro_control_image_button_style"/>

View File

@ -0,0 +1,11 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/fiveDigitButton"
a:text="5"
style="@style/metro_digit_button_style"/>

View File

@ -0,0 +1,11 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/fourDigitButton"
a:text="4"
style="@style/metro_digit_button_style"/>

View File

@ -0,0 +1,13 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/functionsButton"
a:text="ƒ(x)"
a:textStyle="italic"
style="@style/metro_control_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/historyButton"
a:text="@string/c_history_button"
style="@style/metro_control_button_style"
a:textStyle="bold"/>

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:orientation="vertical">
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
a:layout_height="0dp">
<include layout="@layout/widget_seven_digit_button"/>
<include layout="@layout/widget_eight_digit_button"/>
<include layout="@layout/widget_nine_digit_button"/>
<include layout="@layout/widget_multiplication_button"/>
<include layout="@layout/widget_clear_button"/>
</LinearLayout>
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
a:layout_height="0dp">
<include layout="@layout/widget_four_digit_button"/>
<include layout="@layout/widget_five_digit_button"/>
<include layout="@layout/widget_six_digit_button"/>
<include layout="@layout/widget_division_button"/>
<include layout="@layout/widget_erase_button"/>
</LinearLayout>
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
a:layout_height="0dp">
<include layout="@layout/widget_one_digit_button"/>
<include layout="@layout/widget_two_digit_button"/>
<include layout="@layout/widget_three_digit_button"/>
<include layout="@layout/widget_plus_button"/>
<include layout="@layout/widget_copy_button"/>
</LinearLayout>
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
a:layout_height="0dp">
<include layout="@layout/widget_round_brackets_button"/>
<include layout="@layout/widget_zero_digit_button"/>
<include layout="@layout/widget_dot_button"/>
<include layout="@layout/widget_subtraction_button"/>
<include layout="@layout/widget_paste_button"/>
</LinearLayout>
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
a:layout_height="0dp">
<include layout="@layout/widget_left_button"/>
<include layout="@layout/widget_right_button"/>
<include layout="@layout/widget_vars_button"/>
<include layout="@layout/widget_functions_button"/>
<include layout="@layout/widget_history_button"/>
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:orientation="vertical"
style="@style/default_main_layout_style">
<include layout="@layout/widget_editor"
a:layout_weight="2"
a:layout_width="match_parent"
a:layout_height="0dp"/>
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
a:layout_height="0dp">
<include layout="@layout/widget_equals_button"
a:layout_margin="@dimen/button_margin"
a:layout_weight="1"
a:layout_width="0dp"
a:layout_height="match_parent"/>
<include layout="@layout/widget_display"
a:layout_weight="4"
a:layout_width="0dp"
a:layout_height="match_parent"/>
</LinearLayout>
<include layout="@layout/widget_keyboard"
a:layout_weight="5"
a:layout_width="match_parent"
a:layout_height="0dp"/>
</LinearLayout>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/leftButton"
a:text="◀"
style="@style/metro_control_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/multiplicationButton"
a:text="×"
style="@style/metro_blue_operation_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/nineDigitButton"
a:text="9"
style="@style/metro_digit_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/oneDigitButton"
a:text="1"
style="@style/metro_digit_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/pasteButton"
a:drawableTop="@drawable/kb_paste"
style="@style/metro_control_image_button_style"/>

View File

@ -0,0 +1,11 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/plusButton"
a:text="+"
style="@style/metro_blue_operation_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/rightButton"
a:text="▶"
style="@style/metro_control_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/roundBracketsButton"
a:text="()"
style="@style/metro_digit_button_style"/>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/sevenDigitButton"
a:text="7"
style="@style/metro_digit_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/sixDigitButton"
a:text="6"
style="@style/metro_digit_button_style"/>

View File

@ -0,0 +1,11 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/subtractionButton"
a:text="-"
style="@style/metro_blue_operation_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/threeDigitButton"
a:text="3"
style="@style/metro_digit_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/twoDigitButton"
a:text="2"
style="@style/metro_digit_button_style"/>

View File

@ -0,0 +1,13 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/varsButton"
a:text="π,…"
a:textStyle="italic"
style="@style/metro_control_button_style"/>

View File

@ -0,0 +1,12 @@
<?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
-->
<Button xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/zeroDigitButton"
a:text="0"
style="@style/metro_digit_button_style"/>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:a="http://schemas.android.com/apk/res/android"
a:minWidth="150dp"
a:minHeight="200dp"
a:updatePeriodMillis="1000"
a:initialLayout="@layout/widget_layout"
a:resizeMode="horizontal|vertical">
</appwidget-provider>

View File

@ -90,7 +90,7 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
@Override
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
if (dragDirection == DragDirection.down) {
CalculatorActivity.operatorsButtonClickHandler(activity);
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null);
return true;
}
return false;

View File

@ -21,11 +21,15 @@ import java.util.List;
* Date: 9/22/12
* Time: 5:42 PM
*/
public class AndroidCalculator implements Calculator {
public class AndroidCalculator implements Calculator, CalculatorEventListener {
@NotNull
private final Calculator calculator = new CalculatorImpl();
public AndroidCalculator() {
this.calculator.addCalculatorEventListener(this);
}
public static void showEvaluationError(@NotNull Context context, @NotNull final String errorMessage) {
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
@ -170,4 +174,18 @@ public class AndroidCalculator implements Calculator {
calculator.simplify();
}
@Override
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
switch (calculatorEventType) {
case show_history:
CalculatorActivityLauncher.showHistory(CalculatorApplication.getInstance());
break;
case show_functions:
CalculatorActivityLauncher.showFunctions(CalculatorApplication.getInstance());
break;
case show_vars:
CalculatorActivityLauncher.showVars(CalculatorApplication.getInstance());
break;
}
}
}

View File

@ -5,7 +5,6 @@
package org.solovyev.android.calculator;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.SharedPreferences;
@ -18,6 +17,7 @@ import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import org.jetbrains.annotations.NotNull;
@ -241,12 +241,12 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
@SuppressWarnings({"UnusedDeclaration"})
public void historyButtonClickHandler(@NotNull View v) {
CalculatorActivityLauncher.showHistory(this);
buttonPressed(CalculatorButtonActions.SHOW_HISTORY);
}
@SuppressWarnings({"UnusedDeclaration"})
public void eraseButtonClickHandler(@NotNull View v) {
CalculatorLocatorImpl.getInstance().getEditor().erase();
buttonPressed(CalculatorButtonActions.ERASE);
}
@SuppressWarnings({"UnusedDeclaration"})
@ -254,24 +254,14 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
throw new UnsupportedOperationException("Not implemented yet!");
}
@SuppressWarnings({"UnusedDeclaration"})
public void moveLeftButtonClickHandler(@NotNull View v) {
getKeyboard().moveCursorLeft();
}
@SuppressWarnings({"UnusedDeclaration"})
public void moveRightButtonClickHandler(@NotNull View v) {
getKeyboard().moveCursorRight();
}
@SuppressWarnings({"UnusedDeclaration"})
public void pasteButtonClickHandler(@NotNull View v) {
getKeyboard().pasteButtonPressed();
buttonPressed(CalculatorButtonActions.PASTE);
}
@SuppressWarnings({"UnusedDeclaration"})
public void copyButtonClickHandler(@NotNull View v) {
getKeyboard().copyButtonPressed();
buttonPressed(CalculatorButtonActions.COPY);
}
@NotNull
@ -281,34 +271,43 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
@SuppressWarnings({"UnusedDeclaration"})
public void clearButtonClickHandler(@NotNull View v) {
getKeyboard().clearButtonPressed();
buttonPressed(CalculatorButtonActions.CLEAR);
}
@SuppressWarnings({"UnusedDeclaration"})
public void digitButtonClickHandler(@NotNull View v) {
Log.d(String.valueOf(v.getId()), "digitButtonClickHandler() for: " + v.getId() + ". Pressed: " + v.isPressed());
if (((ColorButton) v).isShowText()) {
getKeyboard().digitButtonPressed(((ColorButton) v).getText().toString());
if (v instanceof Button) {
boolean processText = true;
if ( v instanceof ColorButton) {
processText = ((ColorButton) v).isShowText();
}
if ( processText ) {
buttonPressed(((Button)v).getText().toString());
}
}
}
private void buttonPressed(@NotNull String text) {
getKeyboard().buttonPressed(text);
}
@SuppressWarnings({"UnusedDeclaration"})
public void functionsButtonClickHandler(@NotNull View v) {
CalculatorActivityLauncher.showFunctions(this);
buttonPressed(CalculatorButtonActions.SHOW_FUNCTIONS);
}
@SuppressWarnings({"UnusedDeclaration"})
public void operatorsButtonClickHandler(@NotNull View v) {
CalculatorActivityLauncher.showOperators(this);
}
public static void operatorsButtonClickHandler(@NotNull Activity activity) {
CalculatorActivityLauncher.showOperators(activity);
buttonPressed(CalculatorButtonActions.SHOW_OPERATORS);
}
@SuppressWarnings({"UnusedDeclaration"})
public void varsButtonClickHandler(@NotNull View v) {
CalculatorActivityLauncher.showVars(this);
buttonPressed(CalculatorButtonActions.SHOW_VARS);
}
@SuppressWarnings({"UnusedDeclaration"})

View File

@ -7,10 +7,10 @@ package org.solovyev.android.calculator;
import android.view.MotionEvent;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.view.drag.DragDirection;
import org.solovyev.android.view.drag.SimpleOnDragListener;
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;
/**
@ -30,7 +30,7 @@ public class DigitButtonDragProcessor implements SimpleOnDragListener.DragProces
@Override
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
assert dragButton instanceof DirectionDragButton;
calculatorKeyboard.digitButtonPressed(((DirectionDragButton) dragButton).getText(dragDirection));
calculatorKeyboard.buttonPressed(((DirectionDragButton) dragButton).getText(dragDirection));
return true;
}

View File

@ -71,7 +71,7 @@ public class NumeralBaseConverterDialog {
toUnitsValue = ((CalculatorNumeralBase) toUnits.getUnitType()).getNumeralBase().getJsclPrefix() + toUnitsValue;
}
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(toUnitsValue);
CalculatorLocatorImpl.getInstance().getKeyboard().buttonPressed(toUnitsValue);
final AlertDialog alertDialog = alertDialogHolder.getObject();
if (alertDialog != null) {
alertDialog.dismiss();

View File

@ -0,0 +1,11 @@
package org.solovyev.android.calculator.widget;
import android.app.Activity;
/**
* User: Solovyev_S
* Date: 19.10.12
* Time: 16:20
*/
public class CalculatorWidgetConfigurationActivity extends Activity {
}

View File

@ -0,0 +1,11 @@
package org.solovyev.android.calculator.widget;
/**
* User: Solovyev_S
* Date: 19.10.12
* Time: 18:09
*/
public class CalculatorWidgetController {
public static final String BUTTON_PRESSED_ACTION = "org.solovyev.calculator.widget.BUTTON_PRESSED";
}

View File

@ -0,0 +1,46 @@
package org.solovyev.android.calculator.widget;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
import android.widget.Toast;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.CalculatorApplication;
import org.solovyev.android.calculator.R;
/**
* User: Solovyev_S
* Date: 19.10.12
* Time: 16:18
*/
public class CalculatorWidgetProvider extends AppWidgetProvider {
public static final String BUTTON_PRESSED = "org.solovyev.calculator.widget.BUTTON_PRESSED";
@Override
public void onUpdate(@NotNull Context context,
@NotNull AppWidgetManager appWidgetManager,
@NotNull int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
final Intent onButtonClickIntent = new Intent(context, CalculatorWidgetProvider.class);
onButtonClickIntent.setAction(CalculatorWidgetController.BUTTON_PRESSED_ACTION);
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, onButtonClickIntent, 0);
views.setOnClickPendingIntent(R.id.oneDigitButton, pendingIntent);
}
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if ( BUTTON_PRESSED.equals(intent.getAction()) ) {
Toast.makeText(CalculatorApplication.getInstance(), "Button pressed!", Toast.LENGTH_SHORT).show();
}
}
}