onscreen->floating
This commit is contained in:
parent
3cd6d294d7
commit
8c897ba441
@ -119,7 +119,7 @@
|
|||||||
<!-- ONSCREEN CONFIG -->
|
<!-- ONSCREEN CONFIG -->
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".onscreen.CalculatorOnscreenStartActivity"
|
android:name=".floating.FloatingCalculatorActivity"
|
||||||
android:icon="@drawable/ic_launcher_window"
|
android:icon="@drawable/ic_launcher_window"
|
||||||
android:label="@string/c_app_name_on_screen"
|
android:label="@string/c_app_name_on_screen"
|
||||||
android:launchMode="singleInstance"
|
android:launchMode="singleInstance"
|
||||||
@ -133,7 +133,7 @@
|
|||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".onscreen.CalculatorOnscreenService"
|
android:name=".floating.FloatingCalculatorService"
|
||||||
android:exported="false">
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="org.solovyev.android.calculator.onscreen.SHOW_WINDOW" />
|
<action android:name="org.solovyev.android.calculator.onscreen.SHOW_WINDOW" />
|
||||||
@ -141,7 +141,7 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<receiver android:name=".onscreen.CalculatorOnscreenBroadcastReceiver">
|
<receiver android:name=".floating.FloatingCalculatorBroadcastReceiver">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
<action android:name="org.solovyev.android.calculator.onscreen.SHOW_WINDOW" />
|
<action android:name="org.solovyev.android.calculator.onscreen.SHOW_WINDOW" />
|
||||||
|
@ -45,7 +45,7 @@ import org.solovyev.android.Check;
|
|||||||
import org.solovyev.android.Views;
|
import org.solovyev.android.Views;
|
||||||
import org.solovyev.android.calculator.ga.Ga;
|
import org.solovyev.android.calculator.ga.Ga;
|
||||||
import org.solovyev.android.calculator.language.Languages;
|
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.view.ScreenMetrics;
|
||||||
import org.solovyev.android.calculator.wizard.CalculatorWizards;
|
import org.solovyev.android.calculator.wizard.CalculatorWizards;
|
||||||
import org.solovyev.android.wizard.Wizards;
|
import org.solovyev.android.wizard.Wizards;
|
||||||
@ -171,7 +171,7 @@ public final class App {
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static Preferences.Gui.Theme getThemeFor(@Nonnull Context context) {
|
public static Preferences.Gui.Theme getThemeFor(@Nonnull Context context) {
|
||||||
if (context instanceof CalculatorOnscreenService) {
|
if (context instanceof FloatingCalculatorService) {
|
||||||
final SharedPreferences p = getPreferences();
|
final SharedPreferences p = getPreferences();
|
||||||
final Preferences.SimpleTheme onscreenTheme = Preferences.Onscreen.getTheme(p);
|
final Preferences.SimpleTheme onscreenTheme = Preferences.Onscreen.getTheme(p);
|
||||||
final Preferences.Gui.Theme appTheme = Preferences.Gui.getTheme(p);
|
final Preferences.Gui.Theme appTheme = Preferences.Gui.getTheme(p);
|
||||||
|
@ -3,13 +3,13 @@ package org.solovyev.android.calculator;
|
|||||||
import org.solovyev.android.calculator.converter.ConverterFragment;
|
import org.solovyev.android.calculator.converter.ConverterFragment;
|
||||||
import org.solovyev.android.calculator.errors.FixableErrorFragment;
|
import org.solovyev.android.calculator.errors.FixableErrorFragment;
|
||||||
import org.solovyev.android.calculator.errors.FixableErrorsActivity;
|
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.EditFunctionFragment;
|
||||||
import org.solovyev.android.calculator.functions.FunctionsFragment;
|
import org.solovyev.android.calculator.functions.FunctionsFragment;
|
||||||
import org.solovyev.android.calculator.history.BaseHistoryFragment;
|
import org.solovyev.android.calculator.history.BaseHistoryFragment;
|
||||||
import org.solovyev.android.calculator.history.EditHistoryFragment;
|
import org.solovyev.android.calculator.history.EditHistoryFragment;
|
||||||
import org.solovyev.android.calculator.keyboard.BaseKeyboardUi;
|
import org.solovyev.android.calculator.keyboard.BaseKeyboardUi;
|
||||||
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService;
|
import org.solovyev.android.calculator.floating.FloatingCalculatorView;
|
||||||
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenView;
|
|
||||||
import org.solovyev.android.calculator.operators.OperatorsFragment;
|
import org.solovyev.android.calculator.operators.OperatorsFragment;
|
||||||
import org.solovyev.android.calculator.preferences.PreferencesActivity;
|
import org.solovyev.android.calculator.preferences.PreferencesActivity;
|
||||||
import org.solovyev.android.calculator.preferences.PurchaseDialogActivity;
|
import org.solovyev.android.calculator.preferences.PurchaseDialogActivity;
|
||||||
@ -28,7 +28,7 @@ public interface AppComponent {
|
|||||||
void inject(EditorFragment fragment);
|
void inject(EditorFragment fragment);
|
||||||
void inject(BaseUi ui);
|
void inject(BaseUi ui);
|
||||||
void inject(FragmentUi ui);
|
void inject(FragmentUi ui);
|
||||||
void inject(CalculatorOnscreenService service);
|
void inject(FloatingCalculatorService service);
|
||||||
void inject(BaseHistoryFragment fragment);
|
void inject(BaseHistoryFragment fragment);
|
||||||
void inject(BaseDialogFragment fragment);
|
void inject(BaseDialogFragment fragment);
|
||||||
void inject(FixableErrorFragment fragment);
|
void inject(FixableErrorFragment fragment);
|
||||||
@ -47,6 +47,6 @@ public interface AppComponent {
|
|||||||
void inject(PurchaseDialogActivity activity);
|
void inject(PurchaseDialogActivity activity);
|
||||||
void inject(PreferencesActivity activity);
|
void inject(PreferencesActivity activity);
|
||||||
void inject(BaseKeyboardUi ui);
|
void inject(BaseKeyboardUi ui);
|
||||||
void inject(CalculatorOnscreenView view);
|
void inject(FloatingCalculatorView view);
|
||||||
void inject(DragButtonWizardStep fragment);
|
void inject(DragButtonWizardStep fragment);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ import org.solovyev.android.Android;
|
|||||||
import org.solovyev.android.calculator.history.History;
|
import org.solovyev.android.calculator.history.History;
|
||||||
import org.solovyev.android.calculator.language.Language;
|
import org.solovyev.android.calculator.language.Language;
|
||||||
import org.solovyev.android.calculator.language.Languages;
|
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.AndroidCalculatorPlotter;
|
||||||
import org.solovyev.android.calculator.plot.CalculatorPlotterImpl;
|
import org.solovyev.android.calculator.plot.CalculatorPlotterImpl;
|
||||||
import org.solovyev.common.msg.MessageType;
|
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) {
|
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||||
if (Preferences.Onscreen.showAppIcon.getKey().equals(key)) {
|
if (Preferences.Onscreen.showAppIcon.getKey().equals(key)) {
|
||||||
boolean showAppIcon = Preferences.Onscreen.showAppIcon.getPreference(prefs);
|
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);
|
notifier.showMessage(R.string.cpp_this_change_may_require_reboot, MessageType.info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import android.text.TextWatcher;
|
|||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import org.solovyev.android.Check;
|
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 org.solovyev.android.calculator.view.EditTextCompat;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -84,7 +84,7 @@ public class EditorView extends EditTextCompat {
|
|||||||
Check.isMainThread();
|
Check.isMainThread();
|
||||||
// we don't want to be notified about changes we make ourselves
|
// we don't want to be notified about changes we make ourselves
|
||||||
reportChanges = false;
|
reportChanges = false;
|
||||||
if (App.getTheme().light && getContext() instanceof CalculatorOnscreenService) {
|
if (App.getTheme().light && getContext() instanceof FloatingCalculatorService) {
|
||||||
// don't need formatting
|
// don't need formatting
|
||||||
setText(state.getTextString());
|
setText(state.getTextString());
|
||||||
} else {
|
} else {
|
||||||
|
@ -20,18 +20,18 @@
|
|||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.onscreen;
|
package org.solovyev.android.calculator.floating;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
public class CalculatorOnscreenStartActivity extends Activity {
|
public class FloatingCalculatorActivity extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
CalculatorOnscreenService.showOnscreenView(this);
|
FloatingCalculatorService.show(this);
|
||||||
|
|
||||||
this.finish();
|
this.finish();
|
||||||
}
|
}
|
@ -20,7 +20,7 @@
|
|||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.onscreen;
|
package org.solovyev.android.calculator.floating;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -33,14 +33,9 @@ import org.solovyev.android.calculator.Preferences;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
public final class FloatingCalculatorBroadcastReceiver extends BroadcastReceiver {
|
||||||
* User: serso
|
|
||||||
* Date: 11/20/12
|
|
||||||
* Time: 11:05 PM
|
|
||||||
*/
|
|
||||||
public final class CalculatorOnscreenBroadcastReceiver extends BroadcastReceiver {
|
|
||||||
|
|
||||||
public CalculatorOnscreenBroadcastReceiver() {
|
public FloatingCalculatorBroadcastReceiver() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -49,12 +44,12 @@ public final class CalculatorOnscreenBroadcastReceiver extends BroadcastReceiver
|
|||||||
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
if (Preferences.Onscreen.startOnBoot.getPreferenceNoError(preferences)) {
|
if (Preferences.Onscreen.startOnBoot.getPreferenceNoError(preferences)) {
|
||||||
CalculatorOnscreenService.showNotification(context);
|
FloatingCalculatorService.showNotification(context);
|
||||||
App.getGa().onBootStart();
|
App.getGa().onBootStart();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final Intent newIntent = new Intent(intent);
|
final Intent newIntent = new Intent(intent);
|
||||||
newIntent.setClass(context, CalculatorOnscreenService.class);
|
newIntent.setClass(context, FloatingCalculatorService.class);
|
||||||
context.startService(newIntent);
|
context.startService(newIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,7 +20,9 @@
|
|||||||
* Site: http://se.solovyev.org
|
* 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.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
@ -32,26 +34,29 @@ import android.os.IBinder;
|
|||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import org.solovyev.android.Check;
|
import org.solovyev.android.Check;
|
||||||
import org.solovyev.android.Views;
|
import org.solovyev.android.Views;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.App;
|
||||||
|
import org.solovyev.android.calculator.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.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
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<CalculatorOnscreenBroadcastReceiver> INTENT_LISTENER_CLASS = CalculatorOnscreenBroadcastReceiver.class;
|
|
||||||
private static final String SHOW_WINDOW_ACTION = "org.solovyev.android.calculator.onscreen.SHOW_WINDOW";
|
private static final String SHOW_WINDOW_ACTION = "org.solovyev.android.calculator.onscreen.SHOW_WINDOW";
|
||||||
private static final String SHOW_NOTIFICATION_ACTION = "org.solovyev.android.calculator.onscreen.SHOW_NOTIFICATION";
|
private static final String SHOW_NOTIFICATION_ACTION = "org.solovyev.android.calculator.onscreen.SHOW_NOTIFICATION";
|
||||||
private static final int NOTIFICATION_ID = 9031988; // my birthday =)
|
private static final int NOTIFICATION_ID = 9031988; // my birthday =)
|
||||||
|
|
||||||
private CalculatorOnscreenView view;
|
private FloatingCalculatorView view;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Bus bus;
|
Bus bus;
|
||||||
@ -62,26 +67,20 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi
|
|||||||
@Inject
|
@Inject
|
||||||
SharedPreferences preferences;
|
SharedPreferences preferences;
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
private static Class<?> getIntentListenerClass() {
|
|
||||||
return INTENT_LISTENER_CLASS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showNotification(@Nonnull Context context) {
|
public static void showNotification(@Nonnull Context context) {
|
||||||
final Intent intent = new Intent(SHOW_NOTIFICATION_ACTION);
|
final Intent intent = new Intent(SHOW_NOTIFICATION_ACTION);
|
||||||
intent.setClass(context, getIntentListenerClass());
|
intent.setClass(context, FloatingCalculatorBroadcastReceiver.class);
|
||||||
context.sendBroadcast(intent);
|
context.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showOnscreenView(@Nonnull Context context) {
|
public static void show(@Nonnull Context context) {
|
||||||
final Intent intent = createShowWindowIntent(context);
|
context.sendBroadcast(createShowWindowIntent(context));
|
||||||
context.sendBroadcast(intent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static Intent createShowWindowIntent(@Nonnull Context context) {
|
private static Intent createShowWindowIntent(@Nonnull Context context) {
|
||||||
final Intent intent = new Intent(SHOW_WINDOW_ACTION);
|
final Intent intent = new Intent(SHOW_WINDOW_ACTION);
|
||||||
intent.setClass(context, getIntentListenerClass());
|
intent.setClass(context, FloatingCalculatorBroadcastReceiver.class);
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +110,9 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi
|
|||||||
final int width = Math.min(width0, height0);
|
final int width = Math.min(width0, height0);
|
||||||
final int height = Math.max(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.show();
|
||||||
view.updateEditorState(editor.getState());
|
view.updateEditorState(editor.getState());
|
||||||
view.updateDisplayState(display.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));
|
builder.setContentIntent(PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
|
||||||
|
|
||||||
final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
nm.notify(NOTIFICATION_ID, builder.getNotification());
|
nm.notify(NOTIFICATION_ID, builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -204,7 +205,7 @@ public class CalculatorOnscreenService extends Service implements OnscreenViewLi
|
|||||||
Check.isNotNull(view);
|
Check.isNotNull(view);
|
||||||
if (Preferences.Gui.theme.isSameKey(key) || Preferences.Onscreen.theme.isSameKey(key)) {
|
if (Preferences.Gui.theme.isSameKey(key) || Preferences.Onscreen.theme.isSameKey(key)) {
|
||||||
stopSelf();
|
stopSelf();
|
||||||
CalculatorOnscreenService.showOnscreenView(this);
|
FloatingCalculatorService.show(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,7 +20,13 @@
|
|||||||
* Site: http://se.solovyev.org
|
* 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.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
@ -31,24 +37,34 @@ import android.preference.PreferenceManager;
|
|||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
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 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.calculator.buttons.CppButton;
|
||||||
import org.solovyev.android.prefs.Preference;
|
import org.solovyev.android.prefs.Preference;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import static android.view.HapticFeedbackConstants.*;
|
public class FloatingCalculatorView {
|
||||||
import static org.solovyev.android.calculator.App.cast;
|
private static final String TAG = FloatingCalculatorView.class.getSimpleName();
|
||||||
|
|
||||||
public class CalculatorOnscreenView {
|
private static final Preference<FloatingCalculatorViewState> viewStatePreference = new FloatingCalculatorViewState.Preference("onscreen_view_state", FloatingCalculatorViewState
|
||||||
private static final String TAG = CalculatorOnscreenView.class.getSimpleName();
|
.createDefault());
|
||||||
|
|
||||||
private static final Preference<CalculatorOnscreenViewState> viewStatePreference = new CalculatorOnscreenViewState.Preference("onscreen_view_state", CalculatorOnscreenViewState.createDefault());
|
|
||||||
|
|
||||||
private View root;
|
private View root;
|
||||||
private View content;
|
private View content;
|
||||||
@ -59,9 +75,9 @@ public class CalculatorOnscreenView {
|
|||||||
private DisplayView displayView;
|
private DisplayView displayView;
|
||||||
private Context context;
|
private Context context;
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private CalculatorOnscreenViewState state = CalculatorOnscreenViewState.createDefault();
|
private FloatingCalculatorViewState state = FloatingCalculatorViewState.createDefault();
|
||||||
@Nullable
|
@Nullable
|
||||||
private OnscreenViewListener viewListener;
|
private FloatingViewListener viewListener;
|
||||||
@Inject
|
@Inject
|
||||||
Keyboard keyboard;
|
Keyboard keyboard;
|
||||||
@Inject
|
@Inject
|
||||||
@ -74,14 +90,14 @@ public class CalculatorOnscreenView {
|
|||||||
private boolean shown;
|
private boolean shown;
|
||||||
|
|
||||||
|
|
||||||
private CalculatorOnscreenView() {
|
private FloatingCalculatorView() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CalculatorOnscreenView create(@Nonnull Context context,
|
public static FloatingCalculatorView create(@Nonnull Context context,
|
||||||
@Nonnull CalculatorOnscreenViewState state,
|
@Nonnull FloatingCalculatorViewState state,
|
||||||
@Nullable OnscreenViewListener viewListener,
|
@Nullable FloatingViewListener viewListener,
|
||||||
@NonNull SharedPreferences preferences) {
|
@NonNull SharedPreferences preferences) {
|
||||||
final CalculatorOnscreenView view = new CalculatorOnscreenView();
|
final FloatingCalculatorView view = new FloatingCalculatorView();
|
||||||
cast(context).getComponent().inject(view);
|
cast(context).getComponent().inject(view);
|
||||||
final Preferences.SimpleTheme theme = Preferences.Onscreen.theme.getPreferenceNoError(preferences);
|
final Preferences.SimpleTheme theme = Preferences.Onscreen.theme.getPreferenceNoError(preferences);
|
||||||
final Preferences.Gui.Theme appTheme = Preferences.Gui.theme.getPreferenceNoError(preferences);
|
final Preferences.Gui.Theme appTheme = Preferences.Gui.theme.getPreferenceNoError(preferences);
|
||||||
@ -89,7 +105,7 @@ public class CalculatorOnscreenView {
|
|||||||
view.context = context;
|
view.context = context;
|
||||||
view.viewListener = viewListener;
|
view.viewListener = viewListener;
|
||||||
|
|
||||||
final CalculatorOnscreenViewState persistedState = readState(context);
|
final FloatingCalculatorViewState persistedState = readState(context);
|
||||||
if (persistedState != null) {
|
if (persistedState != null) {
|
||||||
view.state = persistedState;
|
view.state = persistedState;
|
||||||
} else {
|
} else {
|
||||||
@ -99,13 +115,14 @@ public class CalculatorOnscreenView {
|
|||||||
return view;
|
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);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
viewStatePreference.putPreference(preferences, state);
|
viewStatePreference.putPreference(preferences, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static CalculatorOnscreenViewState readState(@Nonnull Context context) {
|
public static FloatingCalculatorViewState readState(@Nonnull Context context) {
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
if (viewStatePreference.isSet(preferences)) {
|
if (viewStatePreference.isSet(preferences)) {
|
||||||
return viewStatePreference.getPreference(preferences);
|
return viewStatePreference.getPreference(preferences);
|
||||||
@ -318,45 +335,22 @@ public class CalculatorOnscreenView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public CalculatorOnscreenViewState getCurrentState(boolean useRealSize) {
|
public FloatingCalculatorViewState getCurrentState(boolean useRealSize) {
|
||||||
final WindowManager.LayoutParams params = (WindowManager.LayoutParams) root.getLayoutParams();
|
final WindowManager.LayoutParams params = (WindowManager.LayoutParams) root.getLayoutParams();
|
||||||
if (useRealSize) {
|
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 {
|
} 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 {
|
private static class WindowDragTouchListener implements View.OnTouchListener {
|
||||||
|
|
||||||
/*
|
|
||||||
**********************************************************************
|
|
||||||
*
|
|
||||||
* CONSTANTS
|
|
||||||
*
|
|
||||||
**********************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
private static final float DIST_EPS = 0f;
|
private static final float DIST_EPS = 0f;
|
||||||
private static final float DIST_MAX = 100000f;
|
private static final float DIST_MAX = 100000f;
|
||||||
private static final long TIME_EPS = 0L;
|
private static final long TIME_EPS = 0L;
|
||||||
|
|
||||||
/*
|
|
||||||
**********************************************************************
|
|
||||||
*
|
|
||||||
* FIELDS
|
|
||||||
*
|
|
||||||
**********************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final WindowManager wm;
|
private final WindowManager wm;
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -366,17 +360,8 @@ public class CalculatorOnscreenView {
|
|||||||
private float y0;
|
private float y0;
|
||||||
private long time = 0;
|
private long time = 0;
|
||||||
private int displayWidth;
|
private int displayWidth;
|
||||||
|
|
||||||
private int displayHeight;
|
private int displayHeight;
|
||||||
|
|
||||||
/*
|
|
||||||
**********************************************************************
|
|
||||||
*
|
|
||||||
* CONSTRUCTORS
|
|
||||||
*
|
|
||||||
**********************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
public WindowDragTouchListener(@Nonnull WindowManager wm,
|
public WindowDragTouchListener(@Nonnull WindowManager wm,
|
||||||
@Nonnull View view) {
|
@Nonnull View view) {
|
||||||
this.wm = wm;
|
this.wm = wm;
|
@ -20,44 +20,46 @@
|
|||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.onscreen;
|
package org.solovyev.android.calculator.floating;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.solovyev.android.prefs.AbstractPreference;
|
import org.solovyev.android.prefs.AbstractPreference;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
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 width;
|
||||||
private int height;
|
private int height;
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
public static final Parcelable.Creator<CalculatorOnscreenViewState> CREATOR = new Parcelable.Creator<CalculatorOnscreenViewState>() {
|
public static final Parcelable.Creator<FloatingCalculatorViewState> CREATOR = new Parcelable.Creator<FloatingCalculatorViewState>() {
|
||||||
public CalculatorOnscreenViewState createFromParcel(@Nonnull Parcel in) {
|
public FloatingCalculatorViewState createFromParcel(@Nonnull Parcel in) {
|
||||||
return CalculatorOnscreenViewState.fromParcel(in);
|
return FloatingCalculatorViewState.fromParcel(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CalculatorOnscreenViewState[] newArray(int size) {
|
public FloatingCalculatorViewState[] newArray(int size) {
|
||||||
return new CalculatorOnscreenViewState[size];
|
return new FloatingCalculatorViewState[size];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private CalculatorOnscreenViewState() {
|
private FloatingCalculatorViewState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static CalculatorOnscreenViewState fromParcel(@Nonnull Parcel in) {
|
private static FloatingCalculatorViewState fromParcel(@Nonnull Parcel in) {
|
||||||
final CalculatorOnscreenViewState result = new CalculatorOnscreenViewState();
|
final FloatingCalculatorViewState result = new FloatingCalculatorViewState();
|
||||||
result.width = in.readInt();
|
result.width = in.readInt();
|
||||||
result.height = in.readInt();
|
result.height = in.readInt();
|
||||||
result.x = in.readInt();
|
result.x = in.readInt();
|
||||||
@ -66,13 +68,13 @@ public class CalculatorOnscreenViewState implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static CalculatorOnscreenViewState createDefault() {
|
public static FloatingCalculatorViewState createDefault() {
|
||||||
return create(200, 400, 0, 0);
|
return create(200, 400, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static CalculatorOnscreenViewState create(int width, int height, int x, int y) {
|
public static FloatingCalculatorViewState create(int width, int height, int x, int y) {
|
||||||
final CalculatorOnscreenViewState result = new CalculatorOnscreenViewState();
|
final FloatingCalculatorViewState result = new FloatingCalculatorViewState();
|
||||||
result.width = width;
|
result.width = width;
|
||||||
result.height = height;
|
result.height = height;
|
||||||
result.x = x;
|
result.x = x;
|
||||||
@ -135,17 +137,17 @@ public class CalculatorOnscreenViewState implements Parcelable {
|
|||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Preference extends AbstractPreference<CalculatorOnscreenViewState> {
|
public static class Preference extends AbstractPreference<FloatingCalculatorViewState> {
|
||||||
|
|
||||||
public Preference(@Nonnull String key, @Nullable CalculatorOnscreenViewState defaultValue) {
|
public Preference(@Nonnull String key, @Nullable FloatingCalculatorViewState defaultValue) {
|
||||||
super(key, defaultValue);
|
super(key, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
protected CalculatorOnscreenViewState getPersistedValue(@Nonnull SharedPreferences preferences) {
|
protected FloatingCalculatorViewState getPersistedValue(@Nonnull SharedPreferences preferences) {
|
||||||
try {
|
try {
|
||||||
final CalculatorOnscreenViewState result = new CalculatorOnscreenViewState();
|
final FloatingCalculatorViewState result = new FloatingCalculatorViewState();
|
||||||
final JSONObject jsonObject = new JSONObject(preferences.getString(getKey(), "{}"));
|
final JSONObject jsonObject = new JSONObject(preferences.getString(getKey(), "{}"));
|
||||||
result.width = jsonObject.getInt("width");
|
result.width = jsonObject.getInt("width");
|
||||||
result.height = jsonObject.getInt("height");
|
result.height = jsonObject.getInt("height");
|
||||||
@ -161,7 +163,8 @@ public class CalculatorOnscreenViewState implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void putPersistedValue(@Nonnull SharedPreferences.Editor editor, @Nonnull CalculatorOnscreenViewState value) {
|
protected void putPersistedValue(@Nonnull SharedPreferences.Editor editor, @Nonnull
|
||||||
|
FloatingCalculatorViewState value) {
|
||||||
final Map<String, Object> properties = new HashMap<String, Object>();
|
final Map<String, Object> properties = new HashMap<String, Object>();
|
||||||
properties.put("width", value.getWidth());
|
properties.put("width", value.getWidth());
|
||||||
properties.put("height", value.getHeight());
|
properties.put("height", value.getHeight());
|
@ -20,14 +20,9 @@
|
|||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.onscreen;
|
package org.solovyev.android.calculator.floating;
|
||||||
|
|
||||||
/**
|
public interface FloatingViewListener {
|
||||||
* User: serso
|
|
||||||
* Date: 11/21/12
|
|
||||||
* Time: 9:45 PM
|
|
||||||
*/
|
|
||||||
public interface OnscreenViewListener {
|
|
||||||
|
|
||||||
// view minimized == view is in the action bar
|
// view minimized == view is in the action bar
|
||||||
void onViewMinimized();
|
void onViewMinimized();
|
Loading…
Reference in New Issue
Block a user