From 8d84e24ca9090e81107c592a9303c8551e8923cb Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Sat, 2 Feb 2013 20:21:05 +0400 Subject: [PATCH] version update --- .../org/solovyev/android/AndroidUtils2.java | 103 ------------------ .../main/java/org/solovyev/android/App.java | 69 ------------ .../solovyev/android/UiThreadExecutor.java | 34 ------ .../AndroidCalculatorEditorView.java | 6 +- .../android/calculator/CalculatorButtons.java | 8 +- .../CalculatorDisplayOnClickListener.java | 6 +- .../calculator/CalculatorPreferences.java | 46 ++++---- .../calculator/FixableMessagesDialog.java | 4 +- .../solovyev/android/calculator/Threads.java | 36 ------ .../AndroidExternalListenersContainer.java | 4 +- .../model/AndroidCalculatorEngine.java | 20 ++-- .../model/AndroidMathEntityDao.java | 2 +- .../view/NumeralBaseConverterDialog.java | 10 +- .../view/UnitConverterViewBuilder.java | 4 +- .../onscreen/CalculatorOnscreenService.java | 4 +- .../CalculatorOnscreenStartActivity.java | 10 +- android-app/AndroidManifest.xml | 2 +- android-app/project.properties | 26 ++--- .../calculator/AbstractCalculatorHelper.java | 12 +- .../calculator/AndroidCalculatorNotifier.java | 6 +- .../calculator/CalculatorActivity.java | 18 +-- .../CalculatorActivityHelperImpl.java | 15 +-- .../CalculatorActivityLauncher.java | 40 +++---- .../calculator/CalculatorApplication.java | 6 +- .../calculator/CalculatorDialogActivity.java | 8 +- .../calculator/CalculatorEditorFragment.java | 2 +- .../about/CalculatorReleaseNotesFragment.java | 4 +- .../function/FunctionEditorSaver.java | 4 +- .../AbstractCalculatorHistoryFragment.java | 23 ++-- .../history/HistoryArrayAdapter.java | 4 +- .../history/HistoryItemMenuItem.java | 6 +- .../edit/AbstractMathEntityListFragment.java | 22 ++-- .../edit/CalculatorFunctionsFragment.java | 6 +- .../edit/CalculatorOperatorsFragment.java | 8 +- .../math/edit/CalculatorVarsFragment.java | 18 +-- .../calculator/math/edit/VarEditorSaver.java | 6 +- .../plot/AbstractCalculatorPlotFragment.java | 7 +- .../android/calculator/plot/TouchHandler.java | 8 +- .../CalculatorPreferencesActivity.java | 6 +- .../android/fragments/FragmentUtils.java | 6 +- .../android/AndroidNumeralBaseTest.java | 4 +- .../AndroidCalculatorEditorViewTest.java | 2 +- .../calculator/history/HistoryUtilsTest.java | 8 +- .../common/FloatIntervalMapperTest.java | 22 ---- .../common/math/DiscreteNormalizerTest.java | 34 ------ .../calculator/AbstractNumberBuilder.java | 4 +- .../CalculatorDisplayViewStateImpl.java | 4 +- .../calculator/CalculatorEditorImpl.java | 4 +- .../calculator/CalculatorFixableError.java | 4 +- .../CalculatorFunctionsMathRegistry.java | 4 +- .../android/calculator/CalculatorImpl.java | 15 +-- .../calculator/CalculatorKeyboardImpl.java | 6 +- .../android/calculator/FunctionCategory.java | 7 +- .../ListCalculatorEventContainer.java | 8 +- .../android/calculator/OperatorCategory.java | 7 +- .../calculator/ToJsclTextProcessor.java | 16 +-- .../android/calculator/VarCategory.java | 7 +- .../CalculatorDisplayHistoryState.java | 6 +- .../history/CalculatorHistoryImpl.java | 5 +- .../history/EditorHistoryState.java | 4 +- .../android/calculator/math/MathType.java | 26 ++--- .../android/calculator/model/AFunction.java | 6 +- .../android/calculator/model/Var.java | 4 +- .../android/calculator/plot/XyFunction.java | 4 +- .../units/CalculatorNumeralBase.java | 8 +- .../org/solovyev/common/DelayedExecutor.java | 16 --- .../java/org/solovyev/common/ListMapper.java | 35 ------ .../common/utils/ListListenersContainer.java | 77 ------------- .../math/units/ConversionException.java | 15 --- .../solovyev/math/units/ConversionUtils.java | 38 ------- .../java/org/solovyev/math/units/Unit.java | 17 --- .../solovyev/math/units/UnitConverter.java | 42 ------- .../org/solovyev/math/units/UnitImpl.java | 42 ------- .../org/solovyev/math/units/UnitType.java | 16 --- .../calculator/model/FunctionsTest.java | 6 +- pom.xml | 4 +- 76 files changed, 282 insertions(+), 874 deletions(-) delete mode 100644 android-app-core/src/main/java/org/solovyev/android/App.java delete mode 100644 android-app-core/src/main/java/org/solovyev/android/UiThreadExecutor.java delete mode 100644 android-app-core/src/main/java/org/solovyev/android/calculator/Threads.java delete mode 100644 android-app/src/test/java/org/solovyev/common/FloatIntervalMapperTest.java delete mode 100644 android-app/src/test/java/org/solovyev/common/math/DiscreteNormalizerTest.java delete mode 100644 core/src/main/java/org/solovyev/common/DelayedExecutor.java delete mode 100644 core/src/main/java/org/solovyev/common/ListMapper.java delete mode 100644 core/src/main/java/org/solovyev/common/utils/ListListenersContainer.java delete mode 100644 core/src/main/java/org/solovyev/math/units/ConversionException.java delete mode 100644 core/src/main/java/org/solovyev/math/units/ConversionUtils.java delete mode 100644 core/src/main/java/org/solovyev/math/units/Unit.java delete mode 100644 core/src/main/java/org/solovyev/math/units/UnitConverter.java delete mode 100644 core/src/main/java/org/solovyev/math/units/UnitImpl.java delete mode 100644 core/src/main/java/org/solovyev/math/units/UnitType.java diff --git a/android-app-core/src/main/java/org/solovyev/android/AndroidUtils2.java b/android-app-core/src/main/java/org/solovyev/android/AndroidUtils2.java index e4d2a935..fb2d0cbd 100644 --- a/android-app-core/src/main/java/org/solovyev/android/AndroidUtils2.java +++ b/android-app-core/src/main/java/org/solovyev/android/AndroidUtils2.java @@ -1,21 +1,5 @@ package org.solovyev.android; -import android.app.Activity; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.graphics.Bitmap; -import android.os.Build; -import android.util.Log; -import android.view.MotionEvent; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; - /** * User: Solovyev_S * Date: 03.10.12 @@ -23,95 +7,8 @@ import java.io.IOException; */ public final class AndroidUtils2 { - @NotNull - private static final boolean AT_LEAST_API_5 = Build.VERSION.SDK_INT >= 5; - private AndroidUtils2() { throw new AssertionError(); } - public static void addFlags(@NotNull Intent intent, boolean detached, @NotNull Context context) { - int flags = 0; - - if (!(context instanceof Activity)) { - flags = flags | Intent.FLAG_ACTIVITY_NEW_TASK; - } - - if (detached) { - flags = flags | Intent.FLAG_ACTIVITY_NO_HISTORY; - } - - intent.setFlags(flags); - - } - - public static void toggleComponent(@NotNull Context context, - @NotNull Class componentClass, - boolean enable) { - final PackageManager pm = context.getPackageManager(); - - final int componentState; - if (enable) { - componentState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED; - } else { - componentState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED; - } - - pm.setComponentEnabledSetting(new ComponentName(context, componentClass), componentState, PackageManager.DONT_KILL_APP); - } - - public static boolean isComponentEnabled(@NotNull Context context, - @NotNull Class componentClass) { - final PackageManager pm = context.getPackageManager(); - - int componentEnabledSetting = pm.getComponentEnabledSetting(new ComponentName(context, componentClass)); - return componentEnabledSetting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED || componentEnabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; - } - - public static String saveBitmap(@NotNull Bitmap bitmap, - @NotNull String path, - @NotNull String fileName) { - final File filePath = new File(path); - filePath.mkdirs(); - - final File file = new File(path, fileName); - if (!file.exists()) { - final String name = file.getAbsolutePath(); - - FileOutputStream fos = null; - try { - fos = new FileOutputStream(name); - bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); - fos.flush(); - } catch (FileNotFoundException e) { - Log.e("AndroidUtils", e.getMessage(), e); - } catch (IOException e) { - Log.e("AndroidUtils", e.getMessage(), e); - } finally { - if (fos != null) { - try { - fos.close(); - } catch (IOException e) { - Log.e("AndroidUtils", e.getMessage(), e); - } - } - } - - return name; - } - - return null; - } - - public static int getPointerCountFromMotionEvent(@NotNull MotionEvent event) { - return AT_LEAST_API_5 ? event.getPointerCount() : 1; - } - - public static float getXFromMotionEvent(@NotNull MotionEvent event, int pointer) { - return AT_LEAST_API_5 ? event.getX(pointer) : 0; - } - - public static float getYFromMotionEvent(@NotNull MotionEvent event, int pointer) { - return AT_LEAST_API_5 ? event.getY(pointer) : 0; - } } diff --git a/android-app-core/src/main/java/org/solovyev/android/App.java b/android-app-core/src/main/java/org/solovyev/android/App.java deleted file mode 100644 index e65a5d24..00000000 --- a/android-app-core/src/main/java/org/solovyev/android/App.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.solovyev.android; - -import android.app.Application; -import org.jetbrains.annotations.NotNull; -import org.solovyev.common.DelayedExecutor; - -/** - * User: serso - * Date: 12/1/12 - * Time: 3:58 PM - */ -public final class App { - - /* - ********************************************************************** - * - * STATIC - * - ********************************************************************** - */ - - @NotNull - public static final App instance = new App(); - - @NotNull - public static App getInstance() { - return instance; - } - - - /* - ********************************************************************** - * - * FIELDS - * - ********************************************************************** - */ - - @NotNull - private volatile Application application; - - @NotNull - private volatile DelayedExecutor uiThreadExecutor; - - private volatile boolean initialized; - - private App() { - } - - - public void init(@NotNull Application application) { - if (!initialized) { - this.application = application; - this.uiThreadExecutor = new UiThreadExecutor(); - - this.initialized = true; - } - } - - @NotNull - public A getApplication() { - return (A) application; - } - - @NotNull - public DelayedExecutor getUiThreadExecutor() { - return uiThreadExecutor; - } -} diff --git a/android-app-core/src/main/java/org/solovyev/android/UiThreadExecutor.java b/android-app-core/src/main/java/org/solovyev/android/UiThreadExecutor.java deleted file mode 100644 index e9be0187..00000000 --- a/android-app-core/src/main/java/org/solovyev/android/UiThreadExecutor.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.solovyev.android; - -import android.os.Handler; -import org.jetbrains.annotations.NotNull; -import org.solovyev.common.DelayedExecutor; - -import java.util.concurrent.TimeUnit; - -/** - * User: serso - * Date: 12/1/12 - * Time: 4:11 PM - */ -public class UiThreadExecutor implements DelayedExecutor { - - @NotNull - private final Handler uiHandler; - - public UiThreadExecutor() { - assert AndroidUtils.isUiThread() : "Must be called on UI thread!"; - - this.uiHandler = new Handler(); - } - - @Override - public void execute(@NotNull Runnable command, long delay, @NotNull TimeUnit delayUnit) { - this.uiHandler.postDelayed(command, delayUnit.toMillis(delay)); - } - - @Override - public void execute(@NotNull Runnable command) { - this.uiHandler.post(command); - } -} diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/AndroidCalculatorEditorView.java b/android-app-core/src/main/java/org/solovyev/android/calculator/AndroidCalculatorEditorView.java index e02508d5..51c1e370 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/AndroidCalculatorEditorView.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/AndroidCalculatorEditorView.java @@ -23,7 +23,7 @@ import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.text.TextProcessor; import org.solovyev.android.calculator.view.TextHighlighter; import org.solovyev.android.prefs.BooleanPreference; -import org.solovyev.common.collections.CollectionsUtils; +import org.solovyev.common.collections.Collections; /** * User: serso @@ -33,7 +33,7 @@ import org.solovyev.common.collections.CollectionsUtils; public class AndroidCalculatorEditorView extends EditText implements SharedPreferences.OnSharedPreferenceChangeListener, CalculatorEditorView { @NotNull - private static final BooleanPreference colorDisplay = new BooleanPreference("org.solovyev.android.calculator.CalculatorModel_color_display", true); + private static final BooleanPreference colorDisplay = BooleanPreference.of("org.solovyev.android.calculator.CalculatorModel_color_display", true); private volatile boolean initialized = false; @@ -74,7 +74,7 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe // fix for missing cursor in android 3 and higher try { // IDEA: return false always except if method was called from TextView.isCursorVisible() method - for (StackTraceElement stackTraceElement : CollectionsUtils.asList(Thread.currentThread().getStackTrace())) { + for (StackTraceElement stackTraceElement : Collections.asList(Thread.currentThread().getStackTrace())) { if ("isCursorVisible".equals(stackTraceElement.getMethodName())) { return true; } diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java index 1f39c3f5..43e892ff 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java @@ -15,7 +15,7 @@ import jscl.AngleUnit; import jscl.NumeralBase; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.solovyev.android.AndroidUtils; +import org.solovyev.android.AViews; import org.solovyev.android.calculator.core.R; import org.solovyev.android.calculator.model.AndroidCalculatorEngine; import org.solovyev.android.calculator.view.AngleUnitsButton; @@ -43,7 +43,7 @@ public final class CalculatorButtons { final float textSize = root.getContext().getResources().getDimension(R.dimen.cpp_keyboard_button_text_size_mobile); - AndroidUtils.processViewsOfType(root, DragButton.class, new AndroidUtils.ViewProcessor() { + AViews.processViewsOfType(root, DragButton.class, new AViews.ViewProcessor() { @Override public void process(@NotNull DragButton button) { button.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize); @@ -68,11 +68,11 @@ public final class CalculatorButtons { @NotNull Activity activity) { preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences; - final boolean large = AndroidUtils.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, activity.getResources().getConfiguration()) && + final boolean large = AViews.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, activity.getResources().getConfiguration()) && CalculatorPreferences.Gui.getLayout(preferences) != CalculatorPreferences.Gui.Layout.main_calculator_mobile; if (!large) { - if (AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT + if (AViews.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT || !CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) { final DragButton equalsButton = (DragButton)activity.findViewById(R.id.cpp_button_equals); diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayOnClickListener.java b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayOnClickListener.java index 83b06abe..7e9f9c48 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayOnClickListener.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayOnClickListener.java @@ -3,8 +3,8 @@ package org.solovyev.android.calculator; import android.content.Context; import android.view.View; import org.jetbrains.annotations.NotNull; -import org.solovyev.android.menu.AMenuBuilder; -import org.solovyev.android.menu.MenuImpl; +import org.solovyev.android.menu.ContextMenuBuilder; +import org.solovyev.android.menu.ListContextMenu; import java.util.ArrayList; import java.util.List; @@ -39,7 +39,7 @@ public class CalculatorDisplayOnClickListener implements View.OnClickListener { } if (!filteredMenuItems.isEmpty()) { - AMenuBuilder.newInstance(context, MenuImpl.newInstance(filteredMenuItems)).create(displayViewState).show(); + ContextMenuBuilder.newInstance(context, ListContextMenu.newInstance(filteredMenuItems)).create(displayViewState).show(); } } else { diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorPreferences.java b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorPreferences.java index 5dada2a5..5737d276 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorPreferences.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorPreferences.java @@ -30,37 +30,37 @@ public final class CalculatorPreferences { throw new AssertionError(); } - public static final Preference appVersion = new IntegerPreference("application.version", -1); - public static final Preference appOpenedCounter = new IntegerPreference("app_opened_counter", 0); + public static final Preference appVersion = IntegerPreference.of("application.version", -1); + public static final Preference appOpenedCounter = IntegerPreference.of("app_opened_counter", 0); public static class OnscreenCalculator { - public static final Preference startOnBoot = new BooleanPreference("onscreen_start_on_boot", false); - public static final Preference showAppIcon = new BooleanPreference("onscreen_show_app_icon", true); - public static final Preference removeIconDialogShown = new BooleanPreference("onscreen_remove_icon_dialog_shown", false); + public static final Preference startOnBoot = BooleanPreference.of("onscreen_start_on_boot", false); + public static final Preference showAppIcon = BooleanPreference.of("onscreen_show_app_icon", true); + public static final Preference removeIconDialogShown = BooleanPreference.of("onscreen_remove_icon_dialog_shown", false); } public static class Calculations { - public static final Preference calculateOnFly = new BooleanPreference("calculations_calculate_on_fly", true); - public static final Preference showCalculationMessagesDialog = new BooleanPreference("show_calculation_messages_dialog", true); + public static final Preference calculateOnFly = BooleanPreference.of("calculations_calculate_on_fly", true); + public static final Preference showCalculationMessagesDialog = BooleanPreference.of("show_calculation_messages_dialog", true); - public static final Preference preferredNumeralBase = StringPreference.newInstance("preferred_numeral_base", AndroidCalculatorEngine.Preferences.numeralBase.getDefaultValue(), NumeralBase.class); - public static final Preference preferredAngleUnits = StringPreference.newInstance("preferred_angle_units", AndroidCalculatorEngine.Preferences.angleUnit.getDefaultValue(), AngleUnit.class); - public static final Preference lastPreferredPreferencesCheck = new LongPreference("preferred_preferences_check_time", 0L); + public static final Preference preferredNumeralBase = StringPreference.ofEnum("preferred_numeral_base", AndroidCalculatorEngine.Preferences.numeralBase.getDefaultValue(), NumeralBase.class); + public static final Preference preferredAngleUnits = StringPreference.ofEnum("preferred_angle_units", AndroidCalculatorEngine.Preferences.angleUnit.getDefaultValue(), AngleUnit.class); + public static final Preference lastPreferredPreferencesCheck = LongPreference.of("preferred_preferences_check_time", 0L); } public static class Gui { - public static final Preference theme = StringPreference.newInstance("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Theme.metro_blue_theme, Theme.class); - public static final Preference layout = StringPreference.newInstance("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Layout.main_calculator, Layout.class); - public static final Preference feedbackWindowShown = new BooleanPreference("feedback_window_shown", false); - public static final Preference notesppAnnounceShown = new BooleanPreference("notespp_announce_shown", false); - public static final Preference showReleaseNotes = new BooleanPreference("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true); - public static final Preference usePrevAsBack = new BooleanPreference("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false); - public static final Preference showEqualsButton = new BooleanPreference("showEqualsButton", true); - public static final Preference autoOrientation = new BooleanPreference("autoOrientation", true); - public static final Preference hideNumeralBaseDigits = new BooleanPreference("hideNumeralBaseDigits", true); + public static final Preference theme = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Theme.metro_blue_theme, Theme.class); + public static final Preference layout = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Layout.main_calculator, Layout.class); + public static final Preference feedbackWindowShown = BooleanPreference.of("feedback_window_shown", false); + public static final Preference notesppAnnounceShown = BooleanPreference.of("notespp_announce_shown", false); + public static final Preference showReleaseNotes = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true); + public static final Preference usePrevAsBack = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false); + public static final Preference showEqualsButton = BooleanPreference.of("showEqualsButton", true); + public static final Preference autoOrientation = BooleanPreference.of("autoOrientation", true); + public static final Preference hideNumeralBaseDigits = BooleanPreference.of("hideNumeralBaseDigits", true); @NotNull public static Theme getTheme(@NotNull SharedPreferences preferences) { @@ -131,11 +131,11 @@ public final class CalculatorPreferences { } public static class Graph { - public static final Preference plotImag = new BooleanPreference("graph_plot_imag", false); + public static final Preference plotImag = BooleanPreference.of("graph_plot_imag", false); } public static class History { - public static final Preference showIntermediateCalculations = new BooleanPreference("history_show_intermediate_calculations", false); + public static final Preference showIntermediateCalculations = BooleanPreference.of("history_show_intermediate_calculations", false); } @@ -210,9 +210,7 @@ public final class CalculatorPreferences { } private static void applyDefaultPreference(@NotNull SharedPreferences preferences, @NotNull Preference preference) { - if (!preference.isSet(preferences)) { - preference.putDefault(preferences); - } + preference.tryPutDefault(preferences); } } diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/FixableMessagesDialog.java b/android-app-core/src/main/java/org/solovyev/android/calculator/FixableMessagesDialog.java index f85ee81c..61b10f80 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/FixableMessagesDialog.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/FixableMessagesDialog.java @@ -17,7 +17,7 @@ import com.actionbarsherlock.app.SherlockActivity; import org.jetbrains.annotations.NotNull; import org.solovyev.android.calculator.core.R; import org.solovyev.common.msg.Message; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; import java.util.ArrayList; import java.util.Collections; @@ -101,7 +101,7 @@ public class FixableMessagesDialog extends SherlockActivity { fixButton.setOnClickListener(new FixErrorOnClickListener(messages, message)); final CharSequence fixCaption = fixableError.getFixCaption(); - if (!StringUtils.isEmpty(fixCaption)) { + if (!Strings.isEmpty(fixCaption)) { fixButton.setText(fixCaption); } } diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/Threads.java b/android-app-core/src/main/java/org/solovyev/android/calculator/Threads.java deleted file mode 100644 index fa4d0225..00000000 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/Threads.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.solovyev.android.calculator; - -import android.app.Activity; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.solovyev.android.AndroidUtils; - -/** - * User: serso - * Date: 1/19/13 - * Time: 5:04 PM - */ -public final class Threads { - - private Threads() { - throw new AssertionError(); - } - - public static void tryRunOnUiThread(@Nullable final Activity activity, @NotNull final Runnable runnable) { - if (activity != null && !activity.isFinishing()) { - if (AndroidUtils.isUiThread()) { - runnable.run(); - } else { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - // some time may pass and activity might be closing - if (!activity.isFinishing()) { - runnable.run(); - } - } - }); - } - } - } -} diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/external/AndroidExternalListenersContainer.java b/android-app-core/src/main/java/org/solovyev/android/calculator/external/AndroidExternalListenersContainer.java index 78c3fbfe..b90435ca 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/external/AndroidExternalListenersContainer.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/external/AndroidExternalListenersContainer.java @@ -109,7 +109,7 @@ public class AndroidExternalListenersContainer implements CalculatorExternalList Locator.getInstance().getNotifier().showDebugMessage(TAG, "Editor state changed: " + newEditorState.getText()); - onEditorStateChanged(App.getInstance().getApplication(), calculatorEventData, newEditorState); + onEditorStateChanged(App.getApplication(), calculatorEventData, newEditorState); break; case display_state_changed: @@ -118,7 +118,7 @@ public class AndroidExternalListenersContainer implements CalculatorExternalList Locator.getInstance().getNotifier().showDebugMessage(TAG, "Display state changed: " + newDisplayState.getText()); - onDisplayStateChanged(App.getInstance().getApplication(), calculatorEventData, newDisplayState); + onDisplayStateChanged(App.getApplication(), calculatorEventData, newDisplayState); break; } } diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/model/AndroidCalculatorEngine.java b/android-app-core/src/main/java/org/solovyev/android/calculator/model/AndroidCalculatorEngine.java index 3e7529cb..b33730d7 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/model/AndroidCalculatorEngine.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/model/AndroidCalculatorEngine.java @@ -24,7 +24,7 @@ import org.solovyev.android.prefs.Preference; import org.solovyev.android.prefs.StringPreference; import org.solovyev.common.text.EnumMapper; import org.solovyev.common.text.NumberMapper; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; import java.text.DecimalFormatSymbols; import java.util.ArrayList; @@ -63,14 +63,14 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen private static final String ANGLE_UNITS_DEFAULT = "deg"; public static class Preferences { - public static final Preference groupingSeparator = StringPreference.newInstance(GROUPING_SEPARATOR_P_KEY, JsclMathEngine.GROUPING_SEPARATOR_DEFAULT); - public static final Preference multiplicationSign = StringPreference.newInstance(MULTIPLICATION_SIGN_P_KEY, MULTIPLICATION_SIGN_DEFAULT); - public static final Preference precision = StringPreference.newInstance(RESULT_PRECISION_P_KEY, RESULT_PRECISION_DEFAULT, NumberMapper.getMapper(Integer.class)); - public static final Preference roundResult = new BooleanPreference(ROUND_RESULT_P_KEY, ROUND_RESULT_DEFAULT); - public static final Preference numeralBase = StringPreference.newInstance(NUMERAL_BASES_P_KEY, NUMERAL_BASES_DEFAULT, EnumMapper.newInstance(NumeralBase.class)); - public static final Preference angleUnit = StringPreference.newInstance(ANGLE_UNITS_P_KEY, ANGLE_UNITS_DEFAULT, EnumMapper.newInstance(AngleUnit.class)); - public static final Preference scienceNotation = new BooleanPreference(SCIENCE_NOTATION_P_KEY, SCIENCE_NOTATION_DEFAULT); - public static final Preference maxCalculationTime = StringPreference.newInstance(MAX_CALCULATION_TIME_P_KEY, MAX_CALCULATION_TIME_DEFAULT, NumberMapper.getMapper(Integer.class)); + public static final Preference groupingSeparator = StringPreference.of(GROUPING_SEPARATOR_P_KEY, JsclMathEngine.GROUPING_SEPARATOR_DEFAULT); + public static final Preference multiplicationSign = StringPreference.of(MULTIPLICATION_SIGN_P_KEY, MULTIPLICATION_SIGN_DEFAULT); + public static final Preference precision = StringPreference.ofTypedValue(RESULT_PRECISION_P_KEY, RESULT_PRECISION_DEFAULT, NumberMapper.of(Integer.class)); + public static final Preference roundResult = BooleanPreference.of(ROUND_RESULT_P_KEY, ROUND_RESULT_DEFAULT); + public static final Preference numeralBase = StringPreference.ofTypedValue(NUMERAL_BASES_P_KEY, NUMERAL_BASES_DEFAULT, EnumMapper.of(NumeralBase.class)); + public static final Preference angleUnit = StringPreference.ofTypedValue(ANGLE_UNITS_P_KEY, ANGLE_UNITS_DEFAULT, EnumMapper.of(AngleUnit.class)); + public static final Preference scienceNotation = BooleanPreference.of(SCIENCE_NOTATION_P_KEY, SCIENCE_NOTATION_DEFAULT); + public static final Preference maxCalculationTime = StringPreference.ofTypedValue(MAX_CALCULATION_TIME_P_KEY, MAX_CALCULATION_TIME_DEFAULT, NumberMapper.of(Integer.class)); private static final List preferenceKeys = new ArrayList(); @@ -246,7 +246,7 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen this.setTimeout(Preferences.maxCalculationTime.getPreference(preferences)); final String groupingSeparator = Preferences.groupingSeparator.getPreference(preferences); - if (StringUtils.isEmpty(groupingSeparator)) { + if (Strings.isEmpty(groupingSeparator)) { this.setUseGroupingSeparator(false); } else { this.setUseGroupingSeparator(true); diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/model/AndroidMathEntityDao.java b/android-app-core/src/main/java/org/solovyev/android/calculator/model/AndroidMathEntityDao.java index 14ac73c7..b0694a30 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/model/AndroidMathEntityDao.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/model/AndroidMathEntityDao.java @@ -89,7 +89,7 @@ public class AndroidMathEntityDao implements Ma public String getDescription(@NotNull String descriptionId) { final Resources resources = context.getResources(); - final int stringId = resources.getIdentifier(descriptionId, "string", App.getInstance().getApplication().getClass().getPackage().getName()); + final int stringId = resources.getIdentifier(descriptionId, "string", App.getApplication().getClass().getPackage().getName()); try { return resources.getString(stringId); } catch (Resources.NotFoundException e) { diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/view/NumeralBaseConverterDialog.java b/android-app-core/src/main/java/org/solovyev/android/calculator/view/NumeralBaseConverterDialog.java index 6d099f9f..1a253b3f 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/view/NumeralBaseConverterDialog.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/view/NumeralBaseConverterDialog.java @@ -12,9 +12,9 @@ import org.solovyev.android.calculator.ToJsclTextProcessor; import org.solovyev.android.calculator.core.R; import org.solovyev.android.calculator.units.CalculatorNumeralBase; import org.solovyev.common.MutableObject; -import org.solovyev.common.text.StringUtils; -import org.solovyev.math.units.Unit; -import org.solovyev.math.units.UnitImpl; +import org.solovyev.common.text.Strings; +import org.solovyev.common.units.Unit; +import org.solovyev.common.units.UnitImpl; import java.util.Arrays; @@ -28,7 +28,7 @@ public class NumeralBaseConverterDialog { @Nullable private String initialFromValue; - public NumeralBaseConverterDialog(String initialFromValue) { + public NumeralBaseConverterDialog(@Nullable String initialFromValue) { this.initialFromValue = initialFromValue; } @@ -37,7 +37,7 @@ public class NumeralBaseConverterDialog { b.setFromUnitTypes(Arrays.asList(CalculatorNumeralBase.values())); b.setToUnitTypes(Arrays.asList(CalculatorNumeralBase.values())); - if (!StringUtils.isEmpty(initialFromValue)) { + if (!Strings.isEmpty(initialFromValue)) { String value = initialFromValue; try { value = ToJsclTextProcessor.getInstance().process(value).getExpression(); diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/view/UnitConverterViewBuilder.java b/android-app-core/src/main/java/org/solovyev/android/calculator/view/UnitConverterViewBuilder.java index 1e8b83ff..57c2f476 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/view/UnitConverterViewBuilder.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/view/UnitConverterViewBuilder.java @@ -13,7 +13,7 @@ import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.core.R; import org.solovyev.android.view.ViewBuilder; import org.solovyev.android.view.ViewFromLayoutBuilder; -import org.solovyev.math.units.*; +import org.solovyev.common.units.*; import java.util.Collections; import java.util.List; @@ -169,7 +169,7 @@ public class UnitConverterViewBuilder implements ViewBuilder { final String from = fromEditText.getText().toString(); try { - toEditText.setText(ConversionUtils.doConversion(converter, from, getFromUnitType(main), getToUnitType(main))); + toEditText.setText(Conversions.doConversion(converter, from, getFromUnitType(main), getToUnitType(main))); } catch (ConversionException e) { toEditText.setText(context.getString(R.string.c_error)); } diff --git a/android-app-onscreen/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenService.java b/android-app-onscreen/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenService.java index 060a9385..2273bc02 100644 --- a/android-app-onscreen/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenService.java +++ b/android-app-onscreen/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenService.java @@ -11,7 +11,7 @@ import android.util.DisplayMetrics; import android.view.WindowManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.solovyev.android.AndroidUtils; +import org.solovyev.android.AViews; import org.solovyev.android.calculator.CalculatorDisplayViewState; import org.solovyev.android.calculator.CalculatorEditorViewState; import org.solovyev.android.calculator.Locator; @@ -65,7 +65,7 @@ public class CalculatorOnscreenService extends Service implements ExternalCalcul twoThirdWidth = Math.min(twoThirdWidth, twoThirdHeight); twoThirdHeight = Math.max(twoThirdWidth, getHeight(twoThirdWidth)); - final int baseWidth = AndroidUtils.toPixels(dm, 300); + final int baseWidth = AViews.toPixels(dm, 300); final int width0 = Math.min(twoThirdWidth, baseWidth); final int height0 = Math.min(twoThirdHeight, getHeight(baseWidth)); diff --git a/android-app-onscreen/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenStartActivity.java b/android-app-onscreen/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenStartActivity.java index 1e04f6fb..484e294d 100644 --- a/android-app-onscreen/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenStartActivity.java +++ b/android-app-onscreen/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenStartActivity.java @@ -6,12 +6,12 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import org.jetbrains.annotations.NotNull; -import org.solovyev.android.AndroidUtils2; -import org.solovyev.android.calculator.AbstractFixableError; +import org.solovyev.android.AndroidUtils; import org.solovyev.android.App; +import org.solovyev.android.calculator.AbstractFixableError; +import org.solovyev.android.calculator.CalculatorPreferences; import org.solovyev.android.calculator.FixableMessage; import org.solovyev.android.calculator.FixableMessagesDialog; -import org.solovyev.android.calculator.CalculatorPreferences; import org.solovyev.common.msg.MessageType; import java.util.Arrays; @@ -22,7 +22,7 @@ public class CalculatorOnscreenStartActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (AndroidUtils2.isComponentEnabled(this, CalculatorOnscreenStartActivity.class)) { + if (AndroidUtils.isComponentEnabled(this, CalculatorOnscreenStartActivity.class)) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (!CalculatorPreferences.OnscreenCalculator.removeIconDialogShown.getPreference(prefs)) { @@ -44,7 +44,7 @@ public class CalculatorOnscreenStartActivity extends Activity { @Override public void fix() { - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(App.getInstance().getApplication()); + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(App.getApplication()); CalculatorPreferences.OnscreenCalculator.showAppIcon.putPreference(prefs, false); } } diff --git a/android-app/AndroidManifest.xml b/android-app/AndroidManifest.xml index ab3b238d..aa2e97a3 100644 --- a/android-app/AndroidManifest.xml +++ b/android-app/AndroidManifest.xml @@ -1,5 +1,5 @@ - + diff --git a/android-app/project.properties b/android-app/project.properties index 542cf64d..8c2eef84 100644 --- a/android-app/project.properties +++ b/android-app/project.properties @@ -12,19 +12,19 @@ target=android-15 android.library.reference.1=../android-app-core android.library.reference.2=../android-app-widget android.library.reference.3=../android-app-onscreen -android.library.reference.4=gen-external-apklibs/org.solovyev.android_android-common-all_1.0.6 -android.library.reference.5=gen-external-apklibs/org.solovyev.android_android-common-ads_1.0.6 -android.library.reference.6=gen-external-apklibs/org.solovyev.android_android-common-core_1.0.6 -android.library.reference.7=gen-external-apklibs/org.solovyev.android_android-common-billing_1.0.6 -android.library.reference.8=gen-external-apklibs/org.solovyev.android_android-common-db_1.0.6 -android.library.reference.9=gen-external-apklibs/org.solovyev.android_android-common-http_1.0.6 -android.library.reference.10=gen-external-apklibs/org.solovyev.android_android-common-list_1.0.6 -android.library.reference.11=gen-external-apklibs/org.solovyev.android_android-common-view_1.0.6 -android.library.reference.12=gen-external-apklibs/org.solovyev.android_android-common-preferences_1.0.6 -android.library.reference.13=gen-external-apklibs/org.solovyev.android_android-common-menu_1.0.6 -android.library.reference.14=gen-external-apklibs/org.solovyev.android_android-common-other_1.0.6 -android.library.reference.15=gen-external-apklibs/org.solovyev.android_android-common-sherlock_1.0.6 +android.library.reference.4=gen-external-apklibs/org.solovyev.android_android-common-all_1.0.7-SNAPSHOT +android.library.reference.5=gen-external-apklibs/org.solovyev.android_android-common-ads_1.0.7-SNAPSHOT +android.library.reference.6=gen-external-apklibs/org.solovyev.android_android-common-core_1.0.7-SNAPSHOT +android.library.reference.7=gen-external-apklibs/org.solovyev.android_android-common-billing_1.0.7-SNAPSHOT +android.library.reference.8=gen-external-apklibs/org.solovyev.android_android-common-db_1.0.7-SNAPSHOT +android.library.reference.9=gen-external-apklibs/org.solovyev.android_android-common-http_1.0.7-SNAPSHOT +android.library.reference.10=gen-external-apklibs/org.solovyev.android_android-common-list_1.0.7-SNAPSHOT +android.library.reference.11=gen-external-apklibs/org.solovyev.android_android-common-view_1.0.7-SNAPSHOT +android.library.reference.12=gen-external-apklibs/org.solovyev.android_android-common-preferences_1.0.7-SNAPSHOT +android.library.reference.13=gen-external-apklibs/org.solovyev.android_android-common-menu_1.0.7-SNAPSHOT +android.library.reference.14=gen-external-apklibs/org.solovyev.android_android-common-other_1.0.7-SNAPSHOT +android.library.reference.15=gen-external-apklibs/org.solovyev.android_android-common-sherlock_1.0.7-SNAPSHOT android.library.reference.16=gen-external-apklibs/com.actionbarsherlock_actionbarsherlock_4.2.0 -android.library.reference.17=gen-external-apklibs/org.solovyev.android_android-common-keyboard_1.0.6 +android.library.reference.17=gen-external-apklibs/org.solovyev.android_android-common-keyboard_1.0.7-SNAPSHOT diff --git a/android-app/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java b/android-app/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java index b6bd2a20..2eda58e9 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java @@ -17,7 +17,8 @@ import org.solovyev.android.calculator.view.NumeralBasesButton; import org.solovyev.android.calculator.view.OnDragListenerVibrator; import org.solovyev.android.history.HistoryDragProcessor; import org.solovyev.android.view.drag.*; -import org.solovyev.common.Announcer; +import org.solovyev.common.listeners.JListeners; +import org.solovyev.common.listeners.Listeners; import org.solovyev.common.math.Point2d; import java.lang.reflect.Field; @@ -42,7 +43,7 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh private Vibrator vibrator; @NotNull - private final Announcer dpclRegister = new Announcer(DragPreferencesChangeListener.class); + private final JListeners dpclRegister = Listeners.newHardRefListeners(); @NotNull private String logTag = "CalculatorActivity"; @@ -79,7 +80,7 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh } public void processButtons(@NotNull final Activity activity, @NotNull View root) { - dpclRegister.clear(); + dpclRegister.removeAll(); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, activity); @@ -239,7 +240,10 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh @Override public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { if (key != null && key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) { - dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, CalculatorApplication.getInstance())); + final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, CalculatorApplication.getInstance()); + for (DragPreferencesChangeListener dragPreferencesChangeListener : dpclRegister.getListeners()) { + dragPreferencesChangeListener.onDragPreferencesChange(dragPreferences); + } } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/AndroidCalculatorNotifier.java b/android-app/src/main/java/org/solovyev/android/calculator/AndroidCalculatorNotifier.java index d14e8cc8..6df473b9 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/AndroidCalculatorNotifier.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/AndroidCalculatorNotifier.java @@ -5,7 +5,7 @@ import android.os.Handler; import android.widget.Toast; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.solovyev.android.AndroidUtils; +import org.solovyev.android.AThreads; import org.solovyev.android.msg.AndroidMessage; import org.solovyev.common.msg.Message; import org.solovyev.common.msg.MessageType; @@ -32,7 +32,7 @@ public class AndroidCalculatorNotifier implements CalculatorNotifier { } public AndroidCalculatorNotifier(@NotNull Application application, boolean showDebugMessages) { - assert AndroidUtils.isUiThread(); + assert AThreads.isUiThread(); this.application = application; this.showDebugMessages = showDebugMessages; @@ -61,7 +61,7 @@ public class AndroidCalculatorNotifier implements CalculatorNotifier { } private void showMessageInUiThread(@NotNull final String message) { - if (AndroidUtils.isUiThread()) { + if (AThreads.isUiThread()) { Toast.makeText(application, message, Toast.LENGTH_SHORT).show(); } else { uiHandler.post(new Runnable() { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index c28a0870..d931257c 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -23,14 +23,16 @@ import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.SherlockFragmentActivity; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.solovyev.android.AActivities; +import org.solovyev.android.AThreads; import org.solovyev.android.AndroidUtils; import org.solovyev.android.calculator.about.CalculatorReleaseNotesFragment; import org.solovyev.android.calculator.plot.CalculatorPlotActivity; import org.solovyev.android.fragments.FragmentUtils; import org.solovyev.android.prefs.Preference; -import org.solovyev.common.equals.EqualsTool; +import org.solovyev.common.Objects; import org.solovyev.common.history.HistoryAction; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; public class CalculatorActivity extends SherlockFragmentActivity implements SharedPreferences.OnSharedPreferenceChangeListener, CalculatorEventListener { @@ -114,7 +116,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar if (!CalculatorApplication.isMonkeyRunner(context)) { boolean dialogShown = false; - if (EqualsTool.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) { + if (Objects.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) { // new start final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(R.string.c_first_start_text); builder.setPositiveButton(android.R.string.ok, null); @@ -126,7 +128,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences); if (showReleaseNotes) { final String releaseNotes = CalculatorReleaseNotesFragment.getReleaseNotes(context, savedVersion + 1); - if (!StringUtils.isEmpty(releaseNotes)) { + if (!Strings.isEmpty(releaseNotes)) { final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes)); builder.setPositiveButton(android.R.string.ok, null); builder.setTitle(R.string.c_release_notes); @@ -199,7 +201,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences); if ( newLayout != activityHelper.getLayout() ) { - AndroidUtils.restartActivity(this); + AActivities.restartActivity(this); } this.activityHelper.onResume(this); @@ -330,12 +332,12 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) { switch (calculatorEventType) { case plot_graph: - Threads.tryRunOnUiThread(this, new Runnable() { + AThreads.tryRunOnUiThread(this, new Runnable() { @Override public void run() { - if ( isMultiPane() ) { + if (isMultiPane()) { final ActionBar.Tab selectedTab = getSupportActionBar().getSelectedTab(); - if ( selectedTab != null && CalculatorFragmentType.plotter.getFragmentTag().equals(selectedTab.getTag()) ) { + if (selectedTab != null && CalculatorFragmentType.plotter.getFragmentTag().equals(selectedTab.getTag())) { // do nothing - fragment shown and already registered for plot updates } else { // otherwise - open fragment diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java index 81222854..744a96a2 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java @@ -18,7 +18,8 @@ import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.SherlockFragmentActivity; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.solovyev.android.AndroidUtils; +import org.solovyev.android.AActivities; +import org.solovyev.android.AViews; import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener; /** @@ -112,7 +113,7 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple final ActionBar actionBar = activity.getSupportActionBar(); if (activity instanceof CalculatorActivity) { - if (AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT) { + if (AViews.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT) { actionBar.setDisplayShowTitleEnabled(true); } else { actionBar.setDisplayShowTitleEnabled(false); @@ -144,7 +145,7 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences); if (!theme.equals(newTheme)) { - AndroidUtils.restartActivity(activity); + AActivities.restartActivity(activity); } } @@ -281,13 +282,13 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple final StringBuilder helpText = new StringBuilder(); helpText.append("Size: "); - if (AndroidUtils.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE, c)) { + if (AViews.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE, c)) { helpText.append("xlarge"); - } else if (AndroidUtils.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, c)) { + } else if (AViews.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, c)) { helpText.append("large"); - } else if (AndroidUtils.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_NORMAL, c)) { + } else if (AViews.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_NORMAL, c)) { helpText.append("normal"); - } else if (AndroidUtils.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_SMALL, c)) { + } else if (AViews.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_SMALL, c)) { helpText.append("small"); } else { helpText.append("unknown"); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java index 60bd843a..63e5b51b 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java @@ -14,7 +14,7 @@ import com.actionbarsherlock.app.SherlockFragmentActivity; import jscl.math.Generic; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.solovyev.android.AndroidUtils2; +import org.solovyev.android.AndroidUtils; import org.solovyev.android.App; import org.solovyev.android.calculator.about.CalculatorAboutActivity; import org.solovyev.android.calculator.function.FunctionEditDialogFragment; @@ -27,7 +27,7 @@ import org.solovyev.android.calculator.plot.CalculatorPlotter; import org.solovyev.android.calculator.preferences.CalculatorPreferencesActivity; import org.solovyev.common.msg.Message; import org.solovyev.common.msg.MessageType; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; import java.util.List; @@ -47,7 +47,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener public static void showHistory(@NotNull final Context context, boolean detached) { final Intent intent = new Intent(context, CalculatorHistoryActivity.class); - AndroidUtils2.addFlags(intent, detached, context); + AndroidUtils.addIntentFlags(intent, detached, context); context.startActivity(intent); } @@ -60,7 +60,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener } public static void showSettings(@NotNull final Context context, boolean detached) { final Intent intent = new Intent(context, CalculatorPreferencesActivity.class); - AndroidUtils2.addFlags(intent, detached, context); + AndroidUtils.addIntentFlags(intent, detached, context); context.startActivity(intent); } @@ -74,7 +74,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener public static void showFunctions(@NotNull final Context context, boolean detached) { final Intent intent = new Intent(context, CalculatorFunctionsActivity.class); - AndroidUtils2.addFlags(intent, detached, context); + AndroidUtils.addIntentFlags(intent, detached, context); context.startActivity(intent); } @@ -84,7 +84,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener public static void showOperators(@NotNull final Context context, boolean detached) { final Intent intent = new Intent(context, CalculatorOperatorsActivity.class); - AndroidUtils2.addFlags(intent, detached, context); + AndroidUtils.addIntentFlags(intent, detached, context); context.startActivity(intent); } @@ -94,14 +94,14 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener public static void showVars(@NotNull final Context context, boolean detached) { final Intent intent = new Intent(context, CalculatorVarsActivity.class); - AndroidUtils2.addFlags(intent, detached, context); + AndroidUtils.addIntentFlags(intent, detached, context); context.startActivity(intent); } public static void plotGraph(@NotNull final Context context){ final Intent intent = new Intent(); intent.setClass(context, CalculatorPlotActivity.class); - AndroidUtils2.addFlags(intent, false, context); + AndroidUtils.addIntentFlags(intent, false, context); context.startActivity(intent); } @@ -110,14 +110,14 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener final CalculatorDisplayViewState viewState = display.getViewState(); if (viewState.isValid() ) { final String varValue = viewState.getText(); - if (!StringUtils.isEmpty(varValue)) { + if (!Strings.isEmpty(varValue)) { if (CalculatorVarsFragment.isValidValue(varValue)) { if (context instanceof SherlockFragmentActivity) { VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromValue(varValue), ((SherlockFragmentActivity) context).getSupportFragmentManager()); } else { final Intent intent = new Intent(context, CalculatorVarsActivity.class); intent.putExtra(CalculatorVarsFragment.CREATE_VAR_EXTRA_STRING, varValue); - AndroidUtils2.addFlags(intent, false, context); + AndroidUtils.addIntentFlags(intent, false, context); context.startActivity(intent); } } else { @@ -137,7 +137,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener if (viewState.isValid() ) { final String functionValue = viewState.getText(); - if (!StringUtils.isEmpty(functionValue)) { + if (!Strings.isEmpty(functionValue)) { FunctionEditDialogFragment.showDialog(FunctionEditDialogFragment.Input.newFromDisplay(viewState), context); @@ -162,7 +162,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener if (viewState.isValid() ) { final String functionValue = viewState.getText(); final Generic expression = viewState.getResult(); - if (!StringUtils.isEmpty(functionValue) && expression != null) { + if (!Strings.isEmpty(functionValue) && expression != null) { if ( plotter.isPlotPossibleFor(expression) ) { plotter.plot(expression); } else { @@ -184,7 +184,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener public static void likeButtonPressed(@NotNull final Context context) { final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(CalculatorApplication.FACEBOOK_APP_URL)); - AndroidUtils2.addFlags(intent, false, context); + AndroidUtils.addIntentFlags(intent, false, context); context.startActivity(intent); } @@ -204,22 +204,22 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener if ( source instanceof Context ) { context = ((Context) source); } else { - context = App.getInstance().getApplication(); + context = App.getApplication(); } switch (calculatorEventType){ case show_create_matrix_dialog: - App.getInstance().getUiThreadExecutor().execute(new Runnable() { + App.getUiThreadExecutor().execute(new Runnable() { @Override public void run() { final Intent intent = new Intent(context, CalculatorMatrixActivity.class); - AndroidUtils2.addFlags(intent, false, context); + AndroidUtils.addIntentFlags(intent, false, context); context.startActivity(intent); } }); break; case show_create_var_dialog: - App.getInstance().getUiThreadExecutor().execute(new Runnable() { + App.getUiThreadExecutor().execute(new Runnable() { @Override public void run() { CalculatorActivityLauncher.tryCreateVar(context); @@ -227,7 +227,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener }); break; case show_create_function_dialog: - App.getInstance().getUiThreadExecutor().execute(new Runnable() { + App.getUiThreadExecutor().execute(new Runnable() { @Override public void run() { CalculatorActivityLauncher.tryCreateFunction(context); @@ -237,7 +237,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener case show_evaluation_error: final String errorMessage = (String) data; if (errorMessage != null) { - App.getInstance().getUiThreadExecutor().execute(new Runnable() { + App.getUiThreadExecutor().execute(new Runnable() { @Override public void run() { showEvaluationError(context, errorMessage); @@ -248,7 +248,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener case show_message_dialog: final DialogData dialogData = (DialogData) data; if (dialogData != null) { - App.getInstance().getUiThreadExecutor().execute(new Runnable() { + App.getUiThreadExecutor().execute(new Runnable() { @Override public void run() { CalculatorDialogActivity.showDialog(context, dialogData); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java index 8e2a66a9..4f311ecf 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java @@ -13,7 +13,7 @@ import org.acra.ACRA; import org.acra.ReportingInteractionMode; import org.acra.annotation.ReportsCrashes; import org.jetbrains.annotations.NotNull; -import org.solovyev.android.AndroidUtils2; +import org.solovyev.android.AndroidUtils; import org.solovyev.android.App; import org.solovyev.android.ads.AdsController; import org.solovyev.android.calculator.external.AndroidExternalListenersContainer; @@ -100,7 +100,7 @@ public class CalculatorApplication extends android.app.Application implements Sh public void onCreate() { ACRA.init(this); - App.getInstance().init(this); + App.init(this); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); CalculatorPreferences.setDefaultValues(preferences); @@ -221,7 +221,7 @@ public class CalculatorApplication extends android.app.Application implements Sh public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (CalculatorPreferences.OnscreenCalculator.showAppIcon.getKey().equals(key)) { boolean showAppIcon = CalculatorPreferences.OnscreenCalculator.showAppIcon.getPreference(prefs); - AndroidUtils2.toggleComponent(this, CalculatorOnscreenStartActivity.class, showAppIcon); + AndroidUtils.toggleComponent(this, CalculatorOnscreenStartActivity.class, showAppIcon); Locator.getInstance().getNotifier().showMessage(R.string.cpp_this_change_may_require_reboot, MessageType.info); } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDialogActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDialogActivity.java index e0204584..23b4f902 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDialogActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDialogActivity.java @@ -11,10 +11,10 @@ import android.widget.TextView; import com.actionbarsherlock.app.SherlockFragmentActivity; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.solovyev.android.AndroidUtils2; +import org.solovyev.android.AndroidUtils; import org.solovyev.android.fragments.FragmentUtils; import org.solovyev.common.msg.MessageType; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; /** * User: serso @@ -33,7 +33,7 @@ public class CalculatorDialogActivity extends SherlockFragmentActivity { final Intent intent = new Intent(); intent.setClass(context, CalculatorDialogActivity.class); intent.putExtra(DIALOG_DATA_EXTRA, ParcelableDialogData.wrap(dialogData)); - AndroidUtils2.addFlags(intent, false, context); + AndroidUtils.addIntentFlags(intent, false, context); context.startActivity(intent); } @@ -49,7 +49,7 @@ public class CalculatorDialogActivity extends SherlockFragmentActivity { setContentView(R.layout.cpp_dialog); final String title = dialogData.getTitle(); - if (!StringUtils.isEmpty(title)) { + if (!Strings.isEmpty(title)) { setTitle(title); } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java index c1fdaec2..200bcd35 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java @@ -27,7 +27,7 @@ public class CalculatorEditorFragment extends SherlockFragment { private CalculatorFragmentHelper fragmentHelper; @NotNull - private ActivityMenu menu = ListActivityMenu.fromList(CalculatorMenu.class, SherlockMenuHelper.getInstance()); + private ActivityMenu menu = ListActivityMenu.fromEnum(CalculatorMenu.class, SherlockMenuHelper.getInstance()); public CalculatorEditorFragment() { } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/about/CalculatorReleaseNotesFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/about/CalculatorReleaseNotesFragment.java index 56754d85..abdc54ec 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/about/CalculatorReleaseNotesFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/about/CalculatorReleaseNotesFragment.java @@ -18,7 +18,7 @@ import org.solovyev.android.calculator.CalculatorApplication; import org.solovyev.android.calculator.CalculatorFragment; import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.R; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; /** * User: serso @@ -58,7 +58,7 @@ public class CalculatorReleaseNotesFragment extends CalculatorFragment { boolean first = true; for ( int i = version; i >= minVersion; i-- ) { String releaseNotesForVersion = textHelper.getText("c_release_notes_for_" + i); - if (!StringUtils.isEmpty(releaseNotesForVersion)){ + if (!Strings.isEmpty(releaseNotesForVersion)){ assert releaseNotesForVersion != null; if ( !first ) { result.append("

"); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/function/FunctionEditorSaver.java b/android-app/src/main/java/org/solovyev/android/calculator/function/FunctionEditorSaver.java index d2b803fa..27658550 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/function/FunctionEditorSaver.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/function/FunctionEditorSaver.java @@ -14,7 +14,7 @@ import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.math.edit.VarEditorSaver; import org.solovyev.android.calculator.model.AFunction; import org.solovyev.common.msg.MessageType; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; import java.util.Collections; import java.util.List; @@ -79,7 +79,7 @@ public class FunctionEditorSaver implements View.OnClickListener { if (canBeSaved) { if (validateParameters(parameterNames)) { - if (!StringUtils.isEmpty(content)) { + if (!Strings.isEmpty(content)) { builder.setParameterNames(parameterNames); builder.setName(name); builder.setDescription(description); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/history/AbstractCalculatorHistoryFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/history/AbstractCalculatorHistoryFragment.java index 49c6ca98..a3ce745f 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/history/AbstractCalculatorHistoryFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/AbstractCalculatorHistoryFragment.java @@ -26,15 +26,14 @@ import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.jscl.JsclOperation; import org.solovyev.android.menu.*; import org.solovyev.android.sherlock.menu.SherlockMenuHelper; -import org.solovyev.common.collections.CollectionsUtils; +import org.solovyev.common.JPredicate; +import org.solovyev.common.collections.Collections; import org.solovyev.common.equals.Equalizer; import org.solovyev.common.filter.Filter; -import org.solovyev.common.filter.FilterRule; import org.solovyev.common.filter.FilterRulesChain; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -145,7 +144,7 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag final HistoryItemMenuData data = new HistoryItemMenuData(historyState, adapter); - final List menuItems = CollectionsUtils.asList(HistoryItemMenuItem.values()); + final List menuItems = Collections.asList(HistoryItemMenuItem.values()); if (historyState.isSaved()) { menuItems.remove(HistoryItemMenuItem.save); @@ -157,11 +156,11 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag menuItems.remove(HistoryItemMenuItem.edit); } - if (historyState.getDisplayState().isValid() && StringUtils.isEmpty(historyState.getDisplayState().getEditorState().getText())) { + if (historyState.getDisplayState().isValid() && Strings.isEmpty(historyState.getDisplayState().getEditorState().getText())) { menuItems.remove(HistoryItemMenuItem.copy_result); } - final AMenuBuilder menuBuilder = AMenuBuilder.newInstance(context, MenuImpl.newInstance(menuItems)); + final ContextMenuBuilder menuBuilder = ContextMenuBuilder.newInstance(context, ListContextMenu.newInstance(menuItems)); menuBuilder.create(data).show(); return true; @@ -219,7 +218,7 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag boolean result = false; try { historyState.setSaved(true); - if ( CollectionsUtils.contains(historyState, Locator.getInstance().getHistory().getSavedHistory(), new Equalizer() { + if ( Collections.contains(historyState, Locator.getInstance().getHistory().getSavedHistory(), new Equalizer() { @Override public boolean equals(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) { return first != null && second != null && @@ -244,13 +243,13 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag private List getHistoryList() { final List calculatorHistoryStates = getHistoryItems(); - Collections.sort(calculatorHistoryStates, COMPARATOR); + java.util.Collections.sort(calculatorHistoryStates, COMPARATOR); final FilterRulesChain filterRulesChain = new FilterRulesChain(); - filterRulesChain.addFilterRule(new FilterRule() { + filterRulesChain.addFilterRule(new JPredicate() { @Override - public boolean isFiltered(CalculatorHistoryState object) { - return object == null || StringUtils.isEmpty(object.getEditorState().getText()); + public boolean apply(CalculatorHistoryState object) { + return object == null || Strings.isEmpty(object.getEditorState().getText()); } }); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java b/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java index ea495536..4f0c873f 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java @@ -13,7 +13,7 @@ import android.widget.ArrayAdapter; import android.widget.TextView; import org.jetbrains.annotations.NotNull; import org.solovyev.android.calculator.R; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; import java.text.SimpleDateFormat; import java.util.Date; @@ -45,7 +45,7 @@ public class HistoryArrayAdapter extends ArrayAdapter { final TextView commentView = (TextView) result.findViewById(R.id.history_item_comment); if (commentView != null) { final String comment = state.getComment(); - if (!StringUtils.isEmpty(comment)) { + if (!Strings.isEmpty(comment)) { commentView.setText(comment); } else { commentView.setText(""); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryItemMenuItem.java b/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryItemMenuItem.java index 7cfad817..5cb0f4c2 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryItemMenuItem.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryItemMenuItem.java @@ -20,7 +20,7 @@ import org.jetbrains.annotations.NotNull; import org.solovyev.android.calculator.Locator; import org.solovyev.android.calculator.R; import org.solovyev.android.menu.LabeledMenuItem; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; /** * User: serso @@ -41,7 +41,7 @@ public enum HistoryItemMenuItem implements LabeledMenuItem public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) { final CalculatorHistoryState calculatorHistoryState = data.getHistoryState(); final String text = calculatorHistoryState.getEditorState().getText(); - if (!StringUtils.isEmpty(text)) { + if (!Strings.isEmpty(text)) { final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE); clipboard.setText(text); Toast.makeText(context, context.getText(R.string.c_expression_copied), Toast.LENGTH_SHORT).show(); @@ -54,7 +54,7 @@ public enum HistoryItemMenuItem implements LabeledMenuItem public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) { final CalculatorHistoryState calculatorHistoryState = data.getHistoryState(); final String text = calculatorHistoryState.getDisplayState().getEditorState().getText(); - if (!StringUtils.isEmpty(text)) { + if (!Strings.isEmpty(text)) { final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE); clipboard.setText(text); Toast.makeText(context, context.getText(R.string.c_result_copied), Toast.LENGTH_SHORT).show(); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListFragment.java index bc80f59f..949cefeb 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListFragment.java @@ -20,15 +20,15 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.CalculatorFragmentType; -import org.solovyev.android.menu.AMenuBuilder; import org.solovyev.android.menu.AMenuItem; +import org.solovyev.android.menu.ContextMenuBuilder; import org.solovyev.android.menu.LabeledMenuItem; -import org.solovyev.android.menu.MenuImpl; -import org.solovyev.common.equals.EqualsTool; +import org.solovyev.android.menu.ListContextMenu; +import org.solovyev.common.JPredicate; +import org.solovyev.common.Objects; import org.solovyev.common.filter.Filter; -import org.solovyev.common.filter.FilterRule; import org.solovyev.common.math.MathEntity; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; import java.util.Arrays; import java.util.Comparator; @@ -51,7 +51,7 @@ public abstract class AbstractMathEntityListFragment exten public static final String MATH_ENTITY_CATEGORY_EXTRA_STRING = "org.solovyev.android.calculator.CalculatorVarsActivity_math_entity_category"; - protected final static List acceptableChars = Arrays.asList(StringUtils.toObject("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_".toCharArray())); + protected final static List acceptableChars = Arrays.asList(Strings.toObject("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_".toCharArray())); /* @@ -124,7 +124,7 @@ public abstract class AbstractMathEntityListFragment exten final List> menuItems = getMenuItemsOnLongClick(item); if (!menuItems.isEmpty()) { - final AMenuBuilder, T> menuBuilder = AMenuBuilder.newInstance(AbstractMathEntityListFragment.this.getActivity(), MenuImpl.newInstance(menuItems)); + final ContextMenuBuilder, T> menuBuilder = ContextMenuBuilder.newInstance(AbstractMathEntityListFragment.this.getActivity(), ListContextMenu.newInstance(menuItems)); menuBuilder.create(item).show(); } @@ -169,9 +169,9 @@ public abstract class AbstractMathEntityListFragment exten private List getMathEntitiesByCategory() { final List result = getMathEntities(); - new Filter(new FilterRule() { + new Filter(new JPredicate() { @Override - public boolean isFiltered(T t) { + public boolean apply(T t) { return !isInCategory(t); } }).filter(result.iterator()); @@ -180,7 +180,7 @@ public abstract class AbstractMathEntityListFragment exten } protected boolean isInCategory(@Nullable T t) { - return t != null && (category == null || EqualsTool.areEqual(getMathEntityCategory(t), category)); + return t != null && (category == null || Objects.areEqual(getMathEntityCategory(t), category)); } @NotNull @@ -246,7 +246,7 @@ public abstract class AbstractMathEntityListFragment exten final String mathEntityDescription = descriptionGetter.getDescription(getContext(), mathEntity.getName()); final TextView description = (TextView) result.findViewById(R.id.math_entity_description); - if (!StringUtils.isEmpty(mathEntityDescription)) { + if (!Strings.isEmpty(mathEntityDescription)) { description.setVisibility(View.VISIBLE); description.setText(mathEntityDescription); } else { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsFragment.java index 22a1307e..567bc3d3 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsFragment.java @@ -24,7 +24,7 @@ import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.function.FunctionEditDialogFragment; import org.solovyev.android.menu.AMenuItem; import org.solovyev.android.menu.LabeledMenuItem; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; import java.util.ArrayList; import java.util.Arrays; @@ -73,7 +73,7 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment< List> result = new ArrayList>(Arrays.asList(LongClickMenuItem.values())); final CalculatorMathRegistry functionsRegistry = Locator.getInstance().getEngine().getFunctionsRegistry(); - if ( StringUtils.isEmpty(functionsRegistry.getDescription(item.getName())) ) { + if ( Strings.isEmpty(functionsRegistry.getDescription(item.getName())) ) { result.remove(LongClickMenuItem.copy_description); } @@ -247,7 +247,7 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment< @Override public void onClick(@NotNull Function function, @NotNull Context context) { final String text = Locator.getInstance().getEngine().getFunctionsRegistry().getDescription(function.getName()); - if (!StringUtils.isEmpty(text)) { + if (!Strings.isEmpty(text)) { final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE); clipboard.setText(text); } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorOperatorsFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorOperatorsFragment.java index d8672c65..fc9fefc3 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorOperatorsFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorOperatorsFragment.java @@ -11,7 +11,7 @@ import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.menu.AMenuItem; import org.solovyev.android.menu.LabeledMenuItem; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; import java.util.ArrayList; import java.util.Arrays; @@ -39,7 +39,7 @@ public class CalculatorOperatorsFragment extends AbstractMathEntityListFragment< protected List> getMenuItemsOnLongClick(@NotNull Operator item) { final List> result = new ArrayList>(Arrays.asList(LongClickMenuItem.values())); - if ( StringUtils.isEmpty(OperatorDescriptionGetter.instance.getDescription(this.getActivity(), item.getName())) ) { + if ( Strings.isEmpty(OperatorDescriptionGetter.instance.getDescription(this.getActivity(), item.getName())) ) { result.remove(LongClickMenuItem.copy_description); } @@ -81,7 +81,7 @@ public class CalculatorOperatorsFragment extends AbstractMathEntityListFragment< @Override public String getDescription(@NotNull Context context, @NotNull String mathEntityName) { String result = Locator.getInstance().getEngine().getOperatorsRegistry().getDescription(mathEntityName); - if (StringUtils.isEmpty(result)) { + if (Strings.isEmpty(result)) { result = Locator.getInstance().getEngine().getPostfixFunctionsRegistry().getDescription(mathEntityName); } @@ -110,7 +110,7 @@ public class CalculatorOperatorsFragment extends AbstractMathEntityListFragment< @Override public void onClick(@NotNull Operator data, @NotNull Context context) { final String text = OperatorDescriptionGetter.instance.getDescription(context, data.getName()); - if (!StringUtils.isEmpty(text)) { + if (!Strings.isEmpty(text)) { final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE); clipboard.setText(text); } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsFragment.java index 66276187..4b505338 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsFragment.java @@ -22,8 +22,8 @@ import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.menu.AMenuItem; import org.solovyev.android.menu.LabeledMenuItem; import org.solovyev.common.JPredicate; -import org.solovyev.common.collections.CollectionsUtils; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.collections.Collections; +import org.solovyev.common.text.Strings; import java.util.ArrayList; import java.util.Arrays; @@ -49,7 +49,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment getMathEntities() { final List result = new ArrayList(Locator.getInstance().getEngine().getVarsRegistry().getEntities()); - CollectionsUtils.removeAll(result, new JPredicate() { + Collections.removeAll(result, new JPredicate() { @Override public boolean apply(@Nullable IConstant var) { - return var != null && CollectionsUtils.contains(var.getName(), MathType.INFINITY_JSCL, MathType.NAN); + return var != null && Collections.contains(var.getName(), MathType.INFINITY_JSCL, MathType.NAN); } }); @@ -249,7 +249,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment implements View.OnClickListene if (mathType.getMathType() == MathType.text || mathType.getMathType() == MathType.constant) { - if (StringUtils.isEmpty(value)) { + if (Strings.isEmpty(value)) { // value is empty => undefined variable varBuilder.setName(name); varBuilder.setDescription(description); @@ -126,7 +126,7 @@ public class VarEditorSaver implements View.OnClickListene public static boolean isValidName(@Nullable String name) { boolean result = false; - if (!StringUtils.isEmpty(name)) { + if (!Strings.isEmpty(name)) { try { assert name != null; Identifier.parser.parse(Parser.Parameters.newInstance(name, new MutableInt(0), Locator.getInstance().getEngine().getMathEngine0()), null); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/plot/AbstractCalculatorPlotFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/AbstractCalculatorPlotFragment.java index f79b4726..adc7f953 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/plot/AbstractCalculatorPlotFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/AbstractCalculatorPlotFragment.java @@ -16,7 +16,8 @@ import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.solovyev.android.AndroidUtils2; +import org.solovyev.android.AThreads; +import org.solovyev.android.AndroidUtils; import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.model.AndroidCalculatorEngine; import org.solovyev.android.menu.AMenuItem; @@ -152,7 +153,7 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment } private void updateChart(@NotNull final PlotData plotData, @Nullable final SherlockFragmentActivity activity) { - Threads.tryRunOnUiThread(activity, new Runnable() { + AThreads.tryRunOnUiThread(activity, new Runnable() { @Override public void run() { createChart(plotData); @@ -308,7 +309,7 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment final File externalFilesDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES); if (externalFilesDir != null) { final String path = externalFilesDir.getPath(); - AndroidUtils2.saveBitmap(screenshot, path, screenShotFileName); + AndroidUtils.saveBitmap(screenshot, path, screenShotFileName); Locator.getInstance().getNotifier().showMessage(R.string.cpp_plot_screenshot_saved, MessageType.info, path + "/" + screenShotFileName); } else { Locator.getInstance().getNotifier().showMessage(R.string.cpp_plot_unable_to_save_screenshot, MessageType.error); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/plot/TouchHandler.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/TouchHandler.java index ee115b17..40aab6e5 100755 --- a/android-app/src/main/java/org/solovyev/android/calculator/plot/TouchHandler.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/TouchHandler.java @@ -5,7 +5,7 @@ package org.solovyev.android.calculator.plot; import android.view.MotionEvent; import android.view.VelocityTracker; import org.jetbrains.annotations.NotNull; -import org.solovyev.android.AndroidUtils2; +import org.solovyev.android.AViews; class TouchHandler { @@ -43,7 +43,7 @@ class TouchHandler { float x = event.getX(); float y = event.getY(); - int pointerCount = AndroidUtils2.getPointerCountFromMotionEvent(event); + int pointerCount = AViews.getPointerCountFromMotionEvent(event); switch (action) { case MotionEvent.ACTION_DOWN: @@ -63,7 +63,7 @@ class TouchHandler { velocityTracker.addMovement(event); listener.onTouchMove(x, y); } else if (pointerCount == 2) { - listener.onTouchZoomMove(x, y, AndroidUtils2.getXFromMotionEvent(event, 1), AndroidUtils2.getYFromMotionEvent(event, 1)); + listener.onTouchZoomMove(x, y, AViews.getXFromMotionEvent(event, 1), AViews.getYFromMotionEvent(event, 1)); } break; @@ -75,7 +75,7 @@ class TouchHandler { case MotionEvent.ACTION_POINTER_DOWN: if (pointerCount == 2) { - listener.onTouchZoomDown(x, y, AndroidUtils2.getXFromMotionEvent(event, 1), AndroidUtils2.getYFromMotionEvent(event, 1)); + listener.onTouchZoomDown(x, y, AViews.getXFromMotionEvent(event, 1), AViews.getYFromMotionEvent(event, 1)); } break; diff --git a/android-app/src/main/java/org/solovyev/android/calculator/preferences/CalculatorPreferencesActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/preferences/CalculatorPreferencesActivity.java index 6c31be78..dc80d0e5 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/preferences/CalculatorPreferencesActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/preferences/CalculatorPreferencesActivity.java @@ -21,7 +21,7 @@ import net.robotmedia.billing.ResponseCode; import net.robotmedia.billing.helper.AbstractBillingObserver; import net.robotmedia.billing.model.Transaction; import org.jetbrains.annotations.NotNull; -import org.solovyev.android.AndroidUtils; +import org.solovyev.android.AActivities; import org.solovyev.android.App; import org.solovyev.android.ads.AdsController; import org.solovyev.android.calculator.*; @@ -156,7 +156,7 @@ public class CalculatorPreferencesActivity extends SherlockPreferenceActivity im case PURCHASED: adFreePreference.setEnabled(false); // restart activity to disable ads - AndroidUtils.restartActivity(this); + AActivities.restartActivity(this); break; case CANCELLED: adFreePreference.setEnabled(true); @@ -177,7 +177,7 @@ public class CalculatorPreferencesActivity extends SherlockPreferenceActivity im if (response == ResponseCode.RESULT_OK) { adFreePreference.setEnabled(false); - final Message message = new AndroidMessage(R.string.cpp_purchase_thank_you_text, MessageType.info, App.getInstance().getApplication()); + final Message message = new AndroidMessage(R.string.cpp_purchase_thank_you_text, MessageType.info, App.getApplication()); Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_message_dialog, MessageDialogData.newInstance(message, null)); } } diff --git a/android-app/src/main/java/org/solovyev/android/fragments/FragmentUtils.java b/android-app/src/main/java/org/solovyev/android/fragments/FragmentUtils.java index f1e44288..be54c7a8 100644 --- a/android-app/src/main/java/org/solovyev/android/fragments/FragmentUtils.java +++ b/android-app/src/main/java/org/solovyev/android/fragments/FragmentUtils.java @@ -8,7 +8,7 @@ import android.support.v4.app.FragmentTransaction; import com.actionbarsherlock.app.SherlockFragmentActivity; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.solovyev.common.collections.CollectionsUtils; +import org.solovyev.common.collections.Collections; import java.util.List; @@ -51,7 +51,7 @@ public class FragmentUtils { } public static void removeFragments(@NotNull SherlockFragmentActivity activity, @NotNull String... fragmentTags) { - removeFragments(activity, CollectionsUtils.asList(fragmentTags)); + removeFragments(activity, Collections.asList(fragmentTags)); } public static void removeFragments(@NotNull SherlockFragmentActivity activity, @NotNull List fragmentTags) { @@ -61,7 +61,7 @@ public class FragmentUtils { } public static void detachFragments(@NotNull SherlockFragmentActivity activity, @NotNull String... fragmentTags) { - detachFragments(activity, CollectionsUtils.asList(fragmentTags)); + detachFragments(activity, Collections.asList(fragmentTags)); } public static void detachFragments(@NotNull SherlockFragmentActivity activity, @NotNull List fragmentTags) { diff --git a/android-app/src/test/java/org/solovyev/android/AndroidNumeralBaseTest.java b/android-app/src/test/java/org/solovyev/android/AndroidNumeralBaseTest.java index 56c4bbc9..b4c978c0 100644 --- a/android-app/src/test/java/org/solovyev/android/AndroidNumeralBaseTest.java +++ b/android-app/src/test/java/org/solovyev/android/AndroidNumeralBaseTest.java @@ -4,8 +4,8 @@ import junit.framework.Assert; import org.jetbrains.annotations.NotNull; import org.junit.Test; import org.solovyev.android.calculator.units.CalculatorNumeralBase; -import org.solovyev.math.units.Unit; -import org.solovyev.math.units.UnitConverter; +import org.solovyev.common.units.Unit; +import org.solovyev.common.units.UnitConverter; import java.util.Date; import java.util.Random; diff --git a/android-app/src/test/java/org/solovyev/android/calculator/AndroidCalculatorEditorViewTest.java b/android-app/src/test/java/org/solovyev/android/calculator/AndroidCalculatorEditorViewTest.java index 8e1382f8..acbf18cb 100644 --- a/android-app/src/test/java/org/solovyev/android/calculator/AndroidCalculatorEditorViewTest.java +++ b/android-app/src/test/java/org/solovyev/android/calculator/AndroidCalculatorEditorViewTest.java @@ -53,7 +53,7 @@ public class AndroidCalculatorEditorViewTest { for ( int j = 0; j < count; j++ ) { try { int textLength = random.nextInt(maxTextLength); - Locator.getInstance().getEditor().insert(StringUtils.generateRandomString(textLength), textLength); + Locator.getInstance().getEditor().insert(Strings.generateRandomString(textLength), textLength); } catch (Throwable e) { System.out.println(e); error.set(true); diff --git a/android-app/src/test/java/org/solovyev/android/calculator/history/HistoryUtilsTest.java b/android-app/src/test/java/org/solovyev/android/calculator/history/HistoryUtilsTest.java index bc7b800d..f6e0161e 100644 --- a/android-app/src/test/java/org/solovyev/android/calculator/history/HistoryUtilsTest.java +++ b/android-app/src/test/java/org/solovyev/android/calculator/history/HistoryUtilsTest.java @@ -14,7 +14,7 @@ import org.solovyev.android.calculator.CalculatorEditorViewState; import org.solovyev.android.calculator.CalculatorEditorViewStateImpl; import org.solovyev.android.calculator.jscl.JsclOperation; import org.solovyev.common.equals.CollectionEqualizer; -import org.solovyev.common.equals.EqualsTool; +import org.solovyev.common.Objects; import org.solovyev.common.history.HistoryHelper; import org.solovyev.common.history.SimpleHistoryHelper; @@ -122,7 +122,7 @@ public class HistoryUtilsTest { public void testToXml() throws Exception { final Date date = new Date(100000000); - HistoryHelper history = new SimpleHistoryHelper(); + HistoryHelper history = SimpleHistoryHelper.newInstance(); CalculatorDisplayViewState calculatorDisplay = CalculatorDisplayViewStateImpl.newErrorState(JsclOperation.simplify, "Error"); @@ -170,7 +170,7 @@ public class HistoryUtilsTest { Assert.assertEquals(toXml2, xml); final List fromXml = new ArrayList(); - final HistoryHelper historyFromXml = new SimpleHistoryHelper(); + final HistoryHelper historyFromXml = SimpleHistoryHelper.newInstance(); HistoryUtils.fromXml(xml, fromXml); for (CalculatorHistoryState historyState : fromXml) { historyFromXml.addState(historyState); @@ -186,6 +186,6 @@ public class HistoryUtilsTest { historyState.setId(0); historyState.setSaved(true); } - Assert.assertTrue(EqualsTool.areEqual(history.getStates(), historyFromXml.getStates(), new CollectionEqualizer(null))); + Assert.assertTrue(Objects.areEqual(history.getStates(), historyFromXml.getStates(), new CollectionEqualizer(null))); } } diff --git a/android-app/src/test/java/org/solovyev/common/FloatIntervalMapperTest.java b/android-app/src/test/java/org/solovyev/common/FloatIntervalMapperTest.java deleted file mode 100644 index 7a441384..00000000 --- a/android-app/src/test/java/org/solovyev/common/FloatIntervalMapperTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.solovyev.common; - -import junit.framework.Assert; -import org.junit.Test; -import org.solovyev.common.interval.IntervalImpl; -import org.solovyev.common.text.NumberIntervalMapper; - -/** - * User: serso - * Date: 9/23/11 - * Time: 2:54 PM - */ -public class FloatIntervalMapperTest { - - @Test - public void testParse() throws Exception { - final NumberIntervalMapper mapper = new NumberIntervalMapper(Float.class); - - Assert.assertEquals(IntervalImpl.newClosed(1.2f, 12.2f), mapper.parseValue("1.2;12.2")); - Assert.assertEquals(IntervalImpl.newPoint(0f), mapper.parseValue("0;0")); - } -} diff --git a/android-app/src/test/java/org/solovyev/common/math/DiscreteNormalizerTest.java b/android-app/src/test/java/org/solovyev/common/math/DiscreteNormalizerTest.java deleted file mode 100644 index 468972e1..00000000 --- a/android-app/src/test/java/org/solovyev/common/math/DiscreteNormalizerTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.solovyev.common.math; - -import org.junit.Assert; -import org.junit.Test; - -/** - * User: serso - * Date: 9/20/11 - * Time: 5:51 PM - */ -public class DiscreteNormalizerTest { - - @Test - public void testNormalize() throws Exception { - DiscreteNormalizer dn = new DiscreteNormalizer(0, 10, 1d); - - Assert.assertTrue(MathUtils.equals(0, dn.normalize(0.5), 2)); - Assert.assertTrue(MathUtils.equals(0, dn.normalize(0.99), 2)); - Assert.assertTrue(MathUtils.equals(0.1, dn.normalize(1), 2)); - Assert.assertTrue(MathUtils.equals(0.1, dn.normalize(1.01), 2)); - Assert.assertTrue(MathUtils.equals(1, dn.normalize(10), 2)); - Assert.assertTrue(MathUtils.equals(0.9, dn.normalize(9.99), 2)); - } - - @Test - public void testDenormalize() throws Exception { - DiscreteNormalizer dn = new DiscreteNormalizer(0, 10, 1d); - - Assert.assertTrue(MathUtils.equals(0, dn.normalize(dn.denormalize(0)), 2)); - Assert.assertTrue(MathUtils.equals(0.1, dn.normalize(dn.denormalize(0.1)), 2)); - Assert.assertTrue(MathUtils.equals(1, dn.normalize(dn.denormalize(1)), 2)); - Assert.assertTrue(MathUtils.equals(0.9, dn.normalize(dn.denormalize(0.9)), 2)); - } -} diff --git a/core/src/main/java/org/solovyev/android/calculator/AbstractNumberBuilder.java b/core/src/main/java/org/solovyev/android/calculator/AbstractNumberBuilder.java index c6d19407..a67da63a 100644 --- a/core/src/main/java/org/solovyev/android/calculator/AbstractNumberBuilder.java +++ b/core/src/main/java/org/solovyev/android/calculator/AbstractNumberBuilder.java @@ -10,7 +10,7 @@ import jscl.NumeralBase; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.math.MathType; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; /** * User: serso @@ -48,7 +48,7 @@ public abstract class AbstractNumberBuilder { } private boolean spaceBefore(@NotNull MathType.Result mathTypeResult) { - return numberBuilder == null && StringUtils.isEmpty(mathTypeResult.getMatch().trim()); + return numberBuilder == null && Strings.isEmpty(mathTypeResult.getMatch().trim()); } private boolean numeralBaseInTheStart(@NotNull MathType mathType) { diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayViewStateImpl.java b/core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayViewStateImpl.java index 3772656a..4adc24df 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayViewStateImpl.java +++ b/core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayViewStateImpl.java @@ -4,7 +4,7 @@ import jscl.math.Generic; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.jscl.JsclOperation; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; /** * User: serso @@ -89,7 +89,7 @@ public class CalculatorDisplayViewStateImpl implements CalculatorDisplayViewStat @NotNull @Override public String getText() { - return StringUtils.getNotEmpty(isValid() ? stringResult : errorMessage, ""); + return Strings.getNotEmpty(isValid() ? stringResult : errorMessage, ""); } @Override diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEditorImpl.java b/core/src/main/java/org/solovyev/android/calculator/CalculatorEditorImpl.java index 990555a0..b4b195b8 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorEditorImpl.java +++ b/core/src/main/java/org/solovyev/android/calculator/CalculatorEditorImpl.java @@ -5,7 +5,7 @@ import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.history.CalculatorHistoryState; import org.solovyev.android.calculator.history.EditorHistoryState; import org.solovyev.common.gui.CursorControl; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; /** * User: Solovyev_S @@ -93,7 +93,7 @@ public class CalculatorEditorImpl implements CalculatorEditor { case use_history_state: final CalculatorHistoryState calculatorHistoryState = (CalculatorHistoryState)data; final EditorHistoryState editorState = calculatorHistoryState.getEditorState(); - this.setText(StringUtils.getNotEmpty(editorState.getText(), ""), editorState.getCursorPosition()); + this.setText(Strings.getNotEmpty(editorState.getText(), ""), editorState.getCursorPosition()); break; } } diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorFixableError.java b/core/src/main/java/org/solovyev/android/calculator/CalculatorFixableError.java index f4775936..9857e968 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorFixableError.java +++ b/core/src/main/java/org/solovyev/android/calculator/CalculatorFixableError.java @@ -4,7 +4,7 @@ import jscl.AngleUnit; import jscl.text.msg.Messages; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.solovyev.common.collections.CollectionsUtils; +import org.solovyev.common.collections.Collections; import java.util.List; @@ -40,7 +40,7 @@ public enum CalculatorFixableError implements FixableError { private final List messageCodes; CalculatorFixableError(@Nullable String... messageCodes) { - this.messageCodes = CollectionsUtils.asList(messageCodes); + this.messageCodes = Collections.asList(messageCodes); } @Nullable diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsMathRegistry.java b/core/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsMathRegistry.java index b3d95373..a3992ef4 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsMathRegistry.java +++ b/core/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsMathRegistry.java @@ -18,7 +18,7 @@ import org.solovyev.android.calculator.model.Functions; import org.solovyev.android.calculator.model.MathEntityBuilder; import org.solovyev.common.JBuilder; import org.solovyev.common.math.MathRegistry; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; import java.util.Arrays; import java.util.HashMap; @@ -101,7 +101,7 @@ public class CalculatorFunctionsMathRegistry extends AbstractCalculatorMathRegis result = ((CustomFunction) function).getDescription(); } - if (StringUtils.isEmpty(result) ) { + if (Strings.isEmpty(result) ) { result = super.getDescription(functionName); } diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java b/core/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java index efc6a788..959ccf7a 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java +++ b/core/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java @@ -21,9 +21,9 @@ import org.solovyev.common.msg.ListMessageRegistry; import org.solovyev.common.msg.Message; import org.solovyev.common.msg.MessageRegistry; import org.solovyev.common.msg.MessageType; -import org.solovyev.common.text.StringUtils; -import org.solovyev.math.units.ConversionException; -import org.solovyev.math.units.ConversionUtils; +import org.solovyev.common.text.Strings; +import org.solovyev.common.units.ConversionException; +import org.solovyev.common.units.Conversions; import java.util.ArrayList; import java.util.List; @@ -209,7 +209,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener { expression = expression.trim(); - if (StringUtils.isEmpty(expression)) { + if (Strings.isEmpty(expression)) { fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_result, CalculatorOutputImpl.newEmptyOutput(operation)); } else { preparedExpression = prepareExpression(expression); @@ -367,7 +367,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener { if (from != to) { String fromString = generic.toString(); - if (!StringUtils.isEmpty(fromString)) { + if (!Strings.isEmpty(fromString)) { try { fromString = ToJsclTextProcessor.getInstance().process(fromString).getExpression(); } catch (CalculatorParseException e) { @@ -375,7 +375,8 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener { } } - result = ConversionUtils.doConversion(CalculatorNumeralBase.getConverter(), fromString, CalculatorNumeralBase.valueOf(from), CalculatorNumeralBase.valueOf(to)); + + result = Conversions.doConversion(CalculatorNumeralBase.getConverter(), fromString, CalculatorNumeralBase.valueOf(from), CalculatorNumeralBase.valueOf(to)); } else { result = generic.toString(); } @@ -531,7 +532,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener { final CalculatorDisplayViewState newState = displayChangeEventData.getNewValue(); if (newState.isValid()) { final String result = newState.getStringResult(); - if ( !StringUtils.isEmpty(result) ) { + if ( !Strings.isEmpty(result) ) { final CalculatorMathRegistry varsRegistry = Locator.getInstance().getEngine().getVarsRegistry(); final IConstant ansVar = varsRegistry.get(CalculatorVarsRegistry.ANS); diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardImpl.java b/core/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardImpl.java index b41ac768..d24dde2a 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardImpl.java +++ b/core/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardImpl.java @@ -3,7 +3,7 @@ package org.solovyev.android.calculator; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.math.MathType; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; /** * User: serso @@ -22,7 +22,7 @@ public class CalculatorKeyboardImpl implements CalculatorKeyboard { @Override public void buttonPressed(@Nullable final String text) { - if (!StringUtils.isEmpty(text)) { + if (!Strings.isEmpty(text)) { assert text != null; // process special buttons @@ -105,7 +105,7 @@ public class CalculatorKeyboardImpl implements CalculatorKeyboard { final CalculatorDisplayViewState displayViewState = Locator.getInstance().getDisplay().getViewState(); if (displayViewState.isValid()) { final CharSequence text = displayViewState.getText(); - if (!StringUtils.isEmpty(text)) { + if (!Strings.isEmpty(text)) { Locator.getInstance().getClipboard().setText(text); Locator.getInstance().getNotifier().showMessage(CalculatorMessage.newInfoMessage(CalculatorMessages.result_copied)); } diff --git a/core/src/main/java/org/solovyev/android/calculator/FunctionCategory.java b/core/src/main/java/org/solovyev/android/calculator/FunctionCategory.java index 3b469810..a1e66008 100644 --- a/core/src/main/java/org/solovyev/android/calculator/FunctionCategory.java +++ b/core/src/main/java/org/solovyev/android/calculator/FunctionCategory.java @@ -5,10 +5,9 @@ import jscl.math.function.Comparison; import jscl.math.function.Function; import jscl.math.function.Trigonometric; import org.jetbrains.annotations.NotNull; -import org.solovyev.common.collections.CollectionsUtils; +import org.solovyev.common.collections.Collections; import java.util.Arrays; -import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -75,9 +74,9 @@ public enum FunctionCategory { @NotNull public static List getCategoriesByTabOrder() { - final List result = CollectionsUtils.asList(FunctionCategory.values()); + final List result = Collections.asList(FunctionCategory.values()); - Collections.sort(result, new Comparator() { + java.util.Collections.sort(result, new Comparator() { @Override public int compare(FunctionCategory category, FunctionCategory category1) { return category.tabOrder - category1.tabOrder; diff --git a/core/src/main/java/org/solovyev/android/calculator/ListCalculatorEventContainer.java b/core/src/main/java/org/solovyev/android/calculator/ListCalculatorEventContainer.java index ad4351c6..6a7b3a4c 100644 --- a/core/src/main/java/org/solovyev/android/calculator/ListCalculatorEventContainer.java +++ b/core/src/main/java/org/solovyev/android/calculator/ListCalculatorEventContainer.java @@ -2,9 +2,11 @@ package org.solovyev.android.calculator; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.solovyev.common.utils.ListListenersContainer; +import org.solovyev.common.listeners.JListeners; +import org.solovyev.common.listeners.Listeners; import java.util.Arrays; +import java.util.Collection; import java.util.List; /** @@ -18,7 +20,7 @@ public class ListCalculatorEventContainer implements CalculatorEventContainer { private static final String TAG = "CalculatorEventData"; @NotNull - private final ListListenersContainer listeners = new ListListenersContainer(); + private final JListeners listeners = Listeners.newWeakRefListeners(); @Override public void addCalculatorEventListener(@NotNull CalculatorEventListener calculatorEventListener) { @@ -37,7 +39,7 @@ public class ListCalculatorEventContainer implements CalculatorEventContainer { @Override public void fireCalculatorEvents(@NotNull List calculatorEvents) { - final List listeners = this.listeners.getListeners(); + final Collection listeners = this.listeners.getListeners(); //final CalculatorLogger logger = Locator.getInstance().getLogger(); diff --git a/core/src/main/java/org/solovyev/android/calculator/OperatorCategory.java b/core/src/main/java/org/solovyev/android/calculator/OperatorCategory.java index b6fad9d1..1636faa8 100644 --- a/core/src/main/java/org/solovyev/android/calculator/OperatorCategory.java +++ b/core/src/main/java/org/solovyev/android/calculator/OperatorCategory.java @@ -2,9 +2,8 @@ package org.solovyev.android.calculator; import jscl.math.operator.*; import org.jetbrains.annotations.NotNull; -import org.solovyev.common.collections.CollectionsUtils; +import org.solovyev.common.collections.Collections; -import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -61,9 +60,9 @@ public enum OperatorCategory { @NotNull public static List getCategoriesByTabOrder() { - final List result = CollectionsUtils.asList(OperatorCategory.values()); + final List result = Collections.asList(OperatorCategory.values()); - Collections.sort(result, new Comparator() { + java.util.Collections.sort(result, new Comparator() { @Override public int compare(OperatorCategory category, OperatorCategory category1) { return category.tabOrder - category1.tabOrder; diff --git a/core/src/main/java/org/solovyev/android/calculator/ToJsclTextProcessor.java b/core/src/main/java/org/solovyev/android/calculator/ToJsclTextProcessor.java index abca4ab1..b9744216 100644 --- a/core/src/main/java/org/solovyev/android/calculator/ToJsclTextProcessor.java +++ b/core/src/main/java/org/solovyev/android/calculator/ToJsclTextProcessor.java @@ -11,9 +11,9 @@ import jscl.math.function.IConstant; import org.jetbrains.annotations.NotNull; import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.calculator.text.TextProcessor; -import org.solovyev.common.StartsWithFinder; -import org.solovyev.common.collections.CollectionsUtils; +import org.solovyev.common.collections.Collections; import org.solovyev.common.msg.MessageType; +import org.solovyev.common.search.StartsWithFinder; import java.util.ArrayList; import java.util.List; @@ -47,7 +47,7 @@ public class ToJsclTextProcessor implements TextProcessor 0 ) { @@ -96,18 +96,18 @@ public class ToJsclTextProcessor implements TextProcessor getCategoriesByTabOrder() { - final List result = CollectionsUtils.asList(VarCategory.values()); + final List result = Collections.asList(VarCategory.values()); - Collections.sort(result, new Comparator() { + java.util.Collections.sort(result, new Comparator() { @Override public int compare(VarCategory category, VarCategory category1) { return category.tabOrder - category1.tabOrder; diff --git a/core/src/main/java/org/solovyev/android/calculator/history/CalculatorDisplayHistoryState.java b/core/src/main/java/org/solovyev/android/calculator/history/CalculatorDisplayHistoryState.java index ae498be5..756c5ade 100644 --- a/core/src/main/java/org/solovyev/android/calculator/history/CalculatorDisplayHistoryState.java +++ b/core/src/main/java/org/solovyev/android/calculator/history/CalculatorDisplayHistoryState.java @@ -15,7 +15,7 @@ import org.solovyev.android.calculator.CalculatorDisplay; import org.solovyev.android.calculator.CalculatorDisplayViewState; import org.solovyev.android.calculator.CalculatorDisplayViewStateImpl; import org.solovyev.android.calculator.jscl.JsclOperation; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; /** * User: serso @@ -65,9 +65,9 @@ public class CalculatorDisplayHistoryState implements Cloneable { public void setValuesFromHistory(@NotNull CalculatorDisplay display) { if ( this.isValid() ) { - display.setViewState(CalculatorDisplayViewStateImpl.newValidState(this.getJsclOperation(), this.getGenericResult(), StringUtils.getNotEmpty(this.getEditorState().getText(), ""), this.getEditorState().getCursorPosition())); + display.setViewState(CalculatorDisplayViewStateImpl.newValidState(this.getJsclOperation(), this.getGenericResult(), Strings.getNotEmpty(this.getEditorState().getText(), ""), this.getEditorState().getCursorPosition())); } else { - display.setViewState(CalculatorDisplayViewStateImpl.newErrorState(this.getJsclOperation(), StringUtils.getNotEmpty(this.getErrorMessage(), ""))); + display.setViewState(CalculatorDisplayViewStateImpl.newErrorState(this.getJsclOperation(), Strings.getNotEmpty(this.getErrorMessage(), ""))); } } diff --git a/core/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryImpl.java b/core/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryImpl.java index 92e09af0..d1dad2a8 100644 --- a/core/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryImpl.java +++ b/core/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryImpl.java @@ -3,7 +3,6 @@ package org.solovyev.android.calculator.history; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.*; -import org.solovyev.common.collections.CollectionsUtils; import org.solovyev.common.history.HistoryAction; import org.solovyev.common.history.HistoryHelper; import org.solovyev.common.history.SimpleHistoryHelper; @@ -26,7 +25,7 @@ public class CalculatorHistoryImpl implements CalculatorHistory { private final AtomicInteger counter = new AtomicInteger(0); @NotNull - private final HistoryHelper history = new SimpleHistoryHelper(); + private final HistoryHelper history = SimpleHistoryHelper.newInstance(); @NotNull private final List savedHistory = new ArrayList(); @@ -123,7 +122,7 @@ public class CalculatorHistoryImpl implements CalculatorHistory { final List result = new LinkedList(); CalculatorHistoryState laterState = null; - for (CalculatorHistoryState state : CollectionsUtils.reversed(states)) { + for (CalculatorHistoryState state : org.solovyev.common.collections.Collections.reversed(states)) { if ( laterState != null ) { final String laterEditorText = laterState.getEditorState().getText(); final String editorText = state.getEditorState().getText(); diff --git a/core/src/main/java/org/solovyev/android/calculator/history/EditorHistoryState.java b/core/src/main/java/org/solovyev/android/calculator/history/EditorHistoryState.java index ec50bf17..4b9ab1db 100644 --- a/core/src/main/java/org/solovyev/android/calculator/history/EditorHistoryState.java +++ b/core/src/main/java/org/solovyev/android/calculator/history/EditorHistoryState.java @@ -12,7 +12,7 @@ import org.simpleframework.xml.Root; import org.solovyev.android.calculator.CalculatorDisplayViewState; import org.solovyev.android.calculator.CalculatorEditor; import org.solovyev.android.calculator.CalculatorEditorViewState; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; @Root public class EditorHistoryState implements Cloneable{ @@ -49,7 +49,7 @@ public class EditorHistoryState implements Cloneable{ } public void setValuesFromHistory(@NotNull CalculatorEditor editor) { - editor.setText(StringUtils.getNotEmpty(this.getText(), "")); + editor.setText(Strings.getNotEmpty(this.getText(), "")); editor.setSelection(this.getCursorPosition()); } diff --git a/core/src/main/java/org/solovyev/android/calculator/math/MathType.java b/core/src/main/java/org/solovyev/android/calculator/math/MathType.java index 3a39d422..01d73e1d 100644 --- a/core/src/main/java/org/solovyev/android/calculator/math/MathType.java +++ b/core/src/main/java/org/solovyev/android/calculator/math/MathType.java @@ -13,7 +13,7 @@ import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.CalculatorParseException; import org.solovyev.android.calculator.Locator; import org.solovyev.common.JPredicate; -import org.solovyev.common.collections.CollectionsUtils; +import org.solovyev.common.collections.Collections; import java.util.*; @@ -190,7 +190,7 @@ public enum MathType { boolean needMultiplicationSignAfter, @NotNull MathGroupType groupType, @NotNull String... tokens) { - this(priority, needMultiplicationSignBefore, needMultiplicationSignAfter, groupType, CollectionsUtils.asList(tokens)); + this(priority, needMultiplicationSignBefore, needMultiplicationSignAfter, groupType, Collections.asList(tokens)); } MathType(@NotNull Integer priority, @@ -202,7 +202,7 @@ public enum MathType { this.needMultiplicationSignBefore = needMultiplicationSignBefore; this.needMultiplicationSignAfter = needMultiplicationSignAfter; this.groupType = groupType; - this.tokens = Collections.unmodifiableList(tokens); + this.tokens = java.util.Collections.unmodifiableList(tokens); } @NotNull @@ -219,7 +219,7 @@ public enum MathType { final MathType mathType = getType(s.toString(), result).getMathType(); - if (CollectionsUtils.contains(mathType, digit, dot, grouping_separator, power_10)) { + if (Collections.contains(mathType, digit, dot, grouping_separator, power_10)) { // continue } else if (mathType == close_group_symbol) { numberOfOpenGroups++; @@ -246,7 +246,7 @@ public enum MathType { if (i > 0) { final EndsWithFinder endsWithFinder = new EndsWithFinder(s); endsWithFinder.setI(i + 1); - if (!CollectionsUtils.contains(function.getTokens(), FilterType.included, endsWithFinder)) { + if (!Collections.contains(function.getTokens(), FilterType.included, endsWithFinder)) { MathType type = getType(s.toString(), i).getMathType(); if (type != constant) { return true; @@ -350,7 +350,7 @@ public enum MathType { final StartsWithFinder startsWithFinder = new StartsWithFinder(text, i); for (MathType mathType : getMathTypesByPriority()) { - final String s = CollectionsUtils.find(mathType.getTokens(), startsWithFinder); + final String s = Collections.find(mathType.getTokens(), startsWithFinder); if (s != null) { if ( s.length() == 1 ) { if (hexMode || JsclMathEngine.getInstance().getNumeralBase() == NumeralBase.hex) { @@ -373,14 +373,14 @@ public enum MathType { @NotNull private static List getMathTypesByPriority() { if (mathTypesByPriority == null) { - final List result = CollectionsUtils.asList(MathType.values()); + final List result = Collections.asList(MathType.values()); - Collections.sort(result, new Comparator() { - @Override - public int compare(MathType l, MathType r) { - return l.priority.compareTo(r.priority); - } - }); + java.util.Collections.sort(result, new Comparator() { + @Override + public int compare(MathType l, MathType r) { + return l.priority.compareTo(r.priority); + } + }); mathTypesByPriority = result; } diff --git a/core/src/main/java/org/solovyev/android/calculator/model/AFunction.java b/core/src/main/java/org/solovyev/android/calculator/model/AFunction.java index 583a94cf..ca743bfc 100644 --- a/core/src/main/java/org/solovyev/android/calculator/model/AFunction.java +++ b/core/src/main/java/org/solovyev/android/calculator/model/AFunction.java @@ -19,7 +19,7 @@ import org.solovyev.android.calculator.MathPersistenceEntity; import org.solovyev.common.math.MathEntity; import org.solovyev.common.msg.Message; import org.solovyev.common.msg.MessageType; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; import java.io.Serializable; import java.util.ArrayList; @@ -109,7 +109,7 @@ public class AFunction implements IFunction, MathPersistenceEntity, Serializable @NotNull IFunction source) { target.name = source.getName(); target.content = source.getContent(); - target.description = StringUtils.getNotEmpty(source.getDescription(), ""); + target.description = Strings.getNotEmpty(source.getDescription(), ""); target.system = source.isSystem(); if (source.isIdDefined()) { target.id = source.getId(); @@ -285,7 +285,7 @@ public class AFunction implements IFunction, MathPersistenceEntity, Serializable throw new CreationException(e); } result.system = system; - result.description = StringUtils.getNotEmpty(description, ""); + result.description = Strings.getNotEmpty(description, ""); result.parameterNames = new ArrayList(parameterNames); return result; diff --git a/core/src/main/java/org/solovyev/android/calculator/model/Var.java b/core/src/main/java/org/solovyev/android/calculator/model/Var.java index 9e3f2746..63f5d660 100644 --- a/core/src/main/java/org/solovyev/android/calculator/model/Var.java +++ b/core/src/main/java/org/solovyev/android/calculator/model/Var.java @@ -17,7 +17,7 @@ import org.simpleframework.xml.Transient; import org.solovyev.android.calculator.MathPersistenceEntity; import org.solovyev.common.JBuilder; import org.solovyev.common.math.MathEntity; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; /** * User: serso @@ -226,7 +226,7 @@ public class Var implements IConstant, MathPersistenceEntity { @Override public boolean isDefined() { - return !StringUtils.isEmpty(value); + return !Strings.isEmpty(value); } @Override diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/XyFunction.java b/core/src/main/java/org/solovyev/android/calculator/plot/XyFunction.java index a2916602..03114dce 100644 --- a/core/src/main/java/org/solovyev/android/calculator/plot/XyFunction.java +++ b/core/src/main/java/org/solovyev/android/calculator/plot/XyFunction.java @@ -4,7 +4,7 @@ import jscl.math.Generic; import jscl.math.function.Constant; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; public class XyFunction implements FunctionEvaluator { @@ -71,7 +71,7 @@ public class XyFunction implements FunctionEvaluator { this.arity--; } - this.id = this.expressionString + "_" + StringUtils.getNotEmpty(this.xVariableName, "") + "_" + StringUtils.getNotEmpty(this.yVariableName, ""); + this.id = this.expressionString + "_" + Strings.getNotEmpty(this.xVariableName, "") + "_" + Strings.getNotEmpty(this.yVariableName, ""); } diff --git a/core/src/main/java/org/solovyev/android/calculator/units/CalculatorNumeralBase.java b/core/src/main/java/org/solovyev/android/calculator/units/CalculatorNumeralBase.java index 15a95f04..4bf5a948 100644 --- a/core/src/main/java/org/solovyev/android/calculator/units/CalculatorNumeralBase.java +++ b/core/src/main/java/org/solovyev/android/calculator/units/CalculatorNumeralBase.java @@ -2,10 +2,10 @@ package org.solovyev.android.calculator.units; import jscl.NumeralBase; import org.jetbrains.annotations.NotNull; -import org.solovyev.math.units.Unit; -import org.solovyev.math.units.UnitConverter; -import org.solovyev.math.units.UnitImpl; -import org.solovyev.math.units.UnitType; +import org.solovyev.common.units.Unit; +import org.solovyev.common.units.UnitConverter; +import org.solovyev.common.units.UnitImpl; +import org.solovyev.common.units.UnitType; import java.math.BigInteger; diff --git a/core/src/main/java/org/solovyev/common/DelayedExecutor.java b/core/src/main/java/org/solovyev/common/DelayedExecutor.java deleted file mode 100644 index 46aec463..00000000 --- a/core/src/main/java/org/solovyev/common/DelayedExecutor.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.solovyev.common; - -import org.jetbrains.annotations.NotNull; - -import java.util.concurrent.Executor; -import java.util.concurrent.TimeUnit; - -/** - * User: serso - * Date: 12/1/12 - * Time: 4:10 PM - */ -public interface DelayedExecutor extends Executor { - - void execute(@NotNull Runnable command, long delay, @NotNull TimeUnit delayUnit); -} diff --git a/core/src/main/java/org/solovyev/common/ListMapper.java b/core/src/main/java/org/solovyev/common/ListMapper.java deleted file mode 100644 index ff448c64..00000000 --- a/core/src/main/java/org/solovyev/common/ListMapper.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.solovyev.common; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.solovyev.common.text.CollectionTransformations; -import org.solovyev.common.text.Mapper; - -import java.util.List; - -public class ListMapper implements Mapper> { - - @NotNull - private final Mapper nestedMapper; - - private ListMapper(@NotNull Mapper nestedMapper) { - this.nestedMapper = nestedMapper; - } - - @NotNull - private static Mapper> newInstance(@NotNull Mapper nestedMapper) { - return new ListMapper(nestedMapper); - } - - @Nullable - @Override - public String formatValue(@Nullable List value) throws IllegalArgumentException { - return CollectionTransformations.formatValue(value, ";", nestedMapper); - } - - @Nullable - @Override - public List parseValue(@Nullable String value) throws IllegalArgumentException { - return CollectionTransformations.split(value, ";", nestedMapper); - } -} diff --git a/core/src/main/java/org/solovyev/common/utils/ListListenersContainer.java b/core/src/main/java/org/solovyev/common/utils/ListListenersContainer.java deleted file mode 100644 index fa286f42..00000000 --- a/core/src/main/java/org/solovyev/common/utils/ListListenersContainer.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.solovyev.common.utils; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -/** - * User: Solovyev_S - * Date: 20.09.12 - * Time: 16:43 - */ -// todo serso: move to common -public class ListListenersContainer { - - @NotNull - private final List> listeners = new ArrayList>(); - - public void addListener(@NotNull final T listener) { - synchronized (listeners) { - boolean contains = Iterables.any(listeners, new WeakReferencePredicate(listener)); - - if (!contains) { - listeners.add(new WeakReference(listener)); - } - } - } - - public void removeListener(@NotNull T listener) { - synchronized (listeners) { - Iterables.removeIf(listeners, new WeakReferencePredicate(listener)); - } - } - - @NotNull - public List getListeners() { - final List localListeners; - - synchronized (listeners) { - localListeners = new ArrayList(listeners.size()); - - // copy listeners and remove garbage collected references - for ( Iterator> it = listeners.iterator(); it.hasNext(); ) { - final WeakReference r = it.next(); - final T t = r.get(); - if ( t == null ) { - it.remove(); - } else { - localListeners.add(t); - } - } - } - - return localListeners; - } - - private static class WeakReferencePredicate implements Predicate> { - - @NotNull - private final T t; - - public WeakReferencePredicate(T t) { - this.t = t; - } - - @Override - public boolean apply(@Nullable WeakReference r) { - final T t = r != null ? r.get() : null; - return this.t.equals(t); - } - } -} diff --git a/core/src/main/java/org/solovyev/math/units/ConversionException.java b/core/src/main/java/org/solovyev/math/units/ConversionException.java deleted file mode 100644 index 5384ee2a..00000000 --- a/core/src/main/java/org/solovyev/math/units/ConversionException.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.solovyev.math.units; - -/** -* User: Solovyev_S -* Date: 24.09.12 -* Time: 16:01 -*/ -public final class ConversionException extends Exception { - public ConversionException() { - } - - public ConversionException(Throwable throwable) { - super(throwable); - } -} diff --git a/core/src/main/java/org/solovyev/math/units/ConversionUtils.java b/core/src/main/java/org/solovyev/math/units/ConversionUtils.java deleted file mode 100644 index db0896c1..00000000 --- a/core/src/main/java/org/solovyev/math/units/ConversionUtils.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.solovyev.math.units; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.solovyev.common.text.StringUtils; - -/** - * User: Solovyev_S - * Date: 24.09.12 - * Time: 16:01 - */ -public class ConversionUtils { - @NotNull - public static String doConversion(@NotNull UnitConverter converter, - @Nullable String from, - @NotNull UnitType fromUnitType, - @NotNull UnitType toUnitType) throws ConversionException { - final String result; - - if (StringUtils.isEmpty(from)) { - result = ""; - } else { - - String to = null; - try { - if (converter.isSupported(fromUnitType, toUnitType)) { - to = converter.convert(UnitImpl.newInstance(from, fromUnitType), toUnitType).getValue(); - } - } catch (RuntimeException e) { - throw new ConversionException(e); - } - - result = to; - } - - return result; - } -} diff --git a/core/src/main/java/org/solovyev/math/units/Unit.java b/core/src/main/java/org/solovyev/math/units/Unit.java deleted file mode 100644 index 23921ea8..00000000 --- a/core/src/main/java/org/solovyev/math/units/Unit.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.solovyev.math.units; - -import org.jetbrains.annotations.NotNull; - -/** - * User: serso - * Date: 4/21/12 - * Time: 7:54 PM - */ -public interface Unit { - - @NotNull - V getValue(); - - @NotNull - UnitType getUnitType(); -} diff --git a/core/src/main/java/org/solovyev/math/units/UnitConverter.java b/core/src/main/java/org/solovyev/math/units/UnitConverter.java deleted file mode 100644 index 2d56bebd..00000000 --- a/core/src/main/java/org/solovyev/math/units/UnitConverter.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.solovyev.math.units; - -import org.jetbrains.annotations.NotNull; - -/** - * User: serso - * Date: 4/21/12 - * Time: 7:53 PM - */ -public interface UnitConverter { - - boolean isSupported(@NotNull UnitType from, @NotNull UnitType to); - - @NotNull - Unit convert(@NotNull Unit from, @NotNull UnitType toType); - - public static class Dummy implements UnitConverter { - - @NotNull - private static final Dummy instance = new Dummy(); - - @NotNull - public static UnitConverter getInstance() { - return (UnitConverter)instance; - } - - private Dummy() { - } - - @Override - public boolean isSupported(@NotNull UnitType from, @NotNull UnitType to) { - return false; - } - - @NotNull - @Override - public Unit convert(@NotNull Unit from, @NotNull UnitType toType) { - throw new IllegalArgumentException(); - } - } - -} diff --git a/core/src/main/java/org/solovyev/math/units/UnitImpl.java b/core/src/main/java/org/solovyev/math/units/UnitImpl.java deleted file mode 100644 index 647e0c6f..00000000 --- a/core/src/main/java/org/solovyev/math/units/UnitImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.solovyev.math.units; - -import org.jetbrains.annotations.NotNull; - -/** - * User: serso - * Date: 4/21/12 - * Time: 8:01 PM - */ -public class UnitImpl implements Unit { - - @NotNull - private V value; - - @NotNull - private UnitType unitType; - - private UnitImpl() { - } - - @NotNull - public static Unit newInstance(@NotNull V value, @NotNull UnitType unitType) { - final UnitImpl result = new UnitImpl(); - - result.value = value; - result.unitType = unitType; - - return result; - } - - @NotNull - @Override - public V getValue() { - return this.value; - } - - @NotNull - @Override - public UnitType getUnitType() { - return unitType; - } -} diff --git a/core/src/main/java/org/solovyev/math/units/UnitType.java b/core/src/main/java/org/solovyev/math/units/UnitType.java deleted file mode 100644 index 457442c2..00000000 --- a/core/src/main/java/org/solovyev/math/units/UnitType.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.solovyev.math.units; - -import org.jetbrains.annotations.NotNull; - -/** - * User: serso - * Date: 4/21/12 - * Time: 7:55 PM - */ -public interface UnitType { - - @NotNull - Class getUnitValueClass(); - - boolean equals(@NotNull Object o); -} diff --git a/core/src/test/java/org/solovyev/android/calculator/model/FunctionsTest.java b/core/src/test/java/org/solovyev/android/calculator/model/FunctionsTest.java index 02787d39..82c5aa58 100644 --- a/core/src/test/java/org/solovyev/android/calculator/model/FunctionsTest.java +++ b/core/src/test/java/org/solovyev/android/calculator/model/FunctionsTest.java @@ -13,7 +13,7 @@ import org.simpleframework.xml.core.Persister; import org.solovyev.android.calculator.CalculatorTestUtils; import org.solovyev.common.equals.CollectionEqualizer; import org.solovyev.common.equals.EqualsUtils; -import org.solovyev.common.text.StringUtils; +import org.solovyev.common.text.Strings; import java.io.StringWriter; import java.util.*; @@ -122,7 +122,7 @@ public class FunctionsTest { for ( int i = 0; i < 1000; i++ ) { final String content = generator.generate(); - final String paramsString = StringUtils.generateRandomString(random.nextInt(10)); + final String paramsString = Strings.generateRandomString(random.nextInt(10)); final List parameterNames = new ArrayList(); for (int j = 0; j < paramsString.length(); j++) { parameterNames.add(String.valueOf(paramsString.charAt(j))); @@ -131,7 +131,7 @@ public class FunctionsTest { final AFunction.Builder builder = new AFunction.Builder("test_" + i, content, parameterNames); if ( random.nextBoolean() ) { - builder.setDescription(StringUtils.generateRandomString(random.nextInt(100))); + builder.setDescription(Strings.generateRandomString(random.nextInt(100))); } builder.setSystem(random.nextBoolean()); diff --git a/pom.xml b/pom.xml index a984d337..c7f0b5ed 100644 --- a/pom.xml +++ b/pom.xml @@ -33,8 +33,8 @@ UTF-8 - 1.0.6 - 1.0.3 + 1.0.7-SNAPSHOT + 1.0.4-SNAPSHOT