Fixable errors

This commit is contained in:
Sergey Solovyev 2012-12-02 23:26:59 +04:00
parent af69271f89
commit 51751e7077
8 changed files with 41 additions and 5 deletions

View File

@ -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<? extends Context> 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;
}
}

View File

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

View File

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

View File

@ -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<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);
}
}
CalculatorOnscreenService.showOnscreenView(this);
this.finish();

View File

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

View File

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