From 51751e7077a8cf00c6c102a969a8b14e5b021a14 Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Sun, 2 Dec 2012 23:26:59 +0400 Subject: [PATCH] Fixable errors --- .../res/layout/calculator_messages_dialog.xml | 0 .../layout/calculator_messages_dialog_message.xml | 0 .../java/org/solovyev/android/AndroidUtils2.java | 8 ++++++++ .../calculator/CalculatorFixableMessage.java | 4 ++-- .../calculator/CalculatorMessagesDialog.java | 3 ++- .../onscreen/CalculatorOnscreenStartActivity.java | 15 +++++++++++++++ .../calculator/CalculatorFixableError.java | 3 +-- .../solovyev/android/calculator/FixableError.java | 13 +++++++++++++ 8 files changed, 41 insertions(+), 5 deletions(-) rename {android-app => android-app-core}/res/layout/calculator_messages_dialog.xml (100%) rename {android-app => android-app-core}/res/layout/calculator_messages_dialog_message.xml (100%) rename {android-app => android-app-core}/src/main/java/org/solovyev/android/AndroidUtils2.java (73%) rename {android-app => android-app-core}/src/main/java/org/solovyev/android/calculator/CalculatorFixableMessage.java (95%) rename {android-app => android-app-core}/src/main/java/org/solovyev/android/calculator/CalculatorMessagesDialog.java (98%) create mode 100644 core/src/main/java/org/solovyev/android/calculator/FixableError.java diff --git a/android-app/res/layout/calculator_messages_dialog.xml b/android-app-core/res/layout/calculator_messages_dialog.xml similarity index 100% rename from android-app/res/layout/calculator_messages_dialog.xml rename to android-app-core/res/layout/calculator_messages_dialog.xml diff --git a/android-app/res/layout/calculator_messages_dialog_message.xml b/android-app-core/res/layout/calculator_messages_dialog_message.xml similarity index 100% rename from android-app/res/layout/calculator_messages_dialog_message.xml rename to android-app-core/res/layout/calculator_messages_dialog_message.xml diff --git a/android-app/src/main/java/org/solovyev/android/AndroidUtils2.java b/android-app-core/src/main/java/org/solovyev/android/AndroidUtils2.java similarity index 73% rename from android-app/src/main/java/org/solovyev/android/AndroidUtils2.java rename to android-app-core/src/main/java/org/solovyev/android/AndroidUtils2.java index ab0a2727..ac8251b6 100644 --- a/android-app/src/main/java/org/solovyev/android/AndroidUtils2.java +++ b/android-app-core/src/main/java/org/solovyev/android/AndroidUtils2.java @@ -47,4 +47,12 @@ public final class AndroidUtils2 { 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; + } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFixableMessage.java b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorFixableMessage.java similarity index 95% rename from android-app/src/main/java/org/solovyev/android/calculator/CalculatorFixableMessage.java rename to android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorFixableMessage.java index 8d6110e7..666f61c3 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFixableMessage.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorFixableMessage.java @@ -42,7 +42,7 @@ public class CalculatorFixableMessage implements Parcelable { private final MessageType messageType; @Nullable - private final CalculatorFixableError fixableError; + private final FixableError fixableError; public CalculatorFixableMessage(@NotNull Message message) { this.message = message.getLocalizedMessage(); @@ -81,7 +81,7 @@ public class CalculatorFixableMessage implements Parcelable { } @Nullable - public CalculatorFixableError getFixableError() { + public FixableError getFixableError() { return fixableError; } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorMessagesDialog.java b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorMessagesDialog.java similarity index 98% rename from android-app/src/main/java/org/solovyev/android/calculator/CalculatorMessagesDialog.java rename to android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorMessagesDialog.java index 23f63413..1a9db3a2 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorMessagesDialog.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorMessagesDialog.java @@ -15,6 +15,7 @@ import android.widget.CheckBox; import android.widget.TextView; import com.actionbarsherlock.app.SherlockActivity; import org.jetbrains.annotations.NotNull; +import org.solovyev.android.calculator.core.R; import org.solovyev.common.msg.Message; import java.util.ArrayList; @@ -85,7 +86,7 @@ public class CalculatorMessagesDialog extends SherlockActivity { calculationMessagesTextView.setText(message.getMessage()); final Button fixButton = (Button) view.findViewById(R.id.fix_button); - final CalculatorFixableError fixableError = message.getFixableError(); + final FixableError fixableError = message.getFixableError(); if (fixableError == null) { fixButton.setVisibility(View.GONE); fixButton.setOnClickListener(null); 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 dbb5e1cf..0c466f79 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 @@ -1,14 +1,29 @@ package org.solovyev.android.calculator.onscreen; import android.app.Activity; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; +import org.solovyev.android.AndroidUtils2; +import org.solovyev.android.prefs.BooleanPreference; +import org.solovyev.android.prefs.Preference; public class CalculatorOnscreenStartActivity extends Activity { + private static final Preference removeIconDialogShown = new BooleanPreference("onscreen_remove_icon_dialog_shown", false); + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if (AndroidUtils2.isComponentEnabled(this, CalculatorOnscreenStartActivity.class)) { + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + if (!removeIconDialogShown.getPreference(prefs)) { + + removeIconDialogShown.putPreference(prefs, true); + } + } + CalculatorOnscreenService.showOnscreenView(this); this.finish(); 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 e9e79db2..a73f2742 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorFixableError.java +++ b/core/src/main/java/org/solovyev/android/calculator/CalculatorFixableError.java @@ -13,7 +13,7 @@ import java.util.List; * Date: 11/17/12 * Time: 7:30 PM */ -public enum CalculatorFixableError { +public enum CalculatorFixableError implements FixableError { must_be_rad(Messages.msg_23, Messages.msg_24, Messages.msg_25) { @Override @@ -53,5 +53,4 @@ public enum CalculatorFixableError { return null; } - public abstract void fix(); } diff --git a/core/src/main/java/org/solovyev/android/calculator/FixableError.java b/core/src/main/java/org/solovyev/android/calculator/FixableError.java new file mode 100644 index 00000000..e5eeaed7 --- /dev/null +++ b/core/src/main/java/org/solovyev/android/calculator/FixableError.java @@ -0,0 +1,13 @@ +package org.solovyev.android.calculator; + +import java.io.Serializable; + +/** + * User: serso + * Date: 12/2/12 + * Time: 10:21 PM + */ +public interface FixableError extends Serializable { + + void fix(); +}