/* * Copyright (C) 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.deviceconnect.android.deviceplugin.chromecast; import android.content.Context; import com.google.android.gms.cast.MediaMetadata; import com.google.android.gms.cast.framework.CastOptions; import com.google.android.gms.cast.framework.OptionsProvider; import com.google.android.gms.cast.framework.SessionProvider; import com.google.android.gms.cast.framework.media.ImagePicker; import com.google.android.gms.common.images.WebImage; import java.util.List; /** * Implements {@link OptionsProvider} to provide {@link CastOptions}. */ public class CastOptionsProvider implements OptionsProvider { @Override public CastOptions getCastOptions(Context context) { return new CastOptions.Builder() .setReceiverApplicationId(context.getString(R.string.application_id)) .build(); } @Override public List<SessionProvider> getAdditionalSessionProviders(Context appContext) { return null; } private static class ImagePickerImpl extends ImagePicker { @Override public WebImage onPickImage(MediaMetadata mediaMetadata, int type) { if ((mediaMetadata == null) || !mediaMetadata.hasImages()) { return null; } List<WebImage> images = mediaMetadata.getImages(); if (images.size() == 1) { return images.get(0); } else { if (type == ImagePicker.IMAGE_TYPE_MEDIA_ROUTE_CONTROLLER_DIALOG_BACKGROUND) { return images.get(0); } else { return images.get(1); } } } } }