Calculator Onscreen

This commit is contained in:
Sergey Solovyev 2012-11-23 17:39:58 +04:00
parent ddbb9b3bef
commit b71a21a05f
21 changed files with 320 additions and 112 deletions

View File

@ -55,7 +55,7 @@
<activity android:launchMode="singleInstance"
android:label="@string/c_app_name_on_screen"
android:name=".CalculatorOnScreenStartActivity">
android:name=".CalculatorOnscreenStartActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
@ -66,15 +66,17 @@
<service android:name=".onscreen.CalculatorOnscreenService">
<intent-filter>
<action android:name="org.solovyev.calculator.widget.EDITOR_STATE_CHANGED"/>
<action android:name="org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED"/>
<action android:name="org.solovyev.android.calculator.INIT"/>
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
</intent-filter>
</service>
<receiver android:name=".onscreen.CalculatorOnscreenBroadcastReceiver">
<intent-filter>
<action android:name="org.solovyev.calculator.widget.EDITOR_STATE_CHANGED"/>
<action android:name="org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED"/>
<action android:name="org.solovyev.android.calculator.INIT"/>
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
</intent-filter>
</receiver>
@ -84,9 +86,10 @@
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
<action android:name="org.solovyev.calculator.widget.EDITOR_STATE_CHANGED"/>
<action android:name="org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED"/>
<action android:name="org.solovyev.calculator.widget.BUTTON_PRESSED"/>
<action android:name="org.solovyev.android.calculator.INIT"/>
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
<action android:name="org.solovyev.android.calculator.widget.BUTTON_PRESSED"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/calculator_widget_info_3x3"/>
@ -96,9 +99,10 @@
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
<action android:name="org.solovyev.calculator.widget.EDITOR_STATE_CHANGED"/>
<action android:name="org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED"/>
<action android:name="org.solovyev.calculator.widget.BUTTON_PRESSED"/>
<action android:name="org.solovyev.android.calculator.INIT"/>
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
<action android:name="org.solovyev.android.calculator.widget.BUTTON_PRESSED"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/calculator_widget_info_3x4"/>
@ -108,9 +112,10 @@
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
<action android:name="org.solovyev.calculator.widget.EDITOR_STATE_CHANGED"/>
<action android:name="org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED"/>
<action android:name="org.solovyev.calculator.widget.BUTTON_PRESSED"/>
<action android:name="org.solovyev.android.calculator.INIT"/>
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
<action android:name="org.solovyev.android.calculator.widget.BUTTON_PRESSED"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/calculator_widget_info_4x4"/>
@ -120,9 +125,10 @@
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
<action android:name="org.solovyev.calculator.widget.EDITOR_STATE_CHANGED"/>
<action android:name="org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED"/>
<action android:name="org.solovyev.calculator.widget.BUTTON_PRESSED"/>
<action android:name="org.solovyev.android.calculator.INIT"/>
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
<action android:name="org.solovyev.android.calculator.widget.BUTTON_PRESSED"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/calculator_widget_info_4x5"/>

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

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
-->
<org.solovyev.android.calculator.AndroidCalculatorDisplayView
xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/calculator_display"
style="@style/cpp_onscreen_display_style"
a:padding="@dimen/cpp_display_padding"
a:inputType="textMultiLine"
a:maxLines="3"
a:scrollHorizontally="false"
a:scrollbars="none"/>

View File

@ -0,0 +1,22 @@
<?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="?cpp_fragment_layout_style"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:padding="@dimen/cpp_editor_padding">
<org.solovyev.android.calculator.AndroidCalculatorEditorView
a:id="@+id/calculator_editor"
style="@style/cpp_onscreen_editor_style"
a:textIsSelectable="true"
a:hint="@string/c_calc_editor_hint"/>
</LinearLayout>

View File

@ -9,24 +9,28 @@
a:layout_height="match_parent"
a:layout_alignParentRight="true">
<Button a:id="@+id/onscreen_fold_button"
<ImageButton a:id="@+id/onscreen_fold_button"
style="@style/onscreen_header_button_style"
a:text="_"/>
a:src="@drawable/cpp_onscreen_button_fold"/>
<Button a:id="@+id/onscreen_minimize_button"
<ImageButton a:id="@+id/onscreen_minimize_button"
style="@style/onscreen_header_button_style"
a:text="_"/>
a:src="@drawable/cpp_onscreen_button_minimize"/>
<Button a:id="@+id/onscreen_close_button"
<ImageButton a:id="@+id/onscreen_close_button"
style="@style/onscreen_header_button_style"
a:text="x"/>
a:src="@drawable/cpp_onscreen_button_close"/>
</LinearLayout>
<TextView a:id="@+id/onscreen_title"
a:text="@string/c_app_name"
<ImageView a:id="@+id/onscreen_title"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:src="@drawable/cpp_onscreen_header_logo"
a:scaleType="fitStart"
a:paddingLeft="6dp"
a:paddingTop="2dp"
a:paddingBottom="2dp"
a:layout_toLeftOf="@id/onscreen_header_buttons"/>
</RelativeLayout>

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_erase_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_percent_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_power_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_app_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_app_button"/>
<include layout="@layout/widget_history_button"/>
</LinearLayout>-->
</LinearLayout>

View File

@ -4,17 +4,16 @@
a:orientation="vertical"
style="@style/cpp_widget_main_layout_style">
<include layout="@layout/onscreen_header"/>
<include a:id="@+id/onscreen_header" layout="@layout/onscreen_header"/>
<LinearLayout a:id="@+id/onscreen_content"
a:orientation="vertical"
a:layout_width="match_parent"
a:layout_height="match_parent">
<include layout="@layout/widget_editor"
a:layout_weight="2"
<include layout="@layout/onscreen_editor"
a:layout_width="match_parent"
a:layout_height="0dp"/>
a:layout_height="wrap_content"/>
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
@ -26,15 +25,15 @@
a:layout_width="0dp"
a:layout_height="match_parent"/>
<include layout="@layout/widget_display"
a:layout_weight="5"
<include layout="@layout/onscreen_display"
a:layout_weight="4"
a:layout_width="0dp"
a:layout_height="wrap_content"/>
</LinearLayout>
<include layout="@layout/widget_keyboard"
a:layout_weight="5"
<include layout="@layout/onscreen_keyboard"
a:layout_weight="4"
a:layout_width="match_parent"
a:layout_height="0dp"/>
</LinearLayout>

View File

@ -25,6 +25,7 @@
<dimen name="cpp_widget_display_text_size">25sp</dimen>
<dimen name="cpp_widget_margin">6dp</dimen>
<dimen name="cpp_onscreen_display_text_size">20sp</dimen>
<dimen name="cpp_onscreen_header_button_text_size">10dp</dimen>
<!--only for not multipane-->

View File

@ -44,6 +44,12 @@
<item name="android:textColor">@color/cpp_button_text_color</item>
</style>
<style name="cpp_onscreen_editor_style" parent="cpp_editor_style">
<item name="android:ellipsize">none</item>
<item name="android:singleLine">true</item>
<item name="android:scrollbars">horizontal</item>
</style>
<style name="cpp_editor_style" parent="cpp_default_text">
<item name="android:gravity">left|top</item>
<item name="android:layout_width">fill_parent</item>
@ -66,6 +72,10 @@
<item name="android:textSize">@dimen/cpp_widget_editor_text_size</item>
</style>
<style name="cpp_onscreen_display_style" parent="cpp_display_style">
<item name="android:textSize">@dimen/cpp_onscreen_display_text_size</item>
</style>
<style name="cpp_widget_display_style" parent="cpp_display_style">
<item name="android:textSize">@dimen/cpp_widget_display_text_size</item>
</style>

View File

@ -169,14 +169,21 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
}
public synchronized void init(@NotNull Context context) {
this.init(context, true);
}
public synchronized void init(@NotNull Context context, boolean fromApp) {
if (!initialized) {
if (fromApp) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.getLayout(preferences);
if ( layout == CalculatorPreferences.Gui.Layout.main_calculator_mobile ) {
setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.cpp_display_text_size_mobile));
}
this.setOnClickListener(new CalculatorDisplayOnClickListener(context));
}
this.initialized = true;
}

View File

@ -3,15 +3,18 @@ package org.solovyev.android.calculator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import org.solovyev.android.calculator.external.AndroidExternalListenersContainer;
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService;
public class CalculatorOnScreenStartActivity extends Activity {
public class CalculatorOnscreenStartActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startService(new Intent(this, CalculatorOnscreenService.class));
final Intent intent = new Intent(AndroidExternalListenersContainer.INIT_ACTION);
intent.setClass(this, CalculatorOnscreenService.class);
startService(intent);
this.finish();
}

View File

@ -0,0 +1,21 @@
package org.solovyev.android.calculator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import org.solovyev.android.calculator.external.AndroidExternalListenersContainer;
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService;
public class CalculatorOnscreenStartActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intent = new Intent(AndroidExternalListenersContainer.INIT_ACTION);
intent.setClass(this, CalculatorOnscreenService.class);
startService(intent);
this.finish();
}
}

View File

@ -39,9 +39,13 @@ public class AndroidExternalListenersContainer implements CalculatorExternalList
*/
public static final String EVENT_ID_EXTRA = "eventId";
public static final String EDITOR_STATE_CHANGED_ACTION = "org.solovyev.calculator.widget.EDITOR_STATE_CHANGED";
public static final String INIT_ACTION = "org.solovyev.android.calculator.INIT";
public static final String EDITOR_STATE_CHANGED_ACTION = "org.solovyev.android.calculator.EDITOR_STATE_CHANGED";
public static final String EDITOR_STATE_EXTRA = "editorState";
public static final String DISPLAY_STATE_CHANGED_ACTION = "org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED";
public static final String DISPLAY_STATE_CHANGED_ACTION = "org.solovyev.android.calculator.DISPLAY_STATE_CHANGED";
public static final String DISPLAY_STATE_EXTRA = "displayState";
private static final String TAG = "Calculator++ External Listener Helper";

View File

@ -4,9 +4,9 @@ import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorDisplayViewState;
import org.solovyev.android.calculator.CalculatorEditorViewState;
import org.solovyev.android.calculator.Locator;
import org.solovyev.common.MutableObject;
/**
@ -71,6 +71,8 @@ public class DefaultExternalCalculatorIntentHandler implements ExternalCalculato
onDisplayStateChanged(context, (CalculatorDisplayViewState) object);
}
}
} else if ( AndroidExternalListenersContainer.INIT_ACTION.equals(intent.getAction()) ) {
updateState(context, Locator.getInstance().getEditor().getViewState(), Locator.getInstance().getDisplay().getViewState());
}
}

View File

@ -16,6 +16,7 @@ import org.solovyev.android.calculator.CalculatorDisplayViewState;
import org.solovyev.android.calculator.CalculatorEditorViewState;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.external.AndroidExternalListenersContainer;
import org.solovyev.android.calculator.external.DefaultExternalCalculatorIntentHandler;
import org.solovyev.android.calculator.external.ExternalCalculatorIntentHandler;
import org.solovyev.android.calculator.external.ExternalCalculatorStateUpdater;
@ -38,6 +39,8 @@ public class CalculatorOnscreenService extends Service implements ExternalCalcul
@NotNull
private CalculatorOnscreenView view;
private boolean compatibilityStart = true;
@Override
public IBinder onBind(Intent intent) {
return null;
@ -51,14 +54,15 @@ public class CalculatorOnscreenService extends Service implements ExternalCalcul
final DisplayMetrics dm = getResources().getDisplayMetrics();
final int displayWidth0 = 2 * wm.getDefaultDisplay().getWidth() / 3;
final int displayHeight0 = 2 * wm.getDefaultDisplay().getHeight() / 3;
int twoThirdWidth = 2 * wm.getDefaultDisplay().getWidth() / 3;
int twoThirdHeight = 2 * wm.getDefaultDisplay().getHeight() / 3;
final int displayWidth = Math.min(displayWidth0, displayHeight0);
final int displayHeight = Math.max(displayWidth0, displayHeight0);
twoThirdWidth = Math.min(twoThirdWidth, twoThirdHeight);
twoThirdHeight = Math.max(twoThirdWidth, getHeight(twoThirdWidth));
final int width0 = Math.min(displayWidth, AndroidUtils.toPixels(dm, 300));
final int height0 = Math.min(displayHeight, AndroidUtils.toPixels(dm, 450));
final int baseWidth = AndroidUtils.toPixels(dm, 300);
final int width0 = Math.min(twoThirdWidth, baseWidth);
final int height0 = Math.min(twoThirdHeight, getHeight(baseWidth));
final int width = Math.min(width0, height0);
final int height = Math.max(width0, height0);
@ -69,6 +73,10 @@ public class CalculatorOnscreenService extends Service implements ExternalCalcul
startCalculatorListening();
}
private int getHeight(int width) {
return 4 * width / 3;
}
private void startCalculatorListening() {
Locator.getInstance().getExternalListenersContainer().addExternalListener(getIntentListenerClass());
}
@ -106,20 +114,32 @@ public class CalculatorOnscreenService extends Service implements ExternalCalcul
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
if (this.compatibilityStart) {
handleStart(intent);
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
int result = super.onStartCommand(intent, flags, startId);
final int result;
try {
this.compatibilityStart = false;
result = super.onStartCommand(intent, flags, startId);
handleStart(intent);
} finally {
this.compatibilityStart = true;
}
return result;
}
private void handleStart(@Nullable Intent intent) {
if ( intent != null ) {
intentHandler.onIntent(this, intent);
}
hideNotification();
return result;
}
private void hideNotification() {
@ -144,7 +164,7 @@ public class CalculatorOnscreenService extends Service implements ExternalCalcul
builder.setContentTitle(getText(R.string.c_app_name));
builder.setContentText(getString(R.string.open_onscreen_calculator));
final Intent intent = new Intent();
final Intent intent = new Intent(AndroidExternalListenersContainer.INIT_ACTION);
intent.setClass(this, getIntentListenerClass());
builder.setContentIntent(PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));

View File

@ -2,13 +2,14 @@ package org.solovyev.android.calculator.onscreen;
import android.content.Context;
import android.graphics.PixelFormat;
import android.text.Html;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.ImageView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.AndroidCalculatorDisplayView;
import org.solovyev.android.calculator.AndroidCalculatorEditorView;
import org.solovyev.android.calculator.CalculatorDisplayViewState;
import org.solovyev.android.calculator.CalculatorEditorViewState;
import org.solovyev.android.calculator.R;
@ -44,6 +45,15 @@ public class CalculatorOnscreenView {
@NotNull
private View content;
@NotNull
private View header;
@NotNull
private AndroidCalculatorEditorView editorView;
@NotNull
private AndroidCalculatorDisplayView displayView;
@NotNull
private Context context;
@ -115,33 +125,12 @@ public class CalculatorOnscreenView {
public void updateDisplayState(@NotNull CalculatorDisplayViewState displayState) {
checkInit();
final TextView calculatorDisplayView = (TextView) root.findViewById(R.id.calculator_display);
if (calculatorDisplayView != null) {
if (displayState.isValid()) {
calculatorDisplayView.setText(displayState.getText());
calculatorDisplayView.setTextColor(context.getResources().getColor(R.color.cpp_default_text_color));
} else {
calculatorDisplayView.setTextColor(context.getResources().getColor(R.color.cpp_display_error_text_color));
}
}
displayView.setState(displayState);
}
public void updateEditorState(@NotNull CalculatorEditorViewState editorState) {
checkInit();
final TextView calculatorEditorView = (TextView) root.findViewById(R.id.calculator_editor);
if (calculatorEditorView != null) {
String text = editorState.getText();
CharSequence newText = text;
int selection = editorState.getSelection();
if (selection >= 0 && selection <= text.length()) {
// inject cursor
newText = Html.fromHtml(text.substring(0, selection) + "<font color=\"#" + cursorColor + "\">|</font>" + text.substring(selection));
}
calculatorEditorView.setText(newText);
}
editorView.setState(editorState);
}
private void setHeight(int height) {
@ -176,13 +165,27 @@ public class CalculatorOnscreenView {
widgetButton.onClick(context);
}
});
button.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
widgetButton.onLongClick(context);
return true;
}
});
}
}
final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
header = root.findViewById(R.id.onscreen_header);
content = root.findViewById(R.id.onscreen_content);
displayView = (AndroidCalculatorDisplayView) root.findViewById(R.id.calculator_display);
displayView.init(this.context, false);
editorView = (AndroidCalculatorEditorView) root.findViewById(R.id.calculator_editor);
editorView.init(this.context);
final View onscreenFoldButton = root.findViewById(R.id.onscreen_fold_button);
onscreenFoldButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -210,8 +213,8 @@ public class CalculatorOnscreenView {
}
});
final TextView onscreenTitleTextView = (TextView) root.findViewById(R.id.onscreen_title);
onscreenTitleTextView.setOnTouchListener(new WindowDragTouchListener(wm, root));
final ImageView onscreenTitleImageView = (ImageView) root.findViewById(R.id.onscreen_title);
onscreenTitleImageView.setOnTouchListener(new WindowDragTouchListener(wm, root));
initialized = true;
}
@ -254,7 +257,7 @@ public class CalculatorOnscreenView {
if (!folded) {
final WindowManager.LayoutParams params = (WindowManager.LayoutParams) root.getLayoutParams();
unfoldedHeight = params.height;
int newHeight = root.findViewById(R.id.onscreen_close_button).getHeight();
int newHeight = header.getHeight();
content.setVisibility(View.GONE);
setHeight(newHeight);
folded = true;

View File

@ -26,7 +26,7 @@ import org.solovyev.android.calculator.external.ExternalCalculatorStateUpdater;
abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider implements ExternalCalculatorStateUpdater {
static final String BUTTON_ID_EXTRA = "buttonId";
static final String BUTTON_PRESSED_ACTION = "org.solovyev.calculator.widget.BUTTON_PRESSED";
static final String BUTTON_PRESSED_ACTION = "org.solovyev.android.calculator.widget.BUTTON_PRESSED";
private static final String TAG = "Calculator++ Widget";

View File

@ -53,7 +53,7 @@ public enum WidgetButton {
/*last column*/
clear(R.id.clearButton, CalculatorSpecialButton.clear),
erase(R.id.eraseButton, CalculatorSpecialButton.erase),
erase(R.id.eraseButton, CalculatorSpecialButton.erase, CalculatorSpecialButton.clear),
copy(R.id.copyButton, CalculatorSpecialButton.copy),
paste(R.id.pasteButton, CalculatorSpecialButton.paste),
@ -64,23 +64,43 @@ public enum WidgetButton {
private final int buttonId;
@NotNull
private final String text;
private final String onClickText;
@Nullable
private final String onLongClickText;
@NotNull
private static Map<Integer, WidgetButton> buttonsByIds = new HashMap<Integer, WidgetButton>();
WidgetButton(int buttonId, @NotNull CalculatorSpecialButton button) {
this(buttonId, button.getActionCode());
WidgetButton(int buttonId, @NotNull CalculatorSpecialButton onClickButton, @Nullable CalculatorSpecialButton onLongClickButton) {
this(buttonId, onClickButton.getActionCode(), onLongClickButton == null ? null : onLongClickButton.getActionCode());
}
WidgetButton(int buttonId, @NotNull String text) {
WidgetButton(int buttonId, @NotNull CalculatorSpecialButton onClickButton) {
this(buttonId, onClickButton, null);
}
WidgetButton(int buttonId, @NotNull String onClickText, @Nullable String onLongClickText) {
this.buttonId = buttonId;
this.text = text;
this.onClickText = onClickText;
this.onLongClickText = onLongClickText;
}
WidgetButton(int buttonId, @NotNull String onClickText) {
this(buttonId, onClickText, null);
}
public void onLongClick(@NotNull Context context) {
Locator.getInstance().getNotifier().showDebugMessage("Calculator++ Widget", "Button pressed: " + onLongClickText);
if (onLongClickText != null) {
Locator.getInstance().getKeyboard().buttonPressed(onLongClickText);
}
}
public void onClick(@NotNull Context context) {
Locator.getInstance().getNotifier().showDebugMessage("Calculator++ Widget", "Button pressed: " + text);
Locator.getInstance().getKeyboard().buttonPressed(text);
Locator.getInstance().getNotifier().showDebugMessage("Calculator++ Widget", "Button pressed: " + onClickText);
Locator.getInstance().getKeyboard().buttonPressed(onClickText);
}
@Nullable