Search in sources :

Example 1 with RoutingSessionInfo

use of android.media.RoutingSessionInfo in project android_packages_apps_Settings by omnirom.

the class RemoteMediaSliceTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    // Set-up specs for SliceMetadata.
    SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
    mRemoteMediaSlice = new RemoteMediaSlice(mContext);
    mRemoteMediaSlice.mRouterManager = mock(MediaRouter2Manager.class);
    sMediaDeviceUpdateWorker = spy(new MediaDeviceUpdateWorker(mContext, REMOTE_MEDIA_SLICE_URI));
    sMediaDeviceUpdateWorker.mLocalMediaManager = mLocalMediaManager;
    final RoutingSessionInfo remoteSessionInfo = mock(RoutingSessionInfo.class);
    when(remoteSessionInfo.getId()).thenReturn(TEST_SESSION_1_ID);
    when(remoteSessionInfo.getName()).thenReturn(TEST_SESSION_1_NAME);
    when(remoteSessionInfo.getVolumeMax()).thenReturn(100);
    when(remoteSessionInfo.getVolume()).thenReturn(10);
    when(remoteSessionInfo.isSystemSession()).thenReturn(false);
    mRoutingSessionInfos.add(remoteSessionInfo);
    when(sMediaDeviceUpdateWorker.getActiveRemoteMediaDevice()).thenReturn(mRoutingSessionInfos);
}
Also used : MediaRouter2Manager(android.media.MediaRouter2Manager) RoutingSessionInfo(android.media.RoutingSessionInfo) Before(org.junit.Before)

Example 2 with RoutingSessionInfo

use of android.media.RoutingSessionInfo in project android_packages_apps_Settings by omnirom.

the class MediaDeviceUpdateWorkerTest method getActiveRemoteMediaSession_verifyList.

@Test
public void getActiveRemoteMediaSession_verifyList() {
    mMediaDeviceUpdateWorker.mLocalMediaManager = mock(LocalMediaManager.class);
    final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>();
    final RoutingSessionInfo remoteSessionInfo = mock(RoutingSessionInfo.class);
    final RoutingSessionInfo localSessionInfo = mock(RoutingSessionInfo.class);
    when(remoteSessionInfo.isSystemSession()).thenReturn(false);
    when(localSessionInfo.isSystemSession()).thenReturn(true);
    routingSessionInfos.add(remoteSessionInfo);
    routingSessionInfos.add(localSessionInfo);
    when(mMediaDeviceUpdateWorker.mLocalMediaManager.getActiveMediaSession()).thenReturn(routingSessionInfos);
    assertThat(mMediaDeviceUpdateWorker.getActiveRemoteMediaDevice()).containsExactly(remoteSessionInfo);
}
Also used : LocalMediaManager(com.android.settingslib.media.LocalMediaManager) ArrayList(java.util.ArrayList) RoutingSessionInfo(android.media.RoutingSessionInfo) Test(org.junit.Test)

Example 3 with RoutingSessionInfo

use of android.media.RoutingSessionInfo in project android_packages_apps_Settings by omnirom.

the class RemoteMediaSlice method getSlice.

@Override
public Slice getSlice() {
    final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY).setAccentColor(COLOR_NOT_TINTED);
    if (getWorker() == null) {
        Log.e(TAG, "Unable to get the slice worker.");
        return listBuilder.build();
    }
    if (mRouterManager == null) {
        mRouterManager = MediaRouter2Manager.getInstance(mContext);
    }
    // Only displaying remote devices
    final List<RoutingSessionInfo> infos = getWorker().getActiveRemoteMediaDevice();
    if (infos.isEmpty()) {
        Log.d(TAG, "No active remote media device");
        return listBuilder.build();
    }
    final CharSequence castVolume = mContext.getText(R.string.remote_media_volume_option_title);
    final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.ic_volume_remote);
    // To create an empty icon to indent the row
    final IconCompat emptyIcon = createEmptyIcon();
    for (RoutingSessionInfo info : infos) {
        final int maxVolume = info.getVolumeMax();
        if (maxVolume <= 0) {
            Log.d(TAG, "Unable to add Slice. " + info.getName() + ": max volume is " + maxVolume);
            continue;
        }
        if (!getWorker().shouldEnableVolumeSeekBar(info)) {
            // There is no disable state. We hide it directly.
            Log.d(TAG, "Unable to add Slice. " + info.getName() + ": This is a group session");
            continue;
        }
        final CharSequence appName = Utils.getApplicationLabel(mContext, info.getClientPackageName());
        final CharSequence outputTitle = mContext.getString(R.string.media_output_label_title, appName);
        listBuilder.addInputRange(new InputRangeBuilder().setTitleItem(icon, ListBuilder.ICON_IMAGE).setTitle(castVolume).setInputAction(getSliderInputAction(info.getId().hashCode(), info.getId())).setPrimaryAction(getSoundSettingAction(castVolume, icon, info.getId())).setMax(maxVolume).setValue(info.getVolume()));
        final boolean isMediaOutputDisabled = getWorker().shouldDisableMediaOutput(info.getClientPackageName());
        final SpannableString spannableTitle = new SpannableString(TextUtils.isEmpty(appName) ? "" : appName);
        spannableTitle.setSpan(new ForegroundColorSpan(Utils.getColorAttrDefaultColor(mContext, android.R.attr.textColorSecondary)), 0, spannableTitle.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
        listBuilder.addRow(new ListBuilder.RowBuilder().setTitle(isMediaOutputDisabled ? spannableTitle : outputTitle).setSubtitle(info.getName()).setTitleItem(emptyIcon, ListBuilder.ICON_IMAGE).setPrimaryAction(getMediaOutputDialogAction(info, isMediaOutputDisabled)));
    }
    return listBuilder.build();
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) IconCompat(androidx.core.graphics.drawable.IconCompat) InputRangeBuilder(androidx.slice.builders.ListBuilder.InputRangeBuilder) ListBuilder(androidx.slice.builders.ListBuilder) RoutingSessionInfo(android.media.RoutingSessionInfo)

Example 4 with RoutingSessionInfo

use of android.media.RoutingSessionInfo in project android_packages_apps_Settings by omnirom.

the class RemoteVolumeGroupController method handlePreferenceTreeClick.

@Override
public boolean handlePreferenceTreeClick(Preference preference) {
    if (!preference.getKey().startsWith(SWITCHER_PREFIX)) {
        return false;
    }
    for (RoutingSessionInfo info : mRoutingSessionInfos) {
        if (TextUtils.equals(info.getId(), preference.getKey().substring(SWITCHER_PREFIX.length()))) {
            final Intent intent = new Intent().setAction(MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG).setPackage(MediaOutputConstants.SYSTEMUI_PACKAGE_NAME).putExtra(MediaOutputConstants.EXTRA_PACKAGE_NAME, info.getClientPackageName());
            mContext.sendBroadcast(intent);
            return true;
        }
    }
    return false;
}
Also used : RoutingSessionInfo(android.media.RoutingSessionInfo) Intent(android.content.Intent)

Example 5 with RoutingSessionInfo

use of android.media.RoutingSessionInfo in project android_packages_apps_Settings by omnirom.

the class RemoteVolumeGroupController method refreshPreference.

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) {
        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());
            }
        } else {
            // Add slider
            seekBarPreference = new RemoteVolumeSeekBarPreference(mContext);
            seekBarPreference.setKey(info.getId());
            seekBarPreference.setTitle(castVolume);
            seekBarPreference.setMax(info.getVolumeMax());
            seekBarPreference.setProgress(info.getVolume());
            seekBarPreference.setMin(0);
            seekBarPreference.setOnPreferenceChangeListener(this);
            seekBarPreference.setIcon(R.drawable.ic_volume_remote);
            seekBarPreference.setEnabled(mLocalMediaManager.shouldEnableVolumeSeekBar(info));
            mPreferenceCategory.addPreference(seekBarPreference);
        }
        Preference switcherPreference = mPreferenceCategory.findPreference(SWITCHER_PREFIX + info.getId());
        final boolean isMediaOutputDisabled = mLocalMediaManager.shouldDisableMediaOutput(info.getClientPackageName());
        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);
        }
    }
    // 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);
        }
    }
}
Also used : Preference(androidx.preference.Preference) RoutingSessionInfo(android.media.RoutingSessionInfo)

Aggregations

RoutingSessionInfo (android.media.RoutingSessionInfo)7 Intent (android.content.Intent)2 MediaRouter2Manager (android.media.MediaRouter2Manager)2 SpannableString (android.text.SpannableString)2 Before (org.junit.Before)2 PendingIntent (android.app.PendingIntent)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 IconCompat (androidx.core.graphics.drawable.IconCompat)1 Preference (androidx.preference.Preference)1 PreferenceCategory (androidx.preference.PreferenceCategory)1 ListBuilder (androidx.slice.builders.ListBuilder)1 InputRangeBuilder (androidx.slice.builders.ListBuilder.InputRangeBuilder)1 LocalMediaManager (com.android.settingslib.media.LocalMediaManager)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1