Code reformatted

This commit is contained in:
serso 2016-01-04 12:39:25 +01:00
parent 11bdcae2a8
commit 4eeeb1277e
794 changed files with 35363 additions and 35284 deletions

View File

@ -28,11 +28,11 @@ import org.solovyev.android.calculator.units.CalculatorNumeralBase;
import org.solovyev.common.units.Unit; import org.solovyev.common.units.Unit;
import org.solovyev.common.units.UnitConverter; import org.solovyev.common.units.UnitConverter;
import javax.annotation.Nonnull;
import java.util.Date; import java.util.Date;
import java.util.Random; import java.util.Random;
import javax.annotation.Nonnull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**

View File

@ -4,6 +4,7 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import org.hamcrest.BaseMatcher; import org.hamcrest.BaseMatcher;
import org.hamcrest.Description; import org.hamcrest.Description;
import org.junit.Before; import org.junit.Before;
@ -21,7 +22,9 @@ import static org.mockito.Mockito.verify;
import static org.robolectric.Robolectric.application; import static org.robolectric.Robolectric.application;
import static org.solovyev.android.calculator.CalculatorBroadcaster.ACTION_DISPLAY_STATE_CHANGED; import static org.solovyev.android.calculator.CalculatorBroadcaster.ACTION_DISPLAY_STATE_CHANGED;
import static org.solovyev.android.calculator.CalculatorBroadcaster.ACTION_EDITOR_STATE_CHANGED; import static org.solovyev.android.calculator.CalculatorBroadcaster.ACTION_EDITOR_STATE_CHANGED;
import static org.solovyev.android.calculator.CalculatorEventType.*; import static org.solovyev.android.calculator.CalculatorEventType.display_state_changed;
import static org.solovyev.android.calculator.CalculatorEventType.editor_state_changed;
import static org.solovyev.android.calculator.CalculatorEventType.editor_state_changed_light;
@Config(manifest = Config.NONE) @Config(manifest = Config.NONE)
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)

View File

@ -1,16 +1,21 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.content.Intent; import android.content.Intent;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.robolectric.Robolectric.application; import static org.robolectric.Robolectric.application;
import static org.solovyev.android.calculator.CalculatorButton.four; import static org.solovyev.android.calculator.CalculatorButton.four;
import static org.solovyev.android.calculator.CalculatorReceiver.*; import static org.solovyev.android.calculator.CalculatorReceiver.ACTION_BUTTON_ID_EXTRA;
import static org.solovyev.android.calculator.CalculatorReceiver.ACTION_BUTTON_PRESSED;
import static org.solovyev.android.calculator.CalculatorReceiver.newButtonClickedIntent;
@Config(manifest = Config.NONE) @Config(manifest = Config.NONE)
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)

View File

@ -23,7 +23,6 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.content.Context; import android.content.Context;
import jscl.JsclMathEngine;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.solovyev.android.calculator.history.CalculatorHistory; import org.solovyev.android.calculator.history.CalculatorHistory;
@ -32,6 +31,8 @@ import org.solovyev.android.calculator.plot.CalculatorPlotter;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import jscl.JsclMathEngine;
/** /**
* User: serso * User: serso
* Date: 10/7/12 * Date: 10/7/12

View File

@ -23,8 +23,6 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.graphics.Color; import android.graphics.Color;
import jscl.MathEngine;
import jscl.NumeralBase;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -34,6 +32,9 @@ import org.solovyev.android.calculator.view.TextHighlighter;
import java.util.Date; import java.util.Date;
import java.util.Random; import java.util.Random;
import jscl.MathEngine;
import jscl.NumeralBase;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;

View File

@ -47,15 +47,9 @@ import static org.junit.Assert.assertEquals;
*/ */
public class HistoryUtilsTest { public class HistoryUtilsTest {
@Test
public void testFromXml() throws Exception {
}
private static final String emptyHistory = "<history>\n" + private static final String emptyHistory = "<history>\n" +
" <historyItems class=\"java.util.ArrayList\"/>\n" + " <historyItems class=\"java.util.ArrayList\"/>\n" +
"</history>"; "</history>";
private static final String toXml1 = "<history>\n" + private static final String toXml1 = "<history>\n" +
" <historyItems class=\"java.util.ArrayList\">\n" + " <historyItems class=\"java.util.ArrayList\">\n" +
" <calculatorHistoryState>\n" + " <calculatorHistoryState>\n" +
@ -74,7 +68,6 @@ public class HistoryUtilsTest {
" </calculatorHistoryState>\n" + " </calculatorHistoryState>\n" +
" </historyItems>\n" + " </historyItems>\n" +
"</history>"; "</history>";
private static final String toXml2 = "<history>\n" + private static final String toXml2 = "<history>\n" +
" <historyItems class=\"java.util.ArrayList\">\n" + " <historyItems class=\"java.util.ArrayList\">\n" +
" <calculatorHistoryState>\n" + " <calculatorHistoryState>\n" +
@ -136,6 +129,11 @@ public class HistoryUtilsTest {
" </historyItems>\n" + " </historyItems>\n" +
"</history>"; "</history>";
@Test
public void testFromXml() throws Exception {
}
@Test @Test
public void testToXml() throws Exception { public void testToXml() throws Exception {
final Date date = new Date(100000000); final Date date = new Date(100000000);

View File

@ -22,14 +22,14 @@
package org.solovyev.android.calculator.model; package org.solovyev.android.calculator.model;
import jscl.math.function.IConstant;
import org.junit.Test; import org.junit.Test;
import org.simpleframework.xml.Serializer; import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister; import org.simpleframework.xml.core.Persister;
import java.io.StringWriter; import java.io.StringWriter;
import jscl.math.function.IConstant;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
/** /**

View File

@ -1,6 +1,7 @@
package org.solovyev.android.calculator.view; package org.solovyev.android.calculator.view;
import android.app.Activity; import android.app.Activity;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -12,8 +13,14 @@ import org.robolectric.shadows.ShadowActivity;
import java.util.ArrayList; import java.util.ArrayList;
import static jscl.AngleUnit.*; import static jscl.AngleUnit.deg;
import static org.junit.Assert.*; import static jscl.AngleUnit.grad;
import static jscl.AngleUnit.rad;
import static jscl.AngleUnit.turns;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp; import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp;

View File

@ -1,6 +1,7 @@
package org.solovyev.android.calculator.view; package org.solovyev.android.calculator.view;
import android.app.Activity; import android.app.Activity;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -12,8 +13,14 @@ import org.robolectric.shadows.ShadowActivity;
import java.util.ArrayList; import java.util.ArrayList;
import static jscl.NumeralBase.*; import static jscl.NumeralBase.bin;
import static org.junit.Assert.*; import static jscl.NumeralBase.dec;
import static jscl.NumeralBase.hex;
import static jscl.NumeralBase.oct;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp; import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp;

View File

@ -26,6 +26,7 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -37,10 +38,15 @@ import org.solovyev.android.wizard.Wizard;
import org.solovyev.android.wizard.WizardUi; import org.solovyev.android.wizard.WizardUi;
import org.solovyev.android.wizard.Wizards; import org.solovyev.android.wizard.Wizards;
import javax.annotation.Nonnull;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import static org.junit.Assert.*; import javax.annotation.Nonnull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.choose_mode; import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.choose_mode;
@RunWith(value = CalculatorTestRunner.class) @RunWith(value = CalculatorTestRunner.class)

View File

@ -11,8 +11,15 @@ import org.solovyev.android.wizard.Wizards;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.*; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.choose_mode;
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.last;
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.welcome;
@RunWith(value = CalculatorTestRunner.class) @RunWith(value = CalculatorTestRunner.class)
public class CalculatorWizardTest { public class CalculatorWizardTest {

View File

@ -30,9 +30,10 @@ import org.robolectric.util.ActivityController;
import org.solovyev.android.CalculatorTestRunner; import org.solovyev.android.CalculatorTestRunner;
import org.solovyev.android.wizard.WizardUi; import org.solovyev.android.wizard.WizardUi;
import javax.annotation.Nonnull;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import javax.annotation.Nonnull;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;

View File

@ -55,7 +55,7 @@ android {
} }
repositories { repositories {
flatDir{ flatDir {
dirs 'misc/libs' dirs 'misc/libs'
} }
} }
@ -86,7 +86,7 @@ dependencies {
compile 'com.google.android.gms:play-services-base:8.4.0' compile 'com.google.android.gms:play-services-base:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0' compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.melnykov:floatingactionbutton:1.1.0' compile 'com.melnykov:floatingactionbutton:1.1.0'
compile(name:'plotter', ext:'aar') compile(name: 'plotter', ext: 'aar')
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'

View File

@ -1,185 +1,280 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="org.solovyev.android.calculator"> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.solovyev.android.calculator"
android:installLocation="auto">
<uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.vending.BILLING"/> <uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--TODO: REMOVE IN PRODUCTION--> <!--TODO: REMOVE IN PRODUCTION-->
<!--<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>--> <!--<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>-->
<!-- for onscreen --> <!-- for onscreen -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<supports-screens android:smallScreens="true"/> <supports-screens android:smallScreens="true" />
<supports-screens android:normalScreens="true"/> <supports-screens android:normalScreens="true" />
<supports-screens android:largeScreens="true"/> <supports-screens android:largeScreens="true" />
<supports-screens android:xlargeScreens="true"/> <supports-screens android:xlargeScreens="true" />
<supports-screens android:anyDensity="true"/> <supports-screens android:anyDensity="true" />
<application android:allowBackup="true" android:hardwareAccelerated="true" android:icon="@drawable/ic_launcher" android:label="@string/c_app_name" android:name=".CalculatorApplication" android:theme="@style/Cpp.Theme.Material"> <application
android:name=".CalculatorApplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/ic_launcher"
android:label="@string/c_app_name"
android:theme="@style/Cpp.Theme.Material">
<meta-data <meta-data
android:name="com.google.android.gms.version" android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" /> android:value="@integer/google_play_services_version" />
<activity android:clearTaskOnLaunch="true" android:label="@string/c_app_name" android:launchMode="singleTop" android:name=".CalculatorActivity" android:windowSoftInputMode="adjustPan"> <activity
android:name=".CalculatorActivity"
android:clearTaskOnLaunch="true"
android:label="@string/c_app_name"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<receiver android:exported="false" android:name=".CalculatorReceiver"> <receiver
android:name=".CalculatorReceiver"
android:exported="false">
<intent-filter> <intent-filter>
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED"/> <action android:name="org.solovyev.android.calculator.BUTTON_PRESSED" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<activity android:clearTaskOnLaunch="true" android:label="@string/c_app_name" android:launchMode="singleTop" android:name=".CalculatorActivityMobile" android:windowSoftInputMode="adjustPan"/> <activity
android:name=".CalculatorActivityMobile"
android:clearTaskOnLaunch="true"
android:label="@string/c_app_name"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan" />
<activity android:label="@string/c_app_settings" android:name=".preferences.PreferencesActivity"/> <activity
android:name=".preferences.PreferencesActivity"
android:label="@string/c_app_settings" />
<activity android:label="@string/c_history" android:name=".history.CalculatorHistoryActivity"/> <activity
android:name=".history.CalculatorHistoryActivity"
android:label="@string/c_history" />
<activity android:excludeFromRecents="true" android:finishOnTaskLaunch="true" android:label="@string/calculation_messages_dialog_title" android:launchMode="singleTask" android:name=".FixableMessagesDialog" android:theme="@style/Cpp.Theme.Dialog.Material"/> <activity
android:name=".FixableMessagesDialog"
android:excludeFromRecents="true"
android:finishOnTaskLaunch="true"
android:label="@string/calculation_messages_dialog_title"
android:launchMode="singleTask"
android:theme="@style/Cpp.Theme.Dialog.Material" />
<activity android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/> <activity
android:name=".about.CalculatorAboutActivity"
android:label="@string/c_about" />
<activity android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsActivity"/> <activity
android:name=".math.edit.CalculatorFunctionsActivity"
android:label="@string/c_functions" />
<activity android:label="@string/c_operators" android:name=".math.edit.CalculatorOperatorsActivity"/> <activity
android:name=".math.edit.CalculatorOperatorsActivity"
android:label="@string/c_operators" />
<activity android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsActivity"/> <activity
<activity android:launchMode="singleTop" android:name=".wizard.WizardActivity" android:theme="@style/Cpp.Theme.Wizard"> android:name=".math.edit.CalculatorVarsActivity"
android:label="@string/c_vars_and_constants" />
<activity
android:name=".wizard.WizardActivity"
android:launchMode="singleTop"
android:theme="@style/Cpp.Theme.Wizard">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:hardwareAccelerated="false" android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity" android:theme="@style/Cpp.Theme.Material"/> <activity
<activity android:label="@string/cpp_plot_functions" android:name=".plot.CalculatorPlotFunctionsActivity" android:theme="@style/Cpp.Theme.Dialog.Material"/> android:name=".plot.CalculatorPlotActivity"
<activity android:label="@string/cpp_plot_function_settings" android:name=".plot.CalculatorPlotFunctionSettingsActivity" android:theme="@style/Cpp.Theme.Dialog.Material"/> android:hardwareAccelerated="false"
<activity android:label="@string/cpp_plot_range" android:name=".plot.CalculatorPlotRangeActivity" android:theme="@style/Cpp.Theme.Dialog.Material"/> android:label="@string/c_plot_graph"
android:theme="@style/Cpp.Theme.Material" />
<activity
android:name=".plot.CalculatorPlotFunctionsActivity"
android:label="@string/cpp_plot_functions"
android:theme="@style/Cpp.Theme.Dialog.Material" />
<activity
android:name=".plot.CalculatorPlotFunctionSettingsActivity"
android:label="@string/cpp_plot_function_settings"
android:theme="@style/Cpp.Theme.Dialog.Material" />
<activity
android:name=".plot.CalculatorPlotRangeActivity"
android:label="@string/cpp_plot_range"
android:theme="@style/Cpp.Theme.Dialog.Material" />
<activity android:label="@string/cpp_purchase_title" android:name=".preferences.PurchaseDialogActivity" android:theme="@style/Cpp.Theme.Dialog.Material"/> <activity
android:name=".preferences.PurchaseDialogActivity"
android:label="@string/cpp_purchase_title"
android:theme="@style/Cpp.Theme.Dialog.Material" />
<activity android:name=".CalculatorDialogActivity" android:theme="@style/Cpp.Theme.Dialog.Material"/> <activity
android:name=".CalculatorDialogActivity"
android:theme="@style/Cpp.Theme.Dialog.Material" />
<!-- todo serso: strings--> <!-- todo serso: strings-->
<activity android:label="@string/c_plot_graph" android:name=".matrix.CalculatorMatrixActivity"> <activity
android:name=".matrix.CalculatorMatrixActivity"
android:label="@string/c_plot_graph">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".widget.CalculatorWidgetConfigurationActivity" android:theme="@style/cpp_metro_blue_theme"> <activity
android:name=".widget.CalculatorWidgetConfigurationActivity"
android:theme="@style/cpp_metro_blue_theme">
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/> <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter> </intent-filter>
</activity> </activity>
<!-- ONSCREEN CONFIG --> <!-- ONSCREEN CONFIG -->
<activity android:icon="@drawable/ic_launcher_window" android:label="@string/c_app_name_on_screen" android:launchMode="singleInstance" android:name=".onscreen.CalculatorOnscreenStartActivity" android:theme="@style/Cpp.Theme.Dialog.Material"> <activity
android:name=".onscreen.CalculatorOnscreenStartActivity"
android:icon="@drawable/ic_launcher_window"
android:label="@string/c_app_name_on_screen"
android:launchMode="singleInstance"
android:theme="@style/Cpp.Theme.Dialog.Material">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<service android:exported="false" android:name=".onscreen.CalculatorOnscreenService"> <service
android:name=".onscreen.CalculatorOnscreenService"
android:exported="false">
<intent-filter> <intent-filter>
<action android:name="org.solovyev.android.calculator.onscreen.SHOW_WINDOW"/> <action android:name="org.solovyev.android.calculator.onscreen.SHOW_WINDOW" />
<action android:name="org.solovyev.android.calculator.onscreen.SHOW_NOTIFICATION"/> <action android:name="org.solovyev.android.calculator.onscreen.SHOW_NOTIFICATION" />
</intent-filter> </intent-filter>
</service> </service>
<receiver android:name=".onscreen.CalculatorOnscreenBroadcastReceiver"> <receiver android:name=".onscreen.CalculatorOnscreenBroadcastReceiver">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="org.solovyev.android.calculator.onscreen.SHOW_WINDOW"/> <action android:name="org.solovyev.android.calculator.onscreen.SHOW_WINDOW" />
<action android:name="org.solovyev.android.calculator.onscreen.SHOW_NOTIFICATION"/> <action android:name="org.solovyev.android.calculator.onscreen.SHOW_NOTIFICATION" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<!-- WIDGET CONFIG --> <!-- WIDGET CONFIG -->
<receiver android:icon="@drawable/ic_launcher" android:label="@string/c_app_name" android:name=".widget.CalculatorWidget"> <receiver
android:name=".widget.CalculatorWidget"
android:icon="@drawable/ic_launcher"
android:label="@string/c_app_name">
<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.android.calculator.INIT"/> <action android:name="org.solovyev.android.calculator.INIT" />
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/> <action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED" />
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/> <action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED" />
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED"/> <action android:name="org.solovyev.android.calculator.BUTTON_PRESSED" />
<action android:name="org.solovyev.android.calculator.THEME_CHANGED"/> <action android:name="org.solovyev.android.calculator.THEME_CHANGED" />
</intent-filter> </intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/calculator_widget"/> <meta-data
android:name="android.appwidget.provider"
android:resource="@xml/calculator_widget" />
</receiver> </receiver>
<receiver android:icon="@drawable/ic_launcher" android:label="@string/c_app_widget_3x3_name" android:name=".widget.CalculatorWidgetProvider"> <receiver
android:name=".widget.CalculatorWidgetProvider"
android:icon="@drawable/ic_launcher"
android:label="@string/c_app_widget_3x3_name">
<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.android.calculator.INIT"/> <action android:name="org.solovyev.android.calculator.INIT" />
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/> <action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED" />
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/> <action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED" />
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED"/> <action android:name="org.solovyev.android.calculator.BUTTON_PRESSED" />
<action android:name="org.solovyev.android.calculator.THEME_CHANGED"/> <action android:name="org.solovyev.android.calculator.THEME_CHANGED" />
</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" />
</receiver> </receiver>
<receiver android:icon="@drawable/ic_launcher" android:label="@string/c_app_widget_3x4_name" android:name=".widget.CalculatorWidgetProvider3x4"> <receiver
android:name=".widget.CalculatorWidgetProvider3x4"
android:icon="@drawable/ic_launcher"
android:label="@string/c_app_widget_3x4_name">
<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.android.calculator.INIT"/> <action android:name="org.solovyev.android.calculator.INIT" />
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/> <action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED" />
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/> <action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED" />
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED"/> <action android:name="org.solovyev.android.calculator.BUTTON_PRESSED" />
<action android:name="org.solovyev.android.calculator.THEME_CHANGED"/> <action android:name="org.solovyev.android.calculator.THEME_CHANGED" />
</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" />
</receiver> </receiver>
<receiver android:icon="@drawable/ic_launcher" android:label="@string/c_app_widget_4x4_name" android:name=".widget.CalculatorWidgetProvider4x4"> <receiver
android:name=".widget.CalculatorWidgetProvider4x4"
android:icon="@drawable/ic_launcher"
android:label="@string/c_app_widget_4x4_name">
<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.android.calculator.INIT"/> <action android:name="org.solovyev.android.calculator.INIT" />
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/> <action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED" />
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/> <action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED" />
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED"/> <action android:name="org.solovyev.android.calculator.BUTTON_PRESSED" />
<action android:name="org.solovyev.android.calculator.THEME_CHANGED"/> <action android:name="org.solovyev.android.calculator.THEME_CHANGED" />
</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" />
</receiver> </receiver>
<receiver android:icon="@drawable/ic_launcher" android:label="@string/c_app_widget_4x5_name" android:name=".widget.CalculatorWidgetProvider4x5"> <receiver
android:name=".widget.CalculatorWidgetProvider4x5"
android:icon="@drawable/ic_launcher"
android:label="@string/c_app_widget_4x5_name">
<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.android.calculator.INIT"/> <action android:name="org.solovyev.android.calculator.INIT" />
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/> <action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED" />
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/> <action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED" />
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED"/> <action android:name="org.solovyev.android.calculator.BUTTON_PRESSED" />
<action android:name="org.solovyev.android.calculator.THEME_CHANGED"/> <action android:name="org.solovyev.android.calculator.THEME_CHANGED" />
</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" />
</receiver> </receiver>
<!-- ADMOB --> <!-- ADMOB -->
@ -191,20 +286,25 @@
<!-- ACRA CONFIG --> <!-- ACRA CONFIG -->
<activity android:excludeFromRecents="true" android:finishOnTaskLaunch="true" android:launchMode="singleInstance" android:name="org.acra.CrashReportDialog" android:theme="@android:style/Theme.Dialog"/> <activity
android:name="org.acra.CrashReportDialog"
android:excludeFromRecents="true"
android:finishOnTaskLaunch="true"
android:launchMode="singleInstance"
android:theme="@android:style/Theme.Dialog" />
<!-- Google Analytics --> <!-- Google Analytics -->
<receiver <receiver
android:name="com.google.android.gms.analytics.AnalyticsReceiver" android:name="com.google.android.gms.analytics.AnalyticsReceiver"
android:enabled="true"> android:enabled="true">
<intent-filter> <intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH"/> <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<service <service
android:name="com.google.android.gms.analytics.AnalyticsService" android:name="com.google.android.gms.analytics.AnalyticsService"
android:enabled="true" android:enabled="true"
android:exported="false"/> android:exported="false" />
</application> </application>
</manifest> </manifest>

View File

@ -32,6 +32,7 @@ import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewConfiguration; import android.view.ViewConfiguration;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import static android.graphics.Paint.ANTI_ALIAS_FLAG; import static android.graphics.Paint.ANTI_ALIAS_FLAG;
@ -44,11 +45,10 @@ import static android.widget.LinearLayout.VERTICAL;
*/ */
public class CirclePageIndicator extends View implements PageIndicator { public class CirclePageIndicator extends View implements PageIndicator {
private static final int INVALID_POINTER = -1; private static final int INVALID_POINTER = -1;
private float mRadius;
private final Paint mPaintPageFill = new Paint(ANTI_ALIAS_FLAG); private final Paint mPaintPageFill = new Paint(ANTI_ALIAS_FLAG);
private final Paint mPaintStroke = new Paint(ANTI_ALIAS_FLAG); private final Paint mPaintStroke = new Paint(ANTI_ALIAS_FLAG);
private final Paint mPaintFill = new Paint(ANTI_ALIAS_FLAG); private final Paint mPaintFill = new Paint(ANTI_ALIAS_FLAG);
private float mRadius;
private ViewPager mViewPager; private ViewPager mViewPager;
private ViewPager.OnPageChangeListener mListener; private ViewPager.OnPageChangeListener mListener;
private int mCurrentPage; private int mCurrentPage;
@ -114,18 +114,12 @@ public class CirclePageIndicator extends View implements PageIndicator {
mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
} }
public void setCentered(boolean centered) {
mCentered = centered;
invalidate();
}
public boolean isCentered() { public boolean isCentered() {
return mCentered; return mCentered;
} }
public void setPageColor(int pageColor) { public void setCentered(boolean centered) {
mPaintPageFill.setColor(pageColor); mCentered = centered;
invalidate(); invalidate();
} }
@ -133,8 +127,8 @@ public class CirclePageIndicator extends View implements PageIndicator {
return mPaintPageFill.getColor(); return mPaintPageFill.getColor();
} }
public void setFillColor(int fillColor) { public void setPageColor(int pageColor) {
mPaintFill.setColor(fillColor); mPaintPageFill.setColor(pageColor);
invalidate(); invalidate();
} }
@ -142,6 +136,15 @@ public class CirclePageIndicator extends View implements PageIndicator {
return mPaintFill.getColor(); return mPaintFill.getColor();
} }
public void setFillColor(int fillColor) {
mPaintFill.setColor(fillColor);
invalidate();
}
public int getOrientation() {
return mOrientation;
}
public void setOrientation(int orientation) { public void setOrientation(int orientation) {
switch (orientation) { switch (orientation) {
case HORIZONTAL: case HORIZONTAL:
@ -155,8 +158,8 @@ public class CirclePageIndicator extends View implements PageIndicator {
} }
} }
public int getOrientation() { public int getStrokeColor() {
return mOrientation; return mPaintStroke.getColor();
} }
public void setStrokeColor(int strokeColor) { public void setStrokeColor(int strokeColor) {
@ -164,8 +167,8 @@ public class CirclePageIndicator extends View implements PageIndicator {
invalidate(); invalidate();
} }
public int getStrokeColor() { public float getStrokeWidth() {
return mPaintStroke.getColor(); return mPaintStroke.getStrokeWidth();
} }
public void setStrokeWidth(float strokeWidth) { public void setStrokeWidth(float strokeWidth) {
@ -173,8 +176,8 @@ public class CirclePageIndicator extends View implements PageIndicator {
invalidate(); invalidate();
} }
public float getStrokeWidth() { public float getRadius() {
return mPaintStroke.getStrokeWidth(); return mRadius;
} }
public void setRadius(float radius) { public void setRadius(float radius) {
@ -182,8 +185,8 @@ public class CirclePageIndicator extends View implements PageIndicator {
invalidate(); invalidate();
} }
public float getRadius() { public boolean isSnap() {
return mRadius; return mSnap;
} }
public void setSnap(boolean snap) { public void setSnap(boolean snap) {
@ -191,10 +194,6 @@ public class CirclePageIndicator extends View implements PageIndicator {
invalidate(); invalidate();
} }
public boolean isSnap() {
return mSnap;
}
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
@ -454,8 +453,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
/** /**
* Determines the width of this view * Determines the width of this view
* *
* @param measureSpec * @param measureSpec A measureSpec packed into an int
* A measureSpec packed into an int
* @return The width of the view, honoring constraints from measureSpec * @return The width of the view, honoring constraints from measureSpec
*/ */
private int measureLong(int measureSpec) { private int measureLong(int measureSpec) {
@ -469,7 +467,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
} else { } else {
//Calculate the width according the views count //Calculate the width according the views count
final int count = mViewPager.getAdapter().getCount(); final int count = mViewPager.getAdapter().getCount();
result = (int)(getPaddingLeft() + getPaddingRight() result = (int) (getPaddingLeft() + getPaddingRight()
+ (count * 2 * mRadius) + (count - 1) * mRadius + 1); + (count * 2 * mRadius) + (count - 1) * mRadius + 1);
//Respect AT_MOST value if that was what is called for by measureSpec //Respect AT_MOST value if that was what is called for by measureSpec
if (specMode == MeasureSpec.AT_MOST) { if (specMode == MeasureSpec.AT_MOST) {
@ -482,8 +480,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
/** /**
* Determines the height of this view * Determines the height of this view
* *
* @param measureSpec * @param measureSpec A measureSpec packed into an int
* A measureSpec packed into an int
* @return The height of the view, honoring constraints from measureSpec * @return The height of the view, honoring constraints from measureSpec
*/ */
private int measureShort(int measureSpec) { private int measureShort(int measureSpec) {
@ -496,7 +493,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
result = specSize; result = specSize;
} else { } else {
//Measure the height //Measure the height
result = (int)(2 * mRadius + getPaddingTop() + getPaddingBottom() + 1); result = (int) (2 * mRadius + getPaddingTop() + getPaddingBottom() + 1);
//Respect AT_MOST value if that was what is called for by measureSpec //Respect AT_MOST value if that was what is called for by measureSpec
if (specMode == MeasureSpec.AT_MOST) { if (specMode == MeasureSpec.AT_MOST) {
result = Math.min(result, specSize); result = Math.min(result, specSize);
@ -507,7 +504,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
@Override @Override
public void onRestoreInstanceState(Parcelable state) { public void onRestoreInstanceState(Parcelable state) {
SavedState savedState = (SavedState)state; SavedState savedState = (SavedState) state;
super.onRestoreInstanceState(savedState.getSuperState()); super.onRestoreInstanceState(savedState.getSuperState());
mCurrentPage = savedState.currentPage; mCurrentPage = savedState.currentPage;
mSnapPage = savedState.currentPage; mSnapPage = savedState.currentPage;
@ -523,6 +520,18 @@ public class CirclePageIndicator extends View implements PageIndicator {
} }
static class SavedState extends BaseSavedState { static class SavedState extends BaseSavedState {
@SuppressWarnings("UnusedDeclaration")
public static final Creator<SavedState> CREATOR = new Creator<SavedState>() {
@Override
public SavedState createFromParcel(Parcel in) {
return new SavedState(in);
}
@Override
public SavedState[] newArray(int size) {
return new SavedState[size];
}
};
int currentPage; int currentPage;
public SavedState(Parcelable superState) { public SavedState(Parcelable superState) {
@ -539,18 +548,5 @@ public class CirclePageIndicator extends View implements PageIndicator {
super.writeToParcel(dest, flags); super.writeToParcel(dest, flags);
dest.writeInt(currentPage); dest.writeInt(currentPage);
} }
@SuppressWarnings("UnusedDeclaration")
public static final Creator<SavedState> CREATOR = new Creator<SavedState>() {
@Override
public SavedState createFromParcel(Parcel in) {
return new SavedState(in);
}
@Override
public SavedState[] newArray(int size) {
return new SavedState[size];
}
};
} }
} }

View File

@ -41,7 +41,7 @@ public interface PageIndicator extends ViewPager.OnPageChangeListener {
/** /**
* <p>Set the current page of both the ViewPager and indicator.</p> * <p>Set the current page of both the ViewPager and indicator.</p>
* * <p/>
* <p>This <strong>must</strong> be used if you need to set the page before * <p>This <strong>must</strong> be used if you need to set the page before
* the views are drawn on screen (e.g., default start page).</p> * the views are drawn on screen (e.g., default start page).</p>
* *

View File

@ -36,6 +36,10 @@ public final class Check {
private static final boolean junit = isJunit(); private static final boolean junit = isJunit();
private Check() {
throw new AssertionError();
}
private static boolean isJunit() { private static boolean isJunit() {
final StackTraceElement[] stackTrace = currentThread().getStackTrace(); final StackTraceElement[] stackTrace = currentThread().getStackTrace();
for (StackTraceElement element : stackTrace) { for (StackTraceElement element : stackTrace) {
@ -46,10 +50,6 @@ public final class Check {
return false; return false;
} }
private Check() {
throw new AssertionError();
}
public static void isMainThread() { public static void isMainThread() {
if (!junit && Looper.getMainLooper() != Looper.myLooper()) { if (!junit && Looper.getMainLooper() != Looper.myLooper()) {
throw new AssertionException("Should be called on the main thread"); throw new AssertionException("Should be called on the main thread");

View File

@ -68,8 +68,32 @@ public class ActivityUi extends BaseUi {
this.layoutId = layoutId; this.layoutId = layoutId;
} }
public void setLayoutId(int layoutId) { public static boolean restartIfThemeChanged(@Nonnull Activity activity, @Nonnull Preferences.Gui.Theme oldTheme) {
this.layoutId = layoutId; final Preferences.Gui.Theme newTheme = Preferences.Gui.theme.getPreference(App.getPreferences());
final int themeId = oldTheme.getThemeId(activity);
final int newThemeId = newTheme.getThemeId(activity);
if (themeId != newThemeId) {
Activities.restartActivity(activity);
return true;
}
return false;
}
public static boolean restartIfLanguageChanged(@Nonnull Activity activity, @Nonnull Language oldLanguage) {
final Language current = App.getLanguages().getCurrent();
if (!current.equals(oldLanguage)) {
Activities.restartActivity(activity);
return true;
}
return false;
}
public static void reportActivityStop(@Nonnull Activity activity) {
App.getGa().getAnalytics().reportActivityStop(activity);
}
public static void reportActivityStart(@Nonnull Activity activity) {
App.getGa().getAnalytics().reportActivityStart(activity);
} }
public void onPreCreate(@Nonnull Activity activity) { public void onPreCreate(@Nonnull Activity activity) {
@ -159,26 +183,6 @@ public class ActivityUi extends BaseUi {
} }
} }
public static boolean restartIfThemeChanged(@Nonnull Activity activity, @Nonnull Preferences.Gui.Theme oldTheme) {
final Preferences.Gui.Theme newTheme = Preferences.Gui.theme.getPreference(App.getPreferences());
final int themeId = oldTheme.getThemeId(activity);
final int newThemeId = newTheme.getThemeId(activity);
if (themeId != newThemeId) {
Activities.restartActivity(activity);
return true;
}
return false;
}
public static boolean restartIfLanguageChanged(@Nonnull Activity activity, @Nonnull Language oldLanguage) {
final Language current = App.getLanguages().getCurrent();
if (!current.equals(oldLanguage)) {
Activities.restartActivity(activity);
return true;
}
return false;
}
public void onPause(@Nonnull Activity activity) { public void onPause(@Nonnull Activity activity) {
} }
@ -270,6 +274,10 @@ public class ActivityUi extends BaseUi {
return layoutId; return layoutId;
} }
public void setLayoutId(int layoutId) {
this.layoutId = layoutId;
}
@Nonnull @Nonnull
public Preferences.Gui.Theme getTheme() { public Preferences.Gui.Theme getTheme() {
return theme; return theme;
@ -354,15 +362,7 @@ public class ActivityUi extends BaseUi {
reportActivityStop(activity); reportActivityStop(activity);
} }
public static void reportActivityStop(@Nonnull Activity activity) {
App.getGa().getAnalytics().reportActivityStop(activity);
}
public void onStart(@Nonnull Activity activity) { public void onStart(@Nonnull Activity activity) {
reportActivityStart(activity); reportActivityStart(activity);
} }
public static void reportActivityStart(@Nonnull Activity activity) {
App.getGa().getAnalytics().reportActivityStart(activity);
}
} }

View File

@ -43,7 +43,7 @@ public class AdView extends FrameLayout {
admobView.setAdListener(null); admobView.setAdListener(null);
admobView = null; admobView = null;
} }
if(admobListener != null) { if (admobListener != null) {
admobListener.destroy(); admobListener.destroy();
admobListener = null; admobListener = null;
} }
@ -86,7 +86,7 @@ public class AdView extends FrameLayout {
} }
public void hide() { public void hide() {
if(admobView == null) { if (admobView == null) {
return; return;
} }

View File

@ -80,13 +80,13 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
} }
@Override @Override
public void setCalculateOnFly(boolean calculateOnFly) { public boolean isCalculateOnFly() {
calculator.setCalculateOnFly(calculateOnFly); return calculator.isCalculateOnFly();
} }
@Override @Override
public boolean isCalculateOnFly() { public void setCalculateOnFly(boolean calculateOnFly) {
return calculator.isCalculateOnFly(); calculator.setCalculateOnFly(calculateOnFly);
} }
@Override @Override
@ -157,17 +157,17 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
calculator.doHistoryAction(historyAction); calculator.doHistoryAction(historyAction);
} }
@Override
public void setCurrentHistoryState(@Nonnull CalculatorHistoryState editorHistoryState) {
calculator.setCurrentHistoryState(editorHistoryState);
}
@Override @Override
@Nonnull @Nonnull
public CalculatorHistoryState getCurrentHistoryState() { public CalculatorHistoryState getCurrentHistoryState() {
return calculator.getCurrentHistoryState(); return calculator.getCurrentHistoryState();
} }
@Override
public void setCurrentHistoryState(@Nonnull CalculatorHistoryState editorHistoryState) {
calculator.setCurrentHistoryState(editorHistoryState);
}
@Override @Override
public void evaluate() { public void evaluate() {
calculator.evaluate(); calculator.evaluate();

View File

@ -53,13 +53,13 @@ public class AndroidCalculatorClipboard implements CalculatorClipboard {
} }
@Override @Override
public void setText(@Nonnull String text) { public void setText(@Nonnull CharSequence text) {
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(text); clipboard.setText(text);
} }
@Override @Override
public void setText(@Nonnull CharSequence text) { public void setText(@Nonnull String text) {
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(text); clipboard.setText(text);
} }

View File

@ -64,16 +64,12 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
* *
********************************************************************** **********************************************************************
*/ */
@Nonnull
private volatile CalculatorDisplayViewState state = CalculatorDisplayViewStateImpl.newDefaultInstance();
@Nonnull @Nonnull
private final Object lock = new Object(); private final Object lock = new Object();
@Nonnull @Nonnull
private final Handler uiHandler = new Handler(); private final Handler uiHandler = new Handler();
@Nonnull
private volatile CalculatorDisplayViewState state = CalculatorDisplayViewStateImpl.newDefaultInstance();
private volatile boolean initialized = false; private volatile boolean initialized = false;
/* /*
@ -107,6 +103,18 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
********************************************************************** **********************************************************************
*/ */
private Preferences.Gui.TextColor getTextColor() {
final Context context = getContext();
return App.getThemeIn(context).getTextColor(context);
}
@Nonnull
@Override
public CalculatorDisplayViewState getState() {
synchronized (lock) {
return this.state;
}
}
@Override @Override
public void setState(@Nonnull final CalculatorDisplayViewState state) { public void setState(@Nonnull final CalculatorDisplayViewState state) {
@ -140,19 +148,6 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
}); });
} }
private Preferences.Gui.TextColor getTextColor() {
final Context context = getContext();
return App.getThemeIn(context).getTextColor(context);
}
@Nonnull
@Override
public CalculatorDisplayViewState getState() {
synchronized (lock) {
return this.state;
}
}
@Nullable @Nullable
private CharSequence prepareText(@Nullable String text, boolean valid) { private CharSequence prepareText(@Nullable String text, boolean valid) {
CharSequence result; CharSequence result;

View File

@ -43,17 +43,14 @@ import javax.annotation.Nonnull;
*/ */
public class AndroidCalculatorEditorView extends EditText implements CalculatorEditorView { public class AndroidCalculatorEditorView extends EditText implements CalculatorEditorView {
@Nonnull
private final Handler uiHandler = new Handler();
private volatile boolean initialized = false; private volatile boolean initialized = false;
@SuppressWarnings("UnusedDeclaration") @SuppressWarnings("UnusedDeclaration")
@Nonnull @Nonnull
private volatile CalculatorEditorViewState viewState = CalculatorEditorViewStateImpl.newDefaultInstance(); private volatile CalculatorEditorViewState viewState = CalculatorEditorViewStateImpl.newDefaultInstance();
private volatile boolean viewStateChange = false; private volatile boolean viewStateChange = false;
@Nonnull
private final Handler uiHandler = new Handler();
public AndroidCalculatorEditorView(Context context) { public AndroidCalculatorEditorView(Context context) {
super(context); super(context);
} }

View File

@ -22,13 +22,8 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import org.solovyev.android.view.VibratorContainer;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;

View File

@ -25,14 +25,16 @@ package org.solovyev.android.calculator;
import android.app.Application; import android.app.Application;
import android.os.Handler; import android.os.Handler;
import android.widget.Toast; import android.widget.Toast;
import org.solovyev.android.Threads; import org.solovyev.android.Threads;
import org.solovyev.android.msg.AndroidMessage; import org.solovyev.android.msg.AndroidMessage;
import org.solovyev.common.msg.Message; import org.solovyev.common.msg.Message;
import org.solovyev.common.msg.MessageType; import org.solovyev.common.msg.MessageType;
import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List;
/** /**
* User: serso * User: serso

View File

@ -25,10 +25,6 @@ package org.solovyev.android.calculator;
import android.app.Application; import android.app.Application;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import jscl.AngleUnit;
import jscl.NumeralBase;
import javax.annotation.Nonnull;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine; import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import org.solovyev.android.msg.AndroidMessage; import org.solovyev.android.msg.AndroidMessage;
@ -37,6 +33,11 @@ import org.solovyev.common.msg.MessageType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import jscl.AngleUnit;
import jscl.NumeralBase;
/** /**
* User: serso * User: serso
* Date: 11/17/12 * Date: 11/17/12

View File

@ -44,10 +44,6 @@ public enum AndroidFunctionCategory {
this.captionId = captionId; this.captionId = captionId;
} }
public int getCaptionId() {
return captionId;
}
@Nullable @Nullable
public static AndroidFunctionCategory valueOf(@Nonnull FunctionCategory functionCategory) { public static AndroidFunctionCategory valueOf(@Nonnull FunctionCategory functionCategory) {
for (AndroidFunctionCategory androidFunctionCategory : values()) { for (AndroidFunctionCategory androidFunctionCategory : values()) {
@ -58,4 +54,8 @@ public enum AndroidFunctionCategory {
return null; return null;
} }
public int getCaptionId() {
return captionId;
}
} }

View File

@ -23,18 +23,19 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import jscl.NumeralBase;
import javax.annotation.Nonnull;
import org.solovyev.android.calculator.units.CalculatorNumeralBase;
import org.solovyev.android.calculator.drag.DirectionDragButton; import org.solovyev.android.calculator.drag.DirectionDragButton;
import org.solovyev.android.calculator.drag.DragDirection; import org.solovyev.android.calculator.drag.DragDirection;
import org.solovyev.android.calculator.units.CalculatorNumeralBase;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import jscl.NumeralBase;
/** /**
* User: serso * User: serso
* Date: 4/21/12 * Date: 4/21/12
@ -98,6 +99,17 @@ public enum AndroidNumeralBase {
this.calculatorNumeralBase = calculatorNumeralBase; this.calculatorNumeralBase = calculatorNumeralBase;
} }
@Nonnull
public static AndroidNumeralBase valueOf(@Nonnull NumeralBase nb) {
for (AndroidNumeralBase androidNumeralBase : values()) {
if (androidNumeralBase.calculatorNumeralBase.getNumeralBase() == nb) {
return androidNumeralBase;
}
}
throw new IllegalArgumentException(nb + " is not supported numeral base!");
}
@Nonnull @Nonnull
public abstract List<Integer> getButtonIds(); public abstract List<Integer> getButtonIds();
@ -119,15 +131,4 @@ public enum AndroidNumeralBase {
public NumeralBase getNumeralBase() { public NumeralBase getNumeralBase() {
return calculatorNumeralBase.getNumeralBase(); return calculatorNumeralBase.getNumeralBase();
} }
@Nonnull
public static AndroidNumeralBase valueOf(@Nonnull NumeralBase nb) {
for (AndroidNumeralBase androidNumeralBase : values()) {
if (androidNumeralBase.calculatorNumeralBase.getNumeralBase() == nb) {
return androidNumeralBase;
}
}
throw new IllegalArgumentException(nb + " is not supported numeral base!");
}
} }

View File

@ -43,10 +43,6 @@ public enum AndroidOperatorCategory {
this.captionId = captionId; this.captionId = captionId;
} }
public int getCaptionId() {
return captionId;
}
@Nullable @Nullable
public static AndroidOperatorCategory valueOf(@Nonnull OperatorCategory operatorCategory) { public static AndroidOperatorCategory valueOf(@Nonnull OperatorCategory operatorCategory) {
for (AndroidOperatorCategory androidOperatorCategory : values()) { for (AndroidOperatorCategory androidOperatorCategory : values()) {
@ -57,4 +53,8 @@ public enum AndroidOperatorCategory {
return null; return null;
} }
public int getCaptionId() {
return captionId;
}
} }

View File

@ -41,10 +41,6 @@ public enum AndroidVarCategory {
this.captionId = captionId; this.captionId = captionId;
} }
public int getCaptionId() {
return captionId;
}
@Nullable @Nullable
public static AndroidVarCategory valueOf(@Nonnull VarCategory varCategory) { public static AndroidVarCategory valueOf(@Nonnull VarCategory varCategory) {
for (AndroidVarCategory androidVarCategory : values()) { for (AndroidVarCategory androidVarCategory : values()) {
@ -55,4 +51,8 @@ public enum AndroidVarCategory {
return null; return null;
} }
public int getCaptionId() {
return captionId;
}
} }

View File

@ -86,47 +86,33 @@ import javax.annotation.Nullable;
public final class App { public final class App {
@Nonnull @Nonnull
private static final List<Class<? extends BaseCalculatorWidgetProvider>> OLD_WIDGETS = Arrays.asList(CalculatorWidgetProvider.class, CalculatorWidgetProvider3x4.class, CalculatorWidgetProvider4x4.class, CalculatorWidgetProvider4x5.class); private static final List<Class<? extends BaseCalculatorWidgetProvider>> OLD_WIDGETS = Arrays.asList(CalculatorWidgetProvider.class, CalculatorWidgetProvider3x4.class, CalculatorWidgetProvider4x4.class, CalculatorWidgetProvider4x5.class);
@Nonnull
private static volatile Application application;
@Nonnull
private static volatile DelayedExecutor uiThreadExecutor;
@Nonnull
private static volatile JEventListeners<JEventListener<? extends JEvent>, JEvent> eventBus;
private static volatile boolean initialized;
@Nonnull
private static CalculatorBroadcaster broadcaster;
@Nonnull
private static SharedPreferences preferences;
@Nonnull
private static volatile Ga ga;
@Nonnull
private static volatile Billing billing;
@Nonnull @Nonnull
private static final Products products = Products.create().add(ProductTypes.IN_APP, Arrays.asList("ad_free")); private static final Products products = Products.create().add(ProductTypes.IN_APP, Arrays.asList("ad_free"));
@Nullable
private static Boolean lg = null;
@Nonnull
private static volatile Vibrator vibrator;
@Nonnull
private static volatile ScreenMetrics screenMetrics;
@Nonnull
private static volatile Plotter plotter;
@Nonnull @Nonnull
private static final Languages languages = new Languages(); private static final Languages languages = new Languages();
@Nonnull
private static volatile Application application;
@Nonnull
private static volatile DelayedExecutor uiThreadExecutor;
@Nonnull
private static volatile JEventListeners<JEventListener<? extends JEvent>, JEvent> eventBus;
private static volatile boolean initialized;
@Nonnull
private static CalculatorBroadcaster broadcaster;
@Nonnull
private static SharedPreferences preferences;
@Nonnull
private static volatile Ga ga;
@Nonnull
private static volatile Billing billing;
@Nullable
private static Boolean lg = null;
@Nonnull
private static volatile Vibrator vibrator;
@Nonnull
private static volatile ScreenMetrics screenMetrics;
@Nonnull
private static volatile Plotter plotter;
private App() { private App() {
throw new AssertionError(); throw new AssertionError();

View File

@ -32,8 +32,13 @@ import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import org.solovyev.android.Views; import org.solovyev.android.Views;
import org.solovyev.android.calculator.drag.*; import org.solovyev.android.calculator.drag.DirectionDragButton;
import org.solovyev.android.calculator.drag.DragButton;
import org.solovyev.android.calculator.drag.DragDirection;
import org.solovyev.android.calculator.drag.DragListener;
import org.solovyev.android.calculator.drag.SimpleDragListener;
import org.solovyev.android.calculator.history.CalculatorHistoryState; import org.solovyev.android.calculator.history.CalculatorHistoryState;
import org.solovyev.android.calculator.history.HistoryDragProcessor; import org.solovyev.android.calculator.history.HistoryDragProcessor;
import org.solovyev.android.calculator.view.AngleUnitsButton; import org.solovyev.android.calculator.view.AngleUnitsButton;
@ -42,11 +47,12 @@ import org.solovyev.android.calculator.view.NumeralBasesButton;
import org.solovyev.android.calculator.view.ViewsCache; import org.solovyev.android.calculator.view.ViewsCache;
import org.solovyev.common.math.Point2d; import org.solovyev.common.math.Point2d;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple; import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile; import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile;
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.angleUnit; import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.angleUnit;
@ -79,6 +85,38 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan
this.logTag = logTag; this.logTag = logTag;
} }
@Nonnull
private static List<Integer> getViewIds() {
if (viewIds.isEmpty()) {
viewIds.add(R.id.wizard_dragbutton);
viewIds.add(R.id.cpp_button_vars);
viewIds.add(R.id.cpp_button_round_brackets);
viewIds.add(R.id.cpp_button_right);
viewIds.add(R.id.cpp_button_plus);
viewIds.add(R.id.cpp_button_operators);
viewIds.add(R.id.cpp_button_multiplication);
viewIds.add(R.id.cpp_button_subtraction);
viewIds.add(R.id.cpp_button_left);
viewIds.add(R.id.cpp_button_history);
viewIds.add(R.id.cpp_button_functions);
viewIds.add(R.id.cpp_button_equals);
viewIds.add(R.id.cpp_button_period);
viewIds.add(R.id.cpp_button_division);
viewIds.add(R.id.cpp_button_9);
viewIds.add(R.id.cpp_button_8);
viewIds.add(R.id.cpp_button_7);
viewIds.add(R.id.cpp_button_6);
viewIds.add(R.id.cpp_button_5);
viewIds.add(R.id.cpp_button_4);
viewIds.add(R.id.cpp_button_3);
viewIds.add(R.id.cpp_button_2);
viewIds.add(R.id.cpp_button_1);
viewIds.add(R.id.cpp_button_0);
viewIds.add(R.id.cpp_button_clear);
}
return viewIds;
}
protected void onCreate(@Nonnull Activity activity) { protected void onCreate(@Nonnull Activity activity) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
@ -246,38 +284,6 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan
return Locator.getInstance().getCalculator(); return Locator.getInstance().getCalculator();
} }
@Nonnull
private static List<Integer> getViewIds() {
if (viewIds.isEmpty()) {
viewIds.add(R.id.wizard_dragbutton);
viewIds.add(R.id.cpp_button_vars);
viewIds.add(R.id.cpp_button_round_brackets);
viewIds.add(R.id.cpp_button_right);
viewIds.add(R.id.cpp_button_plus);
viewIds.add(R.id.cpp_button_operators);
viewIds.add(R.id.cpp_button_multiplication);
viewIds.add(R.id.cpp_button_subtraction);
viewIds.add(R.id.cpp_button_left);
viewIds.add(R.id.cpp_button_history);
viewIds.add(R.id.cpp_button_functions);
viewIds.add(R.id.cpp_button_equals);
viewIds.add(R.id.cpp_button_period);
viewIds.add(R.id.cpp_button_division);
viewIds.add(R.id.cpp_button_9);
viewIds.add(R.id.cpp_button_8);
viewIds.add(R.id.cpp_button_7);
viewIds.add(R.id.cpp_button_6);
viewIds.add(R.id.cpp_button_5);
viewIds.add(R.id.cpp_button_4);
viewIds.add(R.id.cpp_button_3);
viewIds.add(R.id.cpp_button_2);
viewIds.add(R.id.cpp_button_1);
viewIds.add(R.id.cpp_button_0);
viewIds.add(R.id.cpp_button_clear);
}
return viewIds;
}
@Nonnull @Nonnull
private CalculatorKeyboard getKeyboard() { private CalculatorKeyboard getKeyboard() {
return Locator.getInstance().getKeyboard(); return Locator.getInstance().getKeyboard();

View File

@ -3,6 +3,7 @@ package org.solovyev.android.calculator;
import android.support.annotation.IdRes; import android.support.annotation.IdRes;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import org.solovyev.android.calculator.view.ViewsCache; import org.solovyev.android.calculator.view.ViewsCache;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;

View File

@ -32,8 +32,13 @@ import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.view.*; import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.Window;
import android.widget.TextView; import android.widget.TextView;
import org.solovyev.android.Activities; import org.solovyev.android.Activities;
import org.solovyev.android.Android; import org.solovyev.android.Android;
import org.solovyev.android.Threads; import org.solovyev.android.Threads;
@ -54,7 +59,9 @@ import static android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
import static org.solovyev.android.calculator.Preferences.Gui.preventScreenFromFading; import static org.solovyev.android.calculator.Preferences.Gui.preventScreenFromFading;
import static org.solovyev.android.calculator.release.ReleaseNotes.hasReleaseNotes; import static org.solovyev.android.calculator.release.ReleaseNotes.hasReleaseNotes;
import static org.solovyev.android.wizard.WizardUi.*; import static org.solovyev.android.wizard.WizardUi.continueWizard;
import static org.solovyev.android.wizard.WizardUi.createLaunchIntent;
import static org.solovyev.android.wizard.WizardUi.startWizard;
public class CalculatorActivity extends BaseActivity implements SharedPreferences.OnSharedPreferenceChangeListener, CalculatorEventListener { public class CalculatorActivity extends BaseActivity implements SharedPreferences.OnSharedPreferenceChangeListener, CalculatorEventListener {
@ -67,70 +74,6 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
super(0, TAG); super(0, TAG);
} }
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
final Preferences.Gui.Layout layout = Preferences.Gui.layout.getPreferenceNoError(preferences);
ui.setLayoutId(layout.getLayoutId());
super.onCreate(savedInstanceState);
if (isMultiPane()) {
ui.addTab(this, CalculatorFragmentType.history, null, R.id.main_second_pane);
ui.addTab(this, CalculatorFragmentType.saved_history, null, R.id.main_second_pane);
ui.addTab(this, CalculatorFragmentType.variables, null, R.id.main_second_pane);
ui.addTab(this, CalculatorFragmentType.functions, null, R.id.main_second_pane);
ui.addTab(this, CalculatorFragmentType.operators, null, R.id.main_second_pane);
ui.addTab(this, CalculatorPlotActivity.getPlotterFragmentType(), null, R.id.main_second_pane);
} else {
final ActionBar actionBar = getSupportActionBar();
if (Build.VERSION.SDK_INT <= GINGERBREAD_MR1 || (Build.VERSION.SDK_INT >= ICE_CREAM_SANDWICH && hasPermanentMenuKey())) {
actionBar.hide();
} else {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
}
}
FragmentUtils.createFragment(this, CalculatorEditorFragment.class, R.id.editorContainer, "editor");
FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display");
FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
this.useBackAsPrev = Preferences.Gui.usePrevAsBack.getPreference(preferences);
if (savedInstanceState == null) {
firstTimeInit(preferences, this);
}
toggleOrientationChange(preferences);
preferences.registerOnSharedPreferenceChangeListener(this);
Locator.getInstance().getPreferenceService().checkPreferredPreferences(false);
if (CalculatorApplication.isMonkeyRunner(this)) {
Locator.getInstance().getKeyboard().buttonPressed("123");
Locator.getInstance().getKeyboard().buttonPressed("+");
Locator.getInstance().getKeyboard().buttonPressed("321");
}
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private boolean hasPermanentMenuKey() {
return ViewConfiguration.get(this).hasPermanentMenuKey();
}
private boolean isMultiPane() {
return findViewById(R.id.main_second_pane) != null;
}
@Nonnull
private AndroidCalculator getCalculator() {
return ((AndroidCalculator) Locator.getInstance().getCalculator());
}
private static void firstTimeInit(@Nonnull SharedPreferences preferences, @Nonnull Context context) { private static void firstTimeInit(@Nonnull SharedPreferences preferences, @Nonnull Context context) {
final Integer appOpenedCounter = Preferences.appOpenedCounter.getPreference(preferences); final Integer appOpenedCounter = Preferences.appOpenedCounter.getPreference(preferences);
if (appOpenedCounter != null) { if (appOpenedCounter != null) {
@ -200,6 +143,70 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
return result; return result;
} }
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
final Preferences.Gui.Layout layout = Preferences.Gui.layout.getPreferenceNoError(preferences);
ui.setLayoutId(layout.getLayoutId());
super.onCreate(savedInstanceState);
if (isMultiPane()) {
ui.addTab(this, CalculatorFragmentType.history, null, R.id.main_second_pane);
ui.addTab(this, CalculatorFragmentType.saved_history, null, R.id.main_second_pane);
ui.addTab(this, CalculatorFragmentType.variables, null, R.id.main_second_pane);
ui.addTab(this, CalculatorFragmentType.functions, null, R.id.main_second_pane);
ui.addTab(this, CalculatorFragmentType.operators, null, R.id.main_second_pane);
ui.addTab(this, CalculatorPlotActivity.getPlotterFragmentType(), null, R.id.main_second_pane);
} else {
final ActionBar actionBar = getSupportActionBar();
if (Build.VERSION.SDK_INT <= GINGERBREAD_MR1 || (Build.VERSION.SDK_INT >= ICE_CREAM_SANDWICH && hasPermanentMenuKey())) {
actionBar.hide();
} else {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
}
}
FragmentUtils.createFragment(this, CalculatorEditorFragment.class, R.id.editorContainer, "editor");
FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display");
FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
this.useBackAsPrev = Preferences.Gui.usePrevAsBack.getPreference(preferences);
if (savedInstanceState == null) {
firstTimeInit(preferences, this);
}
toggleOrientationChange(preferences);
preferences.registerOnSharedPreferenceChangeListener(this);
Locator.getInstance().getPreferenceService().checkPreferredPreferences(false);
if (CalculatorApplication.isMonkeyRunner(this)) {
Locator.getInstance().getKeyboard().buttonPressed("123");
Locator.getInstance().getKeyboard().buttonPressed("+");
Locator.getInstance().getKeyboard().buttonPressed("321");
}
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private boolean hasPermanentMenuKey() {
return ViewConfiguration.get(this).hasPermanentMenuKey();
}
private boolean isMultiPane() {
return findViewById(R.id.main_second_pane) != null;
}
@Nonnull
private AndroidCalculator getCalculator() {
return ((AndroidCalculator) Locator.getInstance().getCalculator());
}
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {

View File

@ -29,16 +29,20 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import android.support.v7.app.ActionBarActivity;
import jscl.math.Generic;
import org.solovyev.android.Android; import org.solovyev.android.Android;
import org.solovyev.android.calculator.about.CalculatorAboutActivity; import org.solovyev.android.calculator.about.CalculatorAboutActivity;
import org.solovyev.android.calculator.function.FunctionEditDialogFragment; import org.solovyev.android.calculator.function.FunctionEditDialogFragment;
import org.solovyev.android.calculator.history.CalculatorHistoryActivity; import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
import org.solovyev.android.calculator.math.edit.*; import org.solovyev.android.calculator.math.edit.CalculatorFunctionsActivity;
import org.solovyev.android.calculator.math.edit.CalculatorOperatorsActivity;
import org.solovyev.android.calculator.math.edit.CalculatorVarsActivity;
import org.solovyev.android.calculator.math.edit.CalculatorVarsFragment;
import org.solovyev.android.calculator.math.edit.VarEditDialogFragment;
import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity; import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity;
import org.solovyev.android.calculator.plot.CalculatorPlotActivity; import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
import org.solovyev.android.calculator.plot.CalculatorPlotter; import org.solovyev.android.calculator.plot.CalculatorPlotter;
@ -47,9 +51,12 @@ import org.solovyev.common.msg.Message;
import org.solovyev.common.msg.MessageType; import org.solovyev.common.msg.MessageType;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List;
import jscl.math.Generic;
/** /**
* User: serso * User: serso
@ -213,6 +220,19 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
} }
} }
public static void showEvaluationError(@Nonnull Context context, @Nonnull final String errorMessage) {
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final View errorMessageView = layoutInflater.inflate(R.layout.display_error_message, null);
((TextView) errorMessageView.findViewById(R.id.error_message_text_view)).setText(errorMessage);
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setPositiveButton(R.string.c_cancel, null)
.setView(errorMessageView);
builder.create().show();
}
@Override @Override
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) { public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
final Context context; final Context context;
@ -276,17 +296,4 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
} }
} }
public static void showEvaluationError(@Nonnull Context context, @Nonnull final String errorMessage) {
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final View errorMessageView = layoutInflater.inflate(R.layout.display_error_message, null);
((TextView) errorMessageView.findViewById(R.id.error_message_text_view)).setText(errorMessage);
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setPositiveButton(R.string.c_cancel, null)
.setView(errorMessageView);
builder.create().show();
}
} }

View File

@ -58,8 +58,8 @@ import javax.annotation.Nonnull;
formUri = "https://serso.cloudant.com/acra-cpp/_design/acra-storage/_update/report", formUri = "https://serso.cloudant.com/acra-cpp/_design/acra-storage/_update/report",
reportType = org.acra.sender.HttpSender.Type.JSON, reportType = org.acra.sender.HttpSender.Type.JSON,
httpMethod = org.acra.sender.HttpSender.Method.PUT, httpMethod = org.acra.sender.HttpSender.Method.PUT,
formUriBasicAuthLogin="timbeenterumisideffecird", formUriBasicAuthLogin = "timbeenterumisideffecird",
formUriBasicAuthPassword="ECL65PO2TH5quIFNAK4hQ5Ng", formUriBasicAuthPassword = "ECL65PO2TH5quIFNAK4hQ5Ng",
mode = ReportingInteractionMode.TOAST, mode = ReportingInteractionMode.TOAST,
resToastText = R.string.crashed) resToastText = R.string.crashed)
public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener { public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -72,15 +72,12 @@ public class CalculatorApplication extends android.app.Application implements Sh
********************************************************************** **********************************************************************
*/ */
@Nonnull
static final String MAIL = "se.solovyev@gmail.com";
private static final String TAG = "C++";
public static final String AD_FREE_PRODUCT_ID = "ad_free"; public static final String AD_FREE_PRODUCT_ID = "ad_free";
public static final String AD_FREE_P_KEY = "org.solovyev.android.calculator_ad_free"; public static final String AD_FREE_P_KEY = "org.solovyev.android.calculator_ad_free";
public static final String ADMOB = "ca-app-pub-2228934497384784/2916398892"; public static final String ADMOB = "ca-app-pub-2228934497384784/2916398892";
@Nonnull
static final String MAIL = "se.solovyev@gmail.com";
private static final String TAG = "C++";
@Nonnull @Nonnull
private static CalculatorApplication instance; private static CalculatorApplication instance;
@ -91,13 +88,10 @@ public class CalculatorApplication extends android.app.Application implements Sh
* *
********************************************************************** **********************************************************************
*/ */
@Nonnull
private final List<CalculatorEventListener> listeners = new ArrayList<CalculatorEventListener>();
@Nonnull @Nonnull
protected final Handler uiHandler = new Handler(); protected final Handler uiHandler = new Handler();
@Nonnull
private final List<CalculatorEventListener> listeners = new ArrayList<CalculatorEventListener>();
@Nonnull @Nonnull
private final Wizards wizards = new CalculatorWizards(this); private final Wizards wizards = new CalculatorWizards(this);
@ -123,6 +117,21 @@ public class CalculatorApplication extends android.app.Application implements Sh
********************************************************************** **********************************************************************
*/ */
@Nonnull
public static CalculatorApplication getInstance() {
return instance;
}
@Nonnull
public static SharedPreferences getPreferences() {
return PreferenceManager.getDefaultSharedPreferences(getInstance());
}
public static boolean isMonkeyRunner(@Nonnull Context context) {
// NOTE: this code is only for monkeyrunner
return context.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) == PackageManager.PERMISSION_GRANTED;
}
@Override @Override
public void onCreate() { public void onCreate() {
if (!BuildConfig.DEBUG) { if (!BuildConfig.DEBUG) {
@ -231,6 +240,14 @@ public class CalculatorApplication extends android.app.Application implements Sh
return new FragmentUi(layoutId, titleResId, listenersOnCreate); return new FragmentUi(layoutId, titleResId, listenersOnCreate);
} }
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
@Nonnull @Nonnull
public Handler getUiHandler() { public Handler getUiHandler() {
return uiHandler; return uiHandler;
@ -249,29 +266,6 @@ public class CalculatorApplication extends android.app.Application implements Sh
return typeFace; return typeFace;
} }
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
@Nonnull
public static CalculatorApplication getInstance() {
return instance;
}
@Nonnull
public static SharedPreferences getPreferences() {
return PreferenceManager.getDefaultSharedPreferences(getInstance());
}
public static boolean isMonkeyRunner(@Nonnull Context context) {
// NOTE: this code is only for monkeyrunner
return context.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) == PackageManager.PERMISSION_GRANTED;
}
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (Preferences.Onscreen.showAppIcon.getKey().equals(key)) { if (Preferences.Onscreen.showAppIcon.getKey().equals(key)) {

View File

@ -22,15 +22,19 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.content.Context;
import android.util.SparseArray; import android.util.SparseArray;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
import static org.solovyev.android.calculator.CalculatorSpecialButton.*; import static org.solovyev.android.calculator.CalculatorSpecialButton.cursor_left;
import static org.solovyev.android.calculator.CalculatorSpecialButton.cursor_right;
import static org.solovyev.android.calculator.CalculatorSpecialButton.functions_detached;
import static org.solovyev.android.calculator.CalculatorSpecialButton.history_detached;
import static org.solovyev.android.calculator.CalculatorSpecialButton.open_app;
import static org.solovyev.android.calculator.CalculatorSpecialButton.operators_detached;
import static org.solovyev.android.calculator.CalculatorSpecialButton.settings_detached;
import static org.solovyev.android.calculator.CalculatorSpecialButton.vars_detached;
/** /**
* User: serso * User: serso
@ -84,16 +88,13 @@ public enum CalculatorButton {
equals(R.id.cpp_button_equals, CalculatorSpecialButton.equals); equals(R.id.cpp_button_equals, CalculatorSpecialButton.equals);
private final int buttonId;
@Nonnull
private final String onClickText;
@Nullable
private final String onLongClickText;
@Nonnull @Nonnull
private static SparseArray<CalculatorButton> buttonsByIds = new SparseArray<>(); private static SparseArray<CalculatorButton> buttonsByIds = new SparseArray<>();
private final int buttonId;
@Nonnull
private final String onClickText;
@Nullable
private final String onLongClickText;
CalculatorButton(int buttonId, @Nonnull CalculatorSpecialButton onClickButton, @Nullable CalculatorSpecialButton onLongClickButton) { CalculatorButton(int buttonId, @Nonnull CalculatorSpecialButton onClickButton, @Nullable CalculatorSpecialButton onLongClickButton) {
this(buttonId, onClickButton.getActionCode(), onLongClickButton == null ? null : onLongClickButton.getActionCode()); this(buttonId, onClickButton.getActionCode(), onLongClickButton == null ? null : onLongClickButton.getActionCode());
@ -114,16 +115,6 @@ public enum CalculatorButton {
this(buttonId, onClickText, null); this(buttonId, onClickText, null);
} }
public void onLongClick() {
if (onLongClickText != null) {
Locator.getInstance().getKeyboard().buttonPressed(onLongClickText);
}
}
public void onClick() {
Locator.getInstance().getKeyboard().buttonPressed(onClickText);
}
@Nullable @Nullable
public static CalculatorButton getById(int buttonId) { public static CalculatorButton getById(int buttonId) {
initButtonsByIdsMap(); initButtonsByIdsMap();
@ -146,6 +137,16 @@ public enum CalculatorButton {
} }
} }
public void onLongClick() {
if (onLongClickText != null) {
Locator.getInstance().getKeyboard().buttonPressed(onLongClickText);
}
}
public void onClick() {
Locator.getInstance().getKeyboard().buttonPressed(onClickText);
}
public int getButtonId() { public int getButtonId() {
return buttonId; return buttonId;
} }

View File

@ -33,22 +33,23 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import jscl.AngleUnit;
import jscl.NumeralBase;
import org.solovyev.android.Views; import org.solovyev.android.Views;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import org.solovyev.android.calculator.view.AngleUnitsButton;
import org.solovyev.android.calculator.view.NumeralBasesButton;
import org.solovyev.android.calculator.drag.DragButton; import org.solovyev.android.calculator.drag.DragButton;
import org.solovyev.android.calculator.drag.DragDirection; import org.solovyev.android.calculator.drag.DragDirection;
import org.solovyev.android.calculator.drag.SimpleDragListener; import org.solovyev.android.calculator.drag.SimpleDragListener;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import org.solovyev.android.calculator.view.AngleUnitsButton;
import org.solovyev.android.calculator.view.NumeralBasesButton;
import org.solovyev.android.calculator.view.ScreenMetrics; import org.solovyev.android.calculator.view.ScreenMetrics;
import org.solovyev.common.math.Point2d; import org.solovyev.common.math.Point2d;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import jscl.AngleUnit;
import jscl.NumeralBase;
/** /**
* User: serso * User: serso
* Date: 9/28/12 * Date: 9/28/12
@ -123,6 +124,11 @@ public final class CalculatorButtons {
********************************************************************** **********************************************************************
*/ */
@Nonnull
private static CalculatorKeyboard getKeyboard() {
return Locator.getInstance().getKeyboard();
}
static class RoundBracketsDragProcessor implements SimpleDragListener.DragProcessor { static class RoundBracketsDragProcessor implements SimpleDragListener.DragProcessor {
@Nonnull @Nonnull
@ -144,11 +150,6 @@ public final class CalculatorButtons {
} }
} }
@Nonnull
private static CalculatorKeyboard getKeyboard() {
return Locator.getInstance().getKeyboard();
}
static class VarsDragProcessor implements SimpleDragListener.DragProcessor { static class VarsDragProcessor implements SimpleDragListener.DragProcessor {
@Nonnull @Nonnull

View File

@ -26,21 +26,20 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; import android.os.Parcelable;
import android.support.v7.app.ActionBarActivity;
import android.text.method.ScrollingMovementMethod; import android.text.method.ScrollingMovementMethod;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import android.support.v7.app.ActionBarActivity;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.solovyev.android.Android; import org.solovyev.android.Android;
import org.solovyev.android.fragments.FragmentUtils; import org.solovyev.android.fragments.FragmentUtils;
import org.solovyev.common.msg.MessageType; import org.solovyev.common.msg.MessageType;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/** /**
* User: serso * User: serso
* Date: 1/20/13 * Date: 1/20/13
@ -62,29 +61,6 @@ public class CalculatorDialogActivity extends ActionBarActivity {
context.startActivity(intent); context.startActivity(intent);
} }
@Override
protected void onCreate(@Nullable Bundle in) {
super.onCreate(in);
final DialogData dialogData = readDialogData(getIntent());
if (dialogData == null) {
Locator.getInstance().getLogger().error(TAG, "Dialog data is null!");
this.finish();
} else {
setContentView(R.layout.cpp_dialog);
final String title = dialogData.getTitle();
if (!Strings.isEmpty(title)) {
setTitle(title);
}
final Bundle args = new Bundle();
args.putParcelable(DIALOG_DATA_EXTRA, ParcelableDialogData.wrap(dialogData));
FragmentUtils.createFragment(this, CalculatorDialogFragment.class, R.id.dialog_layout, "dialog", args);
}
}
@Nullable @Nullable
private static DialogData readDialogData(@Nullable Intent in) { private static DialogData readDialogData(@Nullable Intent in) {
if (in != null) { if (in != null) {
@ -109,6 +85,29 @@ public class CalculatorDialogActivity extends ActionBarActivity {
return null; return null;
} }
@Override
protected void onCreate(@Nullable Bundle in) {
super.onCreate(in);
final DialogData dialogData = readDialogData(getIntent());
if (dialogData == null) {
Locator.getInstance().getLogger().error(TAG, "Dialog data is null!");
this.finish();
} else {
setContentView(R.layout.cpp_dialog);
final String title = dialogData.getTitle();
if (!Strings.isEmpty(title)) {
setTitle(title);
}
final Bundle args = new Bundle();
args.putParcelable(DIALOG_DATA_EXTRA, ParcelableDialogData.wrap(dialogData));
FragmentUtils.createFragment(this, CalculatorDialogFragment.class, R.id.dialog_layout, "dialog", args);
}
}
public static class CalculatorDialogFragment extends CalculatorFragment { public static class CalculatorDialogFragment extends CalculatorFragment {
public CalculatorDialogFragment() { public CalculatorDialogFragment() {

View File

@ -25,12 +25,11 @@ package org.solovyev.android.calculator;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.support.v4.app.Fragment;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
/** /**

View File

@ -23,7 +23,7 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.content.Context; import android.content.Context;
import jscl.math.Generic;
import org.solovyev.android.calculator.jscl.JsclOperation; import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.calculator.plot.CalculatorPlotter; import org.solovyev.android.calculator.plot.CalculatorPlotter;
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog; import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
@ -31,6 +31,8 @@ import org.solovyev.android.menu.LabeledMenuItem;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import jscl.math.Generic;
/** /**
* User: Solovyev_S * User: Solovyev_S
* Date: 21.09.12 * Date: 21.09.12

View File

@ -25,14 +25,14 @@ package org.solovyev.android.calculator;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.view.View; import android.view.View;
import javax.annotation.Nonnull;
import org.solovyev.android.menu.ContextMenuBuilder; import org.solovyev.android.menu.ContextMenuBuilder;
import org.solovyev.android.menu.ListContextMenu; import org.solovyev.android.menu.ListContextMenu;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
/** /**
* User: Solovyev_S * User: Solovyev_S
* Date: 21.09.12 * Date: 21.09.12

View File

@ -27,7 +27,13 @@ import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.*; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import org.solovyev.android.menu.ActivityMenu; import org.solovyev.android.menu.ActivityMenu;
import org.solovyev.android.menu.AndroidMenuHelper; import org.solovyev.android.menu.AndroidMenuHelper;
import org.solovyev.android.menu.ListActivityMenu; import org.solovyev.android.menu.ListActivityMenu;

View File

@ -24,12 +24,11 @@ package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.support.v4.app.Fragment;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
/** /**

View File

@ -69,11 +69,9 @@ public enum CalculatorFragmentType {
matrix_edit(CalculatorMatrixEditFragment.class, R.layout.matrix_edit_fragment, R.string.c_release_notes), matrix_edit(CalculatorMatrixEditFragment.class, R.layout.matrix_edit_fragment, R.string.c_release_notes),
release_notes(CalculatorReleaseNotesFragment.class, R.layout.release_notes_fragment, R.string.c_release_notes); release_notes(CalculatorReleaseNotesFragment.class, R.layout.release_notes_fragment, R.string.c_release_notes);
private final int defaultLayoutId;
@Nonnull @Nonnull
private Class<? extends Fragment> fragmentClass; private Class<? extends Fragment> fragmentClass;
private final int defaultLayoutId;
private int defaultTitleResId; private int defaultTitleResId;
private CalculatorFragmentType(@Nonnull Class<? extends Fragment> fragmentClass, private CalculatorFragmentType(@Nonnull Class<? extends Fragment> fragmentClass,

View File

@ -24,10 +24,10 @@ package org.solovyev.android.calculator;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.support.v4.app.Fragment;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;

View File

@ -24,12 +24,11 @@ package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.support.v4.app.ListFragment;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
/** /**

View File

@ -25,14 +25,13 @@ package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import javax.annotation.Nonnull;
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog; import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
import org.solovyev.android.menu.LabeledMenuItem; import org.solovyev.android.menu.LabeledMenuItem;
import javax.annotation.Nonnull;
/** /**
* User: serso * User: serso
* Date: 4/23/12 * Date: 4/23/12

View File

@ -11,6 +11,14 @@ public final class CalculatorReceiver extends BroadcastReceiver {
public static final String ACTION_BUTTON_ID_EXTRA = "buttonId"; public static final String ACTION_BUTTON_ID_EXTRA = "buttonId";
public static final String ACTION_BUTTON_PRESSED = "org.solovyev.android.calculator.BUTTON_PRESSED"; public static final String ACTION_BUTTON_PRESSED = "org.solovyev.android.calculator.BUTTON_PRESSED";
@Nonnull
public static Intent newButtonClickedIntent(@Nonnull Context context, @Nonnull CalculatorButton button) {
final Intent intent = new Intent(context, CalculatorReceiver.class);
intent.setAction(ACTION_BUTTON_PRESSED);
intent.putExtra(ACTION_BUTTON_ID_EXTRA, button.getButtonId());
return intent;
}
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
final String action = intent.getAction(); final String action = intent.getAction();
@ -24,12 +32,4 @@ public final class CalculatorReceiver extends BroadcastReceiver {
} }
} }
} }
@Nonnull
public static Intent newButtonClickedIntent(@Nonnull Context context, @Nonnull CalculatorButton button) {
final Intent intent = new Intent(context, CalculatorReceiver.class);
intent.setAction(ACTION_BUTTON_PRESSED);
intent.putExtra(ACTION_BUTTON_ID_EXTRA, button.getButtonId());
return intent;
}
} }

View File

@ -22,11 +22,11 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import org.solovyev.common.JPredicate;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.solovyev.common.JPredicate;
/** /**
* User: serso * User: serso
* Date: 10/3/11 * Date: 10/3/11
@ -34,10 +34,9 @@ import org.solovyev.common.JPredicate;
*/ */
public class CharacterAtPositionFinder implements JPredicate<Character> { public class CharacterAtPositionFinder implements JPredicate<Character> {
private int i;
@Nonnull @Nonnull
private final String targetString; private final String targetString;
private int i;
public CharacterAtPositionFinder(@Nonnull String targetString, int i) { public CharacterAtPositionFinder(@Nonnull String targetString, int i) {
this.targetString = targetString; this.targetString = targetString;

View File

@ -23,14 +23,15 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.content.Context; import android.content.Context;
import jscl.NumeralBase;
import jscl.math.Generic;
import javax.annotation.Nonnull;
import org.solovyev.android.calculator.jscl.JsclOperation; import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.menu.AMenuItem; import org.solovyev.android.menu.AMenuItem;
import javax.annotation.Nonnull;
import jscl.NumeralBase;
import jscl.math.Generic;
/** /**
* User: serso * User: serso
* Date: 9/21/12 * Date: 9/21/12

View File

@ -23,6 +23,7 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.view.MotionEvent; import android.view.MotionEvent;
import org.solovyev.android.calculator.drag.DirectionDragButton; import org.solovyev.android.calculator.drag.DirectionDragButton;
import org.solovyev.android.calculator.drag.DragButton; import org.solovyev.android.calculator.drag.DragButton;
import org.solovyev.android.calculator.drag.DragDirection; import org.solovyev.android.calculator.drag.DragDirection;

View File

@ -23,6 +23,7 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.view.MotionEvent; import android.view.MotionEvent;
import org.solovyev.android.calculator.drag.DirectionDragButton; import org.solovyev.android.calculator.drag.DirectionDragButton;
import org.solovyev.android.calculator.drag.DragButton; import org.solovyev.android.calculator.drag.DragButton;
import org.solovyev.android.calculator.drag.DragDirection; import org.solovyev.android.calculator.drag.DragDirection;

View File

@ -24,14 +24,14 @@ package org.solovyev.android.calculator;
import android.view.MotionEvent; import android.view.MotionEvent;
import javax.annotation.Nonnull;
import org.solovyev.android.calculator.drag.DirectionDragButton; import org.solovyev.android.calculator.drag.DirectionDragButton;
import org.solovyev.android.calculator.drag.DragButton; import org.solovyev.android.calculator.drag.DragButton;
import org.solovyev.android.calculator.drag.DragDirection; import org.solovyev.android.calculator.drag.DragDirection;
import org.solovyev.android.calculator.drag.SimpleDragListener; import org.solovyev.android.calculator.drag.SimpleDragListener;
import org.solovyev.common.math.Point2d; import org.solovyev.common.math.Point2d;
import javax.annotation.Nonnull;
/** /**
* User: serso * User: serso
* Date: 10/24/11 * Date: 10/24/11

View File

@ -24,6 +24,7 @@ package org.solovyev.android.calculator;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import org.solovyev.common.msg.Message; import org.solovyev.common.msg.Message;
import org.solovyev.common.msg.MessageType; import org.solovyev.common.msg.MessageType;
@ -48,22 +49,10 @@ public class FixableMessage implements Parcelable {
return new FixableMessage[size]; return new FixableMessage[size];
} }
}; };
@Nonnull
private static FixableMessage fromParcel(@Nonnull Parcel in) {
final String message = in.readString();
final MessageType messageType = (MessageType) in.readSerializable();
final FixableError fixableError = (FixableError) in.readSerializable();
return new FixableMessage(message, messageType, fixableError);
}
@Nonnull @Nonnull
private final String message; private final String message;
@Nonnull @Nonnull
private final MessageType messageType; private final MessageType messageType;
@Nullable @Nullable
private final FixableError fixableError; private final FixableError fixableError;
@ -82,6 +71,15 @@ public class FixableMessage implements Parcelable {
this.fixableError = fixableError; this.fixableError = fixableError;
} }
@Nonnull
private static FixableMessage fromParcel(@Nonnull Parcel in) {
final String message = in.readString();
final MessageType messageType = (MessageType) in.readSerializable();
final FixableError fixableError = (FixableError) in.readSerializable();
return new FixableMessage(message, messageType, fixableError);
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;

View File

@ -36,14 +36,16 @@ import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.TextView; import android.widget.TextView;
import org.solovyev.common.msg.Message; import org.solovyev.common.msg.Message;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
/** /**
* User: serso * User: serso
* Date: 11/17/12 * Date: 11/17/12
@ -59,6 +61,32 @@ public class FixableMessagesDialog extends ActionBarActivity {
public FixableMessagesDialog() { public FixableMessagesDialog() {
} }
public static void showDialogForMessages(@Nonnull List<Message> messages,
@Nonnull Context context,
boolean showCheckbox) {
if (!messages.isEmpty()) {
final Intent intent = new Intent(context, FixableMessagesDialog.class);
intent.putExtra(INPUT, Input.fromMessages(messages, showCheckbox));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
public static void showDialog(@Nonnull List<FixableMessage> messages,
@Nonnull Context context,
boolean showCheckbox) {
if (!messages.isEmpty()) {
final Intent intent = new Intent(context, FixableMessagesDialog.class);
intent.putExtra(INPUT, new Input(messages, showCheckbox));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -99,6 +127,14 @@ public class FixableMessagesDialog extends ActionBarActivity {
} }
} }
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
private void onInputChanged() { private void onInputChanged() {
final ViewGroup viewGroup = (ViewGroup) findViewById(R.id.cpp_fixable_messages_container); final ViewGroup viewGroup = (ViewGroup) findViewById(R.id.cpp_fixable_messages_container);
viewGroup.removeAllViews(); viewGroup.removeAllViews();
@ -139,40 +175,6 @@ public class FixableMessagesDialog extends ActionBarActivity {
parseIntent(intent); parseIntent(intent);
} }
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
public static void showDialogForMessages(@Nonnull List<Message> messages,
@Nonnull Context context,
boolean showCheckbox) {
if (!messages.isEmpty()) {
final Intent intent = new Intent(context, FixableMessagesDialog.class);
intent.putExtra(INPUT, Input.fromMessages(messages, showCheckbox));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
public static void showDialog(@Nonnull List<FixableMessage> messages,
@Nonnull Context context,
boolean showCheckbox) {
if (!messages.isEmpty()) {
final Intent intent = new Intent(context, FixableMessagesDialog.class);
intent.putExtra(INPUT, new Input(messages, showCheckbox));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
private static final class Input implements Parcelable { private static final class Input implements Parcelable {
public static final Creator<Input> CREATOR = new Creator<Input>() { public static final Creator<Input> CREATOR = new Creator<Input>() {
@ -186,6 +188,14 @@ public class FixableMessagesDialog extends ActionBarActivity {
return new Input[size]; return new Input[size];
} }
}; };
@Nonnull
private List<FixableMessage> messages = new ArrayList<FixableMessage>();
private boolean showCheckbox;
private Input(@Nonnull List<FixableMessage> messages, boolean showCheckbox) {
this.messages = messages;
this.showCheckbox = showCheckbox;
}
@Nonnull @Nonnull
private static Input fromParcel(@Nonnull Parcel in) { private static Input fromParcel(@Nonnull Parcel in) {
@ -195,15 +205,14 @@ public class FixableMessagesDialog extends ActionBarActivity {
return new Input(messages, showCheckbox); return new Input(messages, showCheckbox);
} }
@Nonnull @Nonnull
private List<FixableMessage> messages = new ArrayList<FixableMessage>(); public static Input fromMessages(@Nonnull List<Message> messages, boolean showCheckbox) {
final List<FixableMessage> stringMessages = new ArrayList<FixableMessage>(messages.size());
for (Message message : messages) {
stringMessages.add(new FixableMessage(message));
}
private boolean showCheckbox; return new Input(stringMessages, showCheckbox);
private Input(@Nonnull List<FixableMessage> messages, boolean showCheckbox) {
this.messages = messages;
this.showCheckbox = showCheckbox;
} }
@Nonnull @Nonnull
@ -222,16 +231,6 @@ public class FixableMessagesDialog extends ActionBarActivity {
out.writeTypedList(messages); out.writeTypedList(messages);
} }
@Nonnull
public static Input fromMessages(@Nonnull List<Message> messages, boolean showCheckbox) {
final List<FixableMessage> stringMessages = new ArrayList<FixableMessage>(messages.size());
for (Message message : messages) {
stringMessages.add(new FixableMessage(message));
}
return new Input(stringMessages, showCheckbox);
}
public boolean isShowCheckbox() { public boolean isShowCheckbox() {
return showCheckbox; return showCheckbox;
} }

View File

@ -27,7 +27,6 @@ import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.TextView; import android.widget.TextView;
import org.solovyev.android.checkout.ActivityCheckout; import org.solovyev.android.checkout.ActivityCheckout;
@ -125,7 +124,7 @@ public class FragmentUi extends BaseUi {
} }
private void updateAdViewState() { private void updateAdViewState() {
if(adFree == null || adView == null) { if (adFree == null || adView == null) {
return; return;
} }

View File

@ -24,11 +24,10 @@ package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import jscl.NumeralBase;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine; import jscl.NumeralBase;
import static jscl.NumeralBase.hex; import static jscl.NumeralBase.hex;
import static org.solovyev.android.calculator.Preferences.Gui.hideNumeralBaseDigits; import static org.solovyev.android.calculator.Preferences.Gui.hideNumeralBaseDigits;

View File

@ -24,6 +24,7 @@ package org.solovyev.android.calculator;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import org.solovyev.common.msg.MessageLevel; import org.solovyev.common.msg.MessageLevel;
import org.solovyev.common.msg.MessageType; import org.solovyev.common.msg.MessageType;

View File

@ -61,265 +61,12 @@ import static org.solovyev.android.DeviceModel.samsung_galaxy_s_2;
public final class Preferences { public final class Preferences {
public static final Preference<Integer> appVersion = IntegerPreference.of("application.version", -1);
public static final Preference<Integer> appOpenedCounter = IntegerPreference.of("app_opened_counter", 0);
private Preferences() { private Preferences() {
throw new AssertionError(); throw new AssertionError();
} }
public static final Preference<Integer> appVersion = IntegerPreference.of("application.version", -1);
public static final Preference<Integer> appOpenedCounter = IntegerPreference.of("app_opened_counter", 0);
public enum SimpleTheme {
default_theme(0, 0, null),
metro_blue_theme(R.layout.onscreen_layout, R.layout.widget_layout, Gui.Theme.metro_blue_theme),
material_theme(R.layout.onscreen_layout_material, R.layout.widget_layout_material, Gui.Theme.material_theme),
material_light_theme(R.layout.onscreen_layout_material_light, R.layout.widget_layout_material_light, Gui.Theme.material_light_theme);
@LayoutRes
private final int onscreenLayout;
@LayoutRes
private final int widgetLayout;
@Nullable
private final Gui.Theme appTheme;
@Nonnull
private final Map<Gui.Theme, SimpleTheme> cache = new EnumMap<>(Gui.Theme.class);
SimpleTheme(int onscreenLayout, int widgetLayout, @Nullable Gui.Theme appTheme) {
this.onscreenLayout = onscreenLayout;
this.widgetLayout = widgetLayout;
this.appTheme = appTheme;
}
public int getOnscreenLayout(@Nonnull Gui.Theme appTheme) {
return resolveThemeFor(appTheme).onscreenLayout;
}
public int getWidgetLayout(@Nonnull Gui.Theme appTheme) {
return resolveThemeFor(appTheme).widgetLayout;
}
@Nonnull
public SimpleTheme resolveThemeFor(@Nonnull Gui.Theme appTheme) {
if (this == default_theme) {
SimpleTheme theme = cache.get(appTheme);
if (theme == null) {
theme = lookUpThemeFor(appTheme);
cache.put(appTheme, theme);
}
return theme;
}
return this;
}
@Nonnull
private SimpleTheme lookUpThemeFor(@Nonnull Gui.Theme appTheme) {
Check.isTrue(this == default_theme);
// find direct match
for (SimpleTheme theme : values()) {
if (theme.appTheme == appTheme) {
return theme;
}
}
// for metro themes return metro theme
if (appTheme == Gui.Theme.metro_green_theme || appTheme == Gui.Theme.metro_purple_theme) {
return metro_blue_theme;
}
// for old themes return dark material
return material_theme;
}
@Nullable
public Gui.Theme getAppTheme() {
return appTheme;
}
}
public static class Widget {
public static final Preference<SimpleTheme> theme = StringPreference.ofEnum("widget.theme", SimpleTheme.default_theme, SimpleTheme.class);
@Nonnull
public static SimpleTheme getTheme(@Nonnull SharedPreferences preferences) {
return theme.getPreferenceNoError(preferences);
}
}
public static class Onscreen {
public static final Preference<Boolean> startOnBoot = BooleanPreference.of("onscreen_start_on_boot", false);
public static final Preference<Boolean> showAppIcon = BooleanPreference.of("onscreen_show_app_icon", true);
public static final Preference<SimpleTheme> theme = StringPreference.ofEnum("onscreen.theme", SimpleTheme.default_theme, SimpleTheme.class);
@Nonnull
public static SimpleTheme getTheme(@Nonnull SharedPreferences preferences) {
return theme.getPreferenceNoError(preferences);
}
}
public static class Calculations {
public static final Preference<Boolean> calculateOnFly = BooleanPreference.of("calculations_calculate_on_fly", true);
public static final Preference<Boolean> showCalculationMessagesDialog = BooleanPreference.of("show_calculation_messages_dialog", true);
public static final Preference<NumeralBase> preferredNumeralBase = StringPreference.ofEnum("preferred_numeral_base", AndroidCalculatorEngine.Preferences.numeralBase.getDefaultValue(), NumeralBase.class);
public static final Preference<AngleUnit> preferredAngleUnits = StringPreference.ofEnum("preferred_angle_units", AndroidCalculatorEngine.Preferences.angleUnit.getDefaultValue(), AngleUnit.class);
public static final Preference<Long> lastPreferredPreferencesCheck = LongPreference.of("preferred_preferences_check_time", 0L);
}
public static class Ga {
public static final Preference<Boolean> initialReportDone = BooleanPreference.of("ga.initial_report_done", false);
}
public static class Gui {
public static final Preference<Theme> theme = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Theme.material_theme, Theme.class);
public static final Preference<Layout> layout = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Layout.simple, Layout.class);
public static final Preference<String> language = StringPreference.of("gui.language", Languages.SYSTEM_LANGUAGE_CODE);
public static final Preference<Boolean> feedbackWindowShown = BooleanPreference.of("feedback_window_shown", false);
public static final Preference<Boolean> showReleaseNotes = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true);
public static final Preference<Boolean> usePrevAsBack = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false);
public static final Preference<Boolean> showEqualsButton = BooleanPreference.of("showEqualsButton", true);
public static final Preference<Boolean> autoOrientation = BooleanPreference.of("autoOrientation", true);
public static final Preference<Boolean> hideNumeralBaseDigits = BooleanPreference.of("hideNumeralBaseDigits", true);
public static final Preference<Boolean> preventScreenFromFading = BooleanPreference.of("preventScreenFromFading", true);
public static final Preference<Boolean> colorDisplay = BooleanPreference.of("org.solovyev.android.calculator.CalculatorModel_color_display", true);
public static final Preference<Long> hapticFeedback = NumberToStringPreference.of("hapticFeedback", 60L, Long.class);
private static final Preference<Boolean> hapticFeedbackEnabled = BooleanPreference.of("org.solovyev.android.calculator.CalculatorModel_haptic_feedback", false);
private static final Preference<Long> hapticFeedbackDuration = NumberToStringPreference.of("org.solovyev.android.calculator.CalculatorActivity_calc_haptic_feedback_duration_key", 60L, Long.class);
@Nonnull
public static Theme getTheme(@Nonnull SharedPreferences preferences) {
return theme.getPreferenceNoError(preferences);
}
@Nonnull
public static Layout getLayout(@Nonnull SharedPreferences preferences) {
return layout.getPreferenceNoError(preferences);
}
public enum Theme {
default_theme(R.style.Cpp_Theme_Gray),
violet_theme(R.style.Cpp_Theme_Violet),
light_blue_theme(R.style.Cpp_Theme_Blue),
metro_blue_theme(R.style.cpp_metro_blue_theme),
metro_purple_theme(R.style.cpp_metro_purple_theme),
metro_green_theme(R.style.cpp_metro_green_theme),
material_theme(R.style.Cpp_Theme_Material),
material_light_theme(R.style.Cpp_Theme_Material_Light, R.style.Cpp_Theme_Wizard_Light, R.style.Cpp_Theme_Dialog_Material_Light),
;
private static final SparseArray<TextColor> textColors = new SparseArray<>();
private final int themeId;
private final int wizardThemeId;
private final int dialogThemeId;
Theme(@StyleRes int themeId) {
this(themeId, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Dialog_Material);
}
Theme(@StyleRes int themeId, @StyleRes int wizardThemeId, int dialogThemeId) {
this.themeId = themeId;
this.wizardThemeId = wizardThemeId;
this.dialogThemeId = dialogThemeId;
}
public int getThemeId() {
return getThemeId(null);
}
public int getThemeId(@Nullable Context context) {
if (context instanceof WizardActivity) {
return wizardThemeId;
}
if (context instanceof PurchaseDialogActivity) {
return dialogThemeId;
}
return themeId;
}
@Nonnull
public TextColor getTextColor(@Nonnull Context context) {
final int themeId = getThemeId(context);
TextColor textColor = textColors.get(themeId);
if (textColor == null) {
final ContextThemeWrapper themeContext = new ContextThemeWrapper(context, themeId);
final TypedArray a = themeContext.obtainStyledAttributes(themeId, new int[]{R.attr.cpp_text_color, R.attr.cpp_text_color_error});
final int normal = a.getColor(0, Color.BLACK);
final int error = a.getColor(1, Color.WHITE);
a.recycle();
textColor = new TextColor(normal, error);
textColors.append(themeId, textColor);
}
return textColor;
}
public boolean isLight() {
return themeId == R.style.Cpp_Theme_Material_Light;
}
}
public static final class TextColor {
public final int normal;
public final int error;
TextColor(int normal, int error) {
this.normal = normal;
this.error = error;
}
}
public static enum Layout {
main_calculator(R.layout.main_calculator, R.string.p_layout_calculator, true),
main_calculator_mobile(R.layout.main_calculator_mobile, R.string.p_layout_calculator_mobile, false),
// not used anymore
@Deprecated
main_cellphone(R.layout.main_calculator, 0, true),
simple(R.layout.main_calculator, R.string.p_layout_simple, true),
simple_mobile(R.layout.main_calculator_mobile, R.string.p_layout_simple_mobile, false);
private final int layoutId;
private final int nameResId;
private final boolean optimized;
Layout(int layoutId, int nameResId, boolean optimized) {
this.layoutId = layoutId;
this.nameResId = nameResId;
this.optimized = optimized;
}
public int getLayoutId() {
return layoutId;
}
public int getNameResId() {
return nameResId;
}
public boolean isOptimized() {
return optimized;
}
}
}
public static class Graph {
public static final Preference<Boolean> plotImag = BooleanPreference.of("graph_plot_imag", false);
}
public static class History {
public static final Preference<Boolean> showIntermediateCalculations = BooleanPreference.of("history_show_intermediate_calculations", false);
public static final Preference<Boolean> showDatetime = BooleanPreference.of("history_show_datetime", true);
}
static void setDefaultValues(@Nonnull SharedPreferences preferences) { static void setDefaultValues(@Nonnull SharedPreferences preferences) {
if (!AndroidCalculatorEngine.Preferences.groupingSeparator.isSet(preferences)) { if (!AndroidCalculatorEngine.Preferences.groupingSeparator.isSet(preferences)) {
@ -404,4 +151,255 @@ public final class Preferences {
preference.tryPutDefault(preferences); preference.tryPutDefault(preferences);
} }
public enum SimpleTheme {
default_theme(0, 0, null),
metro_blue_theme(R.layout.onscreen_layout, R.layout.widget_layout, Gui.Theme.metro_blue_theme),
material_theme(R.layout.onscreen_layout_material, R.layout.widget_layout_material, Gui.Theme.material_theme),
material_light_theme(R.layout.onscreen_layout_material_light, R.layout.widget_layout_material_light, Gui.Theme.material_light_theme);
@LayoutRes
private final int onscreenLayout;
@LayoutRes
private final int widgetLayout;
@Nullable
private final Gui.Theme appTheme;
@Nonnull
private final Map<Gui.Theme, SimpleTheme> cache = new EnumMap<>(Gui.Theme.class);
SimpleTheme(int onscreenLayout, int widgetLayout, @Nullable Gui.Theme appTheme) {
this.onscreenLayout = onscreenLayout;
this.widgetLayout = widgetLayout;
this.appTheme = appTheme;
}
public int getOnscreenLayout(@Nonnull Gui.Theme appTheme) {
return resolveThemeFor(appTheme).onscreenLayout;
}
public int getWidgetLayout(@Nonnull Gui.Theme appTheme) {
return resolveThemeFor(appTheme).widgetLayout;
}
@Nonnull
public SimpleTheme resolveThemeFor(@Nonnull Gui.Theme appTheme) {
if (this == default_theme) {
SimpleTheme theme = cache.get(appTheme);
if (theme == null) {
theme = lookUpThemeFor(appTheme);
cache.put(appTheme, theme);
}
return theme;
}
return this;
}
@Nonnull
private SimpleTheme lookUpThemeFor(@Nonnull Gui.Theme appTheme) {
Check.isTrue(this == default_theme);
// find direct match
for (SimpleTheme theme : values()) {
if (theme.appTheme == appTheme) {
return theme;
}
}
// for metro themes return metro theme
if (appTheme == Gui.Theme.metro_green_theme || appTheme == Gui.Theme.metro_purple_theme) {
return metro_blue_theme;
}
// for old themes return dark material
return material_theme;
}
@Nullable
public Gui.Theme getAppTheme() {
return appTheme;
}
}
public static class Widget {
public static final Preference<SimpleTheme> theme = StringPreference.ofEnum("widget.theme", SimpleTheme.default_theme, SimpleTheme.class);
@Nonnull
public static SimpleTheme getTheme(@Nonnull SharedPreferences preferences) {
return theme.getPreferenceNoError(preferences);
}
}
public static class Onscreen {
public static final Preference<Boolean> startOnBoot = BooleanPreference.of("onscreen_start_on_boot", false);
public static final Preference<Boolean> showAppIcon = BooleanPreference.of("onscreen_show_app_icon", true);
public static final Preference<SimpleTheme> theme = StringPreference.ofEnum("onscreen.theme", SimpleTheme.default_theme, SimpleTheme.class);
@Nonnull
public static SimpleTheme getTheme(@Nonnull SharedPreferences preferences) {
return theme.getPreferenceNoError(preferences);
}
}
public static class Calculations {
public static final Preference<Boolean> calculateOnFly = BooleanPreference.of("calculations_calculate_on_fly", true);
public static final Preference<Boolean> showCalculationMessagesDialog = BooleanPreference.of("show_calculation_messages_dialog", true);
public static final Preference<NumeralBase> preferredNumeralBase = StringPreference.ofEnum("preferred_numeral_base", AndroidCalculatorEngine.Preferences.numeralBase.getDefaultValue(), NumeralBase.class);
public static final Preference<AngleUnit> preferredAngleUnits = StringPreference.ofEnum("preferred_angle_units", AndroidCalculatorEngine.Preferences.angleUnit.getDefaultValue(), AngleUnit.class);
public static final Preference<Long> lastPreferredPreferencesCheck = LongPreference.of("preferred_preferences_check_time", 0L);
}
public static class Ga {
public static final Preference<Boolean> initialReportDone = BooleanPreference.of("ga.initial_report_done", false);
}
public static class Gui {
public static final Preference<Theme> theme = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Theme.material_theme, Theme.class);
public static final Preference<Layout> layout = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Layout.simple, Layout.class);
public static final Preference<String> language = StringPreference.of("gui.language", Languages.SYSTEM_LANGUAGE_CODE);
public static final Preference<Boolean> feedbackWindowShown = BooleanPreference.of("feedback_window_shown", false);
public static final Preference<Boolean> showReleaseNotes = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true);
public static final Preference<Boolean> usePrevAsBack = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false);
public static final Preference<Boolean> showEqualsButton = BooleanPreference.of("showEqualsButton", true);
public static final Preference<Boolean> autoOrientation = BooleanPreference.of("autoOrientation", true);
public static final Preference<Boolean> hideNumeralBaseDigits = BooleanPreference.of("hideNumeralBaseDigits", true);
public static final Preference<Boolean> preventScreenFromFading = BooleanPreference.of("preventScreenFromFading", true);
public static final Preference<Boolean> colorDisplay = BooleanPreference.of("org.solovyev.android.calculator.CalculatorModel_color_display", true);
public static final Preference<Long> hapticFeedback = NumberToStringPreference.of("hapticFeedback", 60L, Long.class);
private static final Preference<Boolean> hapticFeedbackEnabled = BooleanPreference.of("org.solovyev.android.calculator.CalculatorModel_haptic_feedback", false);
private static final Preference<Long> hapticFeedbackDuration = NumberToStringPreference.of("org.solovyev.android.calculator.CalculatorActivity_calc_haptic_feedback_duration_key", 60L, Long.class);
@Nonnull
public static Theme getTheme(@Nonnull SharedPreferences preferences) {
return theme.getPreferenceNoError(preferences);
}
@Nonnull
public static Layout getLayout(@Nonnull SharedPreferences preferences) {
return layout.getPreferenceNoError(preferences);
}
public enum Theme {
default_theme(R.style.Cpp_Theme_Gray),
violet_theme(R.style.Cpp_Theme_Violet),
light_blue_theme(R.style.Cpp_Theme_Blue),
metro_blue_theme(R.style.cpp_metro_blue_theme),
metro_purple_theme(R.style.cpp_metro_purple_theme),
metro_green_theme(R.style.cpp_metro_green_theme),
material_theme(R.style.Cpp_Theme_Material),
material_light_theme(R.style.Cpp_Theme_Material_Light, R.style.Cpp_Theme_Wizard_Light, R.style.Cpp_Theme_Dialog_Material_Light),;
private static final SparseArray<TextColor> textColors = new SparseArray<>();
private final int themeId;
private final int wizardThemeId;
private final int dialogThemeId;
Theme(@StyleRes int themeId) {
this(themeId, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Dialog_Material);
}
Theme(@StyleRes int themeId, @StyleRes int wizardThemeId, int dialogThemeId) {
this.themeId = themeId;
this.wizardThemeId = wizardThemeId;
this.dialogThemeId = dialogThemeId;
}
public int getThemeId() {
return getThemeId(null);
}
public int getThemeId(@Nullable Context context) {
if (context instanceof WizardActivity) {
return wizardThemeId;
}
if (context instanceof PurchaseDialogActivity) {
return dialogThemeId;
}
return themeId;
}
@Nonnull
public TextColor getTextColor(@Nonnull Context context) {
final int themeId = getThemeId(context);
TextColor textColor = textColors.get(themeId);
if (textColor == null) {
final ContextThemeWrapper themeContext = new ContextThemeWrapper(context, themeId);
final TypedArray a = themeContext.obtainStyledAttributes(themeId, new int[]{R.attr.cpp_text_color, R.attr.cpp_text_color_error});
final int normal = a.getColor(0, Color.BLACK);
final int error = a.getColor(1, Color.WHITE);
a.recycle();
textColor = new TextColor(normal, error);
textColors.append(themeId, textColor);
}
return textColor;
}
public boolean isLight() {
return themeId == R.style.Cpp_Theme_Material_Light;
}
}
public static enum Layout {
main_calculator(R.layout.main_calculator, R.string.p_layout_calculator, true),
main_calculator_mobile(R.layout.main_calculator_mobile, R.string.p_layout_calculator_mobile, false),
// not used anymore
@Deprecated
main_cellphone(R.layout.main_calculator, 0, true),
simple(R.layout.main_calculator, R.string.p_layout_simple, true),
simple_mobile(R.layout.main_calculator_mobile, R.string.p_layout_simple_mobile, false);
private final int layoutId;
private final int nameResId;
private final boolean optimized;
Layout(int layoutId, int nameResId, boolean optimized) {
this.layoutId = layoutId;
this.nameResId = nameResId;
this.optimized = optimized;
}
public int getLayoutId() {
return layoutId;
}
public int getNameResId() {
return nameResId;
}
public boolean isOptimized() {
return optimized;
}
}
public static final class TextColor {
public final int normal;
public final int error;
TextColor(int normal, int error) {
this.normal = normal;
this.error = error;
}
}
}
public static class Graph {
public static final Preference<Boolean> plotImag = BooleanPreference.of("graph_plot_imag", false);
}
public static class History {
public static final Preference<Boolean> showIntermediateCalculations = BooleanPreference.of("history_show_intermediate_calculations", false);
public static final Preference<Boolean> showDatetime = BooleanPreference.of("history_show_datetime", true);
}
} }

View File

@ -23,8 +23,9 @@
package org.solovyev.android.calculator.about; package org.solovyev.android.calculator.about;
import android.os.Bundle; import android.os.Bundle;
import org.solovyev.android.calculator.EmptyActivity;
import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.EmptyActivity;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import javax.annotation.Nullable; import javax.annotation.Nullable;

View File

@ -27,6 +27,7 @@ import android.text.method.LinkMovementMethod;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.CalculatorFragment; import org.solovyev.android.calculator.CalculatorFragment;
import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.CalculatorFragmentType;
@ -60,7 +61,7 @@ public class CalculatorAboutFragment extends CalculatorFragment {
final TextView translatorsTextTextView = (TextView) root.findViewById(R.id.cpp_about_translators_text); final TextView translatorsTextTextView = (TextView) root.findViewById(R.id.cpp_about_translators_text);
final TextView translatorsTextView = (TextView) root.findViewById(R.id.cpp_about_translators); final TextView translatorsTextView = (TextView) root.findViewById(R.id.cpp_about_translators);
if(isEmpty(translatorsTextView.getText())) { if (isEmpty(translatorsTextView.getText())) {
translatorsTextTextView.setVisibility(GONE); translatorsTextTextView.setVisibility(GONE);
translatorsTextView.setVisibility(GONE); translatorsTextView.setVisibility(GONE);
} }

View File

@ -27,6 +27,7 @@ import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import org.solovyev.android.calculator.CalculatorFragment; import org.solovyev.android.calculator.CalculatorFragment;
import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;

View File

@ -30,18 +30,20 @@ import android.graphics.Paint;
import android.text.TextPaint; import android.text.TextPaint;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import org.solovyev.common.math.Point2d; import org.solovyev.common.math.Point2d;
import org.solovyev.common.text.NumberParser; import org.solovyev.common.text.NumberParser;
import org.solovyev.common.text.StringCollections; import org.solovyev.common.text.StringCollections;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class DirectionDragButton extends DragButton { public class DirectionDragButton extends DragButton {
@Nonnull @Nonnull
@ -54,203 +56,13 @@ public class DirectionDragButton extends DragButton {
@Nonnull @Nonnull
private final static String DEFAULT_DIRECTION_TEXT_SCALE = "0.33;0.33;0.33;0.33"; private final static String DEFAULT_DIRECTION_TEXT_SCALE = "0.33;0.33;0.33;0.33";
protected static class DirectionTextData {
@Nonnull
private final GuiDragDirection direction;
@Nonnull
private String text;
@Nonnull
private Point2d position;
@Nonnull
private final TextPaint paint = new TextPaint();
@Nonnull
private Float scale = 0.5f;
private boolean show = true;
private DirectionTextData(@Nonnull GuiDragDirection direction, @Nonnull String text) {
this.direction = direction;
this.text = text;
}
protected void init(@Nonnull Paint basePaint,
int color,
int alpha) {
paint.set(basePaint);
paint.setColor(color);
paint.setAlpha(alpha);
paint.setTextSize(basePaint.getTextSize() * scale);
}
@Nonnull
public GuiDragDirection getDirection() {
return direction;
}
@Nonnull
public String getText() {
return text;
}
@Nonnull
public Point2d getPosition() {
return position;
}
@Nonnull
public TextPaint getPaint() {
return paint;
}
@Nonnull
public Float getScale() {
return scale;
}
public boolean isShow() {
return show;
}
}
public static enum GuiDragDirection {
up(DragDirection.up, 0) {
@Override
public int getAttributeId() {
return org.solovyev.android.view.R.styleable.DirectionDragButton_textUp;
}
@Nonnull
@Override
public Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h) {
return getUpDownTextPosition(paint, basePaint, text, baseText, 1, w, h);
}
},
down(DragDirection.down, 2) {
@Override
public int getAttributeId() {
return org.solovyev.android.view.R.styleable.DirectionDragButton_textDown;
}
@Nonnull
@Override
public Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h) {
return getUpDownTextPosition(paint, basePaint, text, baseText, -1, w, h);
}
},
left(DragDirection.left, 3) {
@Override
public int getAttributeId() {
return org.solovyev.android.view.R.styleable.DirectionDragButton_textLeft;
}
@Nonnull
@Override
public Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h) {
return getLeftRightTextPosition(paint, basePaint, text, baseText, w, h, true);
}
},
right(DragDirection.right, 1) {
@Override
public int getAttributeId() {
return org.solovyev.android.view.R.styleable.DirectionDragButton_textRight;
}
@Nonnull
@Override
public Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h) {
return getLeftRightTextPosition(paint, basePaint, text, baseText, w, h, false);
}
};
@Nonnull
private final DragDirection dragDirection;
private final int attributePosition;
GuiDragDirection(@Nonnull DragDirection dragDirection, int attributePosition) {
this.dragDirection = dragDirection;
this.attributePosition = attributePosition;
}
public abstract int getAttributeId();
public int getAttributePosition() {
return attributePosition;
}
@Nonnull
public abstract Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h);
@Nonnull
private static Point2d getLeftRightTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, CharSequence text, @Nonnull CharSequence baseText, int w, int h, boolean left) {
final Point2d result = new Point2d();
if (left) {
float width = paint.measureText(" ");
result.setX(width);
} else {
float width = paint.measureText(text.toString() + " ");
result.setX(w - width);
}
float selfHeight = paint.ascent() + paint.descent();
basePaint.measureText(Strings.getNotEmpty(baseText, "|"));
result.setY(h / 2 - selfHeight / 2);
return result;
}
@Nonnull
private static Point2d getUpDownTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, float direction, int w, int h) {
final Point2d result = new Point2d();
float width = paint.measureText(text.toString() + " ");
result.setX(w - width);
float selfHeight = paint.ascent() + paint.descent();
basePaint.measureText(Strings.getNotEmpty(baseText, "|"));
if (direction < 0) {
result.setY(h / 2 + h / 3 - selfHeight / 2);
} else {
result.setY(h / 2 - h / 3 - selfHeight / 2);
}
return result;
}
@Nullable
public static GuiDragDirection valueOf(@Nonnull DragDirection dragDirection) {
for (GuiDragDirection guiDragDirection : values()) {
if (guiDragDirection.dragDirection == dragDirection) {
return guiDragDirection;
}
}
return null;
}
}
@Nonnull @Nonnull
private final Map<GuiDragDirection, DirectionTextData> textDataMap = new EnumMap<>(GuiDragDirection.class); private final Map<GuiDragDirection, DirectionTextData> textDataMap = new EnumMap<>(GuiDragDirection.class);
@Nonnull @Nonnull
protected String directionTextScale = DEFAULT_DIRECTION_TEXT_SCALE; protected String directionTextScale = DEFAULT_DIRECTION_TEXT_SCALE;
@Nonnull @Nonnull
protected Integer directionTextAlpha = DEFAULT_DIRECTION_TEXT_ALPHA; protected Integer directionTextAlpha = DEFAULT_DIRECTION_TEXT_ALPHA;
protected int directionTextColor = DEFAULT_DIRECTION_TEXT_COLOR; protected int directionTextColor = DEFAULT_DIRECTION_TEXT_COLOR;
private boolean initialized = false; private boolean initialized = false;
public DirectionDragButton(Context context, @Nonnull AttributeSet attrs) { public DirectionDragButton(Context context, @Nonnull AttributeSet attrs) {
@ -388,7 +200,6 @@ public class DirectionDragButton extends DragButton {
} }
} }
@Nonnull @Nonnull
public String getDirectionTextScale() { public String getDirectionTextScale() {
return directionTextScale; return directionTextScale;
@ -421,4 +232,186 @@ public class DirectionDragButton extends DragButton {
return result; return result;
} }
public static enum GuiDragDirection {
up(DragDirection.up, 0) {
@Override
public int getAttributeId() {
return org.solovyev.android.view.R.styleable.DirectionDragButton_textUp;
}
@Nonnull
@Override
public Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h) {
return getUpDownTextPosition(paint, basePaint, text, baseText, 1, w, h);
}
},
down(DragDirection.down, 2) {
@Override
public int getAttributeId() {
return org.solovyev.android.view.R.styleable.DirectionDragButton_textDown;
}
@Nonnull
@Override
public Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h) {
return getUpDownTextPosition(paint, basePaint, text, baseText, -1, w, h);
}
},
left(DragDirection.left, 3) {
@Override
public int getAttributeId() {
return org.solovyev.android.view.R.styleable.DirectionDragButton_textLeft;
}
@Nonnull
@Override
public Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h) {
return getLeftRightTextPosition(paint, basePaint, text, baseText, w, h, true);
}
},
right(DragDirection.right, 1) {
@Override
public int getAttributeId() {
return org.solovyev.android.view.R.styleable.DirectionDragButton_textRight;
}
@Nonnull
@Override
public Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h) {
return getLeftRightTextPosition(paint, basePaint, text, baseText, w, h, false);
}
};
@Nonnull
private final DragDirection dragDirection;
private final int attributePosition;
GuiDragDirection(@Nonnull DragDirection dragDirection, int attributePosition) {
this.dragDirection = dragDirection;
this.attributePosition = attributePosition;
}
@Nonnull
private static Point2d getLeftRightTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, CharSequence text, @Nonnull CharSequence baseText, int w, int h, boolean left) {
final Point2d result = new Point2d();
if (left) {
float width = paint.measureText(" ");
result.setX(width);
} else {
float width = paint.measureText(text.toString() + " ");
result.setX(w - width);
}
float selfHeight = paint.ascent() + paint.descent();
basePaint.measureText(Strings.getNotEmpty(baseText, "|"));
result.setY(h / 2 - selfHeight / 2);
return result;
}
@Nonnull
private static Point2d getUpDownTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, float direction, int w, int h) {
final Point2d result = new Point2d();
float width = paint.measureText(text.toString() + " ");
result.setX(w - width);
float selfHeight = paint.ascent() + paint.descent();
basePaint.measureText(Strings.getNotEmpty(baseText, "|"));
if (direction < 0) {
result.setY(h / 2 + h / 3 - selfHeight / 2);
} else {
result.setY(h / 2 - h / 3 - selfHeight / 2);
}
return result;
}
@Nullable
public static GuiDragDirection valueOf(@Nonnull DragDirection dragDirection) {
for (GuiDragDirection guiDragDirection : values()) {
if (guiDragDirection.dragDirection == dragDirection) {
return guiDragDirection;
}
}
return null;
}
public abstract int getAttributeId();
public int getAttributePosition() {
return attributePosition;
}
@Nonnull
public abstract Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h);
}
protected static class DirectionTextData {
@Nonnull
private final GuiDragDirection direction;
@Nonnull
private final TextPaint paint = new TextPaint();
@Nonnull
private String text;
@Nonnull
private Point2d position;
@Nonnull
private Float scale = 0.5f;
private boolean show = true;
private DirectionTextData(@Nonnull GuiDragDirection direction, @Nonnull String text) {
this.direction = direction;
this.text = text;
}
protected void init(@Nonnull Paint basePaint,
int color,
int alpha) {
paint.set(basePaint);
paint.setColor(color);
paint.setAlpha(alpha);
paint.setTextSize(basePaint.getTextSize() * scale);
}
@Nonnull
public GuiDragDirection getDirection() {
return direction;
}
@Nonnull
public String getText() {
return text;
}
@Nonnull
public Point2d getPosition() {
return position;
}
@Nonnull
public TextPaint getPaint() {
return paint;
}
@Nonnull
public Float getScale() {
return scale;
}
public boolean isShow() {
return show;
}
}
} }

View File

@ -25,9 +25,9 @@ package org.solovyev.android.calculator.drag;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.widget.Button; import android.widget.Button;
import org.solovyev.android.view.AndroidViewUtils; import org.solovyev.android.view.AndroidViewUtils;
import org.solovyev.common.math.Point2d; import org.solovyev.common.math.Point2d;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;

View File

@ -23,6 +23,7 @@
package org.solovyev.android.calculator.drag; package org.solovyev.android.calculator.drag;
import android.view.MotionEvent; import android.view.MotionEvent;
import org.solovyev.common.math.Point2d; import org.solovyev.common.math.Point2d;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;

View File

@ -22,9 +22,10 @@
package org.solovyev.android.calculator.drag; package org.solovyev.android.calculator.drag;
import javax.annotation.Nonnull;
import java.util.EventListener; import java.util.EventListener;
import javax.annotation.Nonnull;
public interface DragListener extends EventListener { public interface DragListener extends EventListener {

View File

@ -23,9 +23,7 @@
package org.solovyev.android.calculator.drag; package org.solovyev.android.calculator.drag;
import android.content.Context; import android.content.Context;
import android.support.v4.view.ViewConfigurationCompat;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.ViewConfiguration;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.common.MutableObject; import org.solovyev.common.MutableObject;
@ -34,11 +32,11 @@ import org.solovyev.common.interval.Intervals;
import org.solovyev.common.math.Maths; import org.solovyev.common.math.Maths;
import org.solovyev.common.math.Point2d; import org.solovyev.common.math.Point2d;
import java.util.EnumMap;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.EnumMap;
public class SimpleDragListener implements DragListener { public class SimpleDragListener implements DragListener {
@Nonnull @Nonnull
@ -63,6 +61,36 @@ public class SimpleDragListener implements DragListener {
this.minDistancePxs = context.getResources().getDimensionPixelSize(R.dimen.cpp_min_drag_distance); this.minDistancePxs = context.getResources().getDimensionPixelSize(R.dimen.cpp_min_drag_distance);
} }
@Nonnull
private static Interval<Float> makeAngleInterval(@Nonnull DragDirection direction,
float leftLimit,
float rightLimit) {
final Float newLeftLimit;
final Float newRightLimit;
switch (direction) {
case up:
newLeftLimit = 180f - rightLimit;
newRightLimit = 180f - leftLimit;
break;
case down:
newLeftLimit = leftLimit;
newRightLimit = rightLimit;
break;
case left:
newLeftLimit = 90f - rightLimit;
newRightLimit = 90f + rightLimit;
break;
case right:
newLeftLimit = 90f - rightLimit;
newRightLimit = 90f + rightLimit;
break;
default:
throw new AssertionError();
}
return Intervals.newClosedInterval(newLeftLimit, newRightLimit);
}
@Override @Override
public boolean onDrag(@Nonnull DragButton dragButton, @Nonnull DragEvent event) { public boolean onDrag(@Nonnull DragButton dragButton, @Nonnull DragEvent event) {
boolean consumed = false; boolean consumed = false;
@ -109,34 +137,4 @@ public class SimpleDragListener implements DragListener {
boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull Point2d startPoint2d, @Nonnull MotionEvent motionEvent); boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull Point2d startPoint2d, @Nonnull MotionEvent motionEvent);
} }
@Nonnull
private static Interval<Float> makeAngleInterval(@Nonnull DragDirection direction,
float leftLimit,
float rightLimit) {
final Float newLeftLimit;
final Float newRightLimit;
switch (direction) {
case up:
newLeftLimit = 180f - rightLimit;
newRightLimit = 180f - leftLimit;
break;
case down:
newLeftLimit = leftLimit;
newRightLimit = rightLimit;
break;
case left:
newLeftLimit = 90f - rightLimit;
newRightLimit = 90f + rightLimit;
break;
case right:
newLeftLimit = 90f - rightLimit;
newRightLimit = 90f + rightLimit;
break;
default:
throw new AssertionError();
}
return Intervals.newClosedInterval(newLeftLimit, newRightLimit);
}
} }

View File

@ -34,23 +34,33 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.EditText; import android.widget.EditText;
import jscl.math.Generic;
import jscl.math.function.Constant; import org.solovyev.android.calculator.App;
import jscl.math.function.CustomFunction; import org.solovyev.android.calculator.CalculatorDisplayViewState;
import jscl.math.function.Function; import org.solovyev.android.calculator.CalculatorEventData;
import jscl.math.function.IFunction; import org.solovyev.android.calculator.CalculatorEventListener;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorUtils;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsActivity; import org.solovyev.android.calculator.math.edit.CalculatorFunctionsActivity;
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment; import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment;
import org.solovyev.android.calculator.math.edit.MathEntityRemover; import org.solovyev.android.calculator.math.edit.MathEntityRemover;
import org.solovyev.android.calculator.model.AFunction; import org.solovyev.android.calculator.model.AFunction;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jscl.math.Generic;
import jscl.math.function.Constant;
import jscl.math.function.CustomFunction;
import jscl.math.function.Function;
import jscl.math.function.IFunction;
/** /**
* User: serso * User: serso
* Date: 11/13/12 * Date: 11/13/12
@ -75,6 +85,21 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
return fragment; return fragment;
} }
public static void showDialog(@Nonnull Input input, @Nonnull Context context) {
if (context instanceof ActionBarActivity) {
FunctionEditDialogFragment.showDialog(input, ((ActionBarActivity) context).getSupportFragmentManager());
} else {
final Intent intent = new Intent(context, CalculatorFunctionsActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(CalculatorFunctionsFragment.CREATE_FUNCTION_EXTRA, input);
context.startActivity(intent);
}
}
public static void showDialog(@Nonnull Input input, @Nonnull FragmentManager fm) {
App.showDialog(create(input), "function-editor", fm);
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -168,6 +193,14 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
Locator.getInstance().getCalculator().addCalculatorEventListener(this); Locator.getInstance().getCalculator().addCalculatorEventListener(this);
} }
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
@Override @Override
public void onPause() { public void onPause() {
Locator.getInstance().getCalculator().removeCalculatorEventListener(this); Locator.getInstance().getCalculator().removeCalculatorEventListener(this);
@ -189,43 +222,8 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
} }
} }
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
public static void showDialog(@Nonnull Input input, @Nonnull Context context) {
if (context instanceof ActionBarActivity) {
FunctionEditDialogFragment.showDialog(input, ((ActionBarActivity) context).getSupportFragmentManager());
} else {
final Intent intent = new Intent(context, CalculatorFunctionsActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(CalculatorFunctionsFragment.CREATE_FUNCTION_EXTRA, input);
context.startActivity(intent);
}
}
public static void showDialog(@Nonnull Input input, @Nonnull FragmentManager fm) {
App.showDialog(create(input), "function-editor", fm);
}
public static class Input implements Parcelable { public static class Input implements Parcelable {
public static final Parcelable.Creator<Input> CREATOR = new Creator<Input>() {
@Override
public Input createFromParcel(@Nonnull Parcel in) {
return Input.fromParcel(in);
}
@Override
public Input[] newArray(int size) {
return new Input[size];
}
};
private static final Parcelable.Creator<String> STRING_CREATOR = new Creator<String>() { private static final Parcelable.Creator<String> STRING_CREATOR = new Creator<String>() {
@Override @Override
public String createFromParcel(@Nonnull Parcel in) { public String createFromParcel(@Nonnull Parcel in) {
@ -237,6 +235,30 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
return new String[size]; return new String[size];
} }
}; };
@Nullable
private AFunction function;
@Nullable
private String name;
@Nullable
private String content;
@Nullable
private String description;
@Nullable
private List<String> parameterNames;
public static final Parcelable.Creator<Input> CREATOR = new Creator<Input>() {
@Override
public Input createFromParcel(@Nonnull Parcel in) {
return Input.fromParcel(in);
}
@Override
public Input[] newArray(int size) {
return new Input[size];
}
};
private Input() {
}
@Nonnull @Nonnull
private static Input fromParcel(@Nonnull Parcel in) { private static Input fromParcel(@Nonnull Parcel in) {
@ -254,24 +276,6 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
return result; return result;
} }
@Nullable
private AFunction function;
@Nullable
private String name;
@Nullable
private String content;
@Nullable
private String description;
@Nullable
private List<String> parameterNames;
private Input() {
}
@Nonnull @Nonnull
public static Input newInstance() { public static Input newInstance() {
return new Input(); return new Input();
@ -303,6 +307,24 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
return result; return result;
} }
@Nonnull
public static Input newFromDisplay(@Nonnull CalculatorDisplayViewState viewState) {
final Input result = new Input();
result.content = viewState.getText();
final Generic generic = viewState.getResult();
if (generic != null) {
final Set<Constant> constants = CalculatorUtils.getNotSystemConstants(generic);
final List<String> parameterNames = new ArrayList<String>(constants.size());
for (Constant constant : constants) {
parameterNames.add(constant.getName());
}
result.parameterNames = parameterNames;
}
return result;
}
@Nullable @Nullable
public AFunction getFunction() { public AFunction getFunction() {
return function; return function;
@ -341,23 +363,5 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
out.writeList(parameterNames); out.writeList(parameterNames);
out.writeSerializable(function); out.writeSerializable(function);
} }
@Nonnull
public static Input newFromDisplay(@Nonnull CalculatorDisplayViewState viewState) {
final Input result = new Input();
result.content = viewState.getText();
final Generic generic = viewState.getResult();
if (generic != null) {
final Set<Constant> constants = CalculatorUtils.getNotSystemConstants(generic);
final List<String> parameterNames = new ArrayList<String>(constants.size());
for (Constant constant : constants) {
parameterNames.add(constant.getName());
}
result.parameterNames = parameterNames;
}
return result;
}
} }
} }

View File

@ -24,12 +24,6 @@ package org.solovyev.android.calculator.function;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import jscl.CustomFunctionCalculationException;
import jscl.math.function.Function;
import jscl.math.function.IFunction;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.solovyev.android.calculator.CalculatorFunctionsMathRegistry; import org.solovyev.android.calculator.CalculatorFunctionsMathRegistry;
import org.solovyev.android.calculator.CalculatorMathRegistry; import org.solovyev.android.calculator.CalculatorMathRegistry;
@ -43,6 +37,13 @@ import org.solovyev.common.text.Strings;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jscl.CustomFunctionCalculationException;
import jscl.math.function.Function;
import jscl.math.function.IFunction;
public class FunctionEditorSaver implements View.OnClickListener { public class FunctionEditorSaver implements View.OnClickListener {
@Nonnull @Nonnull
@ -74,6 +75,23 @@ public class FunctionEditorSaver implements View.OnClickListener {
this.source = source; this.source = source;
} }
@Nonnull
public static FunctionEditDialogFragment.Input readInput(@Nullable IFunction function, @Nonnull View root) {
final EditText editName = (EditText) root.findViewById(R.id.function_edit_name);
String name = editName.getText().toString();
final EditText editValue = (EditText) root.findViewById(R.id.function_edit_value);
String content = editValue.getText().toString();
final EditText editDescription = (EditText) root.findViewById(R.id.function_edit_description);
String description = editDescription.getText().toString();
final FunctionParamsView editParams = (FunctionParamsView) root.findViewById(R.id.function_params_layout);
List<String> parameterNames = editParams.getParameterNames();
return FunctionEditDialogFragment.Input.newInstance(function, name, content, description, parameterNames);
}
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final Integer error; final Integer error;
@ -135,23 +153,6 @@ public class FunctionEditorSaver implements View.OnClickListener {
} }
} }
@Nonnull
public static FunctionEditDialogFragment.Input readInput(@Nullable IFunction function, @Nonnull View root) {
final EditText editName = (EditText) root.findViewById(R.id.function_edit_name);
String name = editName.getText().toString();
final EditText editValue = (EditText) root.findViewById(R.id.function_edit_value);
String content = editValue.getText().toString();
final EditText editDescription = (EditText) root.findViewById(R.id.function_edit_description);
String description = editDescription.getText().toString();
final FunctionParamsView editParams = (FunctionParamsView) root.findViewById(R.id.function_params_layout);
List<String> parameterNames = editParams.getParameterNames();
return FunctionEditDialogFragment.Input.newInstance(function, name, content, description, parameterNames);
}
private boolean validateParameters(@Nonnull List<String> parameterNames) { private boolean validateParameters(@Nonnull List<String> parameterNames) {
for (String parameterName : parameterNames) { for (String parameterName : parameterNames) {
if (!VarEditorSaver.isValidName(parameterName)) { if (!VarEditorSaver.isValidName(parameterName)) {

View File

@ -32,25 +32,26 @@ import android.view.ViewGroup;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import jscl.text.MutableInt;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jscl.text.MutableInt;
public class FunctionParamsView extends LinearLayout { public class FunctionParamsView extends LinearLayout {
private static final String PARAM_TAG_PREFIX = "function_param_";
@Nonnull @Nonnull
private final MutableInt paramsCount = new MutableInt(0); private final MutableInt paramsCount = new MutableInt(0);
@Nonnull @Nonnull
private final List<Integer> paramIds = new ArrayList<Integer>(10); private final List<Integer> paramIds = new ArrayList<Integer>(10);
private static final String PARAM_TAG_PREFIX = "function_param_";
public FunctionParamsView(Context context) { public FunctionParamsView(Context context) {
super(context); super(context);
} }

View File

@ -4,20 +4,23 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.google.android.gms.analytics.GoogleAnalytics; import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.HitBuilders; import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Tracker;
import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.common.listeners.JEvent; import org.solovyev.common.listeners.JEvent;
import org.solovyev.common.listeners.JEventListener; import org.solovyev.common.listeners.JEventListener;
import org.solovyev.common.listeners.JEventListeners; import org.solovyev.common.listeners.JEventListeners;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public final class Ga implements SharedPreferences.OnSharedPreferenceChangeListener { public final class Ga implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final int LAYOUT = 1; private static final int LAYOUT = 1;

View File

@ -26,14 +26,16 @@ import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import org.solovyev.android.calculator.Calculator; import org.solovyev.android.calculator.Calculator;
import org.solovyev.android.calculator.CalculatorEventData; import org.solovyev.android.calculator.CalculatorEventData;
import org.solovyev.android.calculator.CalculatorEventType; import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.common.history.HistoryAction; import org.solovyev.common.history.HistoryAction;
import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List;
/** /**
* User: serso * User: serso

View File

@ -88,9 +88,6 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
********************************************************************** **********************************************************************
*/ */
@Nonnull
private static final String TAG = "CalculatorHistoryFragment";
public static final Comparator<CalculatorHistoryState> COMPARATOR = new Comparator<CalculatorHistoryState>() { public static final Comparator<CalculatorHistoryState> COMPARATOR = new Comparator<CalculatorHistoryState>() {
@Override @Override
public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) { public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) {
@ -105,6 +102,8 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
return 0; return 0;
} }
}; };
@Nonnull
private static final String TAG = "CalculatorHistoryFragment";
/* /*
********************************************************************** **********************************************************************
@ -113,19 +112,9 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
* *
********************************************************************** **********************************************************************
*/ */
@Nonnull
private HistoryArrayAdapter adapter;
@Nonnull
private FragmentUi ui;
private final ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromResource(R.menu.history_menu, HistoryMenu.class, AndroidMenuHelper.getInstance(), new HistoryMenuFilter()); private final ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromResource(R.menu.history_menu, HistoryMenu.class, AndroidMenuHelper.getInstance(), new HistoryMenuFilter());
@Nonnull @Nonnull
private final SharedPreferences.OnSharedPreferenceChangeListener preferencesListener = new HistoryOnPreferenceChangeListener(); private final SharedPreferences.OnSharedPreferenceChangeListener preferencesListener = new HistoryOnPreferenceChangeListener();
@Nonnull @Nonnull
private final DialogInterface.OnClickListener clearDialogListener = new DialogInterface.OnClickListener() { private final DialogInterface.OnClickListener clearDialogListener = new DialogInterface.OnClickListener() {
@Override @Override
@ -137,6 +126,10 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
} }
} }
}; };
@Nonnull
private HistoryArrayAdapter adapter;
@Nonnull
private FragmentUi ui;
@Nullable @Nullable
private AlertDialog clearDialog; private AlertDialog clearDialog;
@ -144,6 +137,51 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
ui = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId(), false); ui = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId(), false);
} }
public static boolean isAlreadySaved(@Nonnull CalculatorHistoryState historyState) {
if (historyState.isSaved()) throw new AssertionError();
boolean result = false;
try {
historyState.setSaved(true);
if (Collections.contains(historyState, Locator.getInstance().getHistory().getSavedHistory(), new Equalizer<CalculatorHistoryState>() {
@Override
public boolean areEqual(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
return first != null && second != null &&
first.getTime() == second.getTime() &&
first.getDisplayState().equals(second.getDisplayState()) &&
first.getEditorState().equals(second.getEditorState());
}
})) {
result = true;
}
} finally {
historyState.setSaved(false);
}
return result;
}
public static void useHistoryItem(@Nonnull final CalculatorHistoryState historyState) {
App.getVibrator().vibrate();
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_history_state, historyState);
}
@Nonnull
public static String getHistoryText(@Nonnull CalculatorHistoryState state) {
final StringBuilder result = new StringBuilder();
result.append(state.getEditorState().getText());
result.append(getIdentitySign(state.getDisplayState().getJsclOperation()));
final String expressionResult = state.getDisplayState().getEditorState().getText();
if (expressionResult != null) {
result.append(expressionResult);
}
return result.toString();
}
@Nonnull
private static String getIdentitySign(@Nonnull JsclOperation jsclOperation) {
return jsclOperation == JsclOperation.simplify ? "" : "=";
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -287,34 +325,6 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
public static boolean isAlreadySaved(@Nonnull CalculatorHistoryState historyState) {
if (historyState.isSaved()) throw new AssertionError();
boolean result = false;
try {
historyState.setSaved(true);
if (Collections.contains(historyState, Locator.getInstance().getHistory().getSavedHistory(), new Equalizer<CalculatorHistoryState>() {
@Override
public boolean areEqual(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
return first != null && second != null &&
first.getTime() == second.getTime() &&
first.getDisplayState().equals(second.getDisplayState()) &&
first.getEditorState().equals(second.getEditorState());
}
})) {
result = true;
}
} finally {
historyState.setSaved(false);
}
return result;
}
public static void useHistoryItem(@Nonnull final CalculatorHistoryState historyState) {
App.getVibrator().vibrate();
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_history_state, historyState);
}
@Nonnull @Nonnull
private List<CalculatorHistoryState> getHistoryList() { private List<CalculatorHistoryState> getHistoryList() {
final List<CalculatorHistoryState> calculatorHistoryStates = getHistoryItems(); final List<CalculatorHistoryState> calculatorHistoryStates = getHistoryItems();
@ -337,23 +347,6 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
@Nonnull @Nonnull
protected abstract List<CalculatorHistoryState> getHistoryItems(); protected abstract List<CalculatorHistoryState> getHistoryItems();
@Nonnull
public static String getHistoryText(@Nonnull CalculatorHistoryState state) {
final StringBuilder result = new StringBuilder();
result.append(state.getEditorState().getText());
result.append(getIdentitySign(state.getDisplayState().getJsclOperation()));
final String expressionResult = state.getDisplayState().getEditorState().getText();
if (expressionResult != null) {
result.append(expressionResult);
}
return result.toString();
}
@Nonnull
private static String getIdentitySign(@Nonnull JsclOperation jsclOperation) {
return jsclOperation == JsclOperation.simplify ? "" : "=";
}
protected abstract void clearHistory(); protected abstract void clearHistory();
@Nonnull @Nonnull

View File

@ -23,7 +23,12 @@
package org.solovyev.android.calculator.history; package org.solovyev.android.calculator.history;
import android.os.Bundle; import android.os.Bundle;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.CalculatorEventData;
import org.solovyev.android.calculator.CalculatorEventListener;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;

View File

@ -29,13 +29,16 @@ import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
import java.util.List; import java.util.List;
import static android.view.View.*; import javax.annotation.Nonnull;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static org.solovyev.android.calculator.CalculatorFragmentType.saved_history; import static org.solovyev.android.calculator.CalculatorFragmentType.saved_history;
import static org.solovyev.android.calculator.history.BaseHistoryFragment.isAlreadySaved; import static org.solovyev.android.calculator.history.BaseHistoryFragment.isAlreadySaved;

View File

@ -26,15 +26,15 @@ import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.Locator; import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
public class HistoryFragment extends BaseHistoryFragment { public class HistoryFragment extends BaseHistoryFragment {
public HistoryFragment() { public HistoryFragment() {

View File

@ -33,13 +33,13 @@ import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import javax.annotation.Nonnull;
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.menu.LabeledMenuItem; import org.solovyev.android.menu.LabeledMenuItem;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
/** /**
* User: serso * User: serso
* Date: 12/18/11 * Date: 12/18/11
@ -117,6 +117,12 @@ public enum HistoryItemMenuItem implements LabeledMenuItem<HistoryItemMenuData>
} }
}; };
private final int captionId;
private HistoryItemMenuItem(int captionId) {
this.captionId = captionId;
}
private static void createEditHistoryDialog(@Nonnull final HistoryItemMenuData data, @Nonnull final Context context, final boolean save) { private static void createEditHistoryDialog(@Nonnull final HistoryItemMenuData data, @Nonnull final Context context, final boolean save) {
final CalculatorHistoryState historyState = data.getHistoryState(); final CalculatorHistoryState historyState = data.getHistoryState();
@ -154,12 +160,6 @@ public enum HistoryItemMenuItem implements LabeledMenuItem<HistoryItemMenuData>
builder.create().show(); builder.create().show();
} }
private final int captionId;
private HistoryItemMenuItem(int captionId) {
this.captionId = captionId;
}
@Nonnull @Nonnull
@Override @Override
public String getCaption(@Nonnull Context context) { public String getCaption(@Nonnull Context context) {

View File

@ -26,10 +26,11 @@ import org.solovyev.android.calculator.CalculatorFragmentType;
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 javax.annotation.Nonnull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
public class SavedHistoryFragment extends BaseHistoryFragment { public class SavedHistoryFragment extends BaseHistoryFragment {
public SavedHistoryFragment() { public SavedHistoryFragment() {

View File

@ -25,11 +25,11 @@ package org.solovyev.android.calculator.history;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import org.solovyev.android.calculator.Editor;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.solovyev.android.calculator.Editor;
/** /**
* User: serso * User: serso
* Date: 12/17/11 * Date: 12/17/11

View File

@ -25,15 +25,6 @@ public final class Language {
this.name = makeName(code, locale); this.name = makeName(code, locale);
} }
@Nonnull
public String getName(@Nonnull Context context) {
if (!isSystem()) {
return name;
} else {
return context.getString(R.string.cpp_system_language) + " (" + locale.getDisplayLanguage(locale) + ")";
}
}
@Nonnull @Nonnull
private static String makeName(@Nonnull String code, @Nonnull Locale locale) { private static String makeName(@Nonnull String code, @Nonnull Locale locale) {
if (code.equals(Languages.SYSTEM_LANGUAGE_CODE)) { if (code.equals(Languages.SYSTEM_LANGUAGE_CODE)) {
@ -48,6 +39,15 @@ public final class Language {
return locale.getDisplayName(locale); return locale.getDisplayName(locale);
} }
@Nonnull
public String getName(@Nonnull Context context) {
if (!isSystem()) {
return name;
} else {
return context.getString(R.string.cpp_system_language) + " (" + locale.getDisplayLanguage(locale) + ")";
}
}
public boolean isSystem() { public boolean isSystem() {
return code.equals(Languages.SYSTEM_LANGUAGE_CODE); return code.equals(Languages.SYSTEM_LANGUAGE_CODE);
} }

View File

@ -23,15 +23,50 @@ import javax.annotation.Nullable;
public final class Languages implements SharedPreferences.OnSharedPreferenceChangeListener { public final class Languages implements SharedPreferences.OnSharedPreferenceChangeListener {
@Nonnull
private static final Locale[] locales = Locale.getAvailableLocales();
@Nonnull @Nonnull
public static final String SYSTEM_LANGUAGE_CODE = "00"; public static final String SYSTEM_LANGUAGE_CODE = "00";
@Nonnull @Nonnull
public static final Language SYSTEM_LANGUAGE = new Language(SYSTEM_LANGUAGE_CODE, Locale.getDefault()); public static final Language SYSTEM_LANGUAGE = new Language(SYSTEM_LANGUAGE_CODE, Locale.getDefault());
@Nonnull @Nonnull
private static final Locale[] locales = Locale.getAvailableLocales();
@Nonnull
private final List<Language> list = new ArrayList<>(); private final List<Language> list = new ArrayList<>();
@Nullable
private static Language makeLanguage(@Nonnull String localeId) {
final Locale locale = findLocaleById(localeId);
if (locale == null) {
return null;
}
return new Language(localeId, locale);
}
@Nullable
private static Locale findLocaleById(@Nonnull String id) {
for (Locale locale : locales) {
if (TextUtils.equals(locale.toString(), id)) {
return locale;
}
}
final String language;
final int underscore = id.indexOf("_");
if (underscore >= 0) {
language = id.substring(0, underscore);
} else {
language = id;
}
for (Locale locale : locales) {
if (TextUtils.equals(locale.getLanguage(), language)) {
return locale;
}
}
Log.d("Languages", "No locale found for " + id);
return null;
}
public void init(@Nonnull SharedPreferences preferences) { public void init(@Nonnull SharedPreferences preferences) {
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
} }
@ -83,41 +118,6 @@ public final class Languages implements SharedPreferences.OnSharedPreferenceChan
} }
} }
@Nullable
private static Language makeLanguage(@Nonnull String localeId) {
final Locale locale = findLocaleById(localeId);
if (locale == null) {
return null;
}
return new Language(localeId, locale);
}
@Nullable
private static Locale findLocaleById(@Nonnull String id) {
for (Locale locale : locales) {
if (TextUtils.equals(locale.toString(), id)) {
return locale;
}
}
final String language;
final int underscore = id.indexOf("_");
if (underscore >= 0) {
language = id.substring(0, underscore);
} else {
language = id;
}
for (Locale locale : locales) {
if (TextUtils.equals(locale.getLanguage(), language)) {
return locale;
}
}
Log.d("Languages", "No locale found for " + id);
return null;
}
@Nonnull @Nonnull
public Language getCurrent() { public Language getCurrent() {
return get(Preferences.Gui.language.getPreference(App.getPreferences())); return get(Preferences.Gui.language.getPreference(App.getPreferences()));

View File

@ -84,23 +84,30 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
* *
********************************************************************** **********************************************************************
*/ */
@Nonnull
private final FragmentUi ui;
@Nonnull
private final Handler uiHandler = new Handler();
@Nullable @Nullable
private MathEntityArrayAdapter<T> adapter; private MathEntityArrayAdapter<T> adapter;
@Nullable @Nullable
private String category; private String category;
@Nonnull
private final FragmentUi ui;
@Nonnull
private final Handler uiHandler = new Handler();
protected AbstractMathEntityListFragment(@Nonnull CalculatorFragmentType fragmentType) { protected AbstractMathEntityListFragment(@Nonnull CalculatorFragmentType fragmentType) {
ui = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId()); ui = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
} }
@Nonnull
public static Bundle createBundleFor(@Nonnull String categoryId) {
final Bundle result = new Bundle(1);
putCategory(result, categoryId);
return result;
}
static void putCategory(@Nonnull Bundle bundle, @Nonnull String categoryId) {
bundle.putString(MATH_ENTITY_CATEGORY_EXTRA_STRING, categoryId);
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -235,6 +242,52 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
} }
} }
public void addToAdapter(@Nonnull T mathEntity) {
if (this.adapter != null) {
this.adapter.add(mathEntity);
}
}
public void removeFromAdapter(@Nonnull T mathEntity) {
if (this.adapter != null) {
this.adapter.remove(mathEntity);
}
}
public void notifyAdapter() {
if (this.adapter != null) {
this.adapter.notifyDataSetChanged();
}
}
@Nullable
protected MathEntityArrayAdapter<T> getAdapter() {
return adapter;
}
@Nonnull
protected Handler getUiHandler() {
return uiHandler;
}
@Override
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
}
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
protected static interface MathEntityDescriptionGetter {
@Nullable
String getDescription(@Nonnull Context context, @Nonnull String mathEntityName);
}
protected static class MathEntityArrayAdapter<T extends MathEntity> extends ArrayAdapter<T> { protected static class MathEntityArrayAdapter<T extends MathEntity> extends ArrayAdapter<T> {
@Nonnull @Nonnull
@ -295,61 +348,4 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
return this.mathRegistry.getDescription(mathEntityName); return this.mathRegistry.getDescription(mathEntityName);
} }
} }
protected static interface MathEntityDescriptionGetter {
@Nullable
String getDescription(@Nonnull Context context, @Nonnull String mathEntityName);
}
public void addToAdapter(@Nonnull T mathEntity) {
if (this.adapter != null) {
this.adapter.add(mathEntity);
}
}
public void removeFromAdapter(@Nonnull T mathEntity) {
if (this.adapter != null) {
this.adapter.remove(mathEntity);
}
}
public void notifyAdapter() {
if (this.adapter != null) {
this.adapter.notifyDataSetChanged();
}
}
@Nullable
protected MathEntityArrayAdapter<T> getAdapter() {
return adapter;
}
@Nonnull
protected Handler getUiHandler() {
return uiHandler;
}
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
@Nonnull
public static Bundle createBundleFor(@Nonnull String categoryId) {
final Bundle result = new Bundle(1);
putCategory(result, categoryId);
return result;
}
static void putCategory(@Nonnull Bundle bundle, @Nonnull String categoryId) {
bundle.putString(MATH_ENTITY_CATEGORY_EXTRA_STRING, categoryId);
}
@Override
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
}
} }

View File

@ -25,7 +25,15 @@ package org.solovyev.android.calculator.math.edit;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.AndroidFunctionCategory;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.CalculatorEventData;
import org.solovyev.android.calculator.CalculatorEventListener;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.FunctionCategory;
import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;

View File

@ -30,21 +30,31 @@ import android.support.v7.app.ActionBarActivity;
import android.text.ClipboardManager; import android.text.ClipboardManager;
import android.view.View; import android.view.View;
import android.widget.ListView; import android.widget.ListView;
import com.melnykov.fab.FloatingActionButton; import com.melnykov.fab.FloatingActionButton;
import jscl.math.function.Function;
import jscl.math.function.IFunction; import org.solovyev.android.calculator.CalculatorEventData;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.CalculatorMathRegistry;
import org.solovyev.android.calculator.Change;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.function.FunctionEditDialogFragment; import org.solovyev.android.calculator.function.FunctionEditDialogFragment;
import org.solovyev.android.menu.AMenuItem; import org.solovyev.android.menu.AMenuItem;
import org.solovyev.android.menu.LabeledMenuItem; import org.solovyev.android.menu.LabeledMenuItem;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jscl.math.function.Function;
import jscl.math.function.IFunction;
/** /**
* User: serso * User: serso
* Date: 10/29/11 * Date: 10/29/11

View File

@ -23,7 +23,15 @@
package org.solovyev.android.calculator.math.edit; package org.solovyev.android.calculator.math.edit;
import android.os.Bundle; import android.os.Bundle;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.AndroidOperatorCategory;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.CalculatorEventData;
import org.solovyev.android.calculator.CalculatorEventListener;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.OperatorCategory;
import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;

View File

@ -25,9 +25,6 @@ package org.solovyev.android.calculator.math.edit;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.text.ClipboardManager; import android.text.ClipboardManager;
import jscl.math.operator.Operator;
import javax.annotation.Nonnull;
import org.solovyev.android.calculator.CalculatorEventType; import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.CalculatorFragmentType;
@ -41,6 +38,10 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import jscl.math.operator.Operator;
/** /**
* User: serso * User: serso
* Date: 11/17/11 * Date: 11/17/11

View File

@ -24,7 +24,15 @@ package org.solovyev.android.calculator.math.edit;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.AndroidVarCategory;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.CalculatorEventData;
import org.solovyev.android.calculator.CalculatorEventListener;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.VarCategory;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;

View File

@ -27,9 +27,18 @@ import android.os.Bundle;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.view.View; import android.view.View;
import android.widget.ListView; import android.widget.ListView;
import com.melnykov.fab.FloatingActionButton; import com.melnykov.fab.FloatingActionButton;
import jscl.math.function.IConstant;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.CalculatorEventData;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.CalculatorParseException;
import org.solovyev.android.calculator.Change;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.PreparedExpression;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.ToJsclTextProcessor;
import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.menu.AMenuItem; import org.solovyev.android.menu.AMenuItem;
import org.solovyev.android.menu.LabeledMenuItem; import org.solovyev.android.menu.LabeledMenuItem;
@ -37,12 +46,15 @@ import org.solovyev.common.JPredicate;
import org.solovyev.common.collections.Collections; import org.solovyev.common.collections.Collections;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jscl.math.function.IConstant;
/** /**
* User: serso * User: serso
* Date: 9/28/11 * Date: 9/28/11
@ -56,6 +68,18 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
super(CalculatorFragmentType.variables); super(CalculatorFragmentType.variables);
} }
public static boolean isValidValue(@Nonnull String value) {
try {
final PreparedExpression expression = ToJsclTextProcessor.getInstance().process(value);
final List<IConstant> constants = expression.getUndefinedVars();
return constants.isEmpty();
} catch (RuntimeException e) {
return true;
} catch (CalculatorParseException e) {
return true;
}
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -147,18 +171,6 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
return Locator.getInstance().getEngine().getVarsRegistry().getCategory(var); return Locator.getInstance().getEngine().getVarsRegistry().getCategory(var);
} }
public static boolean isValidValue(@Nonnull String value) {
try {
final PreparedExpression expression = ToJsclTextProcessor.getInstance().process(value);
final List<IConstant> constants = expression.getUndefinedVars();
return constants.isEmpty();
} catch (RuntimeException e) {
return true;
} catch (CalculatorParseException e) {
return true;
}
}
@Override @Override
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) { public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
super.onCalculatorEvent(calculatorEventData, calculatorEventType, data); super.onCalculatorEvent(calculatorEventData, calculatorEventType, data);

View File

@ -27,11 +27,6 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import jscl.math.function.Function;
import jscl.math.function.IConstant;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.solovyev.android.calculator.CalculatorEventType; import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorMathRegistry; import org.solovyev.android.calculator.CalculatorMathRegistry;
@ -39,6 +34,12 @@ import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.common.math.MathEntity; import org.solovyev.common.math.MathEntity;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jscl.math.function.Function;
import jscl.math.function.IConstant;
/** /**
* User: serso * User: serso
* Date: 12/22/11 * Date: 12/22/11
@ -56,15 +57,12 @@ public class MathEntityRemover<T extends MathEntity> implements View.OnClickList
@Nonnull @Nonnull
private final CalculatorMathRegistry<? super T> varsRegistry; private final CalculatorMathRegistry<? super T> varsRegistry;
@Nonnull
private Context context;
@Nonnull @Nonnull
private final Object source; private final Object source;
@Nonnull @Nonnull
private final Params params; private final Params params;
@Nonnull
private Context context;
/* /*
********************************************************************** **********************************************************************
@ -163,18 +161,6 @@ public class MathEntityRemover<T extends MathEntity> implements View.OnClickList
private Params() { private Params() {
} }
public int getRemovalConfirmationTitleResId() {
return removalConfirmationTitleResId;
}
public int getRemovalConfirmationQuestionResId() {
return removalConfirmationQuestionResId;
}
public CalculatorEventType getCalculatorEventType() {
return calculatorEventType;
}
private static <T extends MathEntity> Params newConstantInstance() { private static <T extends MathEntity> Params newConstantInstance() {
final Params result = new Params(); final Params result = new Params();
result.removalConfirmationTitleResId = R.string.removal_confirmation; result.removalConfirmationTitleResId = R.string.removal_confirmation;
@ -190,5 +176,17 @@ public class MathEntityRemover<T extends MathEntity> implements View.OnClickList
result.calculatorEventType = CalculatorEventType.function_removed; result.calculatorEventType = CalculatorEventType.function_removed;
return result; return result;
} }
public int getRemovalConfirmationTitleResId() {
return removalConfirmationTitleResId;
}
public int getRemovalConfirmationQuestionResId() {
return removalConfirmationQuestionResId;
}
public CalculatorEventType getCalculatorEventType() {
return calculatorEventType;
}
} }
} }

View File

@ -32,19 +32,31 @@ import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.*; import android.widget.Button;
import jscl.math.function.IConstant; import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import org.solovyev.android.Views; import org.solovyev.android.Views;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.CalculatorEventData;
import org.solovyev.android.calculator.CalculatorEventListener;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.model.Var; import org.solovyev.android.calculator.model.Var;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jscl.math.function.IConstant;
import static android.graphics.Paint.UNDERLINE_TEXT_FLAG; import static android.graphics.Paint.UNDERLINE_TEXT_FLAG;
import static android.view.View.GONE; import static android.view.View.GONE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
@ -71,6 +83,10 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
return fragment; return fragment;
} }
public static void showDialog(@Nonnull Input input, @Nonnull FragmentManager fm) {
App.showDialog(create(input), "constant-editor", fm);
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.var_edit, container, false); return inflater.inflate(R.layout.var_edit, container, false);
@ -233,6 +249,14 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
button.setAllCaps(false); button.setAllCaps(false);
} }
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
@Override @Override
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) { public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
switch (calculatorEventType) { switch (calculatorEventType) {
@ -247,18 +271,6 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
} }
} }
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
public static void showDialog(@Nonnull Input input, @Nonnull FragmentManager fm) {
App.showDialog(create(input), "constant-editor", fm);
}
public static class Input { public static class Input {
@Nullable @Nullable

View File

@ -24,10 +24,7 @@ package org.solovyev.android.calculator.math.edit;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import jscl.text.Identifier;
import jscl.text.MutableInt;
import jscl.text.ParseException;
import jscl.text.Parser;
import org.solovyev.android.calculator.CalculatorMathRegistry; import org.solovyev.android.calculator.CalculatorMathRegistry;
import org.solovyev.android.calculator.CalculatorVarsRegistry; import org.solovyev.android.calculator.CalculatorVarsRegistry;
import org.solovyev.android.calculator.Locator; import org.solovyev.android.calculator.Locator;
@ -41,6 +38,11 @@ import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import jscl.text.Identifier;
import jscl.text.MutableInt;
import jscl.text.ParseException;
import jscl.text.Parser;
/** /**
* User: serso * User: serso
* Date: 12/22/11 * Date: 12/22/11
@ -75,6 +77,22 @@ public class VarEditorSaver<T extends MathEntity> implements View.OnClickListene
this.source = source; this.source = source;
} }
public static boolean isValidName(@Nullable String name) {
boolean result = false;
if (!Strings.isEmpty(name)) {
try {
if (name == null) throw new AssertionError();
Identifier.parser.parse(Parser.Parameters.newInstance(name, new MutableInt(0), Locator.getInstance().getEngine().getMathEngine0()), null);
result = true;
} catch (ParseException e) {
// not valid name;
}
}
return result;
}
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final Integer error; final Integer error;
@ -139,20 +157,4 @@ public class VarEditorSaver<T extends MathEntity> implements View.OnClickListene
CalculatorVarsRegistry.saveVariable(mathRegistry, varBuilder, editedInstance, source, true); CalculatorVarsRegistry.saveVariable(mathRegistry, varBuilder, editedInstance, source, true);
} }
} }
public static boolean isValidName(@Nullable String name) {
boolean result = false;
if (!Strings.isEmpty(name)) {
try {
if (name == null) throw new AssertionError();
Identifier.parser.parse(Parser.Parameters.newInstance(name, new MutableInt(0), Locator.getInstance().getEngine().getMathEngine0()), null);
result = true;
} catch (ParseException e) {
// not valid name;
}
}
return result;
}
} }

View File

@ -24,8 +24,8 @@ package org.solovyev.android.calculator.matrix;
import android.os.Bundle; import android.os.Bundle;
import org.solovyev.android.calculator.EmptyActivity;
import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.EmptyActivity;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import static android.support.v7.app.ActionBar.NAVIGATION_MODE_STANDARD; import static android.support.v7.app.ActionBar.NAVIGATION_MODE_STANDARD;

View File

@ -24,6 +24,7 @@ package org.solovyev.android.calculator.matrix;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import org.solovyev.android.calculator.CalculatorFragment; import org.solovyev.android.calculator.CalculatorFragment;
import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;

View File

@ -1,13 +1,14 @@
package org.solovyev.android.calculator.matrix; package org.solovyev.android.calculator.matrix;
import javax.annotation.Nonnull;
import java.io.Serializable; import java.io.Serializable;
import javax.annotation.Nonnull;
/** /**
* User: serso * User: serso
* Date: 7/11/13 * Date: 7/11/13
* Time: 4:54 PM * Time: 4:54 PM
*/ */
class MatrixUi implements Serializable { class MatrixUi implements Serializable {
@Nonnull @Nonnull

View File

@ -26,18 +26,16 @@ import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import jscl.AngleUnit;
import jscl.JsclMathEngine;
import jscl.MathEngine;
import jscl.NumeralBase;
import jscl.math.function.Function;
import jscl.math.function.IConstant;
import jscl.math.operator.Operator;
import javax.annotation.Nonnull; import org.solovyev.android.calculator.CalculatorEngine;
import org.solovyev.android.calculator.CalculatorEngineImpl;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.CalculatorFunctionsMathRegistry;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.CalculatorMathEngine;
import org.solovyev.android.calculator.CalculatorMathRegistry;
import org.solovyev.android.calculator.CalculatorOperatorsMathRegistry;
import org.solovyev.android.calculator.CalculatorPostfixFunctionsRegistry;
import org.solovyev.android.calculator.CalculatorVarsRegistry;
import org.solovyev.android.calculator.MathPersistenceEntity;
import org.solovyev.android.prefs.BooleanPreference; import org.solovyev.android.prefs.BooleanPreference;
import org.solovyev.android.prefs.Preference; import org.solovyev.android.prefs.Preference;
import org.solovyev.android.prefs.StringPreference; import org.solovyev.android.prefs.StringPreference;
@ -50,6 +48,16 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import jscl.AngleUnit;
import jscl.JsclMathEngine;
import jscl.MathEngine;
import jscl.NumeralBase;
import jscl.math.function.Function;
import jscl.math.function.IConstant;
import jscl.math.operator.Operator;
/** /**
* User: serso * User: serso
* Date: 9/12/11 * Date: 9/12/11
@ -80,42 +88,10 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
private static final String ANGLE_UNITS_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_angle_units"; private static final String ANGLE_UNITS_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_angle_units";
private static final String ANGLE_UNITS_DEFAULT = "deg"; private static final String ANGLE_UNITS_DEFAULT = "deg";
public static class Preferences {
public static final Preference<String> groupingSeparator = StringPreference.of(GROUPING_SEPARATOR_P_KEY, JsclMathEngine.GROUPING_SEPARATOR_DEFAULT);
public static final Preference<String> multiplicationSign = StringPreference.of(MULTIPLICATION_SIGN_P_KEY, MULTIPLICATION_SIGN_DEFAULT);
public static final Preference<Integer> precision = StringPreference.ofTypedValue(RESULT_PRECISION_P_KEY, RESULT_PRECISION_DEFAULT, NumberMapper.of(Integer.class));
public static final Preference<Boolean> roundResult = BooleanPreference.of(ROUND_RESULT_P_KEY, ROUND_RESULT_DEFAULT);
public static final Preference<NumeralBase> numeralBase = StringPreference.ofTypedValue(NUMERAL_BASES_P_KEY, NUMERAL_BASES_DEFAULT, EnumMapper.of(NumeralBase.class));
public static final Preference<AngleUnit> angleUnit = StringPreference.ofTypedValue(ANGLE_UNITS_P_KEY, ANGLE_UNITS_DEFAULT, EnumMapper.of(AngleUnit.class));
public static final Preference<Boolean> scienceNotation = BooleanPreference.of(SCIENCE_NOTATION_P_KEY, SCIENCE_NOTATION_DEFAULT);
public static final Preference<Integer> maxCalculationTime = StringPreference.ofTypedValue(MAX_CALCULATION_TIME_P_KEY, MAX_CALCULATION_TIME_DEFAULT, NumberMapper.of(Integer.class));
private static final List<String> preferenceKeys = new ArrayList<String>();
static {
preferenceKeys.add(groupingSeparator.getKey());
preferenceKeys.add(multiplicationSign.getKey());
preferenceKeys.add(precision.getKey());
preferenceKeys.add(roundResult.getKey());
preferenceKeys.add(numeralBase.getKey());
preferenceKeys.add(angleUnit.getKey());
preferenceKeys.add(scienceNotation.getKey());
preferenceKeys.add(maxCalculationTime.getKey());
}
@Nonnull
public static List<String> getPreferenceKeys() {
return Collections.unmodifiableList(preferenceKeys);
}
}
@Nonnull @Nonnull
private final Context context; private final Context context;
@Nonnull @Nonnull
private final CalculatorEngine calculatorEngine; private final CalculatorEngine calculatorEngine;
@Nonnull @Nonnull
private final Object lock; private final Object lock;
@ -135,6 +111,16 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
this.lock); this.lock);
} }
@Nonnull
public static NumeralBase getNumeralBaseFromPrefs(@Nonnull SharedPreferences preferences) {
return Preferences.numeralBase.getPreference(preferences);
}
@Nonnull
public static AngleUnit getAngleUnitsFromPrefs(@Nonnull SharedPreferences preferences) {
return Preferences.angleUnit.getPreference(preferences);
}
@Override @Override
@Nonnull @Nonnull
public CalculatorMathRegistry<IConstant> getVarsRegistry() { public CalculatorMathRegistry<IConstant> getVarsRegistry() {
@ -177,6 +163,11 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
return calculatorEngine.getNumeralBase(); return calculatorEngine.getNumeralBase();
} }
@Override
public void setNumeralBase(@Nonnull NumeralBase numeralBase) {
calculatorEngine.setNumeralBase(numeralBase);
}
@Override @Override
public void init() { public void init() {
synchronized (lock) { synchronized (lock) {
@ -235,16 +226,6 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
calculatorEngine.setAngleUnits(angleUnits); calculatorEngine.setAngleUnits(angleUnits);
} }
@Override
public void setNumeralBase(@Nonnull NumeralBase numeralBase) {
calculatorEngine.setNumeralBase(numeralBase);
}
@Override
public void setMultiplicationSign(@Nonnull String multiplicationSign) {
calculatorEngine.setMultiplicationSign(multiplicationSign);
}
@Override @Override
public void setScienceNotation(@Nonnull Boolean scienceNotation) { public void setScienceNotation(@Nonnull Boolean scienceNotation) {
calculatorEngine.setScienceNotation(scienceNotation); calculatorEngine.setScienceNotation(scienceNotation);
@ -273,16 +254,6 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
} }
} }
@Nonnull
public static NumeralBase getNumeralBaseFromPrefs(@Nonnull SharedPreferences preferences) {
return Preferences.numeralBase.getPreference(preferences);
}
@Nonnull
public static AngleUnit getAngleUnitsFromPrefs(@Nonnull SharedPreferences preferences) {
return Preferences.angleUnit.getPreference(preferences);
}
//for tests only //for tests only
public void setDecimalGroupSymbols(@Nonnull DecimalFormatSymbols decimalGroupSymbols) { public void setDecimalGroupSymbols(@Nonnull DecimalFormatSymbols decimalGroupSymbols) {
this.calculatorEngine.setDecimalGroupSymbols(decimalGroupSymbols); this.calculatorEngine.setDecimalGroupSymbols(decimalGroupSymbols);
@ -294,6 +265,10 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
return calculatorEngine.getMultiplicationSign(); return calculatorEngine.getMultiplicationSign();
} }
@Override
public void setMultiplicationSign(@Nonnull String multiplicationSign) {
calculatorEngine.setMultiplicationSign(multiplicationSign);
}
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
@ -302,4 +277,33 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
} }
} }
public static class Preferences {
public static final Preference<String> groupingSeparator = StringPreference.of(GROUPING_SEPARATOR_P_KEY, JsclMathEngine.GROUPING_SEPARATOR_DEFAULT);
public static final Preference<String> multiplicationSign = StringPreference.of(MULTIPLICATION_SIGN_P_KEY, MULTIPLICATION_SIGN_DEFAULT);
public static final Preference<Integer> precision = StringPreference.ofTypedValue(RESULT_PRECISION_P_KEY, RESULT_PRECISION_DEFAULT, NumberMapper.of(Integer.class));
public static final Preference<Boolean> roundResult = BooleanPreference.of(ROUND_RESULT_P_KEY, ROUND_RESULT_DEFAULT);
public static final Preference<NumeralBase> numeralBase = StringPreference.ofTypedValue(NUMERAL_BASES_P_KEY, NUMERAL_BASES_DEFAULT, EnumMapper.of(NumeralBase.class));
public static final Preference<AngleUnit> angleUnit = StringPreference.ofTypedValue(ANGLE_UNITS_P_KEY, ANGLE_UNITS_DEFAULT, EnumMapper.of(AngleUnit.class));
public static final Preference<Boolean> scienceNotation = BooleanPreference.of(SCIENCE_NOTATION_P_KEY, SCIENCE_NOTATION_DEFAULT);
public static final Preference<Integer> maxCalculationTime = StringPreference.ofTypedValue(MAX_CALCULATION_TIME_P_KEY, MAX_CALCULATION_TIME_DEFAULT, NumberMapper.of(Integer.class));
private static final List<String> preferenceKeys = new ArrayList<String>();
static {
preferenceKeys.add(groupingSeparator.getKey());
preferenceKeys.add(multiplicationSign.getKey());
preferenceKeys.add(precision.getKey());
preferenceKeys.add(roundResult.getKey());
preferenceKeys.add(numeralBase.getKey());
preferenceKeys.add(angleUnit.getKey());
preferenceKeys.add(scienceNotation.getKey());
preferenceKeys.add(maxCalculationTime.getKey());
}
@Nonnull
public static List<String> getPreferenceKeys() {
return Collections.unmodifiableList(preferenceKeys);
}
}
} }

View File

@ -27,6 +27,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import org.simpleframework.xml.Serializer; import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister; import org.simpleframework.xml.core.Persister;
import org.solovyev.android.calculator.CalculatorApplication; import org.solovyev.android.calculator.CalculatorApplication;
@ -34,9 +35,10 @@ import org.solovyev.android.calculator.MathEntityDao;
import org.solovyev.android.calculator.MathEntityPersistenceContainer; import org.solovyev.android.calculator.MathEntityPersistenceContainer;
import org.solovyev.android.calculator.MathPersistenceEntity; import org.solovyev.android.calculator.MathPersistenceEntity;
import java.io.StringWriter;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.StringWriter;
/** /**
* User: serso * User: serso

View File

@ -54,13 +54,10 @@ import javax.annotation.Nullable;
*/ */
public class CalculatorOnscreenService extends Service implements OnscreenViewListener, CalculatorEventListener, SharedPreferences.OnSharedPreferenceChangeListener { public class CalculatorOnscreenService extends Service implements OnscreenViewListener, CalculatorEventListener, SharedPreferences.OnSharedPreferenceChangeListener {
public static final Class<CalculatorOnscreenBroadcastReceiver> INTENT_LISTENER_CLASS = CalculatorOnscreenBroadcastReceiver.class;
private static final String SHOW_WINDOW_ACTION = "org.solovyev.android.calculator.onscreen.SHOW_WINDOW"; private static final String SHOW_WINDOW_ACTION = "org.solovyev.android.calculator.onscreen.SHOW_WINDOW";
private static final String SHOW_NOTIFICATION_ACTION = "org.solovyev.android.calculator.onscreen.SHOW_NOTIFICATION"; private static final String SHOW_NOTIFICATION_ACTION = "org.solovyev.android.calculator.onscreen.SHOW_NOTIFICATION";
private static final int NOTIFICATION_ID = 9031988; // my birthday =) private static final int NOTIFICATION_ID = 9031988; // my birthday =)
public static final Class<CalculatorOnscreenBroadcastReceiver> INTENT_LISTENER_CLASS = CalculatorOnscreenBroadcastReceiver.class;
@Nonnull @Nonnull
private CalculatorOnscreenView view; private CalculatorOnscreenView view;
@ -68,6 +65,29 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi
private boolean viewCreated = false; private boolean viewCreated = false;
@Nonnull
private static Class<?> getIntentListenerClass() {
return INTENT_LISTENER_CLASS;
}
public static void showNotification(@Nonnull Context context) {
final Intent intent = new Intent(SHOW_NOTIFICATION_ACTION);
intent.setClass(context, getIntentListenerClass());
context.sendBroadcast(intent);
}
public static void showOnscreenView(@Nonnull Context context) {
final Intent intent = createShowWindowIntent(context);
context.sendBroadcast(intent);
}
@Nonnull
private static Intent createShowWindowIntent(@Nonnull Context context) {
final Intent intent = new Intent(SHOW_WINDOW_ACTION);
intent.setClass(context, getIntentListenerClass());
return intent;
}
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
return null; return null;
@ -117,11 +137,6 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi
Locator.getInstance().getCalculator().addCalculatorEventListener(this); Locator.getInstance().getCalculator().addCalculatorEventListener(this);
} }
@Nonnull
private static Class<?> getIntentListenerClass() {
return INTENT_LISTENER_CLASS;
}
private void stopCalculatorListening() { private void stopCalculatorListening() {
Locator.getInstance().getCalculator().removeCalculatorEventListener(this); Locator.getInstance().getCalculator().removeCalculatorEventListener(this);
} }
@ -211,24 +226,6 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi
nm.notify(NOTIFICATION_ID, builder.getNotification()); nm.notify(NOTIFICATION_ID, builder.getNotification());
} }
public static void showNotification(@Nonnull Context context) {
final Intent intent = new Intent(SHOW_NOTIFICATION_ACTION);
intent.setClass(context, getIntentListenerClass());
context.sendBroadcast(intent);
}
public static void showOnscreenView(@Nonnull Context context) {
final Intent intent = createShowWindowIntent(context);
context.sendBroadcast(intent);
}
@Nonnull
private static Intent createShowWindowIntent(@Nonnull Context context) {
final Intent intent = new Intent(SHOW_WINDOW_ACTION);
intent.setClass(context, getIntentListenerClass());
return intent;
}
@Override @Override
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) { public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
switch (calculatorEventType) { switch (calculatorEventType) {

View File

@ -174,11 +174,34 @@ public class CalculatorOnscreenView {
********************************************************************** **********************************************************************
*/ */
public static void persistState(@Nonnull Context context, @Nonnull CalculatorOnscreenViewState state) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
viewStatePreference.putPreference(preferences, state);
}
@Nullable
public static CalculatorOnscreenViewState readState(@Nonnull Context context) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (viewStatePreference.isSet(preferences)) {
return viewStatePreference.getPreference(preferences);
} else {
return null;
}
}
public void updateDisplayState(@Nonnull CalculatorDisplayViewState displayState) { public void updateDisplayState(@Nonnull CalculatorDisplayViewState displayState) {
checkInit(); checkInit();
displayView.setState(displayState); displayView.setState(displayState);
} }
/*
**********************************************************************
*
* LIFECYCLE
*
**********************************************************************
*/
public void updateEditorState(@Nonnull CalculatorEditorViewState editorState) { public void updateEditorState(@Nonnull CalculatorEditorViewState editorState) {
checkInit(); checkInit();
editorView.setState(editorState); editorView.setState(editorState);
@ -194,14 +217,6 @@ public class CalculatorOnscreenView {
getWindowManager().updateViewLayout(root, params); getWindowManager().updateViewLayout(root, params);
} }
/*
**********************************************************************
*
* LIFECYCLE
*
**********************************************************************
*/
private void init() { private void init() {
if (!initialized) { if (!initialized) {
@ -358,21 +373,6 @@ public class CalculatorOnscreenView {
} }
} }
public static void persistState(@Nonnull Context context, @Nonnull CalculatorOnscreenViewState state) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
viewStatePreference.putPreference(preferences, state);
}
@Nullable
public static CalculatorOnscreenViewState readState(@Nonnull Context context) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (viewStatePreference.isSet(preferences)) {
return viewStatePreference.getPreference(preferences);
} else {
return null;
}
}
public void hide() { public void hide() {
checkInit(); checkInit();
@ -437,18 +437,12 @@ public class CalculatorOnscreenView {
@Nonnull @Nonnull
private final WindowManager wm; private final WindowManager wm;
private int orientation;
private float x0;
private float y0;
private long time = 0;
@Nonnull @Nonnull
private final View view; private final View view;
private int orientation;
private float x0;
private float y0;
private long time = 0;
private int displayWidth; private int displayWidth;
private int displayHeight; private int displayHeight;
@ -468,6 +462,19 @@ public class CalculatorOnscreenView {
initDisplayParams(); initDisplayParams();
} }
@Nonnull
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(Locale.ENGLISH, "%.2f", value);
}
}
@Override @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
if (orientation != this.wm.getDefaultDisplay().getOrientation()) { if (orientation != this.wm.getDefaultDisplay().getOrientation()) {
@ -548,18 +555,5 @@ public class CalculatorOnscreenView {
δx = Math.abs(δx); δx = Math.abs(δx);
return δx >= DIST_EPS && δx < DIST_MAX; return δx >= DIST_EPS && δx < DIST_MAX;
} }
@Nonnull
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(Locale.ENGLISH, "%.2f", value);
}
}
} }
} }

View File

@ -45,7 +45,10 @@ import javax.annotation.Nullable;
public class CalculatorOnscreenViewState implements Parcelable { public class CalculatorOnscreenViewState implements Parcelable {
private static final String TAG = CalculatorOnscreenViewState.class.getSimpleName(); private static final String TAG = CalculatorOnscreenViewState.class.getSimpleName();
private int width;
private int height;
private int x;
private int y;
public static final Parcelable.Creator<CalculatorOnscreenViewState> CREATOR = new Parcelable.Creator<CalculatorOnscreenViewState>() { public static final Parcelable.Creator<CalculatorOnscreenViewState> CREATOR = new Parcelable.Creator<CalculatorOnscreenViewState>() {
public CalculatorOnscreenViewState createFromParcel(@Nonnull Parcel in) { public CalculatorOnscreenViewState createFromParcel(@Nonnull Parcel in) {
return CalculatorOnscreenViewState.fromParcel(in); return CalculatorOnscreenViewState.fromParcel(in);
@ -56,14 +59,6 @@ public class CalculatorOnscreenViewState implements Parcelable {
} }
}; };
private int width;
private int height;
private int x;
private int y;
private CalculatorOnscreenViewState() { private CalculatorOnscreenViewState() {
} }

Some files were not shown because too many files have changed in this diff Show More