Update top level menu items summary text.

- Use static summary for most items
- Move summary for user setting to user&account setting

Bug: 34975053
Test: RunSettingsRoboTests
Change-Id: I9bf87267778dc5933f97f5d3b9ae0f4f0b8da1a8
This commit is contained in:
Fan Zhang
2017-02-09 13:06:58 -08:00
parent 3fca717d3b
commit 7520e81ab5
11 changed files with 157 additions and 398 deletions

View File

@@ -16,14 +16,8 @@
package com.android.settings.notification;
import android.app.Activity;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@@ -39,11 +33,9 @@ import com.android.settings.RingtonePreference;
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -109,7 +101,7 @@ public class SoundSettings extends DashboardFragment {
@Override
protected int getPreferenceScreenResId() {
return mDashboardFeatureProvider.isEnabled()
? R.xml.ia_sound_settings : R.xml.sound_settings;
? R.xml.ia_sound_settings : R.xml.sound_settings;
}
@Override
@@ -127,7 +119,7 @@ public class SoundSettings extends DashboardFragment {
controllers.add(new AlarmVolumePreferenceController(context, mVolumeCallback, lifecycle));
controllers.add(new MediaVolumePreferenceController(context, mVolumeCallback, lifecycle));
controllers.add(
new NotificationVolumePreferenceController(context, mVolumeCallback, lifecycle));
new NotificationVolumePreferenceController(context, mVolumeCallback, lifecycle));
controllers.add(new RingVolumePreferenceController(context, mVolumeCallback, lifecycle));
// === Phone & notification ringtone ===
@@ -198,7 +190,9 @@ public class SoundSettings extends DashboardFragment {
mCurrent.stopSample();
}
}
};
}
;
// === Callbacks ===
@@ -220,130 +214,63 @@ public class SoundSettings extends DashboardFragment {
}
}
// === Summary ===
private static class SummaryProvider extends BroadcastReceiver
implements SummaryLoader.SummaryProvider {
private final Context mContext;
private final AudioManager mAudioManager;
private final SummaryLoader mSummaryLoader;
private final int maxVolume;
public SummaryProvider(Context context, SummaryLoader summaryLoader) {
mContext = context;
mSummaryLoader = summaryLoader;
mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
}
@Override
public void setListening(boolean listening) {
if (listening) {
IntentFilter filter = new IntentFilter();
filter.addAction(AudioManager.VOLUME_CHANGED_ACTION);
filter.addAction(AudioManager.STREAM_DEVICES_CHANGED_ACTION);
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
filter.addAction(AudioManager.STREAM_MUTE_CHANGED_ACTION);
filter.addAction(NotificationManager.ACTION_EFFECTS_SUPPRESSOR_CHANGED);
mContext.registerReceiver(this, filter);
} else {
mContext.unregisterReceiver(this);
}
}
@Override
public void onReceive(Context context, Intent intent) {
final int ringerMode = mAudioManager.getRingerMode();
int resId;
String percent = "";
if (ringerMode == mAudioManager.RINGER_MODE_SILENT) {
resId = R.string.sound_settings_summary_silent;
} else if (ringerMode == mAudioManager.RINGER_MODE_VIBRATE){
resId = R.string.sound_settings_summary_vibrate;
}
else {
percent = NumberFormat.getPercentInstance().format(
(double) mAudioManager.getStreamVolume(
AudioManager.STREAM_RING) / maxVolume);
resId = R.string.sound_settings_summary;
}
final ComponentName suppressor = NotificationManager.from(mContext)
.getEffectsSuppressor();
if (suppressor != null) {
String suppressText = SuppressorHelper.getSuppressionText(mContext, suppressor);
mSummaryLoader.setSummary(this, suppressText);
} else {
mSummaryLoader.setSummary(this, mContext.getString(resId, percent));
}
}
}
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
= new SummaryLoader.SummaryProviderFactory() {
@Override
public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
SummaryLoader summaryLoader) {
return new SummaryProvider(activity, summaryLoader);
}
};
// === Indexing ===
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.sound_settings;
return Arrays.asList(sir);
}
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.sound_settings;
return Arrays.asList(sir);
}
public List<String> getNonIndexableKeys(Context context) {
final ArrayList<String> rt = new ArrayList<String>();
new NotificationVolumePreferenceController(
context, null /* Callback */, null /* Lifecycle */).updateNonIndexableKeys(rt);
new RingVolumePreferenceController(
context, null /* Callback */, null /* Lifecycle */).updateNonIndexableKeys(rt);
new PhoneRingtonePreferenceController(context).updateNonIndexableKeys(rt);
new VibrateWhenRingPreferenceController(context).updateNonIndexableKeys(rt);
new EmergencyBroadcastPreferenceController(context).updateNonIndexableKeys(rt);
if (FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
.isEnabled()) {
new DialPadTonePreferenceController(context,
null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new ScreenLockSoundPreferenceController(context,
null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new ChargingSoundPreferenceController(context,
null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new DockingSoundPreferenceController(context,
null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new TouchSoundPreferenceController(context, null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new VibrateOnTouchPreferenceController(context,
null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new DockAudioMediaPreferenceController(context,
null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new BootSoundPreferenceController(context).updateNonIndexableKeys(rt);
new EmergencyTonePreferenceController(context,
null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
} else {
new CastPreferenceController(context).updateNonIndexableKeys(rt);
}
public List<String> getNonIndexableKeys(Context context) {
final ArrayList<String> rt = new ArrayList<String>();
new NotificationVolumePreferenceController(
context, null /* Callback */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new RingVolumePreferenceController(
context, null /* Callback */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new PhoneRingtonePreferenceController(context).updateNonIndexableKeys(rt);
new VibrateWhenRingPreferenceController(context).updateNonIndexableKeys(rt);
new EmergencyBroadcastPreferenceController(context).updateNonIndexableKeys(rt);
if (FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
.isEnabled()) {
new DialPadTonePreferenceController(context,
null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new ScreenLockSoundPreferenceController(context,
null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new ChargingSoundPreferenceController(context,
null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new DockingSoundPreferenceController(context,
null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new TouchSoundPreferenceController(context, null /*
SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new VibrateOnTouchPreferenceController(context,
null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new DockAudioMediaPreferenceController(context,
null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
new BootSoundPreferenceController(context).updateNonIndexableKeys(rt);
new EmergencyTonePreferenceController(context,
null /* SettingsPreferenceFragment */,
null /* Lifecycle */).updateNonIndexableKeys(rt);
} else {
new CastPreferenceController(context).updateNonIndexableKeys(rt);
}
return rt;
}
};
return rt;
}
};
// === Work Sound Settings ===