From 8c897ba441aea1e8865df6965cf0d846a474fe09 Mon Sep 17 00:00:00 2001 From: serso Date: Wed, 17 Feb 2016 10:17:29 +0100 Subject: [PATCH] onscreen->floating --- app/src/main/AndroidManifest.xml | 6 +- .../org/solovyev/android/calculator/App.java | 4 +- .../android/calculator/AppComponent.java | 8 +- .../calculator/CalculatorApplication.java | 4 +- .../android/calculator/EditorView.java | 4 +- .../FloatingCalculatorActivity.java} | 6 +- .../FloatingCalculatorBroadcastReceiver.java} | 15 +-- .../FloatingCalculatorService.java} | 41 ++++---- .../FloatingCalculatorView.java} | 99 ++++++++----------- .../FloatingCalculatorViewState.java} | 45 +++++---- .../FloatingViewListener.java} | 9 +- 11 files changed, 110 insertions(+), 131 deletions(-) rename app/src/main/java/org/solovyev/android/calculator/{onscreen/CalculatorOnscreenStartActivity.java => floating/FloatingCalculatorActivity.java} (84%) rename app/src/main/java/org/solovyev/android/calculator/{onscreen/CalculatorOnscreenBroadcastReceiver.java => floating/FloatingCalculatorBroadcastReceiver.java} (82%) rename app/src/main/java/org/solovyev/android/calculator/{onscreen/CalculatorOnscreenService.java => floating/FloatingCalculatorService.java} (86%) rename app/src/main/java/org/solovyev/android/calculator/{onscreen/CalculatorOnscreenView.java => floating/FloatingCalculatorView.java} (85%) rename app/src/main/java/org/solovyev/android/calculator/{onscreen/CalculatorOnscreenViewState.java => floating/FloatingCalculatorViewState.java} (74%) rename app/src/main/java/org/solovyev/android/calculator/{onscreen/OnscreenViewListener.java => floating/FloatingViewListener.java} (86%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c8360100..207a72cc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -119,7 +119,7 @@ @@ -141,7 +141,7 @@ - + diff --git a/app/src/main/java/org/solovyev/android/calculator/App.java b/app/src/main/java/org/solovyev/android/calculator/App.java index e8ae1e54..6d37bc37 100644 --- a/app/src/main/java/org/solovyev/android/calculator/App.java +++ b/app/src/main/java/org/solovyev/android/calculator/App.java @@ -45,7 +45,7 @@ import org.solovyev.android.Check; import org.solovyev.android.Views; import org.solovyev.android.calculator.ga.Ga; import org.solovyev.android.calculator.language.Languages; -import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService; +import org.solovyev.android.calculator.floating.FloatingCalculatorService; import org.solovyev.android.calculator.view.ScreenMetrics; import org.solovyev.android.calculator.wizard.CalculatorWizards; import org.solovyev.android.wizard.Wizards; @@ -171,7 +171,7 @@ public final class App { @Nonnull public static Preferences.Gui.Theme getThemeFor(@Nonnull Context context) { - if (context instanceof CalculatorOnscreenService) { + if (context instanceof FloatingCalculatorService) { final SharedPreferences p = getPreferences(); final Preferences.SimpleTheme onscreenTheme = Preferences.Onscreen.getTheme(p); final Preferences.Gui.Theme appTheme = Preferences.Gui.getTheme(p); diff --git a/app/src/main/java/org/solovyev/android/calculator/AppComponent.java b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java index af4aca6e..a98a17b8 100644 --- a/app/src/main/java/org/solovyev/android/calculator/AppComponent.java +++ b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java @@ -3,13 +3,13 @@ package org.solovyev.android.calculator; import org.solovyev.android.calculator.converter.ConverterFragment; import org.solovyev.android.calculator.errors.FixableErrorFragment; import org.solovyev.android.calculator.errors.FixableErrorsActivity; +import org.solovyev.android.calculator.floating.FloatingCalculatorService; import org.solovyev.android.calculator.functions.EditFunctionFragment; import org.solovyev.android.calculator.functions.FunctionsFragment; import org.solovyev.android.calculator.history.BaseHistoryFragment; import org.solovyev.android.calculator.history.EditHistoryFragment; import org.solovyev.android.calculator.keyboard.BaseKeyboardUi; -import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService; -import org.solovyev.android.calculator.onscreen.CalculatorOnscreenView; +import org.solovyev.android.calculator.floating.FloatingCalculatorView; import org.solovyev.android.calculator.operators.OperatorsFragment; import org.solovyev.android.calculator.preferences.PreferencesActivity; import org.solovyev.android.calculator.preferences.PurchaseDialogActivity; @@ -28,7 +28,7 @@ public interface AppComponent { void inject(EditorFragment fragment); void inject(BaseUi ui); void inject(FragmentUi ui); - void inject(CalculatorOnscreenService service); + void inject(FloatingCalculatorService service); void inject(BaseHistoryFragment fragment); void inject(BaseDialogFragment fragment); void inject(FixableErrorFragment fragment); @@ -47,6 +47,6 @@ public interface AppComponent { void inject(PurchaseDialogActivity activity); void inject(PreferencesActivity activity); void inject(BaseKeyboardUi ui); - void inject(CalculatorOnscreenView view); + void inject(FloatingCalculatorView view); void inject(DragButtonWizardStep fragment); } diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java index aecc589a..ccf9f1a2 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java @@ -37,7 +37,7 @@ import org.solovyev.android.Android; import org.solovyev.android.calculator.history.History; import org.solovyev.android.calculator.language.Language; import org.solovyev.android.calculator.language.Languages; -import org.solovyev.android.calculator.onscreen.CalculatorOnscreenStartActivity; +import org.solovyev.android.calculator.floating.FloatingCalculatorActivity; import org.solovyev.android.calculator.plot.AndroidCalculatorPlotter; import org.solovyev.android.calculator.plot.CalculatorPlotterImpl; import org.solovyev.common.msg.MessageType; @@ -198,7 +198,7 @@ public class CalculatorApplication extends android.app.Application implements Sh public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (Preferences.Onscreen.showAppIcon.getKey().equals(key)) { boolean showAppIcon = Preferences.Onscreen.showAppIcon.getPreference(prefs); - Android.enableComponent(this, CalculatorOnscreenStartActivity.class, showAppIcon); + Android.enableComponent(this, FloatingCalculatorActivity.class, showAppIcon); notifier.showMessage(R.string.cpp_this_change_may_require_reboot, MessageType.info); } } diff --git a/app/src/main/java/org/solovyev/android/calculator/EditorView.java b/app/src/main/java/org/solovyev/android/calculator/EditorView.java index e0ff304f..8017b788 100644 --- a/app/src/main/java/org/solovyev/android/calculator/EditorView.java +++ b/app/src/main/java/org/solovyev/android/calculator/EditorView.java @@ -30,7 +30,7 @@ import android.text.TextWatcher; import android.util.AttributeSet; import android.view.ContextMenu; import org.solovyev.android.Check; -import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService; +import org.solovyev.android.calculator.floating.FloatingCalculatorService; import org.solovyev.android.calculator.view.EditTextCompat; import javax.annotation.Nonnull; @@ -84,7 +84,7 @@ public class EditorView extends EditTextCompat { Check.isMainThread(); // we don't want to be notified about changes we make ourselves reportChanges = false; - if (App.getTheme().light && getContext() instanceof CalculatorOnscreenService) { + if (App.getTheme().light && getContext() instanceof FloatingCalculatorService) { // don't need formatting setText(state.getTextString()); } else { diff --git a/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenStartActivity.java b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorActivity.java similarity index 84% rename from app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenStartActivity.java rename to app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorActivity.java index 43cd6ce4..5fa4c8ce 100644 --- a/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenStartActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorActivity.java @@ -20,18 +20,18 @@ * Site: http://se.solovyev.org */ -package org.solovyev.android.calculator.onscreen; +package org.solovyev.android.calculator.floating; import android.app.Activity; import android.os.Bundle; -public class CalculatorOnscreenStartActivity extends Activity { +public class FloatingCalculatorActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - CalculatorOnscreenService.showOnscreenView(this); + FloatingCalculatorService.show(this); this.finish(); } diff --git a/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenBroadcastReceiver.java b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorBroadcastReceiver.java similarity index 82% rename from app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenBroadcastReceiver.java rename to app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorBroadcastReceiver.java index f7687ddc..99891c38 100644 --- a/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenBroadcastReceiver.java +++ b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorBroadcastReceiver.java @@ -20,7 +20,7 @@ * Site: http://se.solovyev.org */ -package org.solovyev.android.calculator.onscreen; +package org.solovyev.android.calculator.floating; import android.content.BroadcastReceiver; import android.content.Context; @@ -33,14 +33,9 @@ import org.solovyev.android.calculator.Preferences; import javax.annotation.Nonnull; -/** - * User: serso - * Date: 11/20/12 - * Time: 11:05 PM - */ -public final class CalculatorOnscreenBroadcastReceiver extends BroadcastReceiver { +public final class FloatingCalculatorBroadcastReceiver extends BroadcastReceiver { - public CalculatorOnscreenBroadcastReceiver() { + public FloatingCalculatorBroadcastReceiver() { } @Override @@ -49,12 +44,12 @@ public final class CalculatorOnscreenBroadcastReceiver extends BroadcastReceiver if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); if (Preferences.Onscreen.startOnBoot.getPreferenceNoError(preferences)) { - CalculatorOnscreenService.showNotification(context); + FloatingCalculatorService.showNotification(context); App.getGa().onBootStart(); } } else { final Intent newIntent = new Intent(intent); - newIntent.setClass(context, CalculatorOnscreenService.class); + newIntent.setClass(context, FloatingCalculatorService.class); context.startService(newIntent); } } diff --git a/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenService.java b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorService.java similarity index 86% rename from app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenService.java rename to app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorService.java index 9c6f2fe2..97352e94 100644 --- a/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenService.java +++ b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorService.java @@ -20,7 +20,9 @@ * Site: http://se.solovyev.org */ -package org.solovyev.android.calculator.onscreen; +package org.solovyev.android.calculator.floating; + +import static org.solovyev.android.calculator.App.cast; import android.app.NotificationManager; import android.app.PendingIntent; @@ -32,26 +34,29 @@ import android.os.IBinder; import android.support.v4.app.NotificationCompat; import android.util.DisplayMetrics; import android.view.WindowManager; + import com.squareup.otto.Bus; import com.squareup.otto.Subscribe; + import org.solovyev.android.Check; import org.solovyev.android.Views; -import org.solovyev.android.calculator.*; +import org.solovyev.android.calculator.App; +import org.solovyev.android.calculator.Display; +import org.solovyev.android.calculator.Editor; +import org.solovyev.android.calculator.Preferences; +import org.solovyev.android.calculator.R; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.inject.Inject; -import static org.solovyev.android.calculator.App.cast; +public class FloatingCalculatorService extends Service implements FloatingViewListener, SharedPreferences.OnSharedPreferenceChangeListener { -public class CalculatorOnscreenService extends Service implements OnscreenViewListener, SharedPreferences.OnSharedPreferenceChangeListener { - - public static final Class INTENT_LISTENER_CLASS = CalculatorOnscreenBroadcastReceiver.class; private static final String SHOW_WINDOW_ACTION = "org.solovyev.android.calculator.onscreen.SHOW_WINDOW"; private static final String SHOW_NOTIFICATION_ACTION = "org.solovyev.android.calculator.onscreen.SHOW_NOTIFICATION"; private static final int NOTIFICATION_ID = 9031988; // my birthday =) - private CalculatorOnscreenView view; + private FloatingCalculatorView view; @Inject Bus bus; @@ -62,26 +67,20 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi @Inject SharedPreferences preferences; - @Nonnull - private static Class getIntentListenerClass() { - return INTENT_LISTENER_CLASS; - } - public static void showNotification(@Nonnull Context context) { final Intent intent = new Intent(SHOW_NOTIFICATION_ACTION); - intent.setClass(context, getIntentListenerClass()); + intent.setClass(context, FloatingCalculatorBroadcastReceiver.class); context.sendBroadcast(intent); } - public static void showOnscreenView(@Nonnull Context context) { - final Intent intent = createShowWindowIntent(context); - context.sendBroadcast(intent); + public static void show(@Nonnull Context context) { + context.sendBroadcast(createShowWindowIntent(context)); } @Nonnull private static Intent createShowWindowIntent(@Nonnull Context context) { final Intent intent = new Intent(SHOW_WINDOW_ACTION); - intent.setClass(context, getIntentListenerClass()); + intent.setClass(context, FloatingCalculatorBroadcastReceiver.class); return intent; } @@ -111,7 +110,9 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi final int width = Math.min(width0, height0); final int height = Math.max(width0, height0); - view = CalculatorOnscreenView.create(this, CalculatorOnscreenViewState.create(width, height, -1, -1), this, preferences); + view = FloatingCalculatorView + .create(this, FloatingCalculatorViewState.create(width, height, -1, -1), this, + preferences); view.show(); view.updateEditorState(editor.getState()); view.updateDisplayState(display.getState()); @@ -196,7 +197,7 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi builder.setContentIntent(PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)); final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - nm.notify(NOTIFICATION_ID, builder.getNotification()); + nm.notify(NOTIFICATION_ID, builder.build()); } @Override @@ -204,7 +205,7 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi Check.isNotNull(view); if (Preferences.Gui.theme.isSameKey(key) || Preferences.Onscreen.theme.isSameKey(key)) { stopSelf(); - CalculatorOnscreenService.showOnscreenView(this); + FloatingCalculatorService.show(this); } } diff --git a/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenView.java b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorView.java similarity index 85% rename from app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenView.java rename to app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorView.java index 1973a261..5ea48042 100644 --- a/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenView.java +++ b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorView.java @@ -20,7 +20,13 @@ * Site: http://se.solovyev.org */ -package org.solovyev.android.calculator.onscreen; +package org.solovyev.android.calculator.floating; + +import static android.view.HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING; +import static android.view.HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING; +import static android.view.HapticFeedbackConstants.KEYBOARD_TAP; +import static android.view.HapticFeedbackConstants.LONG_PRESS; +import static org.solovyev.android.calculator.App.cast; import android.content.Context; import android.content.SharedPreferences; @@ -31,24 +37,34 @@ import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.util.DisplayMetrics; import android.util.Log; -import android.view.*; +import android.view.Gravity; +import android.view.MotionEvent; +import android.view.View; +import android.view.WindowManager; import android.widget.ImageView; -import org.solovyev.android.calculator.*; + +import org.solovyev.android.calculator.DisplayState; +import org.solovyev.android.calculator.DisplayView; +import org.solovyev.android.calculator.Editor; +import org.solovyev.android.calculator.EditorState; +import org.solovyev.android.calculator.EditorView; +import org.solovyev.android.calculator.Keyboard; +import org.solovyev.android.calculator.Preferences; +import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.buttons.CppButton; import org.solovyev.android.prefs.Preference; +import java.util.Locale; + import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.inject.Inject; -import java.util.Locale; -import static android.view.HapticFeedbackConstants.*; -import static org.solovyev.android.calculator.App.cast; +public class FloatingCalculatorView { + private static final String TAG = FloatingCalculatorView.class.getSimpleName(); -public class CalculatorOnscreenView { - private static final String TAG = CalculatorOnscreenView.class.getSimpleName(); - - private static final Preference viewStatePreference = new CalculatorOnscreenViewState.Preference("onscreen_view_state", CalculatorOnscreenViewState.createDefault()); + private static final Preference viewStatePreference = new FloatingCalculatorViewState.Preference("onscreen_view_state", FloatingCalculatorViewState + .createDefault()); private View root; private View content; @@ -59,9 +75,9 @@ public class CalculatorOnscreenView { private DisplayView displayView; private Context context; @Nonnull - private CalculatorOnscreenViewState state = CalculatorOnscreenViewState.createDefault(); + private FloatingCalculatorViewState state = FloatingCalculatorViewState.createDefault(); @Nullable - private OnscreenViewListener viewListener; + private FloatingViewListener viewListener; @Inject Keyboard keyboard; @Inject @@ -74,14 +90,14 @@ public class CalculatorOnscreenView { private boolean shown; - private CalculatorOnscreenView() { + private FloatingCalculatorView() { } - public static CalculatorOnscreenView create(@Nonnull Context context, - @Nonnull CalculatorOnscreenViewState state, - @Nullable OnscreenViewListener viewListener, + public static FloatingCalculatorView create(@Nonnull Context context, + @Nonnull FloatingCalculatorViewState state, + @Nullable FloatingViewListener viewListener, @NonNull SharedPreferences preferences) { - final CalculatorOnscreenView view = new CalculatorOnscreenView(); + final FloatingCalculatorView view = new FloatingCalculatorView(); cast(context).getComponent().inject(view); final Preferences.SimpleTheme theme = Preferences.Onscreen.theme.getPreferenceNoError(preferences); final Preferences.Gui.Theme appTheme = Preferences.Gui.theme.getPreferenceNoError(preferences); @@ -89,7 +105,7 @@ public class CalculatorOnscreenView { view.context = context; view.viewListener = viewListener; - final CalculatorOnscreenViewState persistedState = readState(context); + final FloatingCalculatorViewState persistedState = readState(context); if (persistedState != null) { view.state = persistedState; } else { @@ -99,13 +115,14 @@ public class CalculatorOnscreenView { return view; } - public static void persistState(@Nonnull Context context, @Nonnull CalculatorOnscreenViewState state) { + public static void persistState(@Nonnull Context context, @Nonnull + FloatingCalculatorViewState state) { final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); viewStatePreference.putPreference(preferences, state); } @Nullable - public static CalculatorOnscreenViewState readState(@Nonnull Context context) { + public static FloatingCalculatorViewState readState(@Nonnull Context context) { final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); if (viewStatePreference.isSet(preferences)) { return viewStatePreference.getPreference(preferences); @@ -318,45 +335,22 @@ public class CalculatorOnscreenView { } @Nonnull - public CalculatorOnscreenViewState getCurrentState(boolean useRealSize) { + public FloatingCalculatorViewState getCurrentState(boolean useRealSize) { final WindowManager.LayoutParams params = (WindowManager.LayoutParams) root.getLayoutParams(); if (useRealSize) { - return CalculatorOnscreenViewState.create(params.width, params.height, params.x, params.y); + return FloatingCalculatorViewState + .create(params.width, params.height, params.x, params.y); } else { - return CalculatorOnscreenViewState.create(state.getWidth(), state.getHeight(), params.x, params.y); + return FloatingCalculatorViewState + .create(state.getWidth(), state.getHeight(), params.x, params.y); } } - /* - ********************************************************************** - * - * STATIC - * - ********************************************************************** - */ - private static class WindowDragTouchListener implements View.OnTouchListener { - - /* - ********************************************************************** - * - * CONSTANTS - * - ********************************************************************** - */ - private static final float DIST_EPS = 0f; private static final float DIST_MAX = 100000f; private static final long TIME_EPS = 0L; - /* - ********************************************************************** - * - * FIELDS - * - ********************************************************************** - */ - @Nonnull private final WindowManager wm; @Nonnull @@ -366,17 +360,8 @@ public class CalculatorOnscreenView { private float y0; private long time = 0; private int displayWidth; - private int displayHeight; - /* - ********************************************************************** - * - * CONSTRUCTORS - * - ********************************************************************** - */ - public WindowDragTouchListener(@Nonnull WindowManager wm, @Nonnull View view) { this.wm = wm; diff --git a/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenViewState.java b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorViewState.java similarity index 74% rename from app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenViewState.java rename to app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorViewState.java index 01d9e25a..38e8f1cc 100644 --- a/app/src/main/java/org/solovyev/android/calculator/onscreen/CalculatorOnscreenViewState.java +++ b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorViewState.java @@ -20,44 +20,46 @@ * Site: http://se.solovyev.org */ -package org.solovyev.android.calculator.onscreen; +package org.solovyev.android.calculator.floating; import android.content.SharedPreferences; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; + import org.json.JSONException; import org.json.JSONObject; import org.solovyev.android.prefs.AbstractPreference; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; -public class CalculatorOnscreenViewState implements Parcelable { +import javax.annotation.Nonnull; +import javax.annotation.Nullable; - private static final String TAG = CalculatorOnscreenViewState.class.getSimpleName(); +public class FloatingCalculatorViewState implements Parcelable { + + private static final String TAG = FloatingCalculatorViewState.class.getSimpleName(); private int width; private int height; private int x; private int y; - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public CalculatorOnscreenViewState createFromParcel(@Nonnull Parcel in) { - return CalculatorOnscreenViewState.fromParcel(in); + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public FloatingCalculatorViewState createFromParcel(@Nonnull Parcel in) { + return FloatingCalculatorViewState.fromParcel(in); } - public CalculatorOnscreenViewState[] newArray(int size) { - return new CalculatorOnscreenViewState[size]; + public FloatingCalculatorViewState[] newArray(int size) { + return new FloatingCalculatorViewState[size]; } }; - private CalculatorOnscreenViewState() { + private FloatingCalculatorViewState() { } @Nonnull - private static CalculatorOnscreenViewState fromParcel(@Nonnull Parcel in) { - final CalculatorOnscreenViewState result = new CalculatorOnscreenViewState(); + private static FloatingCalculatorViewState fromParcel(@Nonnull Parcel in) { + final FloatingCalculatorViewState result = new FloatingCalculatorViewState(); result.width = in.readInt(); result.height = in.readInt(); result.x = in.readInt(); @@ -66,13 +68,13 @@ public class CalculatorOnscreenViewState implements Parcelable { } @Nonnull - public static CalculatorOnscreenViewState createDefault() { + public static FloatingCalculatorViewState createDefault() { return create(200, 400, 0, 0); } @Nonnull - public static CalculatorOnscreenViewState create(int width, int height, int x, int y) { - final CalculatorOnscreenViewState result = new CalculatorOnscreenViewState(); + public static FloatingCalculatorViewState create(int width, int height, int x, int y) { + final FloatingCalculatorViewState result = new FloatingCalculatorViewState(); result.width = width; result.height = height; result.x = x; @@ -135,17 +137,17 @@ public class CalculatorOnscreenViewState implements Parcelable { '}'; } - public static class Preference extends AbstractPreference { + public static class Preference extends AbstractPreference { - public Preference(@Nonnull String key, @Nullable CalculatorOnscreenViewState defaultValue) { + public Preference(@Nonnull String key, @Nullable FloatingCalculatorViewState defaultValue) { super(key, defaultValue); } @Nullable @Override - protected CalculatorOnscreenViewState getPersistedValue(@Nonnull SharedPreferences preferences) { + protected FloatingCalculatorViewState getPersistedValue(@Nonnull SharedPreferences preferences) { try { - final CalculatorOnscreenViewState result = new CalculatorOnscreenViewState(); + final FloatingCalculatorViewState result = new FloatingCalculatorViewState(); final JSONObject jsonObject = new JSONObject(preferences.getString(getKey(), "{}")); result.width = jsonObject.getInt("width"); result.height = jsonObject.getInt("height"); @@ -161,7 +163,8 @@ public class CalculatorOnscreenViewState implements Parcelable { } @Override - protected void putPersistedValue(@Nonnull SharedPreferences.Editor editor, @Nonnull CalculatorOnscreenViewState value) { + protected void putPersistedValue(@Nonnull SharedPreferences.Editor editor, @Nonnull + FloatingCalculatorViewState value) { final Map properties = new HashMap(); properties.put("width", value.getWidth()); properties.put("height", value.getHeight()); diff --git a/app/src/main/java/org/solovyev/android/calculator/onscreen/OnscreenViewListener.java b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingViewListener.java similarity index 86% rename from app/src/main/java/org/solovyev/android/calculator/onscreen/OnscreenViewListener.java rename to app/src/main/java/org/solovyev/android/calculator/floating/FloatingViewListener.java index 511a207f..a704aaea 100644 --- a/app/src/main/java/org/solovyev/android/calculator/onscreen/OnscreenViewListener.java +++ b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingViewListener.java @@ -20,14 +20,9 @@ * Site: http://se.solovyev.org */ -package org.solovyev.android.calculator.onscreen; +package org.solovyev.android.calculator.floating; -/** - * User: serso - * Date: 11/21/12 - * Time: 9:45 PM - */ -public interface OnscreenViewListener { +public interface FloatingViewListener { // view minimized == view is in the action bar void onViewMinimized();