Code reformatted
This commit is contained in:
parent
11bdcae2a8
commit
4eeeb1277e
@ -28,11 +28,11 @@ import org.solovyev.android.calculator.units.CalculatorNumeralBase;
|
||||
import org.solovyev.common.units.Unit;
|
||||
import org.solovyev.common.units.UnitConverter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
|
@ -4,6 +4,7 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.junit.Before;
|
||||
@ -21,7 +22,9 @@ import static org.mockito.Mockito.verify;
|
||||
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_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)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
|
@ -1,16 +1,21 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
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.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)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
|
@ -23,7 +23,6 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.Context;
|
||||
import jscl.JsclMathEngine;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
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.Nullable;
|
||||
|
||||
import jscl.JsclMathEngine;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/7/12
|
||||
|
@ -23,8 +23,6 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.graphics.Color;
|
||||
import jscl.MathEngine;
|
||||
import jscl.NumeralBase;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -34,6 +32,9 @@ import org.solovyev.android.calculator.view.TextHighlighter;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
import jscl.MathEngine;
|
||||
import jscl.NumeralBase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -47,15 +47,9 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
public class HistoryUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testFromXml() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
private static final String emptyHistory = "<history>\n" +
|
||||
" <historyItems class=\"java.util.ArrayList\"/>\n" +
|
||||
"</history>";
|
||||
|
||||
private static final String toXml1 = "<history>\n" +
|
||||
" <historyItems class=\"java.util.ArrayList\">\n" +
|
||||
" <calculatorHistoryState>\n" +
|
||||
@ -74,7 +68,6 @@ public class HistoryUtilsTest {
|
||||
" </calculatorHistoryState>\n" +
|
||||
" </historyItems>\n" +
|
||||
"</history>";
|
||||
|
||||
private static final String toXml2 = "<history>\n" +
|
||||
" <historyItems class=\"java.util.ArrayList\">\n" +
|
||||
" <calculatorHistoryState>\n" +
|
||||
@ -136,6 +129,11 @@ public class HistoryUtilsTest {
|
||||
" </historyItems>\n" +
|
||||
"</history>";
|
||||
|
||||
@Test
|
||||
public void testFromXml() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToXml() throws Exception {
|
||||
final Date date = new Date(100000000);
|
||||
|
@ -22,14 +22,14 @@
|
||||
|
||||
package org.solovyev.android.calculator.model;
|
||||
|
||||
import jscl.math.function.IConstant;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.simpleframework.xml.Serializer;
|
||||
import org.simpleframework.xml.core.Persister;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import jscl.math.function.IConstant;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.solovyev.android.calculator.view;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -12,8 +13,14 @@ import org.robolectric.shadows.ShadowActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static jscl.AngleUnit.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static jscl.AngleUnit.deg;
|
||||
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.verify;
|
||||
import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.solovyev.android.calculator.view;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -12,8 +13,14 @@ import org.robolectric.shadows.ShadowActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static jscl.NumeralBase.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static jscl.NumeralBase.bin;
|
||||
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.verify;
|
||||
import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp;
|
||||
|
@ -26,6 +26,7 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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.Wizards;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
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;
|
||||
|
||||
@RunWith(value = CalculatorTestRunner.class)
|
||||
|
@ -11,8 +11,15 @@ import org.solovyev.android.wizard.Wizards;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.*;
|
||||
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.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)
|
||||
public class CalculatorWizardTest {
|
||||
|
@ -30,9 +30,10 @@ import org.robolectric.util.ActivityController;
|
||||
import org.solovyev.android.CalculatorTestRunner;
|
||||
import org.solovyev.android.wizard.WizardUi;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -55,7 +55,7 @@ android {
|
||||
}
|
||||
|
||||
repositories {
|
||||
flatDir{
|
||||
flatDir {
|
||||
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-analytics:8.4.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'
|
||||
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
|
||||
|
@ -1,185 +1,280 @@
|
||||
<?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.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="com.android.vending.BILLING"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="com.android.vending.BILLING" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<!--TODO: REMOVE IN PRODUCTION-->
|
||||
<!--<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>-->
|
||||
|
||||
<!-- for onscreen -->
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<supports-screens android:smallScreens="true"/>
|
||||
<supports-screens android:normalScreens="true"/>
|
||||
<supports-screens android:largeScreens="true"/>
|
||||
<supports-screens android:xlargeScreens="true"/>
|
||||
<supports-screens android:anyDensity="true"/>
|
||||
<supports-screens android:smallScreens="true" />
|
||||
<supports-screens android:normalScreens="true" />
|
||||
<supports-screens android:largeScreens="true" />
|
||||
<supports-screens android:xlargeScreens="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
|
||||
android:name="com.google.android.gms.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>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<receiver android:exported="false" android:name=".CalculatorReceiver">
|
||||
<receiver
|
||||
android:name=".CalculatorReceiver"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED"/>
|
||||
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED" />
|
||||
</intent-filter>
|
||||
</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 android:launchMode="singleTop" android:name=".wizard.WizardActivity" android:theme="@style/Cpp.Theme.Wizard">
|
||||
<activity
|
||||
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>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:hardwareAccelerated="false" android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity" android:theme="@style/Cpp.Theme.Material"/>
|
||||
<activity android:label="@string/cpp_plot_functions" android:name=".plot.CalculatorPlotFunctionsActivity" android:theme="@style/Cpp.Theme.Dialog.Material"/>
|
||||
<activity android:label="@string/cpp_plot_function_settings" android:name=".plot.CalculatorPlotFunctionSettingsActivity" android:theme="@style/Cpp.Theme.Dialog.Material"/>
|
||||
<activity android:label="@string/cpp_plot_range" android:name=".plot.CalculatorPlotRangeActivity" android:theme="@style/Cpp.Theme.Dialog.Material"/>
|
||||
<activity
|
||||
android:name=".plot.CalculatorPlotActivity"
|
||||
android:hardwareAccelerated="false"
|
||||
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-->
|
||||
<activity android:label="@string/c_plot_graph" android:name=".matrix.CalculatorMatrixActivity">
|
||||
<activity
|
||||
android:name=".matrix.CalculatorMatrixActivity"
|
||||
android:label="@string/c_plot_graph">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
</intent-filter>
|
||||
</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>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- 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>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<service android:exported="false" android:name=".onscreen.CalculatorOnscreenService">
|
||||
<service
|
||||
android:name=".onscreen.CalculatorOnscreenService"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<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_WINDOW" />
|
||||
<action android:name="org.solovyev.android.calculator.onscreen.SHOW_NOTIFICATION" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<receiver android:name=".onscreen.CalculatorOnscreenBroadcastReceiver">
|
||||
<intent-filter>
|
||||
<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_NOTIFICATION"/>
|
||||
<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_NOTIFICATION" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<!-- 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>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||
<action android:name="org.solovyev.android.calculator.INIT"/>
|
||||
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
|
||||
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
|
||||
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED"/>
|
||||
<action android:name="org.solovyev.android.calculator.THEME_CHANGED"/>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
<action android:name="org.solovyev.android.calculator.INIT" />
|
||||
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED" />
|
||||
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED" />
|
||||
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED" />
|
||||
<action android:name="org.solovyev.android.calculator.THEME_CHANGED" />
|
||||
</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 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>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||
<action android:name="org.solovyev.android.calculator.INIT"/>
|
||||
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
|
||||
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
|
||||
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED"/>
|
||||
<action android:name="org.solovyev.android.calculator.THEME_CHANGED"/>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
<action android:name="org.solovyev.android.calculator.INIT" />
|
||||
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED" />
|
||||
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED" />
|
||||
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED" />
|
||||
<action android:name="org.solovyev.android.calculator.THEME_CHANGED" />
|
||||
</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 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>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||
<action android:name="org.solovyev.android.calculator.INIT"/>
|
||||
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
|
||||
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
|
||||
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED"/>
|
||||
<action android:name="org.solovyev.android.calculator.THEME_CHANGED"/>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
<action android:name="org.solovyev.android.calculator.INIT" />
|
||||
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED" />
|
||||
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED" />
|
||||
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED" />
|
||||
<action android:name="org.solovyev.android.calculator.THEME_CHANGED" />
|
||||
</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 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>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||
<action android:name="org.solovyev.android.calculator.INIT"/>
|
||||
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
|
||||
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
|
||||
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED"/>
|
||||
<action android:name="org.solovyev.android.calculator.THEME_CHANGED"/>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
<action android:name="org.solovyev.android.calculator.INIT" />
|
||||
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED" />
|
||||
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED" />
|
||||
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED" />
|
||||
<action android:name="org.solovyev.android.calculator.THEME_CHANGED" />
|
||||
</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 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>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||
<action android:name="org.solovyev.android.calculator.INIT"/>
|
||||
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED"/>
|
||||
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED"/>
|
||||
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED"/>
|
||||
<action android:name="org.solovyev.android.calculator.THEME_CHANGED"/>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
<action android:name="org.solovyev.android.calculator.INIT" />
|
||||
<action android:name="org.solovyev.android.calculator.EDITOR_STATE_CHANGED" />
|
||||
<action android:name="org.solovyev.android.calculator.DISPLAY_STATE_CHANGED" />
|
||||
<action android:name="org.solovyev.android.calculator.BUTTON_PRESSED" />
|
||||
<action android:name="org.solovyev.android.calculator.THEME_CHANGED" />
|
||||
</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>
|
||||
|
||||
<!-- ADMOB -->
|
||||
@ -191,20 +286,25 @@
|
||||
|
||||
<!-- 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 -->
|
||||
<receiver
|
||||
android:name="com.google.android.gms.analytics.AnalyticsReceiver"
|
||||
android:enabled="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH"/>
|
||||
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<service
|
||||
android:name="com.google.android.gms.analytics.AnalyticsService"
|
||||
android:enabled="true"
|
||||
android:exported="false"/>
|
||||
android:exported="false" />
|
||||
|
||||
</application>
|
||||
</manifest>
|
@ -32,6 +32,7 @@ import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
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 {
|
||||
private static final int INVALID_POINTER = -1;
|
||||
|
||||
private float mRadius;
|
||||
private final Paint mPaintPageFill = new Paint(ANTI_ALIAS_FLAG);
|
||||
private final Paint mPaintStroke = new Paint(ANTI_ALIAS_FLAG);
|
||||
private final Paint mPaintFill = new Paint(ANTI_ALIAS_FLAG);
|
||||
private float mRadius;
|
||||
private ViewPager mViewPager;
|
||||
private ViewPager.OnPageChangeListener mListener;
|
||||
private int mCurrentPage;
|
||||
@ -114,18 +114,12 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
|
||||
}
|
||||
|
||||
|
||||
public void setCentered(boolean centered) {
|
||||
mCentered = centered;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public boolean isCentered() {
|
||||
return mCentered;
|
||||
}
|
||||
|
||||
public void setPageColor(int pageColor) {
|
||||
mPaintPageFill.setColor(pageColor);
|
||||
public void setCentered(boolean centered) {
|
||||
mCentered = centered;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@ -133,8 +127,8 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
return mPaintPageFill.getColor();
|
||||
}
|
||||
|
||||
public void setFillColor(int fillColor) {
|
||||
mPaintFill.setColor(fillColor);
|
||||
public void setPageColor(int pageColor) {
|
||||
mPaintPageFill.setColor(pageColor);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@ -142,6 +136,15 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
return mPaintFill.getColor();
|
||||
}
|
||||
|
||||
public void setFillColor(int fillColor) {
|
||||
mPaintFill.setColor(fillColor);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public int getOrientation() {
|
||||
return mOrientation;
|
||||
}
|
||||
|
||||
public void setOrientation(int orientation) {
|
||||
switch (orientation) {
|
||||
case HORIZONTAL:
|
||||
@ -155,8 +158,8 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
}
|
||||
}
|
||||
|
||||
public int getOrientation() {
|
||||
return mOrientation;
|
||||
public int getStrokeColor() {
|
||||
return mPaintStroke.getColor();
|
||||
}
|
||||
|
||||
public void setStrokeColor(int strokeColor) {
|
||||
@ -164,8 +167,8 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public int getStrokeColor() {
|
||||
return mPaintStroke.getColor();
|
||||
public float getStrokeWidth() {
|
||||
return mPaintStroke.getStrokeWidth();
|
||||
}
|
||||
|
||||
public void setStrokeWidth(float strokeWidth) {
|
||||
@ -173,8 +176,8 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public float getStrokeWidth() {
|
||||
return mPaintStroke.getStrokeWidth();
|
||||
public float getRadius() {
|
||||
return mRadius;
|
||||
}
|
||||
|
||||
public void setRadius(float radius) {
|
||||
@ -182,8 +185,8 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public float getRadius() {
|
||||
return mRadius;
|
||||
public boolean isSnap() {
|
||||
return mSnap;
|
||||
}
|
||||
|
||||
public void setSnap(boolean snap) {
|
||||
@ -191,10 +194,6 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public boolean isSnap() {
|
||||
return mSnap;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
@ -454,8 +453,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
/**
|
||||
* Determines the width of this view
|
||||
*
|
||||
* @param measureSpec
|
||||
* A measureSpec packed into an int
|
||||
* @param measureSpec A measureSpec packed into an int
|
||||
* @return The width of the view, honoring constraints from measureSpec
|
||||
*/
|
||||
private int measureLong(int measureSpec) {
|
||||
@ -469,7 +467,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
} else {
|
||||
//Calculate the width according the views count
|
||||
final int count = mViewPager.getAdapter().getCount();
|
||||
result = (int)(getPaddingLeft() + getPaddingRight()
|
||||
result = (int) (getPaddingLeft() + getPaddingRight()
|
||||
+ (count * 2 * mRadius) + (count - 1) * mRadius + 1);
|
||||
//Respect AT_MOST value if that was what is called for by measureSpec
|
||||
if (specMode == MeasureSpec.AT_MOST) {
|
||||
@ -482,8 +480,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
/**
|
||||
* Determines the height of this view
|
||||
*
|
||||
* @param measureSpec
|
||||
* A measureSpec packed into an int
|
||||
* @param measureSpec A measureSpec packed into an int
|
||||
* @return The height of the view, honoring constraints from measureSpec
|
||||
*/
|
||||
private int measureShort(int measureSpec) {
|
||||
@ -496,7 +493,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
result = specSize;
|
||||
} else {
|
||||
//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
|
||||
if (specMode == MeasureSpec.AT_MOST) {
|
||||
result = Math.min(result, specSize);
|
||||
@ -507,7 +504,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Parcelable state) {
|
||||
SavedState savedState = (SavedState)state;
|
||||
SavedState savedState = (SavedState) state;
|
||||
super.onRestoreInstanceState(savedState.getSuperState());
|
||||
mCurrentPage = savedState.currentPage;
|
||||
mSnapPage = savedState.currentPage;
|
||||
@ -523,6 +520,18 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
public SavedState(Parcelable superState) {
|
||||
@ -539,18 +548,5 @@ public class CirclePageIndicator extends View implements PageIndicator {
|
||||
super.writeToParcel(dest, flags);
|
||||
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];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public interface PageIndicator extends ViewPager.OnPageChangeListener {
|
||||
|
||||
/**
|
||||
* <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
|
||||
* the views are drawn on screen (e.g., default start page).</p>
|
||||
*
|
||||
|
@ -36,6 +36,10 @@ public final class Check {
|
||||
|
||||
private static final boolean junit = isJunit();
|
||||
|
||||
private Check() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
private static boolean isJunit() {
|
||||
final StackTraceElement[] stackTrace = currentThread().getStackTrace();
|
||||
for (StackTraceElement element : stackTrace) {
|
||||
@ -46,10 +50,6 @@ public final class Check {
|
||||
return false;
|
||||
}
|
||||
|
||||
private Check() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static void isMainThread() {
|
||||
if (!junit && Looper.getMainLooper() != Looper.myLooper()) {
|
||||
throw new AssertionException("Should be called on the main thread");
|
||||
|
@ -68,8 +68,32 @@ public class ActivityUi extends BaseUi {
|
||||
this.layoutId = layoutId;
|
||||
}
|
||||
|
||||
public void setLayoutId(int layoutId) {
|
||||
this.layoutId = layoutId;
|
||||
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 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) {
|
||||
@ -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) {
|
||||
}
|
||||
|
||||
@ -270,6 +274,10 @@ public class ActivityUi extends BaseUi {
|
||||
return layoutId;
|
||||
}
|
||||
|
||||
public void setLayoutId(int layoutId) {
|
||||
this.layoutId = layoutId;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Preferences.Gui.Theme getTheme() {
|
||||
return theme;
|
||||
@ -354,15 +362,7 @@ public class ActivityUi extends BaseUi {
|
||||
reportActivityStop(activity);
|
||||
}
|
||||
|
||||
public static void reportActivityStop(@Nonnull Activity activity) {
|
||||
App.getGa().getAnalytics().reportActivityStop(activity);
|
||||
}
|
||||
|
||||
public void onStart(@Nonnull Activity activity) {
|
||||
reportActivityStart(activity);
|
||||
}
|
||||
|
||||
public static void reportActivityStart(@Nonnull Activity activity) {
|
||||
App.getGa().getAnalytics().reportActivityStart(activity);
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class AdView extends FrameLayout {
|
||||
admobView.setAdListener(null);
|
||||
admobView = null;
|
||||
}
|
||||
if(admobListener != null) {
|
||||
if (admobListener != null) {
|
||||
admobListener.destroy();
|
||||
admobListener = null;
|
||||
}
|
||||
@ -86,7 +86,7 @@ public class AdView extends FrameLayout {
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
if(admobView == null) {
|
||||
if (admobView == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -80,13 +80,13 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCalculateOnFly(boolean calculateOnFly) {
|
||||
calculator.setCalculateOnFly(calculateOnFly);
|
||||
public boolean isCalculateOnFly() {
|
||||
return calculator.isCalculateOnFly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCalculateOnFly() {
|
||||
return calculator.isCalculateOnFly();
|
||||
public void setCalculateOnFly(boolean calculateOnFly) {
|
||||
calculator.setCalculateOnFly(calculateOnFly);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -157,17 +157,17 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
|
||||
calculator.doHistoryAction(historyAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentHistoryState(@Nonnull CalculatorHistoryState editorHistoryState) {
|
||||
calculator.setCurrentHistoryState(editorHistoryState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public CalculatorHistoryState getCurrentHistoryState() {
|
||||
return calculator.getCurrentHistoryState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentHistoryState(@Nonnull CalculatorHistoryState editorHistoryState) {
|
||||
calculator.setCurrentHistoryState(editorHistoryState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate() {
|
||||
calculator.evaluate();
|
||||
|
@ -53,13 +53,13 @@ public class AndroidCalculatorClipboard implements CalculatorClipboard {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(@Nonnull String text) {
|
||||
public void setText(@Nonnull CharSequence text) {
|
||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipboard.setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(@Nonnull CharSequence text) {
|
||||
public void setText(@Nonnull String text) {
|
||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipboard.setText(text);
|
||||
}
|
||||
|
@ -64,16 +64,12 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@Nonnull
|
||||
private volatile CalculatorDisplayViewState state = CalculatorDisplayViewStateImpl.newDefaultInstance();
|
||||
|
||||
@Nonnull
|
||||
private final Object lock = new Object();
|
||||
|
||||
@Nonnull
|
||||
private final Handler uiHandler = new Handler();
|
||||
|
||||
@Nonnull
|
||||
private volatile CalculatorDisplayViewState state = CalculatorDisplayViewStateImpl.newDefaultInstance();
|
||||
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
|
||||
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
|
||||
private CharSequence prepareText(@Nullable String text, boolean valid) {
|
||||
CharSequence result;
|
||||
|
@ -43,17 +43,14 @@ import javax.annotation.Nonnull;
|
||||
*/
|
||||
public class AndroidCalculatorEditorView extends EditText implements CalculatorEditorView {
|
||||
|
||||
@Nonnull
|
||||
private final Handler uiHandler = new Handler();
|
||||
private volatile boolean initialized = false;
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
@Nonnull
|
||||
private volatile CalculatorEditorViewState viewState = CalculatorEditorViewStateImpl.newDefaultInstance();
|
||||
|
||||
private volatile boolean viewStateChange = false;
|
||||
|
||||
@Nonnull
|
||||
private final Handler uiHandler = new Handler();
|
||||
|
||||
public AndroidCalculatorEditorView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
@ -22,13 +22,8 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
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.Nullable;
|
||||
|
@ -25,14 +25,16 @@ package org.solovyev.android.calculator;
|
||||
import android.app.Application;
|
||||
import android.os.Handler;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.solovyev.android.Threads;
|
||||
import org.solovyev.android.msg.AndroidMessage;
|
||||
import org.solovyev.common.msg.Message;
|
||||
import org.solovyev.common.msg.MessageType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
|
@ -25,10 +25,6 @@ package org.solovyev.android.calculator;
|
||||
import android.app.Application;
|
||||
import android.content.SharedPreferences;
|
||||
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.msg.AndroidMessage;
|
||||
@ -37,6 +33,11 @@ import org.solovyev.common.msg.MessageType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import jscl.AngleUnit;
|
||||
import jscl.NumeralBase;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/17/12
|
||||
|
@ -44,10 +44,6 @@ public enum AndroidFunctionCategory {
|
||||
this.captionId = captionId;
|
||||
}
|
||||
|
||||
public int getCaptionId() {
|
||||
return captionId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static AndroidFunctionCategory valueOf(@Nonnull FunctionCategory functionCategory) {
|
||||
for (AndroidFunctionCategory androidFunctionCategory : values()) {
|
||||
@ -58,4 +54,8 @@ public enum AndroidFunctionCategory {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getCaptionId() {
|
||||
return captionId;
|
||||
}
|
||||
}
|
||||
|
@ -23,18 +23,19 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
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.DragDirection;
|
||||
import org.solovyev.android.calculator.units.CalculatorNumeralBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import jscl.NumeralBase;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 4/21/12
|
||||
@ -98,6 +99,17 @@ public enum AndroidNumeralBase {
|
||||
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
|
||||
public abstract List<Integer> getButtonIds();
|
||||
|
||||
@ -119,15 +131,4 @@ public enum AndroidNumeralBase {
|
||||
public NumeralBase 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!");
|
||||
}
|
||||
}
|
||||
|
@ -43,10 +43,6 @@ public enum AndroidOperatorCategory {
|
||||
this.captionId = captionId;
|
||||
}
|
||||
|
||||
public int getCaptionId() {
|
||||
return captionId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static AndroidOperatorCategory valueOf(@Nonnull OperatorCategory operatorCategory) {
|
||||
for (AndroidOperatorCategory androidOperatorCategory : values()) {
|
||||
@ -57,4 +53,8 @@ public enum AndroidOperatorCategory {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getCaptionId() {
|
||||
return captionId;
|
||||
}
|
||||
}
|
||||
|
@ -41,10 +41,6 @@ public enum AndroidVarCategory {
|
||||
this.captionId = captionId;
|
||||
}
|
||||
|
||||
public int getCaptionId() {
|
||||
return captionId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static AndroidVarCategory valueOf(@Nonnull VarCategory varCategory) {
|
||||
for (AndroidVarCategory androidVarCategory : values()) {
|
||||
@ -55,4 +51,8 @@ public enum AndroidVarCategory {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getCaptionId() {
|
||||
return captionId;
|
||||
}
|
||||
}
|
||||
|
@ -86,47 +86,33 @@ import javax.annotation.Nullable;
|
||||
public final class App {
|
||||
@Nonnull
|
||||
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
|
||||
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
|
||||
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() {
|
||||
throw new AssertionError();
|
||||
|
@ -32,8 +32,13 @@ import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
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.HistoryDragProcessor;
|
||||
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.common.math.Point2d;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
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_mobile;
|
||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.angleUnit;
|
||||
@ -79,6 +85,38 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan
|
||||
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) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
|
||||
@ -246,38 +284,6 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan
|
||||
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
|
||||
private CalculatorKeyboard getKeyboard() {
|
||||
return Locator.getInstance().getKeyboard();
|
||||
|
@ -3,6 +3,7 @@ package org.solovyev.android.calculator;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import org.solovyev.android.calculator.view.ViewsCache;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -32,8 +32,13 @@ import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
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 org.solovyev.android.Activities;
|
||||
import org.solovyev.android.Android;
|
||||
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 org.solovyev.android.calculator.Preferences.Gui.preventScreenFromFading;
|
||||
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 {
|
||||
|
||||
@ -67,70 +74,6 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
|
||||
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) {
|
||||
final Integer appOpenedCounter = Preferences.appOpenedCounter.getPreference(preferences);
|
||||
if (appOpenedCounter != null) {
|
||||
@ -200,6 +143,70 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
|
||||
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
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
|
@ -29,16 +29,20 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import jscl.math.Generic;
|
||||
|
||||
import org.solovyev.android.Android;
|
||||
import org.solovyev.android.calculator.about.CalculatorAboutActivity;
|
||||
import org.solovyev.android.calculator.function.FunctionEditDialogFragment;
|
||||
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.plot.CalculatorPlotActivity;
|
||||
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.text.Strings;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import jscl.math.Generic;
|
||||
|
||||
/**
|
||||
* 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
|
||||
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -58,8 +58,8 @@ import javax.annotation.Nonnull;
|
||||
formUri = "https://serso.cloudant.com/acra-cpp/_design/acra-storage/_update/report",
|
||||
reportType = org.acra.sender.HttpSender.Type.JSON,
|
||||
httpMethod = org.acra.sender.HttpSender.Method.PUT,
|
||||
formUriBasicAuthLogin="timbeenterumisideffecird",
|
||||
formUriBasicAuthPassword="ECL65PO2TH5quIFNAK4hQ5Ng",
|
||||
formUriBasicAuthLogin = "timbeenterumisideffecird",
|
||||
formUriBasicAuthPassword = "ECL65PO2TH5quIFNAK4hQ5Ng",
|
||||
mode = ReportingInteractionMode.TOAST,
|
||||
resToastText = R.string.crashed)
|
||||
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_P_KEY = "org.solovyev.android.calculator_ad_free";
|
||||
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
|
||||
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
|
||||
protected final Handler uiHandler = new Handler();
|
||||
|
||||
@Nonnull
|
||||
private final List<CalculatorEventListener> listeners = new ArrayList<CalculatorEventListener>();
|
||||
@Nonnull
|
||||
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
|
||||
public void onCreate() {
|
||||
if (!BuildConfig.DEBUG) {
|
||||
@ -231,6 +240,14 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
||||
return new FragmentUi(layoutId, titleResId, listenersOnCreate);
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@Nonnull
|
||||
public Handler getUiHandler() {
|
||||
return uiHandler;
|
||||
@ -249,29 +266,6 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
||||
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
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
if (Preferences.Onscreen.showAppIcon.getKey().equals(key)) {
|
||||
|
@ -22,15 +22,19 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
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
|
||||
@ -84,16 +88,13 @@ public enum CalculatorButton {
|
||||
equals(R.id.cpp_button_equals, CalculatorSpecialButton.equals);
|
||||
|
||||
|
||||
private final int buttonId;
|
||||
|
||||
@Nonnull
|
||||
private final String onClickText;
|
||||
|
||||
@Nullable
|
||||
private final String onLongClickText;
|
||||
|
||||
@Nonnull
|
||||
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) {
|
||||
this(buttonId, onClickButton.getActionCode(), onLongClickButton == null ? null : onLongClickButton.getActionCode());
|
||||
@ -114,16 +115,6 @@ public enum CalculatorButton {
|
||||
this(buttonId, onClickText, null);
|
||||
}
|
||||
|
||||
public void onLongClick() {
|
||||
if (onLongClickText != null) {
|
||||
Locator.getInstance().getKeyboard().buttonPressed(onLongClickText);
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick() {
|
||||
Locator.getInstance().getKeyboard().buttonPressed(onClickText);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CalculatorButton getById(int buttonId) {
|
||||
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() {
|
||||
return buttonId;
|
||||
}
|
||||
|
@ -33,22 +33,23 @@ import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.RemoteViews;
|
||||
import jscl.AngleUnit;
|
||||
import jscl.NumeralBase;
|
||||
|
||||
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.DragDirection;
|
||||
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.common.math.Point2d;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import jscl.AngleUnit;
|
||||
import jscl.NumeralBase;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* 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 {
|
||||
|
||||
@Nonnull
|
||||
@ -144,11 +150,6 @@ public final class CalculatorButtons {
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static CalculatorKeyboard getKeyboard() {
|
||||
return Locator.getInstance().getKeyboard();
|
||||
}
|
||||
|
||||
static class VarsDragProcessor implements SimpleDragListener.DragProcessor {
|
||||
|
||||
@Nonnull
|
||||
|
@ -26,21 +26,20 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
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.fragments.FragmentUtils;
|
||||
import org.solovyev.common.msg.MessageType;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 1/20/13
|
||||
@ -62,29 +61,6 @@ public class CalculatorDialogActivity extends ActionBarActivity {
|
||||
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
|
||||
private static DialogData readDialogData(@Nullable Intent in) {
|
||||
if (in != null) {
|
||||
@ -109,6 +85,29 @@ public class CalculatorDialogActivity extends ActionBarActivity {
|
||||
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 CalculatorDialogFragment() {
|
||||
|
@ -25,12 +25,11 @@ package org.solovyev.android.calculator;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
|
@ -23,7 +23,7 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.Context;
|
||||
import jscl.math.Generic;
|
||||
|
||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
||||
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
|
||||
@ -31,6 +31,8 @@ import org.solovyev.android.menu.LabeledMenuItem;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import jscl.math.Generic;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
* Date: 21.09.12
|
||||
|
@ -25,14 +25,14 @@ package org.solovyev.android.calculator;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.View;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.solovyev.android.menu.ContextMenuBuilder;
|
||||
import org.solovyev.android.menu.ListContextMenu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
* Date: 21.09.12
|
||||
|
@ -27,7 +27,13 @@ import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
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.AndroidMenuHelper;
|
||||
import org.solovyev.android.menu.ListActivityMenu;
|
||||
|
@ -24,12 +24,11 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
|
@ -69,11 +69,9 @@ public enum CalculatorFragmentType {
|
||||
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);
|
||||
|
||||
private final int defaultLayoutId;
|
||||
@Nonnull
|
||||
private Class<? extends Fragment> fragmentClass;
|
||||
|
||||
private final int defaultLayoutId;
|
||||
|
||||
private int defaultTitleResId;
|
||||
|
||||
private CalculatorFragmentType(@Nonnull Class<? extends Fragment> fragmentClass,
|
||||
|
@ -24,10 +24,10 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
@ -24,12 +24,11 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import android.support.v4.app.ListFragment;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
|
@ -25,14 +25,13 @@ package org.solovyev.android.calculator;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import android.view.MenuItem;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
|
||||
import org.solovyev.android.menu.LabeledMenuItem;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 4/23/12
|
||||
|
@ -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_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
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -22,11 +22,11 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import org.solovyev.common.JPredicate;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.solovyev.common.JPredicate;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/3/11
|
||||
@ -34,10 +34,9 @@ import org.solovyev.common.JPredicate;
|
||||
*/
|
||||
public class CharacterAtPositionFinder implements JPredicate<Character> {
|
||||
|
||||
private int i;
|
||||
|
||||
@Nonnull
|
||||
private final String targetString;
|
||||
private int i;
|
||||
|
||||
public CharacterAtPositionFinder(@Nonnull String targetString, int i) {
|
||||
this.targetString = targetString;
|
||||
|
@ -23,14 +23,15 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
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.menu.AMenuItem;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import jscl.NumeralBase;
|
||||
import jscl.math.Generic;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/21/12
|
||||
|
@ -23,6 +23,7 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import org.solovyev.android.calculator.drag.DirectionDragButton;
|
||||
import org.solovyev.android.calculator.drag.DragButton;
|
||||
import org.solovyev.android.calculator.drag.DragDirection;
|
||||
|
@ -23,6 +23,7 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import org.solovyev.android.calculator.drag.DirectionDragButton;
|
||||
import org.solovyev.android.calculator.drag.DragButton;
|
||||
import org.solovyev.android.calculator.drag.DragDirection;
|
||||
|
@ -24,14 +24,14 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
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.SimpleDragListener;
|
||||
import org.solovyev.common.math.Point2d;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/24/11
|
||||
|
@ -24,6 +24,7 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.solovyev.common.msg.Message;
|
||||
import org.solovyev.common.msg.MessageType;
|
||||
|
||||
@ -48,22 +49,10 @@ public class FixableMessage implements Parcelable {
|
||||
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
|
||||
private final String message;
|
||||
|
||||
@Nonnull
|
||||
private final MessageType messageType;
|
||||
|
||||
@Nullable
|
||||
private final FixableError fixableError;
|
||||
|
||||
@ -82,6 +71,15 @@ public class FixableMessage implements Parcelable {
|
||||
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
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
@ -36,14 +36,16 @@ import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.solovyev.common.msg.Message;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/17/12
|
||||
@ -59,6 +61,32 @@ public class FixableMessagesDialog extends ActionBarActivity {
|
||||
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
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -99,6 +127,14 @@ public class FixableMessagesDialog extends ActionBarActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private void onInputChanged() {
|
||||
final ViewGroup viewGroup = (ViewGroup) findViewById(R.id.cpp_fixable_messages_container);
|
||||
viewGroup.removeAllViews();
|
||||
@ -139,40 +175,6 @@ public class FixableMessagesDialog extends ActionBarActivity {
|
||||
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 {
|
||||
|
||||
public static final Creator<Input> CREATOR = new Creator<Input>() {
|
||||
@ -186,6 +188,14 @@ public class FixableMessagesDialog extends ActionBarActivity {
|
||||
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
|
||||
private static Input fromParcel(@Nonnull Parcel in) {
|
||||
@ -195,15 +205,14 @@ public class FixableMessagesDialog extends ActionBarActivity {
|
||||
return new Input(messages, showCheckbox);
|
||||
}
|
||||
|
||||
|
||||
@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;
|
||||
|
||||
private Input(@Nonnull List<FixableMessage> messages, boolean showCheckbox) {
|
||||
this.messages = messages;
|
||||
this.showCheckbox = showCheckbox;
|
||||
return new Input(stringMessages, showCheckbox);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@ -222,16 +231,6 @@ public class FixableMessagesDialog extends ActionBarActivity {
|
||||
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() {
|
||||
return showCheckbox;
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ import android.support.v4.app.FragmentActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.solovyev.android.checkout.ActivityCheckout;
|
||||
@ -125,7 +124,7 @@ public class FragmentUi extends BaseUi {
|
||||
}
|
||||
|
||||
private void updateAdViewState() {
|
||||
if(adFree == null || adView == null) {
|
||||
if (adFree == null || adView == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,10 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import jscl.NumeralBase;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import jscl.NumeralBase;
|
||||
|
||||
import static jscl.NumeralBase.hex;
|
||||
import static org.solovyev.android.calculator.Preferences.Gui.hideNumeralBaseDigits;
|
||||
|
@ -24,6 +24,7 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.solovyev.common.msg.MessageLevel;
|
||||
import org.solovyev.common.msg.MessageType;
|
||||
|
||||
|
@ -61,265 +61,12 @@ import static org.solovyev.android.DeviceModel.samsung_galaxy_s_2;
|
||||
|
||||
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() {
|
||||
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) {
|
||||
|
||||
if (!AndroidCalculatorEngine.Preferences.groupingSeparator.isSet(preferences)) {
|
||||
@ -404,4 +151,255 @@ public final class 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,8 +23,9 @@
|
||||
package org.solovyev.android.calculator.about;
|
||||
|
||||
import android.os.Bundle;
|
||||
import org.solovyev.android.calculator.EmptyActivity;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.EmptyActivity;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -27,6 +27,7 @@ import android.text.method.LinkMovementMethod;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.CalculatorFragment;
|
||||
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 translatorsTextView = (TextView) root.findViewById(R.id.cpp_about_translators);
|
||||
if(isEmpty(translatorsTextView.getText())) {
|
||||
if (isEmpty(translatorsTextView.getText())) {
|
||||
translatorsTextTextView.setVisibility(GONE);
|
||||
translatorsTextView.setVisibility(GONE);
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import android.text.Html;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorFragment;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
@ -30,18 +30,20 @@ import android.graphics.Paint;
|
||||
import android.text.TextPaint;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import org.solovyev.common.math.Point2d;
|
||||
import org.solovyev.common.text.NumberParser;
|
||||
import org.solovyev.common.text.StringCollections;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class DirectionDragButton extends DragButton {
|
||||
|
||||
@Nonnull
|
||||
@ -54,203 +56,13 @@ public class DirectionDragButton extends DragButton {
|
||||
|
||||
@Nonnull
|
||||
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
|
||||
private final Map<GuiDragDirection, DirectionTextData> textDataMap = new EnumMap<>(GuiDragDirection.class);
|
||||
|
||||
@Nonnull
|
||||
protected String directionTextScale = DEFAULT_DIRECTION_TEXT_SCALE;
|
||||
|
||||
@Nonnull
|
||||
protected Integer directionTextAlpha = DEFAULT_DIRECTION_TEXT_ALPHA;
|
||||
|
||||
protected int directionTextColor = DEFAULT_DIRECTION_TEXT_COLOR;
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
public DirectionDragButton(Context context, @Nonnull AttributeSet attrs) {
|
||||
@ -388,7 +200,6 @@ public class DirectionDragButton extends DragButton {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
public String getDirectionTextScale() {
|
||||
return directionTextScale;
|
||||
@ -421,4 +232,186 @@ public class DirectionDragButton extends DragButton {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ package org.solovyev.android.calculator.drag;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.Button;
|
||||
|
||||
import org.solovyev.android.view.AndroidViewUtils;
|
||||
import org.solovyev.common.math.Point2d;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
@ -23,6 +23,7 @@
|
||||
package org.solovyev.android.calculator.drag;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import org.solovyev.common.math.Point2d;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -22,9 +22,10 @@
|
||||
|
||||
package org.solovyev.android.calculator.drag;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.EventListener;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
public interface DragListener extends EventListener {
|
||||
|
||||
|
@ -23,9 +23,7 @@
|
||||
package org.solovyev.android.calculator.drag;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.view.ViewConfigurationCompat;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewConfiguration;
|
||||
|
||||
import org.solovyev.android.calculator.R;
|
||||
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.Point2d;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
public class SimpleDragListener implements DragListener {
|
||||
|
||||
@Nonnull
|
||||
@ -63,6 +61,36 @@ public class SimpleDragListener implements DragListener {
|
||||
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
|
||||
public boolean onDrag(@Nonnull DragButton dragButton, @Nonnull DragEvent event) {
|
||||
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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
@ -34,23 +34,33 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import jscl.math.Generic;
|
||||
import jscl.math.function.Constant;
|
||||
import jscl.math.function.CustomFunction;
|
||||
import jscl.math.function.Function;
|
||||
import jscl.math.function.IFunction;
|
||||
import org.solovyev.android.calculator.*;
|
||||
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.CalculatorDisplayViewState;
|
||||
import org.solovyev.android.calculator.CalculatorEventData;
|
||||
import org.solovyev.android.calculator.CalculatorEventListener;
|
||||
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.CalculatorFunctionsFragment;
|
||||
import org.solovyev.android.calculator.math.edit.MathEntityRemover;
|
||||
import org.solovyev.android.calculator.model.AFunction;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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
|
||||
* Date: 11/13/12
|
||||
@ -75,6 +85,21 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
|
||||
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
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -168,6 +193,14 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
|
||||
Locator.getInstance().getCalculator().addCalculatorEventListener(this);
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
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 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>() {
|
||||
@Override
|
||||
public String createFromParcel(@Nonnull Parcel in) {
|
||||
@ -237,6 +235,30 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
|
||||
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
|
||||
private static Input fromParcel(@Nonnull Parcel in) {
|
||||
@ -254,24 +276,6 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
|
||||
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
|
||||
public static Input newInstance() {
|
||||
return new Input();
|
||||
@ -303,6 +307,24 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
|
||||
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
|
||||
public AFunction getFunction() {
|
||||
return function;
|
||||
@ -341,23 +363,5 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul
|
||||
out.writeList(parameterNames);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,12 +24,6 @@ package org.solovyev.android.calculator.function;
|
||||
|
||||
import android.view.View;
|
||||
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.CalculatorMathRegistry;
|
||||
@ -43,6 +37,13 @@ import org.solovyev.common.text.Strings;
|
||||
import java.util.Collections;
|
||||
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 {
|
||||
|
||||
@Nonnull
|
||||
@ -74,6 +75,23 @@ public class FunctionEditorSaver implements View.OnClickListener {
|
||||
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
|
||||
public void onClick(View v) {
|
||||
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) {
|
||||
for (String parameterName : parameterNames) {
|
||||
if (!VarEditorSaver.isValidName(parameterName)) {
|
||||
|
@ -32,25 +32,26 @@ import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import jscl.text.MutableInt;
|
||||
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import jscl.text.MutableInt;
|
||||
|
||||
public class FunctionParamsView extends LinearLayout {
|
||||
|
||||
private static final String PARAM_TAG_PREFIX = "function_param_";
|
||||
@Nonnull
|
||||
private final MutableInt paramsCount = new MutableInt(0);
|
||||
|
||||
@Nonnull
|
||||
private final List<Integer> paramIds = new ArrayList<Integer>(10);
|
||||
|
||||
private static final String PARAM_TAG_PREFIX = "function_param_";
|
||||
|
||||
public FunctionParamsView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
@ -4,20 +4,23 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.gms.analytics.GoogleAnalytics;
|
||||
import com.google.android.gms.analytics.HitBuilders;
|
||||
import com.google.android.gms.analytics.Tracker;
|
||||
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.common.listeners.JEvent;
|
||||
import org.solovyev.common.listeners.JEventListener;
|
||||
import org.solovyev.common.listeners.JEventListeners;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class Ga implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private static final int LAYOUT = 1;
|
||||
|
@ -26,14 +26,16 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.solovyev.android.calculator.Calculator;
|
||||
import org.solovyev.android.calculator.CalculatorEventData;
|
||||
import org.solovyev.android.calculator.CalculatorEventType;
|
||||
import org.solovyev.common.history.HistoryAction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
|
@ -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>() {
|
||||
@Override
|
||||
public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) {
|
||||
@ -105,6 +102,8 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
|
||||
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());
|
||||
|
||||
@Nonnull
|
||||
private final SharedPreferences.OnSharedPreferenceChangeListener preferencesListener = new HistoryOnPreferenceChangeListener();
|
||||
|
||||
@Nonnull
|
||||
private final DialogInterface.OnClickListener clearDialogListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@ -137,6 +126,10 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
|
||||
}
|
||||
}
|
||||
};
|
||||
@Nonnull
|
||||
private HistoryArrayAdapter adapter;
|
||||
@Nonnull
|
||||
private FragmentUi ui;
|
||||
@Nullable
|
||||
private AlertDialog clearDialog;
|
||||
|
||||
@ -144,6 +137,51 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
|
||||
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
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -287,34 +325,6 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
|
||||
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
|
||||
private List<CalculatorHistoryState> getHistoryList() {
|
||||
final List<CalculatorHistoryState> calculatorHistoryStates = getHistoryItems();
|
||||
@ -337,23 +347,6 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
|
||||
@Nonnull
|
||||
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();
|
||||
|
||||
@Nonnull
|
||||
|
@ -23,7 +23,12 @@
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
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.Nullable;
|
||||
|
@ -29,13 +29,16 @@ import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
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.history.BaseHistoryFragment.isAlreadySaved;
|
||||
|
||||
|
@ -26,15 +26,15 @@ import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class HistoryFragment extends BaseHistoryFragment {
|
||||
|
||||
public HistoryFragment() {
|
||||
|
@ -33,13 +33,13 @@ import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.menu.LabeledMenuItem;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* 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) {
|
||||
final CalculatorHistoryState historyState = data.getHistoryState();
|
||||
|
||||
@ -154,12 +160,6 @@ public enum HistoryItemMenuItem implements LabeledMenuItem<HistoryItemMenuData>
|
||||
builder.create().show();
|
||||
}
|
||||
|
||||
private final int captionId;
|
||||
|
||||
private HistoryItemMenuItem(int captionId) {
|
||||
this.captionId = captionId;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getCaption(@Nonnull Context context) {
|
||||
|
@ -26,10 +26,11 @@ import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class SavedHistoryFragment extends BaseHistoryFragment {
|
||||
|
||||
public SavedHistoryFragment() {
|
||||
|
@ -25,11 +25,11 @@ package org.solovyev.android.calculator.history;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.solovyev.android.calculator.Editor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.solovyev.android.calculator.Editor;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 12/17/11
|
||||
|
@ -25,15 +25,6 @@ public final class Language {
|
||||
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
|
||||
private static String makeName(@Nonnull String code, @Nonnull Locale locale) {
|
||||
if (code.equals(Languages.SYSTEM_LANGUAGE_CODE)) {
|
||||
@ -48,6 +39,15 @@ public final class Language {
|
||||
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() {
|
||||
return code.equals(Languages.SYSTEM_LANGUAGE_CODE);
|
||||
}
|
||||
|
@ -23,15 +23,50 @@ import javax.annotation.Nullable;
|
||||
|
||||
public final class Languages implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
@Nonnull
|
||||
private static final Locale[] locales = Locale.getAvailableLocales();
|
||||
@Nonnull
|
||||
public static final String SYSTEM_LANGUAGE_CODE = "00";
|
||||
@Nonnull
|
||||
public static final Language SYSTEM_LANGUAGE = new Language(SYSTEM_LANGUAGE_CODE, Locale.getDefault());
|
||||
@Nonnull
|
||||
private static final Locale[] locales = Locale.getAvailableLocales();
|
||||
@Nonnull
|
||||
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) {
|
||||
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
|
||||
public Language getCurrent() {
|
||||
return get(Preferences.Gui.language.getPreference(App.getPreferences()));
|
||||
|
@ -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
|
||||
private MathEntityArrayAdapter<T> adapter;
|
||||
|
||||
@Nullable
|
||||
private String category;
|
||||
|
||||
@Nonnull
|
||||
private final FragmentUi ui;
|
||||
|
||||
@Nonnull
|
||||
private final Handler uiHandler = new Handler();
|
||||
|
||||
protected AbstractMathEntityListFragment(@Nonnull CalculatorFragmentType fragmentType) {
|
||||
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
|
||||
public void onCreate(Bundle 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> {
|
||||
|
||||
@Nonnull
|
||||
@ -295,61 +348,4 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
|
||||
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) {
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,15 @@ package org.solovyev.android.calculator.math.edit;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
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.Nullable;
|
||||
|
@ -30,21 +30,31 @@ import android.support.v7.app.ActionBarActivity;
|
||||
import android.text.ClipboardManager;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.melnykov.fab.FloatingActionButton;
|
||||
import jscl.math.function.Function;
|
||||
import jscl.math.function.IFunction;
|
||||
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.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.menu.AMenuItem;
|
||||
import org.solovyev.android.menu.LabeledMenuItem;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import jscl.math.function.Function;
|
||||
import jscl.math.function.IFunction;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/29/11
|
||||
|
@ -23,7 +23,15 @@
|
||||
package org.solovyev.android.calculator.math.edit;
|
||||
|
||||
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.Nullable;
|
||||
|
@ -25,9 +25,6 @@ package org.solovyev.android.calculator.math.edit;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.text.ClipboardManager;
|
||||
import jscl.math.operator.Operator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorEventType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
@ -41,6 +38,10 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import jscl.math.operator.Operator;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/17/11
|
||||
|
@ -24,7 +24,15 @@ package org.solovyev.android.calculator.math.edit;
|
||||
|
||||
import android.content.Intent;
|
||||
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.Nullable;
|
||||
|
@ -27,9 +27,18 @@ import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
||||
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.menu.AMenuItem;
|
||||
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.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import jscl.math.function.IConstant;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/28/11
|
||||
@ -56,6 +68,18 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
|
||||
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
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -147,18 +171,6 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
|
||||
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
|
||||
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||
super.onCalculatorEvent(calculatorEventData, calculatorEventType, data);
|
||||
|
@ -27,11 +27,6 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.view.View;
|
||||
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.CalculatorMathRegistry;
|
||||
@ -39,6 +34,12 @@ import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.R;
|
||||
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
|
||||
* Date: 12/22/11
|
||||
@ -56,15 +57,12 @@ public class MathEntityRemover<T extends MathEntity> implements View.OnClickList
|
||||
|
||||
@Nonnull
|
||||
private final CalculatorMathRegistry<? super T> varsRegistry;
|
||||
|
||||
@Nonnull
|
||||
private Context context;
|
||||
|
||||
@Nonnull
|
||||
private final Object source;
|
||||
|
||||
@Nonnull
|
||||
private final Params params;
|
||||
@Nonnull
|
||||
private Context context;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
@ -163,18 +161,6 @@ public class MathEntityRemover<T extends MathEntity> implements View.OnClickList
|
||||
private Params() {
|
||||
}
|
||||
|
||||
public int getRemovalConfirmationTitleResId() {
|
||||
return removalConfirmationTitleResId;
|
||||
}
|
||||
|
||||
public int getRemovalConfirmationQuestionResId() {
|
||||
return removalConfirmationQuestionResId;
|
||||
}
|
||||
|
||||
public CalculatorEventType getCalculatorEventType() {
|
||||
return calculatorEventType;
|
||||
}
|
||||
|
||||
private static <T extends MathEntity> Params newConstantInstance() {
|
||||
final Params result = new Params();
|
||||
result.removalConfirmationTitleResId = R.string.removal_confirmation;
|
||||
@ -190,5 +176,17 @@ public class MathEntityRemover<T extends MathEntity> implements View.OnClickList
|
||||
result.calculatorEventType = CalculatorEventType.function_removed;
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getRemovalConfirmationTitleResId() {
|
||||
return removalConfirmationTitleResId;
|
||||
}
|
||||
|
||||
public int getRemovalConfirmationQuestionResId() {
|
||||
return removalConfirmationQuestionResId;
|
||||
}
|
||||
|
||||
public CalculatorEventType getCalculatorEventType() {
|
||||
return calculatorEventType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,19 +32,31 @@ import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.*;
|
||||
import jscl.math.function.IConstant;
|
||||
import android.widget.Button;
|
||||
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.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.common.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
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.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
@ -71,6 +83,10 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public static void showDialog(@Nonnull Input input, @Nonnull FragmentManager fm) {
|
||||
App.showDialog(create(input), "constant-editor", fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.var_edit, container, false);
|
||||
@ -233,6 +249,14 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
|
||||
button.setAllCaps(false);
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||
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 {
|
||||
|
||||
@Nullable
|
||||
|
@ -24,10 +24,7 @@ package org.solovyev.android.calculator.math.edit;
|
||||
|
||||
import android.view.View;
|
||||
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.CalculatorVarsRegistry;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
@ -41,6 +38,11 @@ import org.solovyev.common.text.Strings;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import jscl.text.Identifier;
|
||||
import jscl.text.MutableInt;
|
||||
import jscl.text.ParseException;
|
||||
import jscl.text.Parser;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 12/22/11
|
||||
@ -75,6 +77,22 @@ public class VarEditorSaver<T extends MathEntity> implements View.OnClickListene
|
||||
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
|
||||
public void onClick(View v) {
|
||||
final Integer error;
|
||||
@ -139,20 +157,4 @@ public class VarEditorSaver<T extends MathEntity> implements View.OnClickListene
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ package org.solovyev.android.calculator.matrix;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.solovyev.android.calculator.EmptyActivity;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.EmptyActivity;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import static android.support.v7.app.ActionBar.NAVIGATION_MODE_STANDARD;
|
||||
|
@ -24,6 +24,7 @@ package org.solovyev.android.calculator.matrix;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorFragment;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
@ -1,13 +1,14 @@
|
||||
package org.solovyev.android.calculator.matrix;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 7/11/13
|
||||
* Time: 4:54 PM
|
||||
*/
|
||||
* User: serso
|
||||
* Date: 7/11/13
|
||||
* Time: 4:54 PM
|
||||
*/
|
||||
class MatrixUi implements Serializable {
|
||||
|
||||
@Nonnull
|
||||
|
@ -26,18 +26,16 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
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.*;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.CalculatorEngine;
|
||||
import org.solovyev.android.calculator.CalculatorEngineImpl;
|
||||
import org.solovyev.android.calculator.CalculatorFunctionsMathRegistry;
|
||||
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.Preference;
|
||||
import org.solovyev.android.prefs.StringPreference;
|
||||
@ -50,6 +48,16 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
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
|
||||
* 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_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
|
||||
private final Context context;
|
||||
|
||||
@Nonnull
|
||||
private final CalculatorEngine calculatorEngine;
|
||||
|
||||
@Nonnull
|
||||
private final Object lock;
|
||||
|
||||
@ -135,6 +111,16 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
|
||||
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
|
||||
@Nonnull
|
||||
public CalculatorMathRegistry<IConstant> getVarsRegistry() {
|
||||
@ -177,6 +163,11 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
|
||||
return calculatorEngine.getNumeralBase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumeralBase(@Nonnull NumeralBase numeralBase) {
|
||||
calculatorEngine.setNumeralBase(numeralBase);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
synchronized (lock) {
|
||||
@ -235,16 +226,6 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
|
||||
calculatorEngine.setAngleUnits(angleUnits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumeralBase(@Nonnull NumeralBase numeralBase) {
|
||||
calculatorEngine.setNumeralBase(numeralBase);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMultiplicationSign(@Nonnull String multiplicationSign) {
|
||||
calculatorEngine.setMultiplicationSign(multiplicationSign);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScienceNotation(@Nonnull Boolean 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
|
||||
public void setDecimalGroupSymbols(@Nonnull DecimalFormatSymbols decimalGroupSymbols) {
|
||||
this.calculatorEngine.setDecimalGroupSymbols(decimalGroupSymbols);
|
||||
@ -294,6 +265,10 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
|
||||
return calculatorEngine.getMultiplicationSign();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMultiplicationSign(@Nonnull String multiplicationSign) {
|
||||
calculatorEngine.setMultiplicationSign(multiplicationSign);
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.simpleframework.xml.Serializer;
|
||||
import org.simpleframework.xml.core.Persister;
|
||||
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.MathPersistenceEntity;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
|
@ -54,13 +54,10 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
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_NOTIFICATION_ACTION = "org.solovyev.android.calculator.onscreen.SHOW_NOTIFICATION";
|
||||
|
||||
private static final int NOTIFICATION_ID = 9031988; // my birthday =)
|
||||
|
||||
public static final Class<CalculatorOnscreenBroadcastReceiver> INTENT_LISTENER_CLASS = CalculatorOnscreenBroadcastReceiver.class;
|
||||
|
||||
@Nonnull
|
||||
private CalculatorOnscreenView view;
|
||||
|
||||
@ -68,6 +65,29 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi
|
||||
|
||||
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
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
@ -117,11 +137,6 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi
|
||||
Locator.getInstance().getCalculator().addCalculatorEventListener(this);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static Class<?> getIntentListenerClass() {
|
||||
return INTENT_LISTENER_CLASS;
|
||||
}
|
||||
|
||||
private void stopCalculatorListening() {
|
||||
Locator.getInstance().getCalculator().removeCalculatorEventListener(this);
|
||||
}
|
||||
@ -211,24 +226,6 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi
|
||||
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
|
||||
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||
switch (calculatorEventType) {
|
||||
|
@ -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) {
|
||||
checkInit();
|
||||
displayView.setState(displayState);
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* LIFECYCLE
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
public void updateEditorState(@Nonnull CalculatorEditorViewState editorState) {
|
||||
checkInit();
|
||||
editorView.setState(editorState);
|
||||
@ -194,14 +217,6 @@ public class CalculatorOnscreenView {
|
||||
getWindowManager().updateViewLayout(root, params);
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* LIFECYCLE
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private void init() {
|
||||
|
||||
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() {
|
||||
checkInit();
|
||||
|
||||
@ -437,18 +437,12 @@ public class CalculatorOnscreenView {
|
||||
|
||||
@Nonnull
|
||||
private final WindowManager wm;
|
||||
|
||||
private int orientation;
|
||||
|
||||
private float x0;
|
||||
|
||||
private float y0;
|
||||
|
||||
private long time = 0;
|
||||
|
||||
@Nonnull
|
||||
private final View view;
|
||||
|
||||
private int orientation;
|
||||
private float x0;
|
||||
private float y0;
|
||||
private long time = 0;
|
||||
private int displayWidth;
|
||||
|
||||
private int displayHeight;
|
||||
@ -468,6 +462,19 @@ public class CalculatorOnscreenView {
|
||||
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
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (orientation != this.wm.getDefaultDisplay().getOrientation()) {
|
||||
@ -548,18 +555,5 @@ public class CalculatorOnscreenView {
|
||||
δx = Math.abs(δx);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,10 @@ import javax.annotation.Nullable;
|
||||
public class CalculatorOnscreenViewState implements Parcelable {
|
||||
|
||||
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 CalculatorOnscreenViewState createFromParcel(@Nonnull Parcel 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() {
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user