Loading src/com/android/settings/notification/RemoteVolumeGroupController.java +68 −29 Original line number Diff line number Diff line Loading @@ -102,26 +102,26 @@ public class RemoteVolumeGroupController extends BasePreferenceController implem mLocalMediaManager.stopScan(); } private void refreshPreference() { mPreferenceCategory.removeAll(); private synchronized void refreshPreference() { if (!isAvailable()) { mPreferenceCategory.setVisible(false); return; } final CharSequence castVolume = mContext.getText(R.string.remote_media_volume_option_title); mPreferenceCategory.setVisible(true); for (RoutingSessionInfo info : mRoutingSessionInfos) { if (mPreferenceCategory.findPreference(info.getId()) != null) { continue; final CharSequence appName = Utils.getApplicationLabel(mContext, info.getClientPackageName()); RemoteVolumeSeekBarPreference seekBarPreference = mPreferenceCategory.findPreference( info.getId()); if (seekBarPreference != null) { // Update slider if (seekBarPreference.getProgress() != info.getVolume()) { seekBarPreference.setProgress(info.getVolume()); } final CharSequence appName = Utils.getApplicationLabel( mContext, info.getClientPackageName()); final CharSequence outputTitle = mContext.getString(R.string.media_output_label_title, appName); } else { // Add slider final RemoteVolumeSeekBarPreference seekBarPreference = new RemoteVolumeSeekBarPreference(mContext); seekBarPreference = new RemoteVolumeSeekBarPreference(mContext); seekBarPreference.setKey(info.getId()); seekBarPreference.setTitle(castVolume); seekBarPreference.setMax(info.getVolumeMax()); Loading @@ -130,15 +130,52 @@ public class RemoteVolumeGroupController extends BasePreferenceController implem seekBarPreference.setOnPreferenceChangeListener(this); seekBarPreference.setIcon(R.drawable.ic_volume_remote); mPreferenceCategory.addPreference(seekBarPreference); // Add output indicator } Preference switcherPreference = mPreferenceCategory.findPreference( SWITCHER_PREFIX + info.getId()); final boolean isMediaOutputDisabled = mLocalMediaManager.shouldDisableMediaOutput( info.getClientPackageName()); final Preference preference = new Preference(mContext); preference.setKey(SWITCHER_PREFIX + info.getId()); preference.setTitle(isMediaOutputDisabled ? appName : outputTitle); preference.setSummary(info.getName()); preference.setEnabled(!isMediaOutputDisabled); mPreferenceCategory.addPreference(preference); final CharSequence outputTitle = mContext.getString(R.string.media_output_label_title, appName); if (switcherPreference != null) { // Update output indicator switcherPreference.setTitle(isMediaOutputDisabled ? appName : outputTitle); switcherPreference.setSummary(info.getName()); switcherPreference.setEnabled(!isMediaOutputDisabled); } else { // Add output indicator switcherPreference = new Preference(mContext); switcherPreference.setKey(SWITCHER_PREFIX + info.getId()); switcherPreference.setTitle(isMediaOutputDisabled ? appName : outputTitle); switcherPreference.setSummary(info.getName()); switcherPreference.setEnabled(!isMediaOutputDisabled); mPreferenceCategory.addPreference(switcherPreference); } } // Check and remove non-active session preference // There is a pair of preferences for each session. First one is a seekBar preference. // The second one shows the session information and provide an entry-point to launch output // switcher. It is unnecessary to go through all preferences. It is fine ignore the second // preference and only to check the seekBar's key value. for (int i = 0; i < mPreferenceCategory.getPreferenceCount(); i = i + 2) { final Preference preference = mPreferenceCategory.getPreference(i); boolean isActive = false; for (RoutingSessionInfo info : mRoutingSessionInfos) { if (TextUtils.equals(preference.getKey(), info.getId())) { isActive = true; break; } } if (isActive) { continue; } final Preference switcherPreference = mPreferenceCategory.getPreference(i + 1); if (switcherPreference != null) { mPreferenceCategory.removePreference(preference); mPreferenceCategory.removePreference(switcherPreference); } } } Loading Loading @@ -181,8 +218,10 @@ public class RemoteVolumeGroupController extends BasePreferenceController implem // Preference group is not ready. return; } ThreadUtils.postOnMainThread(() -> { initRemoteMediaSession(); refreshPreference(); }); } @Override Loading Loading
src/com/android/settings/notification/RemoteVolumeGroupController.java +68 −29 Original line number Diff line number Diff line Loading @@ -102,26 +102,26 @@ public class RemoteVolumeGroupController extends BasePreferenceController implem mLocalMediaManager.stopScan(); } private void refreshPreference() { mPreferenceCategory.removeAll(); private synchronized void refreshPreference() { if (!isAvailable()) { mPreferenceCategory.setVisible(false); return; } final CharSequence castVolume = mContext.getText(R.string.remote_media_volume_option_title); mPreferenceCategory.setVisible(true); for (RoutingSessionInfo info : mRoutingSessionInfos) { if (mPreferenceCategory.findPreference(info.getId()) != null) { continue; final CharSequence appName = Utils.getApplicationLabel(mContext, info.getClientPackageName()); RemoteVolumeSeekBarPreference seekBarPreference = mPreferenceCategory.findPreference( info.getId()); if (seekBarPreference != null) { // Update slider if (seekBarPreference.getProgress() != info.getVolume()) { seekBarPreference.setProgress(info.getVolume()); } final CharSequence appName = Utils.getApplicationLabel( mContext, info.getClientPackageName()); final CharSequence outputTitle = mContext.getString(R.string.media_output_label_title, appName); } else { // Add slider final RemoteVolumeSeekBarPreference seekBarPreference = new RemoteVolumeSeekBarPreference(mContext); seekBarPreference = new RemoteVolumeSeekBarPreference(mContext); seekBarPreference.setKey(info.getId()); seekBarPreference.setTitle(castVolume); seekBarPreference.setMax(info.getVolumeMax()); Loading @@ -130,15 +130,52 @@ public class RemoteVolumeGroupController extends BasePreferenceController implem seekBarPreference.setOnPreferenceChangeListener(this); seekBarPreference.setIcon(R.drawable.ic_volume_remote); mPreferenceCategory.addPreference(seekBarPreference); // Add output indicator } Preference switcherPreference = mPreferenceCategory.findPreference( SWITCHER_PREFIX + info.getId()); final boolean isMediaOutputDisabled = mLocalMediaManager.shouldDisableMediaOutput( info.getClientPackageName()); final Preference preference = new Preference(mContext); preference.setKey(SWITCHER_PREFIX + info.getId()); preference.setTitle(isMediaOutputDisabled ? appName : outputTitle); preference.setSummary(info.getName()); preference.setEnabled(!isMediaOutputDisabled); mPreferenceCategory.addPreference(preference); final CharSequence outputTitle = mContext.getString(R.string.media_output_label_title, appName); if (switcherPreference != null) { // Update output indicator switcherPreference.setTitle(isMediaOutputDisabled ? appName : outputTitle); switcherPreference.setSummary(info.getName()); switcherPreference.setEnabled(!isMediaOutputDisabled); } else { // Add output indicator switcherPreference = new Preference(mContext); switcherPreference.setKey(SWITCHER_PREFIX + info.getId()); switcherPreference.setTitle(isMediaOutputDisabled ? appName : outputTitle); switcherPreference.setSummary(info.getName()); switcherPreference.setEnabled(!isMediaOutputDisabled); mPreferenceCategory.addPreference(switcherPreference); } } // Check and remove non-active session preference // There is a pair of preferences for each session. First one is a seekBar preference. // The second one shows the session information and provide an entry-point to launch output // switcher. It is unnecessary to go through all preferences. It is fine ignore the second // preference and only to check the seekBar's key value. for (int i = 0; i < mPreferenceCategory.getPreferenceCount(); i = i + 2) { final Preference preference = mPreferenceCategory.getPreference(i); boolean isActive = false; for (RoutingSessionInfo info : mRoutingSessionInfos) { if (TextUtils.equals(preference.getKey(), info.getId())) { isActive = true; break; } } if (isActive) { continue; } final Preference switcherPreference = mPreferenceCategory.getPreference(i + 1); if (switcherPreference != null) { mPreferenceCategory.removePreference(preference); mPreferenceCategory.removePreference(switcherPreference); } } } Loading Loading @@ -181,8 +218,10 @@ public class RemoteVolumeGroupController extends BasePreferenceController implem // Preference group is not ready. return; } ThreadUtils.postOnMainThread(() -> { initRemoteMediaSession(); refreshPreference(); }); } @Override Loading