Calculator Onscreen
This commit is contained in:
parent
ddbb9b3bef
commit
b71a21a05f
@ -55,7 +55,7 @@
|
|||||||
|
|
||||||
<activity android:launchMode="singleInstance"
|
<activity android:launchMode="singleInstance"
|
||||||
android:label="@string/c_app_name_on_screen"
|
android:label="@string/c_app_name_on_screen"
|
||||||
android:name=".CalculatorOnScreenStartActivity">
|
android:name=".CalculatorOnscreenStartActivity">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
@ -66,15 +66,17 @@
|
|||||||
|
|
||||||
<service android:name=".onscreen.CalculatorOnscreenService">
|
<service android:name=".onscreen.CalculatorOnscreenService">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="org.solovyev.calculator.widget.EDITOR_STATE_CHANGED"/>
|
<action android:name="org.solovyev.android.calculator.INIT"/>
|
||||||
<action android:name="org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED"/>
|
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
|
||||||
|
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<receiver android:name=".onscreen.CalculatorOnscreenBroadcastReceiver">
|
<receiver android:name=".onscreen.CalculatorOnscreenBroadcastReceiver">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="org.solovyev.calculator.widget.EDITOR_STATE_CHANGED"/>
|
<action android:name="org.solovyev.android.calculator.INIT"/>
|
||||||
<action android:name="org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED"/>
|
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
|
||||||
|
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
@ -84,9 +86,10 @@
|
|||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||||
<action android:name="org.solovyev.calculator.widget.EDITOR_STATE_CHANGED"/>
|
<action android:name="org.solovyev.android.calculator.INIT"/>
|
||||||
<action android:name="org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED"/>
|
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
|
||||||
<action android:name="org.solovyev.calculator.widget.BUTTON_PRESSED"/>
|
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
|
||||||
|
<action android:name="org.solovyev.android.calculator.widget.BUTTON_PRESSED"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data android:name="android.appwidget.provider" android:resource="@xml/calculator_widget_info_3x3"/>
|
<meta-data android:name="android.appwidget.provider" android:resource="@xml/calculator_widget_info_3x3"/>
|
||||||
@ -96,9 +99,10 @@
|
|||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||||
<action android:name="org.solovyev.calculator.widget.EDITOR_STATE_CHANGED"/>
|
<action android:name="org.solovyev.android.calculator.INIT"/>
|
||||||
<action android:name="org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED"/>
|
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
|
||||||
<action android:name="org.solovyev.calculator.widget.BUTTON_PRESSED"/>
|
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
|
||||||
|
<action android:name="org.solovyev.android.calculator.widget.BUTTON_PRESSED"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data android:name="android.appwidget.provider" android:resource="@xml/calculator_widget_info_3x4"/>
|
<meta-data android:name="android.appwidget.provider" android:resource="@xml/calculator_widget_info_3x4"/>
|
||||||
@ -108,9 +112,10 @@
|
|||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||||
<action android:name="org.solovyev.calculator.widget.EDITOR_STATE_CHANGED"/>
|
<action android:name="org.solovyev.android.calculator.INIT"/>
|
||||||
<action android:name="org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED"/>
|
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
|
||||||
<action android:name="org.solovyev.calculator.widget.BUTTON_PRESSED"/>
|
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
|
||||||
|
<action android:name="org.solovyev.android.calculator.widget.BUTTON_PRESSED"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data android:name="android.appwidget.provider" android:resource="@xml/calculator_widget_info_4x4"/>
|
<meta-data android:name="android.appwidget.provider" android:resource="@xml/calculator_widget_info_4x4"/>
|
||||||
@ -120,9 +125,10 @@
|
|||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||||
<action android:name="org.solovyev.calculator.widget.EDITOR_STATE_CHANGED"/>
|
<action android:name="org.solovyev.android.calculator.INIT"/>
|
||||||
<action android:name="org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED"/>
|
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
|
||||||
<action android:name="org.solovyev.calculator.widget.BUTTON_PRESSED"/>
|
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
|
||||||
|
<action android:name="org.solovyev.android.calculator.widget.BUTTON_PRESSED"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data android:name="android.appwidget.provider" android:resource="@xml/calculator_widget_info_4x5"/>
|
<meta-data android:name="android.appwidget.provider" android:resource="@xml/calculator_widget_info_4x5"/>
|
||||||
|
BIN
calculatorpp/res/drawable-nodpi/cpp_onscreen_button_close.png
Normal file
BIN
calculatorpp/res/drawable-nodpi/cpp_onscreen_button_close.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 235 B |
BIN
calculatorpp/res/drawable-nodpi/cpp_onscreen_button_fold.png
Normal file
BIN
calculatorpp/res/drawable-nodpi/cpp_onscreen_button_fold.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 170 B |
BIN
calculatorpp/res/drawable-nodpi/cpp_onscreen_button_minimize.png
Normal file
BIN
calculatorpp/res/drawable-nodpi/cpp_onscreen_button_minimize.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 333 B |
BIN
calculatorpp/res/drawable-nodpi/cpp_onscreen_header_logo.png
Normal file
BIN
calculatorpp/res/drawable-nodpi/cpp_onscreen_header_logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
17
calculatorpp/res/layout/onscreen_display.xml
Normal file
17
calculatorpp/res/layout/onscreen_display.xml
Normal 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"/>
|
22
calculatorpp/res/layout/onscreen_editor.xml
Normal file
22
calculatorpp/res/layout/onscreen_editor.xml
Normal 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>
|
@ -9,24 +9,28 @@
|
|||||||
a:layout_height="match_parent"
|
a:layout_height="match_parent"
|
||||||
a:layout_alignParentRight="true">
|
a:layout_alignParentRight="true">
|
||||||
|
|
||||||
<Button a:id="@+id/onscreen_fold_button"
|
<ImageButton a:id="@+id/onscreen_fold_button"
|
||||||
style="@style/onscreen_header_button_style"
|
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"
|
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"
|
style="@style/onscreen_header_button_style"
|
||||||
a:text="x"/>
|
a:src="@drawable/cpp_onscreen_button_close"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView a:id="@+id/onscreen_title"
|
<ImageView a:id="@+id/onscreen_title"
|
||||||
a:text="@string/c_app_name"
|
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="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"/>
|
a:layout_toLeftOf="@id/onscreen_header_buttons"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
69
calculatorpp/res/layout/onscreen_keyboard.xml
Normal file
69
calculatorpp/res/layout/onscreen_keyboard.xml
Normal 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>
|
@ -4,17 +4,16 @@
|
|||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
style="@style/cpp_widget_main_layout_style">
|
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"
|
<LinearLayout a:id="@+id/onscreen_content"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="match_parent">
|
a:layout_height="match_parent">
|
||||||
|
|
||||||
<include layout="@layout/widget_editor"
|
<include layout="@layout/onscreen_editor"
|
||||||
a:layout_weight="2"
|
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="0dp"/>
|
a:layout_height="wrap_content"/>
|
||||||
|
|
||||||
<LinearLayout a:layout_weight="1"
|
<LinearLayout a:layout_weight="1"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
@ -26,15 +25,15 @@
|
|||||||
a:layout_width="0dp"
|
a:layout_width="0dp"
|
||||||
a:layout_height="match_parent"/>
|
a:layout_height="match_parent"/>
|
||||||
|
|
||||||
<include layout="@layout/widget_display"
|
<include layout="@layout/onscreen_display"
|
||||||
a:layout_weight="5"
|
a:layout_weight="4"
|
||||||
a:layout_width="0dp"
|
a:layout_width="0dp"
|
||||||
a:layout_height="wrap_content"/>
|
a:layout_height="wrap_content"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<include layout="@layout/widget_keyboard"
|
<include layout="@layout/onscreen_keyboard"
|
||||||
a:layout_weight="5"
|
a:layout_weight="4"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="0dp"/>
|
a:layout_height="0dp"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
<dimen name="cpp_widget_display_text_size">25sp</dimen>
|
<dimen name="cpp_widget_display_text_size">25sp</dimen>
|
||||||
<dimen name="cpp_widget_margin">6dp</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>
|
<dimen name="cpp_onscreen_header_button_text_size">10dp</dimen>
|
||||||
|
|
||||||
<!--only for not multipane-->
|
<!--only for not multipane-->
|
||||||
|
@ -44,6 +44,12 @@
|
|||||||
<item name="android:textColor">@color/cpp_button_text_color</item>
|
<item name="android:textColor">@color/cpp_button_text_color</item>
|
||||||
</style>
|
</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">
|
<style name="cpp_editor_style" parent="cpp_default_text">
|
||||||
<item name="android:gravity">left|top</item>
|
<item name="android:gravity">left|top</item>
|
||||||
<item name="android:layout_width">fill_parent</item>
|
<item name="android:layout_width">fill_parent</item>
|
||||||
@ -66,6 +72,10 @@
|
|||||||
<item name="android:textSize">@dimen/cpp_widget_editor_text_size</item>
|
<item name="android:textSize">@dimen/cpp_widget_editor_text_size</item>
|
||||||
</style>
|
</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">
|
<style name="cpp_widget_display_style" parent="cpp_display_style">
|
||||||
<item name="android:textSize">@dimen/cpp_widget_display_text_size</item>
|
<item name="android:textSize">@dimen/cpp_widget_display_text_size</item>
|
||||||
</style>
|
</style>
|
||||||
|
@ -169,14 +169,21 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void init(@NotNull Context context) {
|
public synchronized void init(@NotNull Context context) {
|
||||||
|
this.init(context, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void init(@NotNull Context context, boolean fromApp) {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
|
if (fromApp) {
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.getLayout(preferences);
|
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.getLayout(preferences);
|
||||||
|
|
||||||
if ( layout == CalculatorPreferences.Gui.Layout.main_calculator_mobile ) {
|
if ( layout == CalculatorPreferences.Gui.Layout.main_calculator_mobile ) {
|
||||||
setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.cpp_display_text_size_mobile));
|
setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.cpp_display_text_size_mobile));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setOnClickListener(new CalculatorDisplayOnClickListener(context));
|
this.setOnClickListener(new CalculatorDisplayOnClickListener(context));
|
||||||
|
}
|
||||||
|
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,18 @@ package org.solovyev.android.calculator;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import org.solovyev.android.calculator.external.AndroidExternalListenersContainer;
|
||||||
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService;
|
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService;
|
||||||
|
|
||||||
public class CalculatorOnScreenStartActivity extends Activity {
|
public class CalculatorOnscreenStartActivity extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(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();
|
this.finish();
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -39,9 +39,13 @@ public class AndroidExternalListenersContainer implements CalculatorExternalList
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public static final String EVENT_ID_EXTRA = "eventId";
|
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 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";
|
public static final String DISPLAY_STATE_EXTRA = "displayState";
|
||||||
|
|
||||||
private static final String TAG = "Calculator++ External Listener Helper";
|
private static final String TAG = "Calculator++ External Listener Helper";
|
||||||
|
@ -4,9 +4,9 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.Locator;
|
|
||||||
import org.solovyev.android.calculator.CalculatorDisplayViewState;
|
import org.solovyev.android.calculator.CalculatorDisplayViewState;
|
||||||
import org.solovyev.android.calculator.CalculatorEditorViewState;
|
import org.solovyev.android.calculator.CalculatorEditorViewState;
|
||||||
|
import org.solovyev.android.calculator.Locator;
|
||||||
import org.solovyev.common.MutableObject;
|
import org.solovyev.common.MutableObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,6 +71,8 @@ public class DefaultExternalCalculatorIntentHandler implements ExternalCalculato
|
|||||||
onDisplayStateChanged(context, (CalculatorDisplayViewState) object);
|
onDisplayStateChanged(context, (CalculatorDisplayViewState) object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if ( AndroidExternalListenersContainer.INIT_ACTION.equals(intent.getAction()) ) {
|
||||||
|
updateState(context, Locator.getInstance().getEditor().getViewState(), Locator.getInstance().getDisplay().getViewState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import org.solovyev.android.calculator.CalculatorDisplayViewState;
|
|||||||
import org.solovyev.android.calculator.CalculatorEditorViewState;
|
import org.solovyev.android.calculator.CalculatorEditorViewState;
|
||||||
import org.solovyev.android.calculator.Locator;
|
import org.solovyev.android.calculator.Locator;
|
||||||
import org.solovyev.android.calculator.R;
|
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.DefaultExternalCalculatorIntentHandler;
|
||||||
import org.solovyev.android.calculator.external.ExternalCalculatorIntentHandler;
|
import org.solovyev.android.calculator.external.ExternalCalculatorIntentHandler;
|
||||||
import org.solovyev.android.calculator.external.ExternalCalculatorStateUpdater;
|
import org.solovyev.android.calculator.external.ExternalCalculatorStateUpdater;
|
||||||
@ -38,6 +39,8 @@ public class CalculatorOnscreenService extends Service implements ExternalCalcul
|
|||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorOnscreenView view;
|
private CalculatorOnscreenView view;
|
||||||
|
|
||||||
|
private boolean compatibilityStart = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
return null;
|
return null;
|
||||||
@ -51,14 +54,15 @@ public class CalculatorOnscreenService extends Service implements ExternalCalcul
|
|||||||
|
|
||||||
final DisplayMetrics dm = getResources().getDisplayMetrics();
|
final DisplayMetrics dm = getResources().getDisplayMetrics();
|
||||||
|
|
||||||
final int displayWidth0 = 2 * wm.getDefaultDisplay().getWidth() / 3;
|
int twoThirdWidth = 2 * wm.getDefaultDisplay().getWidth() / 3;
|
||||||
final int displayHeight0 = 2 * wm.getDefaultDisplay().getHeight() / 3;
|
int twoThirdHeight = 2 * wm.getDefaultDisplay().getHeight() / 3;
|
||||||
|
|
||||||
final int displayWidth = Math.min(displayWidth0, displayHeight0);
|
twoThirdWidth = Math.min(twoThirdWidth, twoThirdHeight);
|
||||||
final int displayHeight = Math.max(displayWidth0, displayHeight0);
|
twoThirdHeight = Math.max(twoThirdWidth, getHeight(twoThirdWidth));
|
||||||
|
|
||||||
final int width0 = Math.min(displayWidth, AndroidUtils.toPixels(dm, 300));
|
final int baseWidth = AndroidUtils.toPixels(dm, 300);
|
||||||
final int height0 = Math.min(displayHeight, AndroidUtils.toPixels(dm, 450));
|
final int width0 = Math.min(twoThirdWidth, baseWidth);
|
||||||
|
final int height0 = Math.min(twoThirdHeight, getHeight(baseWidth));
|
||||||
|
|
||||||
final int width = Math.min(width0, height0);
|
final int width = Math.min(width0, height0);
|
||||||
final int height = Math.max(width0, height0);
|
final int height = Math.max(width0, height0);
|
||||||
@ -69,6 +73,10 @@ public class CalculatorOnscreenService extends Service implements ExternalCalcul
|
|||||||
startCalculatorListening();
|
startCalculatorListening();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getHeight(int width) {
|
||||||
|
return 4 * width / 3;
|
||||||
|
}
|
||||||
|
|
||||||
private void startCalculatorListening() {
|
private void startCalculatorListening() {
|
||||||
Locator.getInstance().getExternalListenersContainer().addExternalListener(getIntentListenerClass());
|
Locator.getInstance().getExternalListenersContainer().addExternalListener(getIntentListenerClass());
|
||||||
}
|
}
|
||||||
@ -106,20 +114,32 @@ public class CalculatorOnscreenService extends Service implements ExternalCalcul
|
|||||||
@Override
|
@Override
|
||||||
public void onStart(Intent intent, int startId) {
|
public void onStart(Intent intent, int startId) {
|
||||||
super.onStart(intent, startId);
|
super.onStart(intent, startId);
|
||||||
|
|
||||||
|
if (this.compatibilityStart) {
|
||||||
|
handleStart(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
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 ) {
|
if ( intent != null ) {
|
||||||
intentHandler.onIntent(this, intent);
|
intentHandler.onIntent(this, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
hideNotification();
|
hideNotification();
|
||||||
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideNotification() {
|
private void hideNotification() {
|
||||||
@ -144,7 +164,7 @@ public class CalculatorOnscreenService extends Service implements ExternalCalcul
|
|||||||
builder.setContentTitle(getText(R.string.c_app_name));
|
builder.setContentTitle(getText(R.string.c_app_name));
|
||||||
builder.setContentText(getString(R.string.open_onscreen_calculator));
|
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());
|
intent.setClass(this, getIntentListenerClass());
|
||||||
builder.setContentIntent(PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
|
builder.setContentIntent(PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
|
||||||
|
|
||||||
|
@ -2,13 +2,14 @@ package org.solovyev.android.calculator.onscreen;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
import android.text.Html;
|
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.TextView;
|
import android.widget.ImageView;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
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.CalculatorDisplayViewState;
|
||||||
import org.solovyev.android.calculator.CalculatorEditorViewState;
|
import org.solovyev.android.calculator.CalculatorEditorViewState;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
@ -44,6 +45,15 @@ public class CalculatorOnscreenView {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private View content;
|
private View content;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private View header;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private AndroidCalculatorEditorView editorView;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private AndroidCalculatorDisplayView displayView;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
@ -115,33 +125,12 @@ public class CalculatorOnscreenView {
|
|||||||
|
|
||||||
public void updateDisplayState(@NotNull CalculatorDisplayViewState displayState) {
|
public void updateDisplayState(@NotNull CalculatorDisplayViewState displayState) {
|
||||||
checkInit();
|
checkInit();
|
||||||
|
displayView.setState(displayState);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateEditorState(@NotNull CalculatorEditorViewState editorState) {
|
public void updateEditorState(@NotNull CalculatorEditorViewState editorState) {
|
||||||
checkInit();
|
checkInit();
|
||||||
final TextView calculatorEditorView = (TextView) root.findViewById(R.id.calculator_editor);
|
editorView.setState(editorState);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setHeight(int height) {
|
private void setHeight(int height) {
|
||||||
@ -176,13 +165,27 @@ public class CalculatorOnscreenView {
|
|||||||
widgetButton.onClick(context);
|
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);
|
final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||||
|
|
||||||
|
header = root.findViewById(R.id.onscreen_header);
|
||||||
content = root.findViewById(R.id.onscreen_content);
|
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);
|
final View onscreenFoldButton = root.findViewById(R.id.onscreen_fold_button);
|
||||||
onscreenFoldButton.setOnClickListener(new View.OnClickListener() {
|
onscreenFoldButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -210,8 +213,8 @@ public class CalculatorOnscreenView {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final TextView onscreenTitleTextView = (TextView) root.findViewById(R.id.onscreen_title);
|
final ImageView onscreenTitleImageView = (ImageView) root.findViewById(R.id.onscreen_title);
|
||||||
onscreenTitleTextView.setOnTouchListener(new WindowDragTouchListener(wm, root));
|
onscreenTitleImageView.setOnTouchListener(new WindowDragTouchListener(wm, root));
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
@ -254,7 +257,7 @@ public class CalculatorOnscreenView {
|
|||||||
if (!folded) {
|
if (!folded) {
|
||||||
final WindowManager.LayoutParams params = (WindowManager.LayoutParams) root.getLayoutParams();
|
final WindowManager.LayoutParams params = (WindowManager.LayoutParams) root.getLayoutParams();
|
||||||
unfoldedHeight = params.height;
|
unfoldedHeight = params.height;
|
||||||
int newHeight = root.findViewById(R.id.onscreen_close_button).getHeight();
|
int newHeight = header.getHeight();
|
||||||
content.setVisibility(View.GONE);
|
content.setVisibility(View.GONE);
|
||||||
setHeight(newHeight);
|
setHeight(newHeight);
|
||||||
folded = true;
|
folded = true;
|
||||||
|
@ -26,7 +26,7 @@ import org.solovyev.android.calculator.external.ExternalCalculatorStateUpdater;
|
|||||||
abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider implements ExternalCalculatorStateUpdater {
|
abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider implements ExternalCalculatorStateUpdater {
|
||||||
|
|
||||||
static final String BUTTON_ID_EXTRA = "buttonId";
|
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";
|
private static final String TAG = "Calculator++ Widget";
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public enum WidgetButton {
|
|||||||
|
|
||||||
/*last column*/
|
/*last column*/
|
||||||
clear(R.id.clearButton, CalculatorSpecialButton.clear),
|
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),
|
copy(R.id.copyButton, CalculatorSpecialButton.copy),
|
||||||
paste(R.id.pasteButton, CalculatorSpecialButton.paste),
|
paste(R.id.pasteButton, CalculatorSpecialButton.paste),
|
||||||
|
|
||||||
@ -64,23 +64,43 @@ public enum WidgetButton {
|
|||||||
private final int buttonId;
|
private final int buttonId;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String text;
|
private final String onClickText;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private final String onLongClickText;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static Map<Integer, WidgetButton> buttonsByIds = new HashMap<Integer, WidgetButton>();
|
private static Map<Integer, WidgetButton> buttonsByIds = new HashMap<Integer, WidgetButton>();
|
||||||
|
|
||||||
WidgetButton(int buttonId, @NotNull CalculatorSpecialButton button) {
|
WidgetButton(int buttonId, @NotNull CalculatorSpecialButton onClickButton, @Nullable CalculatorSpecialButton onLongClickButton) {
|
||||||
this(buttonId, button.getActionCode());
|
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.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) {
|
public void onClick(@NotNull Context context) {
|
||||||
Locator.getInstance().getNotifier().showDebugMessage("Calculator++ Widget", "Button pressed: " + text);
|
Locator.getInstance().getNotifier().showDebugMessage("Calculator++ Widget", "Button pressed: " + onClickText);
|
||||||
Locator.getInstance().getKeyboard().buttonPressed(text);
|
Locator.getInstance().getKeyboard().buttonPressed(onClickText);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
Loading…
Reference in New Issue
Block a user