code reformat
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.solovyev.android.calculator.onscreen"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0"/>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.solovyev.android.calculator.onscreen"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" />
|
@@ -1,54 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.solovyev.android</groupId>
|
||||
<artifactId>calculatorpp-parent</artifactId>
|
||||
<version>1.6.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>org.solovyev.android</groupId>
|
||||
<artifactId>calculatorpp-parent</artifactId>
|
||||
<version>1.6.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.solovyev.android</groupId>
|
||||
<artifactId>calculatorpp-android-app-onscreen</artifactId>
|
||||
<version>1.6.3-SNAPSHOT</version>
|
||||
<name>Calculator++ Application Onscreen</name>
|
||||
<packaging>apklib</packaging>
|
||||
<groupId>org.solovyev.android</groupId>
|
||||
<artifactId>calculatorpp-android-app-onscreen</artifactId>
|
||||
<version>1.6.3-SNAPSHOT</version>
|
||||
<name>Calculator++ Application Onscreen</name>
|
||||
<packaging>apklib</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.solovyev.android</groupId>
|
||||
<artifactId>calculatorpp-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.solovyev.android</groupId>
|
||||
<artifactId>calculatorpp-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.solovyev.android</groupId>
|
||||
<artifactId>calculatorpp-android-app-core</artifactId>
|
||||
<type>apklib</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.solovyev.android</groupId>
|
||||
<artifactId>calculatorpp-android-app-core</artifactId>
|
||||
<type>apklib</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>android</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>android</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>support-v4</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>support-v4</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<build>
|
||||
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
|
||||
<artifactId>android-maven-plugin</artifactId>
|
||||
</extension>
|
||||
</extensions>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
|
||||
<artifactId>android-maven-plugin</artifactId>
|
||||
</extension>
|
||||
</extensions>
|
||||
|
||||
</build>
|
||||
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
@@ -6,12 +6,11 @@
|
||||
~ 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"/>
|
||||
<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" />
|
@@ -7,16 +7,16 @@
|
||||
-->
|
||||
|
||||
<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">
|
||||
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"/>
|
||||
a:id="@+id/calculator_editor"
|
||||
style="@style/cpp_onscreen_editor_style"
|
||||
a:textIsSelectable="true"
|
||||
a:hint="@string/c_calc_editor_hint" />
|
||||
|
||||
</LinearLayout>
|
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
</LinearLayout>
|
@@ -1,36 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<RelativeLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="30dp">
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="30dp">
|
||||
|
||||
<LinearLayout a:id="@+id/onscreen_header_buttons"
|
||||
a:layout_width="wrap_content"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_alignParentRight="true">
|
||||
<LinearLayout
|
||||
a:id="@+id/onscreen_header_buttons"
|
||||
a:layout_width="wrap_content"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_alignParentRight="true">
|
||||
|
||||
<ImageButton a:id="@+id/onscreen_fold_button"
|
||||
style="@style/onscreen_header_button_style"
|
||||
a:src="@drawable/cpp_onscreen_button_fold"/>
|
||||
<ImageButton
|
||||
a:id="@+id/onscreen_fold_button"
|
||||
style="@style/onscreen_header_button_style"
|
||||
a:src="@drawable/cpp_onscreen_button_fold" />
|
||||
|
||||
<ImageButton a:id="@+id/onscreen_minimize_button"
|
||||
style="@style/onscreen_header_button_style"
|
||||
a:src="@drawable/cpp_onscreen_button_minimize"/>
|
||||
<ImageButton
|
||||
a:id="@+id/onscreen_minimize_button"
|
||||
style="@style/onscreen_header_button_style"
|
||||
a:src="@drawable/cpp_onscreen_button_minimize" />
|
||||
|
||||
<ImageButton a:id="@+id/onscreen_close_button"
|
||||
style="@style/onscreen_header_button_style"
|
||||
a:src="@drawable/cpp_onscreen_button_close"/>
|
||||
<ImageButton
|
||||
a:id="@+id/onscreen_close_button"
|
||||
style="@style/onscreen_header_button_style"
|
||||
a:src="@drawable/cpp_onscreen_button_close" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<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"/>
|
||||
<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>
|
@@ -1,69 +1,89 @@
|
||||
<?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">
|
||||
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">
|
||||
<LinearLayout
|
||||
a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
|
||||
<include layout="@layout/cpp_simple_button_7"/>
|
||||
<include layout="@layout/cpp_simple_button_8"/>
|
||||
<include layout="@layout/cpp_simple_button_9"/>
|
||||
<include layout="@layout/cpp_simple_button_multiplication"/>
|
||||
<include layout="@layout/cpp_simple_button_erase"/>
|
||||
<include layout="@layout/cpp_simple_button_7" />
|
||||
|
||||
</LinearLayout>
|
||||
<include layout="@layout/cpp_simple_button_8" />
|
||||
|
||||
<LinearLayout a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
<include layout="@layout/cpp_simple_button_9" />
|
||||
|
||||
<include layout="@layout/cpp_simple_button_4"/>
|
||||
<include layout="@layout/cpp_simple_button_5"/>
|
||||
<include layout="@layout/cpp_simple_button_6"/>
|
||||
<include layout="@layout/cpp_simple_button_division"/>
|
||||
<include layout="@layout/cpp_simple_button_percent"/>
|
||||
<include layout="@layout/cpp_simple_button_multiplication" />
|
||||
|
||||
<include layout="@layout/cpp_simple_button_erase" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout a:layout_weight="1"
|
||||
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/cpp_simple_button_1"/>
|
||||
<include layout="@layout/cpp_simple_button_2"/>
|
||||
<include layout="@layout/cpp_simple_button_3"/>
|
||||
<include layout="@layout/cpp_simple_button_plus"/>
|
||||
<include layout="@layout/cpp_simple_button_power"/>
|
||||
</LinearLayout>
|
||||
<include layout="@layout/cpp_simple_button_4" />
|
||||
|
||||
<LinearLayout a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
<include layout="@layout/cpp_simple_button_5" />
|
||||
|
||||
<include layout="@layout/cpp_simple_button_round_brackets"/>
|
||||
<include layout="@layout/cpp_simple_button_0"/>
|
||||
<include layout="@layout/cpp_simple_button_dot"/>
|
||||
<include layout="@layout/cpp_simple_button_subtraction"/>
|
||||
<include layout="@layout/cpp_simple_button_app"/>
|
||||
<include layout="@layout/cpp_simple_button_6" />
|
||||
|
||||
<include layout="@layout/cpp_simple_button_division" />
|
||||
|
||||
<include layout="@layout/cpp_simple_button_percent" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
|
||||
<include layout="@layout/cpp_simple_button_1" />
|
||||
|
||||
<include layout="@layout/cpp_simple_button_2" />
|
||||
|
||||
<include layout="@layout/cpp_simple_button_3" />
|
||||
|
||||
<include layout="@layout/cpp_simple_button_plus" />
|
||||
|
||||
<include layout="@layout/cpp_simple_button_power" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
|
||||
<include layout="@layout/cpp_simple_button_round_brackets" />
|
||||
|
||||
<include layout="@layout/cpp_simple_button_0" />
|
||||
|
||||
<include layout="@layout/cpp_simple_button_dot" />
|
||||
|
||||
<include layout="@layout/cpp_simple_button_subtraction" />
|
||||
|
||||
<include layout="@layout/cpp_simple_button_app" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<!-- <LinearLayout a:layout_weight="1"
|
||||
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_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"/>
|
||||
<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>-->
|
||||
|
||||
</LinearLayout>
|
@@ -1,43 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:orientation="vertical"
|
||||
style="@style/cpp_onscreen_main_layout_style">
|
||||
a:orientation="vertical"
|
||||
style="@style/cpp_onscreen_main_layout_style">
|
||||
|
||||
<include a:id="@+id/onscreen_header" 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">
|
||||
<LinearLayout
|
||||
a:id="@+id/onscreen_content"
|
||||
a:orientation="vertical"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent">
|
||||
|
||||
<include layout="@layout/onscreen_editor"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"/>
|
||||
<include
|
||||
layout="@layout/onscreen_editor"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content" />
|
||||
|
||||
<LinearLayout a:layout_weight="1"
|
||||
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/cpp_simple_button_equals"
|
||||
a:layout_margin="@dimen/cpp_button_margin"
|
||||
a:layout_weight="1"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"/>
|
||||
<include
|
||||
layout="@layout/cpp_simple_button_equals"
|
||||
a:layout_margin="@dimen/cpp_button_margin"
|
||||
a:layout_weight="1"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent" />
|
||||
|
||||
<include layout="@layout/onscreen_display"
|
||||
a:layout_weight="4"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="wrap_content"/>
|
||||
<include
|
||||
layout="@layout/onscreen_display"
|
||||
a:layout_weight="4"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/onscreen_keyboard"
|
||||
a:layout_weight="4"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp"/>
|
||||
<include
|
||||
layout="@layout/onscreen_keyboard"
|
||||
a:layout_weight="4"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/onscreen_footer"/>
|
||||
<include layout="@layout/onscreen_footer" />
|
||||
|
||||
</LinearLayout>
|
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="cpp_onscreen_cursor_color">#ff707070</color>
|
||||
<color name="cpp_onscreen_cursor_color">#ff707070</color>
|
||||
</resources>
|
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="cpp_onscreen_main_layout_style" parent="cpp_default_main_layout_style">
|
||||
<item name="android:padding">1dp</item>
|
||||
</style>
|
||||
<style name="cpp_onscreen_main_layout_style" parent="cpp_default_main_layout_style">
|
||||
<item name="android:padding">1dp</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
@@ -9,27 +9,27 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.CalculatorPreferences;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/20/12
|
||||
* Time: 11:05 PM
|
||||
*/
|
||||
* User: serso
|
||||
* Date: 11/20/12
|
||||
* Time: 11:05 PM
|
||||
*/
|
||||
public final class CalculatorOnscreenBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
public CalculatorOnscreenBroadcastReceiver() {
|
||||
}
|
||||
public CalculatorOnscreenBroadcastReceiver() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(@NotNull Context context,
|
||||
@NotNull Intent intent) {
|
||||
if ( intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) ) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if ( CalculatorPreferences.OnscreenCalculator.startOnBoot.getPreferenceNoError(preferences) ) {
|
||||
CalculatorOnscreenService.showNotification(context);
|
||||
}
|
||||
} else {
|
||||
final Intent newIntent = new Intent(intent);
|
||||
newIntent.setClass(context, CalculatorOnscreenService.class);
|
||||
context.startService(newIntent);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onReceive(@NotNull Context context,
|
||||
@NotNull Intent intent) {
|
||||
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if (CalculatorPreferences.OnscreenCalculator.startOnBoot.getPreferenceNoError(preferences)) {
|
||||
CalculatorOnscreenService.showNotification(context);
|
||||
}
|
||||
} else {
|
||||
final Intent newIntent = new Intent(intent);
|
||||
newIntent.setClass(context, CalculatorOnscreenService.class);
|
||||
context.startService(newIntent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -27,111 +27,111 @@ import org.solovyev.android.calculator.external.ExternalCalculatorStateUpdater;
|
||||
*/
|
||||
public class CalculatorOnscreenService extends Service implements ExternalCalculatorStateUpdater, OnscreenViewListener {
|
||||
|
||||
private static final int NOTIFICATION_ID = 9031988; // my birthday =)
|
||||
private static final int NOTIFICATION_ID = 9031988; // my birthday =)
|
||||
|
||||
@NotNull
|
||||
private final ExternalCalculatorIntentHandler intentHandler = new DefaultExternalCalculatorIntentHandler(this);
|
||||
public static final Class<CalculatorOnscreenBroadcastReceiver> INTENT_LISTENER_CLASS = CalculatorOnscreenBroadcastReceiver.class;
|
||||
@NotNull
|
||||
private final ExternalCalculatorIntentHandler intentHandler = new DefaultExternalCalculatorIntentHandler(this);
|
||||
public static final Class<CalculatorOnscreenBroadcastReceiver> INTENT_LISTENER_CLASS = CalculatorOnscreenBroadcastReceiver.class;
|
||||
|
||||
@Nullable
|
||||
private static String cursorColor;
|
||||
@Nullable
|
||||
private static String cursorColor;
|
||||
|
||||
@NotNull
|
||||
private CalculatorOnscreenView view;
|
||||
@NotNull
|
||||
private CalculatorOnscreenView view;
|
||||
|
||||
private boolean compatibilityStart = true;
|
||||
|
||||
private boolean viewCreated = false;
|
||||
private boolean viewCreated = false;
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
}
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
}
|
||||
|
||||
private void createView() {
|
||||
if (!viewCreated) {
|
||||
final WindowManager wm = ((WindowManager) this.getSystemService(Context.WINDOW_SERVICE));
|
||||
private void createView() {
|
||||
if (!viewCreated) {
|
||||
final WindowManager wm = ((WindowManager) this.getSystemService(Context.WINDOW_SERVICE));
|
||||
|
||||
final DisplayMetrics dm = getResources().getDisplayMetrics();
|
||||
final DisplayMetrics dm = getResources().getDisplayMetrics();
|
||||
|
||||
int twoThirdWidth = 2 * wm.getDefaultDisplay().getWidth() / 3;
|
||||
int twoThirdHeight = 2 * wm.getDefaultDisplay().getHeight() / 3;
|
||||
int twoThirdWidth = 2 * wm.getDefaultDisplay().getWidth() / 3;
|
||||
int twoThirdHeight = 2 * wm.getDefaultDisplay().getHeight() / 3;
|
||||
|
||||
twoThirdWidth = Math.min(twoThirdWidth, twoThirdHeight);
|
||||
twoThirdHeight = Math.max(twoThirdWidth, getHeight(twoThirdWidth));
|
||||
twoThirdWidth = Math.min(twoThirdWidth, twoThirdHeight);
|
||||
twoThirdHeight = Math.max(twoThirdWidth, getHeight(twoThirdWidth));
|
||||
|
||||
final int baseWidth = Views.toPixels(dm, 300);
|
||||
final int width0 = Math.min(twoThirdWidth, baseWidth);
|
||||
final int height0 = Math.min(twoThirdHeight, getHeight(baseWidth));
|
||||
final int baseWidth = Views.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);
|
||||
final int width = Math.min(width0, height0);
|
||||
final int height = Math.max(width0, height0);
|
||||
|
||||
view = CalculatorOnscreenView.newInstance(this, CalculatorOnscreenViewState.newInstance(width, height, -1, -1), getCursorColor(this), this);
|
||||
view.show();
|
||||
view = CalculatorOnscreenView.newInstance(this, CalculatorOnscreenViewState.newInstance(width, height, -1, -1), getCursorColor(this), this);
|
||||
view.show();
|
||||
|
||||
startCalculatorListening();
|
||||
startCalculatorListening();
|
||||
|
||||
viewCreated = true;
|
||||
}
|
||||
}
|
||||
viewCreated = true;
|
||||
}
|
||||
}
|
||||
|
||||
private int getHeight(int width) {
|
||||
private int getHeight(int width) {
|
||||
return 4 * width / 3;
|
||||
}
|
||||
|
||||
private void startCalculatorListening() {
|
||||
Locator.getInstance().getExternalListenersContainer().addExternalListener(getIntentListenerClass());
|
||||
}
|
||||
Locator.getInstance().getExternalListenersContainer().addExternalListener(getIntentListenerClass());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Class<?> getIntentListenerClass() {
|
||||
return INTENT_LISTENER_CLASS;
|
||||
}
|
||||
@NotNull
|
||||
private static Class<?> getIntentListenerClass() {
|
||||
return INTENT_LISTENER_CLASS;
|
||||
}
|
||||
|
||||
private void stopCalculatorListening() {
|
||||
private void stopCalculatorListening() {
|
||||
Locator.getInstance().getExternalListenersContainer().removeExternalListener(getIntentListenerClass());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
stopCalculatorListening();
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
stopCalculatorListening();
|
||||
if (viewCreated) {
|
||||
this.view.hide();
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(@NotNull Context context, @NotNull CalculatorEditorViewState editorState, @NotNull CalculatorDisplayViewState displayState) {
|
||||
view.updateDisplayState(displayState);
|
||||
view.updateEditorState(editorState);
|
||||
}
|
||||
@Override
|
||||
public void updateState(@NotNull Context context, @NotNull CalculatorEditorViewState editorState, @NotNull CalculatorDisplayViewState displayState) {
|
||||
view.updateDisplayState(displayState);
|
||||
view.updateEditorState(editorState);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getCursorColor(@NotNull Context context) {
|
||||
if (cursorColor == null) {
|
||||
cursorColor = Integer.toHexString(context.getResources().getColor(R.color.cpp_onscreen_cursor_color)).substring(2);
|
||||
}
|
||||
return cursorColor;
|
||||
}
|
||||
@NotNull
|
||||
private static String getCursorColor(@NotNull Context context) {
|
||||
if (cursorColor == null) {
|
||||
cursorColor = Integer.toHexString(context.getResources().getColor(R.color.cpp_onscreen_cursor_color)).substring(2);
|
||||
}
|
||||
return cursorColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Intent intent, int startId) {
|
||||
super.onStart(intent, startId);
|
||||
@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) {
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
|
||||
final int result;
|
||||
try {
|
||||
@@ -143,80 +143,80 @@ public class CalculatorOnscreenService extends Service implements ExternalCalcul
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void handleStart(@Nullable Intent intent) {
|
||||
if ( intent != null ) {
|
||||
|
||||
if (isInitIntent(intent)) {
|
||||
|
||||
boolean createView = intent.getBooleanExtra(AndroidExternalListenersContainer.INIT_ACTION_CREATE_VIEW_EXTRA, false);
|
||||
if (createView) {
|
||||
hideNotification();
|
||||
createView();
|
||||
} else {
|
||||
showNotification();
|
||||
}
|
||||
}
|
||||
|
||||
if (viewCreated) {
|
||||
intentHandler.onIntent(this, intent);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInitIntent(@NotNull Intent intent) {
|
||||
return intent.getAction().equals(AndroidExternalListenersContainer.INIT_ACTION);
|
||||
}
|
||||
private void handleStart(@Nullable Intent intent) {
|
||||
if (intent != null) {
|
||||
|
||||
private void hideNotification() {
|
||||
final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.cancel(NOTIFICATION_ID);
|
||||
}
|
||||
if (isInitIntent(intent)) {
|
||||
|
||||
@Override
|
||||
public void onViewMinimized() {
|
||||
showNotification();
|
||||
stopSelf();
|
||||
}
|
||||
boolean createView = intent.getBooleanExtra(AndroidExternalListenersContainer.INIT_ACTION_CREATE_VIEW_EXTRA, false);
|
||||
if (createView) {
|
||||
hideNotification();
|
||||
createView();
|
||||
} else {
|
||||
showNotification();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewHidden() {
|
||||
stopSelf();
|
||||
}
|
||||
if (viewCreated) {
|
||||
intentHandler.onIntent(this, intent);
|
||||
}
|
||||
|
||||
private void showNotification() {
|
||||
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
|
||||
builder.setSmallIcon(R.drawable.kb_logo);
|
||||
builder.setContentTitle(getText(R.string.c_app_name));
|
||||
builder.setContentText(getString(R.string.open_onscreen_calculator));
|
||||
builder.setOngoing(true);
|
||||
}
|
||||
}
|
||||
|
||||
final Intent intent = createShowOnscreenViewIntent(this);
|
||||
builder.setContentIntent(PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
|
||||
private boolean isInitIntent(@NotNull Intent intent) {
|
||||
return intent.getAction().equals(AndroidExternalListenersContainer.INIT_ACTION);
|
||||
}
|
||||
|
||||
final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.notify(NOTIFICATION_ID, builder.getNotification());
|
||||
}
|
||||
private void hideNotification() {
|
||||
final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.cancel(NOTIFICATION_ID);
|
||||
}
|
||||
|
||||
public static void showNotification(@NotNull Context context) {
|
||||
final Intent intent = new Intent(AndroidExternalListenersContainer.INIT_ACTION);
|
||||
intent.setClass(context, getIntentListenerClass());
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
@Override
|
||||
public void onViewMinimized() {
|
||||
showNotification();
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
public static void showOnscreenView(@NotNull Context context) {
|
||||
final Intent intent = createShowOnscreenViewIntent(context);
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
@Override
|
||||
public void onViewHidden() {
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Intent createShowOnscreenViewIntent(@NotNull Context context) {
|
||||
final Intent intent = new Intent(AndroidExternalListenersContainer.INIT_ACTION);
|
||||
intent.setClass(context, getIntentListenerClass());
|
||||
intent.putExtra(AndroidExternalListenersContainer.INIT_ACTION_CREATE_VIEW_EXTRA, true);
|
||||
return intent;
|
||||
}
|
||||
private void showNotification() {
|
||||
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
|
||||
builder.setSmallIcon(R.drawable.kb_logo);
|
||||
builder.setContentTitle(getText(R.string.c_app_name));
|
||||
builder.setContentText(getString(R.string.open_onscreen_calculator));
|
||||
builder.setOngoing(true);
|
||||
|
||||
final Intent intent = createShowOnscreenViewIntent(this);
|
||||
builder.setContentIntent(PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
|
||||
|
||||
final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.notify(NOTIFICATION_ID, builder.getNotification());
|
||||
}
|
||||
|
||||
public static void showNotification(@NotNull Context context) {
|
||||
final Intent intent = new Intent(AndroidExternalListenersContainer.INIT_ACTION);
|
||||
intent.setClass(context, getIntentListenerClass());
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
public static void showOnscreenView(@NotNull Context context) {
|
||||
final Intent intent = createShowOnscreenViewIntent(context);
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Intent createShowOnscreenViewIntent(@NotNull Context context) {
|
||||
final Intent intent = new Intent(AndroidExternalListenersContainer.INIT_ACTION);
|
||||
intent.setClass(context, getIntentListenerClass());
|
||||
intent.putExtra(AndroidExternalListenersContainer.INIT_ACTION_CREATE_VIEW_EXTRA, true);
|
||||
return intent;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -22,16 +22,16 @@ public class CalculatorOnscreenStartActivity extends Activity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (Android.isComponentEnabled(this, CalculatorOnscreenStartActivity.class)) {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if (Android.isComponentEnabled(this, CalculatorOnscreenStartActivity.class)) {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
if (!CalculatorPreferences.OnscreenCalculator.removeIconDialogShown.getPreference(prefs)) {
|
||||
FixableMessagesDialog.showDialog(Arrays.asList(new FixableMessage(getString(R.string.cpp_onscreen_remove_icon_message), MessageType.warning, new RemoveIconFixableError(this))), this, false);
|
||||
CalculatorPreferences.OnscreenCalculator.removeIconDialogShown.putPreference(prefs, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CalculatorOnscreenService.showOnscreenView(this);
|
||||
CalculatorOnscreenService.showOnscreenView(this);
|
||||
|
||||
this.finish();
|
||||
}
|
||||
|
@@ -13,11 +13,7 @@ import android.view.WindowManager;
|
||||
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.CalculatorButton;
|
||||
import org.solovyev.android.calculator.CalculatorDisplayViewState;
|
||||
import org.solovyev.android.calculator.CalculatorEditorViewState;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.prefs.Preference;
|
||||
|
||||
/**
|
||||
@@ -26,39 +22,39 @@ import org.solovyev.android.prefs.Preference;
|
||||
* Time: 9:03 PM
|
||||
*/
|
||||
public class CalculatorOnscreenView {
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTANTS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTANTS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private static final String TAG = CalculatorOnscreenView.class.getSimpleName();
|
||||
private static final String TAG = CalculatorOnscreenView.class.getSimpleName();
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private static final Preference<CalculatorOnscreenViewState> viewStatePreference = new CalculatorOnscreenViewState.Preference("onscreen_view_state", CalculatorOnscreenViewState.newDefaultState());
|
||||
private static final Preference<CalculatorOnscreenViewState> viewStatePreference = new CalculatorOnscreenViewState.Preference("onscreen_view_state", CalculatorOnscreenViewState.newDefaultState());
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@NotNull
|
||||
private View root;
|
||||
@NotNull
|
||||
private View root;
|
||||
|
||||
@NotNull
|
||||
private View content;
|
||||
@NotNull
|
||||
private View content;
|
||||
|
||||
@NotNull
|
||||
private View header;
|
||||
@@ -70,133 +66,133 @@ public class CalculatorOnscreenView {
|
||||
private AndroidCalculatorDisplayView displayView;
|
||||
|
||||
@NotNull
|
||||
private Context context;
|
||||
private Context context;
|
||||
|
||||
@NotNull
|
||||
private CalculatorOnscreenViewState state = CalculatorOnscreenViewState.newDefaultState();
|
||||
@NotNull
|
||||
private CalculatorOnscreenViewState state = CalculatorOnscreenViewState.newDefaultState();
|
||||
|
||||
@NotNull
|
||||
private String cursorColor;
|
||||
@NotNull
|
||||
private String cursorColor;
|
||||
|
||||
@Nullable
|
||||
private OnscreenViewListener viewListener;
|
||||
@Nullable
|
||||
private OnscreenViewListener viewListener;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATES
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATES
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private boolean minimized = false;
|
||||
private boolean minimized = false;
|
||||
|
||||
private boolean attached = false;
|
||||
private boolean attached = false;
|
||||
|
||||
private boolean folded = false;
|
||||
private boolean folded = false;
|
||||
|
||||
private boolean initialized = false;
|
||||
private boolean initialized = false;
|
||||
|
||||
private boolean hidden = true;
|
||||
private boolean hidden = true;
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTRUCTORS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTRUCTORS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private CalculatorOnscreenView() {
|
||||
}
|
||||
private CalculatorOnscreenView() {
|
||||
}
|
||||
|
||||
public static CalculatorOnscreenView newInstance(@NotNull Context context,
|
||||
@NotNull CalculatorOnscreenViewState state,
|
||||
@NotNull String cursorColor,
|
||||
@Nullable OnscreenViewListener viewListener) {
|
||||
final CalculatorOnscreenView result = new CalculatorOnscreenView();
|
||||
public static CalculatorOnscreenView newInstance(@NotNull Context context,
|
||||
@NotNull CalculatorOnscreenViewState state,
|
||||
@NotNull String cursorColor,
|
||||
@Nullable OnscreenViewListener viewListener) {
|
||||
final CalculatorOnscreenView result = new CalculatorOnscreenView();
|
||||
|
||||
result.root = View.inflate(context, R.layout.onscreen_layout, null);
|
||||
result.context = context;
|
||||
result.cursorColor = cursorColor;
|
||||
result.viewListener = viewListener;
|
||||
result.root = View.inflate(context, R.layout.onscreen_layout, null);
|
||||
result.context = context;
|
||||
result.cursorColor = cursorColor;
|
||||
result.viewListener = viewListener;
|
||||
|
||||
final CalculatorOnscreenViewState persistedState = readState(context);
|
||||
if (persistedState != null) {
|
||||
result.state = persistedState;
|
||||
} else {
|
||||
result.state = state;
|
||||
}
|
||||
final CalculatorOnscreenViewState persistedState = readState(context);
|
||||
if (persistedState != null) {
|
||||
result.state = persistedState;
|
||||
} else {
|
||||
result.state = state;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* METHODS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* METHODS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
public void updateDisplayState(@NotNull CalculatorDisplayViewState displayState) {
|
||||
checkInit();
|
||||
public void updateDisplayState(@NotNull CalculatorDisplayViewState displayState) {
|
||||
checkInit();
|
||||
displayView.setState(displayState);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateEditorState(@NotNull CalculatorEditorViewState editorState) {
|
||||
checkInit();
|
||||
public void updateEditorState(@NotNull CalculatorEditorViewState editorState) {
|
||||
checkInit();
|
||||
editorView.setState(editorState);
|
||||
}
|
||||
}
|
||||
|
||||
private void setHeight(int height) {
|
||||
checkInit();
|
||||
private void setHeight(int height) {
|
||||
checkInit();
|
||||
|
||||
final WindowManager.LayoutParams params = (WindowManager.LayoutParams) root.getLayoutParams();
|
||||
final WindowManager.LayoutParams params = (WindowManager.LayoutParams) root.getLayoutParams();
|
||||
|
||||
params.height = height;
|
||||
params.height = height;
|
||||
|
||||
getWindowManager().updateViewLayout(root, params);
|
||||
}
|
||||
getWindowManager().updateViewLayout(root, params);
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* LIFECYCLE
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* LIFECYCLE
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private void init() {
|
||||
private void init() {
|
||||
|
||||
if (!initialized) {
|
||||
for (final CalculatorButton widgetButton : CalculatorButton.values()) {
|
||||
final View button = root.findViewById(widgetButton.getButtonId());
|
||||
if (button != null) {
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!initialized) {
|
||||
for (final CalculatorButton widgetButton : CalculatorButton.values()) {
|
||||
final View button = root.findViewById(widgetButton.getButtonId());
|
||||
if (button != null) {
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
widgetButton.onClick(context);
|
||||
if ( widgetButton == CalculatorButton.app ) {
|
||||
if (widgetButton == CalculatorButton.app) {
|
||||
minimize();
|
||||
}
|
||||
}
|
||||
});
|
||||
button.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
}
|
||||
});
|
||||
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);
|
||||
@@ -204,320 +200,320 @@ public class CalculatorOnscreenView {
|
||||
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
|
||||
public void onClick(View v) {
|
||||
if (folded) {
|
||||
unfold();
|
||||
} else {
|
||||
fold();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
final View onscreenHideButton = root.findViewById(R.id.onscreen_minimize_button);
|
||||
onscreenHideButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
minimize();
|
||||
}
|
||||
});
|
||||
|
||||
root.findViewById(R.id.onscreen_close_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
hide();
|
||||
}
|
||||
});
|
||||
|
||||
final ImageView onscreenTitleImageView = (ImageView) root.findViewById(R.id.onscreen_title);
|
||||
onscreenTitleImageView.setOnTouchListener(new WindowDragTouchListener(wm, root));
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkInit() {
|
||||
if (!initialized) {
|
||||
throw new IllegalStateException("init() must be called!");
|
||||
}
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (hidden) {
|
||||
init();
|
||||
attach();
|
||||
|
||||
hidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void attach() {
|
||||
checkInit();
|
||||
|
||||
final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
if (!attached) {
|
||||
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
|
||||
state.getWidth(),
|
||||
state.getHeight(),
|
||||
state.getX(),
|
||||
state.getY(),
|
||||
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
|
||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
|
||||
PixelFormat.TRANSLUCENT);
|
||||
|
||||
params.gravity = Gravity.TOP | Gravity.LEFT;
|
||||
|
||||
wm.addView(root, params);
|
||||
attached = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void fold() {
|
||||
if (!folded) {
|
||||
int newHeight = header.getHeight();
|
||||
content.setVisibility(View.GONE);
|
||||
setHeight(newHeight);
|
||||
folded = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void unfold() {
|
||||
if (folded) {
|
||||
content.setVisibility(View.VISIBLE);
|
||||
setHeight(state.getHeight());
|
||||
folded = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void detach() {
|
||||
checkInit();
|
||||
|
||||
if (attached) {
|
||||
getWindowManager().removeView(root);
|
||||
attached = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void minimize() {
|
||||
checkInit();
|
||||
if (!minimized) {
|
||||
persistState(context, getCurrentState(!folded));
|
||||
|
||||
detach();
|
||||
|
||||
if (viewListener != null) {
|
||||
viewListener.onViewMinimized();
|
||||
}
|
||||
|
||||
minimized = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void persistState(@NotNull Context context, @NotNull CalculatorOnscreenViewState state) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
viewStatePreference.putPreference(preferences, state);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CalculatorOnscreenViewState readState(@NotNull Context context) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if (viewStatePreference.isSet(preferences)) {
|
||||
return viewStatePreference.getPreference(preferences);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
checkInit();
|
||||
|
||||
if (!hidden) {
|
||||
|
||||
persistState(context, getCurrentState(!folded));
|
||||
|
||||
detach();
|
||||
|
||||
if (viewListener != null) {
|
||||
viewListener.onViewHidden();
|
||||
}
|
||||
|
||||
hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private WindowManager getWindowManager() {
|
||||
return ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CalculatorOnscreenViewState getCurrentState(boolean useRealSize) {
|
||||
final WindowManager.LayoutParams params = (WindowManager.LayoutParams) root.getLayoutParams();
|
||||
if (useRealSize) {
|
||||
return CalculatorOnscreenViewState.newInstance(params.width, params.height, params.x, params.y);
|
||||
} else {
|
||||
return CalculatorOnscreenViewState.newInstance(state.getWidth(), state.getHeight(), params.x, params.y);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private static class WindowDragTouchListener implements View.OnTouchListener {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTANTS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private static final float DIST_EPS = 0f;
|
||||
private static final float DIST_MAX = 100000f;
|
||||
private static final long TIME_EPS = 0L;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@NotNull
|
||||
private final WindowManager wm;
|
||||
|
||||
private int orientation;
|
||||
|
||||
private float x0;
|
||||
|
||||
private float y0;
|
||||
|
||||
private long time = 0;
|
||||
|
||||
@NotNull
|
||||
private final View view;
|
||||
|
||||
private int displayWidth;
|
||||
|
||||
private int displayHeight;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTRUCTORS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
public WindowDragTouchListener(@NotNull WindowManager wm,
|
||||
@NotNull View view) {
|
||||
this.wm = wm;
|
||||
this.view = view;
|
||||
initDisplayParams();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (orientation != this.wm.getDefaultDisplay().getOrientation()) {
|
||||
// orientation has changed => we need to check display width/height each time window moved
|
||||
initDisplayParams();
|
||||
}
|
||||
|
||||
//Log.d(TAG, "Action: " + event.getAction());
|
||||
|
||||
final float x1 = event.getRawX();
|
||||
final float y1 = event.getRawY();
|
||||
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
Log.d(TAG, "0:" + toString(x0, y0) + ", 1: " + toString(x1, y1));
|
||||
x0 = x1;
|
||||
y0 = y1;
|
||||
return true;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
final long currentTime = System.currentTimeMillis();
|
||||
|
||||
if ( currentTime - time >= TIME_EPS ) {
|
||||
time = currentTime;
|
||||
processMove(x1, y1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void initDisplayParams() {
|
||||
this.orientation = this.wm.getDefaultDisplay().getOrientation();
|
||||
|
||||
final DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
wm.getDefaultDisplay().getMetrics(displayMetrics);
|
||||
|
||||
this.displayWidth = displayMetrics.widthPixels;
|
||||
this.displayHeight = displayMetrics.heightPixels;
|
||||
}
|
||||
|
||||
private void processMove(float x1, float y1) {
|
||||
final float Δx = x1 - x0;
|
||||
final float Δy = y1 - y0;
|
||||
|
||||
final WindowManager.LayoutParams params = (WindowManager.LayoutParams) view.getLayoutParams();
|
||||
Log.d(TAG, "0:" + toString(x0, y0) + ", 1: " + toString(x1, y1) + ", Δ: " + toString(Δx, Δy) + ", params: " + toString(params.x, params.y));
|
||||
|
||||
boolean xInBounds = isDistanceInBounds(Δx);
|
||||
boolean yInBounds = isDistanceInBounds(Δy);
|
||||
if (xInBounds || yInBounds) {
|
||||
|
||||
if (xInBounds) {
|
||||
params.x = (int) (params.x + Δx);
|
||||
}
|
||||
|
||||
if (yInBounds) {
|
||||
params.y = (int) (params.y + Δy);
|
||||
}
|
||||
|
||||
params.x = Math.min(Math.max(params.x, 0), displayWidth - params.width);
|
||||
params.y = Math.min(Math.max(params.y, 0), displayHeight - params.height);
|
||||
final View onscreenFoldButton = root.findViewById(R.id.onscreen_fold_button);
|
||||
onscreenFoldButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (folded) {
|
||||
unfold();
|
||||
} else {
|
||||
fold();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
final View onscreenHideButton = root.findViewById(R.id.onscreen_minimize_button);
|
||||
onscreenHideButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
minimize();
|
||||
}
|
||||
});
|
||||
|
||||
root.findViewById(R.id.onscreen_close_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
hide();
|
||||
}
|
||||
});
|
||||
|
||||
final ImageView onscreenTitleImageView = (ImageView) root.findViewById(R.id.onscreen_title);
|
||||
onscreenTitleImageView.setOnTouchListener(new WindowDragTouchListener(wm, root));
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkInit() {
|
||||
if (!initialized) {
|
||||
throw new IllegalStateException("init() must be called!");
|
||||
}
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (hidden) {
|
||||
init();
|
||||
attach();
|
||||
|
||||
hidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void attach() {
|
||||
checkInit();
|
||||
|
||||
final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
if (!attached) {
|
||||
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
|
||||
state.getWidth(),
|
||||
state.getHeight(),
|
||||
state.getX(),
|
||||
state.getY(),
|
||||
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
|
||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
|
||||
PixelFormat.TRANSLUCENT);
|
||||
|
||||
params.gravity = Gravity.TOP | Gravity.LEFT;
|
||||
|
||||
wm.addView(root, params);
|
||||
attached = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void fold() {
|
||||
if (!folded) {
|
||||
int newHeight = header.getHeight();
|
||||
content.setVisibility(View.GONE);
|
||||
setHeight(newHeight);
|
||||
folded = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void unfold() {
|
||||
if (folded) {
|
||||
content.setVisibility(View.VISIBLE);
|
||||
setHeight(state.getHeight());
|
||||
folded = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void detach() {
|
||||
checkInit();
|
||||
|
||||
if (attached) {
|
||||
getWindowManager().removeView(root);
|
||||
attached = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void minimize() {
|
||||
checkInit();
|
||||
if (!minimized) {
|
||||
persistState(context, getCurrentState(!folded));
|
||||
|
||||
detach();
|
||||
|
||||
if (viewListener != null) {
|
||||
viewListener.onViewMinimized();
|
||||
}
|
||||
|
||||
minimized = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void persistState(@NotNull Context context, @NotNull CalculatorOnscreenViewState state) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
viewStatePreference.putPreference(preferences, state);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CalculatorOnscreenViewState readState(@NotNull Context context) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if (viewStatePreference.isSet(preferences)) {
|
||||
return viewStatePreference.getPreference(preferences);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
checkInit();
|
||||
|
||||
if (!hidden) {
|
||||
|
||||
persistState(context, getCurrentState(!folded));
|
||||
|
||||
detach();
|
||||
|
||||
if (viewListener != null) {
|
||||
viewListener.onViewHidden();
|
||||
}
|
||||
|
||||
hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private WindowManager getWindowManager() {
|
||||
return ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CalculatorOnscreenViewState getCurrentState(boolean useRealSize) {
|
||||
final WindowManager.LayoutParams params = (WindowManager.LayoutParams) root.getLayoutParams();
|
||||
if (useRealSize) {
|
||||
return CalculatorOnscreenViewState.newInstance(params.width, params.height, params.x, params.y);
|
||||
} else {
|
||||
return CalculatorOnscreenViewState.newInstance(state.getWidth(), state.getHeight(), params.x, params.y);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private static class WindowDragTouchListener implements View.OnTouchListener {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTANTS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private static final float DIST_EPS = 0f;
|
||||
private static final float DIST_MAX = 100000f;
|
||||
private static final long TIME_EPS = 0L;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@NotNull
|
||||
private final WindowManager wm;
|
||||
|
||||
private int orientation;
|
||||
|
||||
private float x0;
|
||||
|
||||
private float y0;
|
||||
|
||||
private long time = 0;
|
||||
|
||||
@NotNull
|
||||
private final View view;
|
||||
|
||||
private int displayWidth;
|
||||
|
||||
private int displayHeight;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTRUCTORS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
public WindowDragTouchListener(@NotNull WindowManager wm,
|
||||
@NotNull View view) {
|
||||
this.wm = wm;
|
||||
this.view = view;
|
||||
initDisplayParams();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (orientation != this.wm.getDefaultDisplay().getOrientation()) {
|
||||
// orientation has changed => we need to check display width/height each time window moved
|
||||
initDisplayParams();
|
||||
}
|
||||
|
||||
//Log.d(TAG, "Action: " + event.getAction());
|
||||
|
||||
final float x1 = event.getRawX();
|
||||
final float y1 = event.getRawY();
|
||||
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
Log.d(TAG, "0:" + toString(x0, y0) + ", 1: " + toString(x1, y1));
|
||||
x0 = x1;
|
||||
y0 = y1;
|
||||
return true;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
final long currentTime = System.currentTimeMillis();
|
||||
|
||||
if (currentTime - time >= TIME_EPS) {
|
||||
time = currentTime;
|
||||
processMove(x1, y1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void initDisplayParams() {
|
||||
this.orientation = this.wm.getDefaultDisplay().getOrientation();
|
||||
|
||||
final DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
wm.getDefaultDisplay().getMetrics(displayMetrics);
|
||||
|
||||
this.displayWidth = displayMetrics.widthPixels;
|
||||
this.displayHeight = displayMetrics.heightPixels;
|
||||
}
|
||||
|
||||
private void processMove(float x1, float y1) {
|
||||
final float Δx = x1 - x0;
|
||||
final float Δy = y1 - y0;
|
||||
|
||||
final WindowManager.LayoutParams params = (WindowManager.LayoutParams) view.getLayoutParams();
|
||||
Log.d(TAG, "0:" + toString(x0, y0) + ", 1: " + toString(x1, y1) + ", Δ: " + toString(Δx, Δy) + ", params: " + toString(params.x, params.y));
|
||||
|
||||
boolean xInBounds = isDistanceInBounds(Δx);
|
||||
boolean yInBounds = isDistanceInBounds(Δy);
|
||||
if (xInBounds || yInBounds) {
|
||||
|
||||
if (xInBounds) {
|
||||
params.x = (int) (params.x + Δx);
|
||||
}
|
||||
|
||||
if (yInBounds) {
|
||||
params.y = (int) (params.y + Δy);
|
||||
}
|
||||
|
||||
params.x = Math.min(Math.max(params.x, 0), displayWidth - params.width);
|
||||
params.y = Math.min(Math.max(params.y, 0), displayHeight - params.height);
|
||||
|
||||
wm.updateViewLayout(view, params);
|
||||
wm.updateViewLayout(view, params);
|
||||
|
||||
if (xInBounds) {
|
||||
x0 = x1;
|
||||
}
|
||||
if (xInBounds) {
|
||||
x0 = x1;
|
||||
}
|
||||
|
||||
if (yInBounds) {
|
||||
y0 = y1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDistanceInBounds(float δx) {
|
||||
δx = Math.abs(δx);
|
||||
return δx >= DIST_EPS && δx < DIST_MAX;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String toString(float x, float y) {
|
||||
return "(" + formatFloat(x) + ", " + formatFloat(y) + ")";
|
||||
}
|
||||
|
||||
private static String formatFloat(float value) {
|
||||
if (value >= 0) {
|
||||
return "+" + String.format("%.2f", value);
|
||||
} else {
|
||||
return String.format("%.2f", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (yInBounds) {
|
||||
y0 = y1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDistanceInBounds(float δx) {
|
||||
δx = Math.abs(δx);
|
||||
return δx >= DIST_EPS && δx < DIST_MAX;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String toString(float x, float y) {
|
||||
return "(" + formatFloat(x) + ", " + formatFloat(y) + ")";
|
||||
}
|
||||
|
||||
private static String formatFloat(float value) {
|
||||
if (value >= 0) {
|
||||
return "+" + String.format("%.2f", value);
|
||||
} else {
|
||||
return String.format("%.2f", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -20,147 +20,147 @@ import java.util.Map;
|
||||
*/
|
||||
public class CalculatorOnscreenViewState implements Parcelable {
|
||||
|
||||
private static final String TAG = CalculatorOnscreenViewState.class.getSimpleName();
|
||||
private static final String TAG = CalculatorOnscreenViewState.class.getSimpleName();
|
||||
|
||||
public static final Parcelable.Creator<CalculatorOnscreenViewState> CREATOR = new Parcelable.Creator<CalculatorOnscreenViewState>() {
|
||||
public CalculatorOnscreenViewState createFromParcel(@NotNull Parcel in) {
|
||||
return CalculatorOnscreenViewState.fromParcel(in);
|
||||
}
|
||||
public static final Parcelable.Creator<CalculatorOnscreenViewState> CREATOR = new Parcelable.Creator<CalculatorOnscreenViewState>() {
|
||||
public CalculatorOnscreenViewState createFromParcel(@NotNull Parcel in) {
|
||||
return CalculatorOnscreenViewState.fromParcel(in);
|
||||
}
|
||||
|
||||
public CalculatorOnscreenViewState[] newArray(int size) {
|
||||
return new CalculatorOnscreenViewState[size];
|
||||
}
|
||||
};
|
||||
public CalculatorOnscreenViewState[] newArray(int size) {
|
||||
return new CalculatorOnscreenViewState[size];
|
||||
}
|
||||
};
|
||||
|
||||
private int width;
|
||||
private int width;
|
||||
|
||||
private int height;
|
||||
private int height;
|
||||
|
||||
private int x;
|
||||
private int x;
|
||||
|
||||
private int y;
|
||||
private int y;
|
||||
|
||||
private CalculatorOnscreenViewState() {
|
||||
}
|
||||
private CalculatorOnscreenViewState() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static CalculatorOnscreenViewState fromParcel(@NotNull Parcel in) {
|
||||
final CalculatorOnscreenViewState result = new CalculatorOnscreenViewState();
|
||||
result.width = in.readInt();
|
||||
result.height = in.readInt();
|
||||
result.x = in.readInt();
|
||||
result.y = in.readInt();
|
||||
return result;
|
||||
}
|
||||
@NotNull
|
||||
private static CalculatorOnscreenViewState fromParcel(@NotNull Parcel in) {
|
||||
final CalculatorOnscreenViewState result = new CalculatorOnscreenViewState();
|
||||
result.width = in.readInt();
|
||||
result.height = in.readInt();
|
||||
result.x = in.readInt();
|
||||
result.y = in.readInt();
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CalculatorOnscreenViewState newDefaultState() {
|
||||
return newInstance(200, 400, 0, 0);
|
||||
}
|
||||
@NotNull
|
||||
public static CalculatorOnscreenViewState newDefaultState() {
|
||||
return newInstance(200, 400, 0, 0);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CalculatorOnscreenViewState newInstance(int width, int height, int x, int y) {
|
||||
final CalculatorOnscreenViewState result = new CalculatorOnscreenViewState();
|
||||
result.width = width;
|
||||
result.height = height;
|
||||
result.x = x;
|
||||
result.y = y;
|
||||
return result;
|
||||
}
|
||||
@NotNull
|
||||
public static CalculatorOnscreenViewState newInstance(int width, int height, int x, int y) {
|
||||
final CalculatorOnscreenViewState result = new CalculatorOnscreenViewState();
|
||||
result.width = width;
|
||||
result.height = height;
|
||||
result.x = x;
|
||||
result.y = y;
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(@NotNull Parcel out, int flags) {
|
||||
out.writeInt(width);
|
||||
out.writeInt(height);
|
||||
out.writeInt(x);
|
||||
out.writeInt(y);
|
||||
}
|
||||
@Override
|
||||
public void writeToParcel(@NotNull Parcel out, int flags) {
|
||||
out.writeInt(width);
|
||||
out.writeInt(height);
|
||||
out.writeInt(x);
|
||||
out.writeInt(y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CalculatorOnscreenViewState{" +
|
||||
"y=" + y +
|
||||
", x=" + x +
|
||||
", height=" + height +
|
||||
", width=" + width +
|
||||
'}';
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CalculatorOnscreenViewState{" +
|
||||
"y=" + y +
|
||||
", x=" + x +
|
||||
", height=" + height +
|
||||
", width=" + width +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class Preference extends AbstractPreference<CalculatorOnscreenViewState> {
|
||||
public static class Preference extends AbstractPreference<CalculatorOnscreenViewState> {
|
||||
|
||||
public Preference(@NotNull String key, @Nullable CalculatorOnscreenViewState defaultValue) {
|
||||
super(key, defaultValue);
|
||||
}
|
||||
public Preference(@NotNull String key, @Nullable CalculatorOnscreenViewState defaultValue) {
|
||||
super(key, defaultValue);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected CalculatorOnscreenViewState getPersistedValue(@NotNull SharedPreferences preferences) {
|
||||
try {
|
||||
final CalculatorOnscreenViewState result = new CalculatorOnscreenViewState();
|
||||
final JSONObject jsonObject = new JSONObject(preferences.getString(getKey(), "{}"));
|
||||
result.width = jsonObject.getInt("width");
|
||||
result.height = jsonObject.getInt("height");
|
||||
result.x = jsonObject.getInt("x");
|
||||
result.y = jsonObject.getInt("y");
|
||||
@Nullable
|
||||
@Override
|
||||
protected CalculatorOnscreenViewState getPersistedValue(@NotNull SharedPreferences preferences) {
|
||||
try {
|
||||
final CalculatorOnscreenViewState result = new CalculatorOnscreenViewState();
|
||||
final JSONObject jsonObject = new JSONObject(preferences.getString(getKey(), "{}"));
|
||||
result.width = jsonObject.getInt("width");
|
||||
result.height = jsonObject.getInt("height");
|
||||
result.x = jsonObject.getInt("x");
|
||||
result.y = jsonObject.getInt("y");
|
||||
|
||||
Log.d(TAG, "Reading onscreen view state: " + result);
|
||||
Log.d(TAG, "Reading onscreen view state: " + result);
|
||||
|
||||
return result;
|
||||
} catch (JSONException e) {
|
||||
return getDefaultValue();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (JSONException e) {
|
||||
return getDefaultValue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void putPersistedValue(@NotNull SharedPreferences.Editor editor, @NotNull CalculatorOnscreenViewState value) {
|
||||
final Map<String, Object> properties = new HashMap<String, Object>();
|
||||
properties.put("width", value.getWidth());
|
||||
properties.put("height", value.getHeight());
|
||||
properties.put("x", value.getX());
|
||||
properties.put("y", value.getY());
|
||||
@Override
|
||||
protected void putPersistedValue(@NotNull SharedPreferences.Editor editor, @NotNull CalculatorOnscreenViewState value) {
|
||||
final Map<String, Object> properties = new HashMap<String, Object>();
|
||||
properties.put("width", value.getWidth());
|
||||
properties.put("height", value.getHeight());
|
||||
properties.put("x", value.getX());
|
||||
properties.put("y", value.getY());
|
||||
|
||||
final JSONObject jsonObject = new JSONObject(properties);
|
||||
final JSONObject jsonObject = new JSONObject(properties);
|
||||
|
||||
final String json = jsonObject.toString();
|
||||
Log.d(TAG, "Persisting onscreen view state: " + json);
|
||||
editor.putString(getKey(), json);
|
||||
}
|
||||
}
|
||||
final String json = jsonObject.toString();
|
||||
Log.d(TAG, "Persisting onscreen view state: " + json);
|
||||
editor.putString(getKey(), json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,9 +7,9 @@ package org.solovyev.android.calculator.onscreen;
|
||||
*/
|
||||
public interface OnscreenViewListener {
|
||||
|
||||
// view minimized == view is in the action bar
|
||||
void onViewMinimized();
|
||||
// view minimized == view is in the action bar
|
||||
void onViewMinimized();
|
||||
|
||||
// view hidden == view closed
|
||||
void onViewHidden();
|
||||
// view hidden == view closed
|
||||
void onViewHidden();
|
||||
}
|
||||
|
Reference in New Issue
Block a user