diff --git a/android-app-core/res/values/text_strings.xml b/android-app-core/res/values/text_strings.xml index 7ab7b1bb..8ae2894e 100644 --- a/android-app-core/res/values/text_strings.xml +++ b/android-app-core/res/values/text_strings.xml @@ -279,4 +279,7 @@ Show separate icon (require reboot) If turned on second icon will be shown in applications\' list + You can remove second icon in applications\' list from application settings or by pressing next button + Remove icon + \ No newline at end of file diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorFixableMessage.java b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorFixableMessage.java index 666f61c3..9938847b 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorFixableMessage.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorFixableMessage.java @@ -30,7 +30,7 @@ public class CalculatorFixableMessage implements Parcelable { private static CalculatorFixableMessage fromParcel(@NotNull Parcel in) { final String message = in.readString(); final MessageType messageType = (MessageType) in.readSerializable(); - final CalculatorFixableError fixableError = (CalculatorFixableError) in.readSerializable(); + final FixableError fixableError = (FixableError) in.readSerializable(); return new CalculatorFixableMessage(message, messageType, fixableError); } @@ -52,7 +52,7 @@ public class CalculatorFixableMessage implements Parcelable { public CalculatorFixableMessage(@NotNull String message, @NotNull MessageType messageType, - @Nullable CalculatorFixableError fixableError) { + @Nullable FixableError fixableError) { this.message = message; this.messageType = messageType; this.fixableError = fixableError; diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorMessagesDialog.java b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorMessagesDialog.java index 1a9db3a2..14b5a0c8 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorMessagesDialog.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorMessagesDialog.java @@ -17,6 +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 java.util.ArrayList; import java.util.Collections; @@ -93,8 +94,15 @@ public class CalculatorMessagesDialog extends SherlockActivity { } else { fixButton.setVisibility(View.VISIBLE); fixButton.setOnClickListener(new FixErrorOnClickListener(messages, message)); + + final CharSequence fixCaption = fixableError.getFixCaption(); + if (!StringUtils.isEmpty(fixCaption)) { + fixButton.setText(fixCaption); + } } + + viewGroup.addView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } 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 4bf5f8d8..fb44db76 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 @@ -31,7 +31,8 @@ public final class CalculatorPreferences { 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 class Calculations { 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 0c466f79..2f260ce5 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,26 +1,33 @@ package org.solovyev.android.calculator.onscreen; import android.app.Activity; +import android.content.Context; 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.prefs.BooleanPreference; -import org.solovyev.android.prefs.Preference; +import org.solovyev.android.calculator.AbstractFixableError; +import org.solovyev.android.calculator.App; +import org.solovyev.android.calculator.CalculatorFixableMessage; +import org.solovyev.android.calculator.CalculatorMessagesDialog; +import org.solovyev.android.calculator.CalculatorPreferences; +import org.solovyev.common.msg.MessageType; + +import java.util.Arrays; 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); + if (!CalculatorPreferences.OnscreenCalculator.removeIconDialogShown.getPreference(prefs)) { + CalculatorMessagesDialog.showDialog(Arrays.asList(new CalculatorFixableMessage(getString(R.string.cpp_onscreen_remove_icon_message), MessageType.warning, new RemoveIconFixableError(this))), this); + CalculatorPreferences.OnscreenCalculator.removeIconDialogShown.putPreference(prefs, true); } } @@ -28,4 +35,18 @@ public class CalculatorOnscreenStartActivity extends Activity { this.finish(); } + + public static class RemoveIconFixableError extends AbstractFixableError { + + public RemoveIconFixableError(@NotNull Context context) { + super(context.getString(R.string.cpp_onscreen_remove_icon_button_text)); + } + + @Override + public void fix() { + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(App.getInstance().getApplication()); + CalculatorPreferences.OnscreenCalculator.showAppIcon.putPreference(prefs, false); + } + } + } diff --git a/core/src/main/java/org/solovyev/android/calculator/AbstractFixableError.java b/core/src/main/java/org/solovyev/android/calculator/AbstractFixableError.java new file mode 100644 index 00000000..8e21930b --- /dev/null +++ b/core/src/main/java/org/solovyev/android/calculator/AbstractFixableError.java @@ -0,0 +1,22 @@ +package org.solovyev.android.calculator; + +import org.jetbrains.annotations.Nullable; + +public abstract class AbstractFixableError implements FixableError { + + @Nullable + private String fixCaption; + + protected AbstractFixableError() { + } + + protected AbstractFixableError(@Nullable String fixCaption) { + this.fixCaption = fixCaption; + } + + @Nullable + @Override + public CharSequence getFixCaption() { + return fixCaption; + } +} 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 a73f2742..f4775936 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorFixableError.java +++ b/core/src/main/java/org/solovyev/android/calculator/CalculatorFixableError.java @@ -53,4 +53,10 @@ public enum CalculatorFixableError implements FixableError { return null; } + + @Nullable + @Override + public CharSequence getFixCaption() { + return null; + } } diff --git a/core/src/main/java/org/solovyev/android/calculator/FixableError.java b/core/src/main/java/org/solovyev/android/calculator/FixableError.java index e5eeaed7..afeb6176 100644 --- a/core/src/main/java/org/solovyev/android/calculator/FixableError.java +++ b/core/src/main/java/org/solovyev/android/calculator/FixableError.java @@ -1,5 +1,7 @@ package org.solovyev.android.calculator; +import org.jetbrains.annotations.Nullable; + import java.io.Serializable; /** @@ -9,5 +11,8 @@ import java.io.Serializable; */ public interface FixableError extends Serializable { + @Nullable + CharSequence getFixCaption(); + void fix(); }