Properly reflect the default value.
The switch should be on if the default state is on. Also, make sure the revert button is accessible if the default value is on. Bug: 240726265 Test: Toggle the switch and then Revert to Defaults with the default value as on Change-Id: I07d1713316281b0590fab7f1581e15d9f5e57969
This commit is contained in:
@@ -27,6 +27,7 @@ import android.net.Uri;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.provider.DeviceConfig;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@@ -66,7 +67,7 @@ public class TareHomePage extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if (mConfigObserver.mEnableTareSetting == SETTING_VALUE_DEFAULT
|
if (mConfigObserver.mEnableTareSetting == SETTING_VALUE_DEFAULT
|
||||||
&& isChecked == (Settings.Global.DEFAULT_ENABLE_TARE == SETTING_VALUE_ON)) {
|
&& isChecked == mConfigObserver.getDefaultEnabledStatus()) {
|
||||||
// Don't bother writing something that's not new information. It would make
|
// Don't bother writing something that's not new information. It would make
|
||||||
// it hard to use DeviceConfig if we did.
|
// it hard to use DeviceConfig if we did.
|
||||||
return;
|
return;
|
||||||
@@ -93,12 +94,19 @@ public class TareHomePage extends Activity {
|
|||||||
/** Reverts the TARE settings to the original default settings */
|
/** Reverts the TARE settings to the original default settings */
|
||||||
public void revertSettings(View v) {
|
public void revertSettings(View v) {
|
||||||
Toast.makeText(this, R.string.tare_settings_reverted_toast, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.tare_settings_reverted_toast, Toast.LENGTH_LONG).show();
|
||||||
|
final boolean wasSettingsDefault =
|
||||||
|
mConfigObserver.mEnableTareSetting == SETTING_VALUE_DEFAULT;
|
||||||
Settings.Global.putString(getApplicationContext().getContentResolver(),
|
Settings.Global.putString(getApplicationContext().getContentResolver(),
|
||||||
Settings.Global.ENABLE_TARE, null);
|
Settings.Global.ENABLE_TARE, null);
|
||||||
Settings.Global.putString(getApplicationContext().getContentResolver(),
|
Settings.Global.putString(getApplicationContext().getContentResolver(),
|
||||||
Settings.Global.TARE_ALARM_MANAGER_CONSTANTS, null);
|
Settings.Global.TARE_ALARM_MANAGER_CONSTANTS, null);
|
||||||
Settings.Global.putString(getApplicationContext().getContentResolver(),
|
Settings.Global.putString(getApplicationContext().getContentResolver(),
|
||||||
Settings.Global.TARE_JOB_SCHEDULER_CONSTANTS, null);
|
Settings.Global.TARE_JOB_SCHEDULER_CONSTANTS, null);
|
||||||
|
if (wasSettingsDefault) {
|
||||||
|
// Only do this manually here to force a DeviceConfig check if the settings value isn't
|
||||||
|
// actually changing.
|
||||||
|
setEnabled(mConfigObserver.getDefaultEnabledStatus());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Opens up the AlarmManager TARE policy page with its factors to view and edit */
|
/** Opens up the AlarmManager TARE policy page with its factors to view and edit */
|
||||||
@@ -117,13 +125,14 @@ public class TareHomePage extends Activity {
|
|||||||
|
|
||||||
/** Changes the enabled state of the TARE homepage buttons based on global toggle */
|
/** Changes the enabled state of the TARE homepage buttons based on global toggle */
|
||||||
private void setEnabled(boolean tareStatus) {
|
private void setEnabled(boolean tareStatus) {
|
||||||
mRevButton.setEnabled(tareStatus);
|
|
||||||
mAlarmManagerView.setEnabled(tareStatus);
|
mAlarmManagerView.setEnabled(tareStatus);
|
||||||
mJobSchedulerView.setEnabled(tareStatus);
|
mJobSchedulerView.setEnabled(tareStatus);
|
||||||
mOnSwitch.setChecked(tareStatus);
|
mOnSwitch.setChecked(tareStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ConfigObserver extends ContentObserver {
|
private class ConfigObserver extends ContentObserver {
|
||||||
|
private static final String KEY_DC_ENABLE_TARE = "enable_tare";
|
||||||
|
|
||||||
private int mEnableTareSetting;
|
private int mEnableTareSetting;
|
||||||
|
|
||||||
ConfigObserver(Handler handler) {
|
ConfigObserver(Handler handler) {
|
||||||
@@ -157,7 +166,21 @@ public class TareHomePage extends Activity {
|
|||||||
mEnableTareSetting = Settings.Global.DEFAULT_ENABLE_TARE;
|
mEnableTareSetting = Settings.Global.DEFAULT_ENABLE_TARE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setEnabled(mEnableTareSetting == SETTING_VALUE_ON);
|
final boolean enabled;
|
||||||
}
|
if (mEnableTareSetting == SETTING_VALUE_ON) {
|
||||||
|
enabled = true;
|
||||||
|
} else if (mEnableTareSetting == SETTING_VALUE_OFF) {
|
||||||
|
enabled = false;
|
||||||
|
} else {
|
||||||
|
enabled = getDefaultEnabledStatus();
|
||||||
|
}
|
||||||
|
setEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean getDefaultEnabledStatus() {
|
||||||
|
return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TARE, KEY_DC_ENABLE_TARE,
|
||||||
|
Settings.Global.DEFAULT_ENABLE_TARE == SETTING_VALUE_ON);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user