message for remove onscreen icon

This commit is contained in:
Sergey Solovyev 2012-12-03 13:25:43 +04:00
parent e35b447924
commit 061a559778
8 changed files with 75 additions and 9 deletions

View File

@ -279,4 +279,7 @@
<string name="prefs_onscreen_show_app_icon_title">Show separate icon (require reboot)</string>
<string name="prefs_onscreen_show_app_icon_summary">If turned on second icon will be shown in applications\' list</string>
<string name="cpp_onscreen_remove_icon_message">You can remove second icon in applications\' list from application settings or by pressing next button</string>
<string name="cpp_onscreen_remove_icon_button_text">Remove icon</string>
</resources>

View File

@ -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;

View File

@ -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));
}

View File

@ -31,7 +31,8 @@ public final class CalculatorPreferences {
public static class OnscreenCalculator {
public static final Preference<Boolean> startOnBoot = new BooleanPreference("onscreen_start_on_boot", false);
public static final Preference<Boolean> showAppIcon = new BooleanPreference("onscreen_show_app_icon", true);
}
public static final Preference<Boolean> removeIconDialogShown = new BooleanPreference("onscreen_remove_icon_dialog_shown", false);
}
public static class Calculations {

View File

@ -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<Boolean> 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);
}
}
}

View File

@ -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;
}
}

View File

@ -53,4 +53,10 @@ public enum CalculatorFixableError implements FixableError {
return null;
}
@Nullable
@Override
public CharSequence getFixCaption() {
return null;
}
}

View File

@ -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();
}