Merge "Add night display pref controllers and change UX" into pi-dev
diff --git a/res/xml/configure_notification_settings.xml b/res/xml/configure_notification_settings.xml
index 612f5e7..291d9a8 100644
--- a/res/xml/configure_notification_settings.xml
+++ b/res/xml/configure_notification_settings.xml
@@ -28,7 +28,8 @@
<!-- Notification badging -->
<SwitchPreference
android:key="notification_badging"
- android:title="@string/notification_badging_title"/>
+ android:title="@string/notification_badging_title"
+ settings:controller="com.android.settings.notification.BadgingNotificationPreferenceController"/>
<!-- Pulse notification light -->
<SwitchPreference
diff --git a/src/com/android/settings/deviceinfo/StorageWizardFormatSlow.java b/src/com/android/settings/deviceinfo/StorageWizardFormatSlow.java
index 37df2170..f1ac1c2 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardFormatSlow.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardFormatSlow.java
@@ -23,7 +23,9 @@
import android.text.TextUtils;
import android.view.View;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
+import com.android.settings.overlay.FeatureFactory;
public class StorageWizardFormatSlow extends StorageWizardBase {
private boolean mFormatPrivate;
@@ -55,6 +57,9 @@
@Override
public void onNavigateBack(View view) {
+ FeatureFactory.getFactory(this).getMetricsFeatureProvider().action(this,
+ MetricsEvent.ACTION_STORAGE_BENCHMARK_SLOW_ABORT);
+
final Intent intent = new Intent(this, StorageWizardInit.class);
startActivity(intent);
finishAffinity();
@@ -62,6 +67,16 @@
@Override
public void onNavigateNext(View view) {
+ if (view != null) {
+ // User made an explicit choice to continue when slow
+ FeatureFactory.getFactory(this).getMetricsFeatureProvider().action(this,
+ MetricsEvent.ACTION_STORAGE_BENCHMARK_SLOW_CONTINUE);
+ } else {
+ // User made an implicit choice to continue when fast
+ FeatureFactory.getFactory(this).getMetricsFeatureProvider().action(this,
+ MetricsEvent.ACTION_STORAGE_BENCHMARK_FAST_CONTINUE);
+ }
+
final String forgetUuid = getIntent().getStringExtra(EXTRA_FORMAT_FORGET_UUID);
if (!TextUtils.isEmpty(forgetUuid)) {
mStorage.forgetVolume(forgetUuid);
diff --git a/src/com/android/settings/deviceinfo/StorageWizardInit.java b/src/com/android/settings/deviceinfo/StorageWizardInit.java
index b271d02..076e606 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardInit.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardInit.java
@@ -25,7 +25,9 @@
import android.view.View;
import android.widget.Button;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
+import com.android.settings.overlay.FeatureFactory;
public class StorageWizardInit extends StorageWizardBase {
private Button mExternal;
@@ -68,6 +70,12 @@
}
public void onNavigateExternal(View view) {
+ if (view != null) {
+ // User made an explicit choice for external
+ FeatureFactory.getFactory(this).getMetricsFeatureProvider().action(this,
+ MetricsEvent.ACTION_STORAGE_INIT_EXTERNAL);
+ }
+
if (mVolume != null && mVolume.getType() == VolumeInfo.TYPE_PUBLIC
&& mVolume.getState() != VolumeInfo.STATE_UNMOUNTABLE) {
// Remember that user made decision
@@ -85,6 +93,12 @@
}
public void onNavigateInternal(View view) {
+ if (view != null) {
+ // User made an explicit choice for internal
+ FeatureFactory.getFactory(this).getMetricsFeatureProvider().action(this,
+ MetricsEvent.ACTION_STORAGE_INIT_INTERNAL);
+ }
+
StorageWizardFormatConfirm.showPrivate(this, mDisk.getId());
}
}
diff --git a/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java b/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java
index 969a50a..b17defd 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java
@@ -31,7 +31,9 @@
import android.view.View;
import android.widget.Toast;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settings.password.ChooseLockSettingsHelper;
import java.util.Objects;
@@ -80,6 +82,9 @@
@Override
public void onNavigateBack(View view) {
+ FeatureFactory.getFactory(this).getMetricsFeatureProvider().action(this,
+ MetricsEvent.ACTION_STORAGE_MIGRATE_LATER);
+
final Intent intent = new Intent(this, StorageWizardReady.class);
intent.putExtra(EXTRA_MIGRATE_SKIP, true);
startActivity(intent);
@@ -127,6 +132,9 @@
return;
}
+ FeatureFactory.getFactory(this).getMetricsFeatureProvider().action(this,
+ MetricsEvent.ACTION_STORAGE_MIGRATE_NOW);
+
final Intent intent = new Intent(this, StorageWizardMigrateProgress.class);
intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, mVolume.getId());
intent.putExtra(PackageManager.EXTRA_MOVE_ID, moveId);
diff --git a/src/com/android/settings/notification/BadgingNotificationPreferenceController.java b/src/com/android/settings/notification/BadgingNotificationPreferenceController.java
index 18efd43..37e3db0 100644
--- a/src/com/android/settings/notification/BadgingNotificationPreferenceController.java
+++ b/src/com/android/settings/notification/BadgingNotificationPreferenceController.java
@@ -23,11 +23,13 @@
import android.net.Uri;
import android.os.Handler;
import android.provider.Settings;
+import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.TwoStatePreference;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settings.R;
import com.android.settings.search.DatabaseIndexingUtils;
@@ -39,19 +41,20 @@
import static android.provider.Settings.Secure.NOTIFICATION_BADGING;
-public class BadgingNotificationPreferenceController extends AbstractPreferenceController
+public class BadgingNotificationPreferenceController extends TogglePreferenceController
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
LifecycleObserver, OnResume, OnPause {
private static final String TAG = "BadgeNotifPrefContr";
- private static final String KEY_NOTIFICATION_BADGING = "notification_badging";
- private static final int ON = 1;
- private static final int OFF = 0;
+ @VisibleForTesting
+ static final int ON = 1;
+ @VisibleForTesting
+ static final int OFF = 0;
private SettingObserver mSettingObserver;
- public BadgingNotificationPreferenceController(Context context) {
- super(context);
+ public BadgingNotificationPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
}
@Override
@@ -78,28 +81,22 @@
}
@Override
- public String getPreferenceKey() {
- return KEY_NOTIFICATION_BADGING;
- }
-
- @Override
- public boolean isAvailable() {
+ public int getAvailabilityStatus() {
return mContext.getResources()
- .getBoolean(com.android.internal.R.bool.config_notificationBadging);
+ .getBoolean(com.android.internal.R.bool.config_notificationBadging)
+ ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
- public void updateState(Preference preference) {
- final boolean checked = Settings.Secure.getInt(mContext.getContentResolver(),
+ public boolean isChecked() {
+ return Settings.Secure.getInt(mContext.getContentResolver(),
NOTIFICATION_BADGING, ON) == ON;
- ((TwoStatePreference) preference).setChecked(checked);
}
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean val = (Boolean) newValue;
+ public boolean setChecked(boolean isChecked) {
return Settings.Secure.putInt(mContext.getContentResolver(),
- NOTIFICATION_BADGING, val ? ON : OFF);
+ NOTIFICATION_BADGING, isChecked ? ON : OFF);
}
class SettingObserver extends ContentObserver {
@@ -134,7 +131,7 @@
@Override
public ResultPayload getResultPayload() {
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
- ConfigureNotificationSettings.class.getName(), KEY_NOTIFICATION_BADGING,
+ ConfigureNotificationSettings.class.getName(), getPreferenceKey(),
mContext.getString(R.string.configure_notification_settings));
return new InlineSwitchPayload(Settings.Secure.NOTIFICATION_BADGING,
diff --git a/src/com/android/settings/notification/ConfigureNotificationSettings.java b/src/com/android/settings/notification/ConfigureNotificationSettings.java
index 1ca4a4d..4bf5b70 100644
--- a/src/com/android/settings/notification/ConfigureNotificationSettings.java
+++ b/src/com/android/settings/notification/ConfigureNotificationSettings.java
@@ -93,8 +93,6 @@
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle, Application app, Fragment host) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
- final BadgingNotificationPreferenceController badgeController =
- new BadgingNotificationPreferenceController(context);
final PulseNotificationPreferenceController pulseController =
new PulseNotificationPreferenceController(context);
final LockScreenNotificationPreferenceController lockScreenNotificationController =
@@ -108,7 +106,6 @@
}
controllers.add(new RecentNotifyingAppsPreferenceController(
context, new NotificationBackend(), app, host));
- controllers.add(badgeController);
controllers.add(pulseController);
controllers.add(lockScreenNotificationController);
controllers.add(new NotificationRingtonePreferenceController(context) {
diff --git a/src/com/android/settings/notification/ZenCustomRadioButtonPreference.java b/src/com/android/settings/notification/ZenCustomRadioButtonPreference.java
index 6035b49..91472f9 100644
--- a/src/com/android/settings/notification/ZenCustomRadioButtonPreference.java
+++ b/src/com/android/settings/notification/ZenCustomRadioButtonPreference.java
@@ -86,10 +86,13 @@
}
final View gear = holder.findViewById(android.R.id.widget_frame);
+ final View divider = holder.findViewById(R.id.two_target_divider);
if (mOnGearClickListener != null) {
+ divider.setVisibility(View.VISIBLE);
gear.setVisibility(View.VISIBLE);
gear.setOnClickListener(this);
} else {
+ divider.setVisibility(View.GONE);
gear.setVisibility(View.GONE);
gear.setOnClickListener(null);
}
diff --git a/tests/robotests/src/com/android/settings/notification/BadgingNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BadgingNotificationPreferenceControllerTest.java
index d852aaa..f999194 100644
--- a/tests/robotests/src/com/android/settings/notification/BadgingNotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/BadgingNotificationPreferenceControllerTest.java
@@ -17,6 +17,12 @@
package com.android.settings.notification;
import static android.provider.Settings.Secure.NOTIFICATION_BADGING;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.DISABLED_UNSUPPORTED;
+import static com.android.settings.notification.BadgingNotificationPreferenceController.OFF;
+import static com.android.settings.notification.BadgingNotificationPreferenceController.ON;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -54,10 +60,13 @@
private BadgingNotificationPreferenceController mController;
private Preference mPreference;
+ private static final String KEY_NOTIFICATION_BADGING = "notification_badging";
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mController = new BadgingNotificationPreferenceController(mContext);
+ mController = new BadgingNotificationPreferenceController(mContext,
+ KEY_NOTIFICATION_BADGING);
mPreference = new Preference(RuntimeEnvironment.application);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
@@ -88,9 +97,10 @@
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
final TwoStatePreference preference = mock(TwoStatePreference.class);
final Context context = RuntimeEnvironment.application;
- Settings.Secure.putInt(context.getContentResolver(), NOTIFICATION_BADGING, 1);
+ Settings.Secure.putInt(context.getContentResolver(), NOTIFICATION_BADGING, ON);
- mController = new BadgingNotificationPreferenceController(context);
+ mController = new BadgingNotificationPreferenceController(context,
+ KEY_NOTIFICATION_BADGING);
mController.updateState(preference);
verify(preference).setChecked(true);
@@ -100,9 +110,10 @@
public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
final TwoStatePreference preference = mock(TwoStatePreference.class);
final Context context = RuntimeEnvironment.application;
- Settings.Secure.putInt(context.getContentResolver(), NOTIFICATION_BADGING, 0);
+ Settings.Secure.putInt(context.getContentResolver(), NOTIFICATION_BADGING, OFF);
- mController = new BadgingNotificationPreferenceController(context);
+ mController = new BadgingNotificationPreferenceController(context,
+ KEY_NOTIFICATION_BADGING);
mController.updateState(preference);
verify(preference).setChecked(false);
@@ -118,11 +129,11 @@
public void testSetValue_updatesCorrectly() {
final int newValue = 0;
ContentResolver resolver = mContext.getContentResolver();
- Settings.Secure.putInt(resolver, Settings.Secure.NOTIFICATION_BADGING, 1);
+ Settings.Secure.putInt(resolver, Settings.Secure.NOTIFICATION_BADGING, ON);
((InlinePayload) mController.getResultPayload()).setValue(mContext, newValue);
final int updatedValue =
- Settings.Secure.getInt(resolver, Settings.Secure.NOTIFICATION_BADGING, 1);
+ Settings.Secure.getInt(resolver, Settings.Secure.NOTIFICATION_BADGING, ON);
assertThat(updatedValue).isEqualTo(newValue);
}
@@ -138,4 +149,40 @@
assertThat(newValue).isEqualTo(currentValue);
}
+
+ @Test
+ public void isChecked_settingIsOff_shouldReturnFalse() {
+ Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, OFF);
+
+ assertThat(mController.isChecked()).isFalse();
+ }
+
+ @Test
+ public void isChecked_settingIsOn_shouldReturnTrue() {
+ Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, ON);
+
+ assertThat(mController.isChecked()).isTrue();
+ }
+
+ @Test
+ public void setChecked_setFalse_disablesSetting() {
+ Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, ON);
+
+ mController.setChecked(false);
+ int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(),
+ NOTIFICATION_BADGING, -1);
+
+ assertThat(updatedValue).isEqualTo(OFF);
+ }
+
+ @Test
+ public void setChecked_setTrue_enablesSetting() {
+ Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, OFF);
+
+ mController.setChecked(true);
+ int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(),
+ NOTIFICATION_BADGING, -1);
+
+ assertThat(updatedValue).isEqualTo(ON);
+ }
}