onscreen calculator improvement
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package org.solovyev.android;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -30,4 +32,19 @@ public final class AndroidUtils2 {
|
||||
intent.setFlags(flags);
|
||||
|
||||
}
|
||||
|
||||
public static void toggleComponent(@NotNull Context context,
|
||||
@NotNull Class<? extends Context> componentClass,
|
||||
boolean enable) {
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
|
||||
final int componentState;
|
||||
if (enable) {
|
||||
componentState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
|
||||
} else {
|
||||
componentState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
|
||||
}
|
||||
|
||||
pm.setComponentEnabledSetting(new ComponentName(context, componentClass), componentState, PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
}
|
||||
|
@@ -12,10 +12,12 @@ import org.acra.ACRA;
|
||||
import org.acra.ReportingInteractionMode;
|
||||
import org.acra.annotation.ReportsCrashes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.AndroidUtils2;
|
||||
import org.solovyev.android.ads.AdsController;
|
||||
import org.solovyev.android.calculator.external.AndroidExternalListenersContainer;
|
||||
import org.solovyev.android.calculator.history.AndroidCalculatorHistory;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenStartActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -33,7 +35,7 @@ import java.util.List;
|
||||
resToastText = R.string.crashed,
|
||||
resDialogTitle = R.string.crash_dialog_title,
|
||||
resDialogText = R.string.crash_dialog_text)
|
||||
public class CalculatorApplication extends android.app.Application {
|
||||
public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
@@ -94,6 +96,8 @@ public class CalculatorApplication extends android.app.Application {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
CalculatorPreferences.setDefaultValues(preferences);
|
||||
|
||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
setTheme(preferences);
|
||||
|
||||
super.onCreate();
|
||||
@@ -198,4 +202,12 @@ public class CalculatorApplication extends android.app.Application {
|
||||
// NOTE: this code is only for monkeyrunner
|
||||
return context.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
if (CalculatorPreferences.OnscreenCalculator.showAppIcon.getKey().equals(key)) {
|
||||
boolean showAppIcon = CalculatorPreferences.OnscreenCalculator.showAppIcon.getPreference(prefs);
|
||||
AndroidUtils2.toggleComponent(this, CalculatorOnscreenStartActivity.class, showAppIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user