Example usage for android.content Context MEDIA_ROUTER_SERVICE

List of usage examples for android.content Context MEDIA_ROUTER_SERVICE

Introduction

In this page you can find the example usage for android.content Context MEDIA_ROUTER_SERVICE.

Prototype

String MEDIA_ROUTER_SERVICE

To view the source code for android.content Context MEDIA_ROUTER_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.media.MediaRouter for controlling and managing routing of media.

Usage

From source file:com.nick.scalpel.core.AutoFoundWirer.java

private void wireFromContext(Context context, AutoFound.Type type, int idRes, Resources.Theme theme,
        Field field, Object forWho) {
    Resources resources = context.getResources();
    switch (type) {
    case STRING://from ww  w .  j  a  va 2  s.  c o m
        setField(field, forWho, resources.getString(idRes));
        break;
    case COLOR:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, resources.getColor(idRes, theme));
        } else {
            //noinspection deprecation
            setField(field, forWho, resources.getColor(idRes));
        }
        break;
    case INTEGER:
        setField(field, forWho, resources.getInteger(idRes));
        break;
    case BOOL:
        setField(field, forWho, resources.getBoolean(idRes));
        break;
    case STRING_ARRAY:
        setField(field, forWho, resources.getStringArray(idRes));
        break;
    case INT_ARRAY:
        setField(field, forWho, resources.getIntArray(idRes));
        break;
    case PM:
        setField(field, forWho, context.getSystemService(Context.POWER_SERVICE));
        break;
    case ACCOUNT:
        setField(field, forWho, context.getSystemService(Context.ACCOUNT_SERVICE));
        break;
    case ALARM:
        setField(field, forWho, context.getSystemService(Context.ALARM_SERVICE));
        break;
    case AM:
        setField(field, forWho, context.getSystemService(Context.ACTIVITY_SERVICE));
        break;
    case WM:
        setField(field, forWho, context.getSystemService(Context.WINDOW_SERVICE));
        break;
    case NM:
        setField(field, forWho, context.getSystemService(Context.NOTIFICATION_SERVICE));
        break;
    case TM:
        setField(field, forWho, context.getSystemService(Context.TELEPHONY_SERVICE));
        break;
    case TCM:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.TELECOM_SERVICE));
        }
        break;
    case SP:
        setField(field, forWho, PreferenceManager.getDefaultSharedPreferences(context));
        break;
    case PKM:
        setField(field, forWho, context.getPackageManager());
        break;
    case HANDLE:
        setField(field, forWho, new Handler(Looper.getMainLooper()));
        break;
    case ASM:
        setField(field, forWho, context.getSystemService(Context.ACCESSIBILITY_SERVICE));
        break;
    case CAP:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setField(field, forWho, context.getSystemService(Context.CAPTIONING_SERVICE));
        }
        break;
    case KGD:
        setField(field, forWho, context.getSystemService(Context.KEYGUARD_SERVICE));
        break;
    case LOCATION:
        setField(field, forWho, context.getSystemService(Context.LOCATION_SERVICE));
        break;
    case SEARCH:
        setField(field, forWho, context.getSystemService(Context.SEARCH_SERVICE));
        break;
    case SENSOR:
        setField(field, forWho, context.getSystemService(Context.SENSOR_SERVICE));
        break;
    case STORAGE:
        setField(field, forWho, context.getSystemService(Context.STORAGE_SERVICE));
        break;
    case WALLPAPER:
        setField(field, forWho, context.getSystemService(Context.WALLPAPER_SERVICE));
        break;
    case VIBRATOR:
        setField(field, forWho, context.getSystemService(Context.VIBRATOR_SERVICE));
        break;
    case CONNECT:
        setField(field, forWho, context.getSystemService(Context.CONNECTIVITY_SERVICE));
        break;
    case NETWORK_STATUS:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, context.getSystemService(Context.NETWORK_STATS_SERVICE));
        }
        break;
    case WIFI:
        setField(field, forWho, context.getSystemService(Context.WIFI_SERVICE));
        break;
    case AUDIO:
        setField(field, forWho, context.getSystemService(Context.AUDIO_SERVICE));
        break;
    case FP:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, context.getSystemService(Context.FINGERPRINT_SERVICE));
        }
        break;
    case MEDIA_ROUTER:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            setField(field, forWho, context.getSystemService(Context.MEDIA_ROUTER_SERVICE));
        }
        break;
    case SUB:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            setField(field, forWho, context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE));
        }
        break;
    case IME:
        setField(field, forWho, context.getSystemService(Context.INPUT_METHOD_SERVICE));
        break;
    case CLIP_BOARD:
        setField(field, forWho, context.getSystemService(Context.CLIPBOARD_SERVICE));
        break;
    case APP_WIDGET:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.APPWIDGET_SERVICE));
        }
        break;
    case DEVICE_POLICY:
        setField(field, forWho, context.getSystemService(Context.DEVICE_POLICY_SERVICE));
        break;
    case DOWNLOAD:
        setField(field, forWho, context.getSystemService(Context.DOWNLOAD_SERVICE));
        break;
    case BATTERY:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.BATTERY_SERVICE));
        }
        break;
    case NFC:
        setField(field, forWho, context.getSystemService(Context.NFC_SERVICE));
        break;
    case DISPLAY:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setField(field, forWho, context.getSystemService(Context.DISPLAY_SERVICE));
        }
        break;
    case USER:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setField(field, forWho, context.getSystemService(Context.USER_SERVICE));
        }
        break;
    case APP_OPS:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setField(field, forWho, context.getSystemService(Context.APP_OPS_SERVICE));
        }
        break;
    case BITMAP:
        setField(field, forWho, BitmapFactory.decodeResource(resources, idRes, null));
        break;
    }
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.SessionLivestreamActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override// w w  w . ja v  a 2  s .  co m
protected void onCreate(Bundle savedInstanceState) {
    if (UIUtils.hasICS()) {
        // We can't use this mode on HC as compatible ActionBar doesn't work well with the YT
        // player in full screen mode (no overlays allowed).
        requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_session_livestream);
    mIsTablet = UIUtils.isHoneycombTablet(this);

    // Set up YouTube player
    mYouTubeFragment = (YouTubePlayerSupportFragment) getSupportFragmentManager()
            .findFragmentById(R.id.livestream_player);
    mYouTubeFragment.initialize(Config.YOUTUBE_API_KEY, this);

    // Views that are common over all layouts
    mMainLayout = (LinearLayout) findViewById(R.id.livestream_mainlayout);
    mPresentationControls = (FrameLayout) findViewById(R.id.presentation_controls);
    adjustMainLayoutForActionBar();
    mPlayerContainer = (LinearLayout) findViewById(R.id.livestream_player_container);
    mFullscreenCaptions = (FrameLayout) findViewById(R.id.fullscreen_captions);
    final LayoutParams params = (LayoutParams) mFullscreenCaptions.getLayoutParams();
    params.setMargins(0, getActionBarHeightPx(), 0, getActionBarHeightPx());
    mFullscreenCaptions.setLayoutParams(params);

    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setOffscreenPageLimit(2);
    if (!mIsTablet) {
        viewPager.setPageMarginDrawable(R.drawable.grey_border_inset_lr);
    }
    viewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.page_margin_width));

    // Set up tabs w/ViewPager
    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();
    mTabsAdapter = new TabsAdapter(this, mTabHost, viewPager);

    if (mIsTablet) {
        // Tablet UI specific views
        getSupportFragmentManager().beginTransaction()
                .add(R.id.livestream_summary, new SessionSummaryFragment(), TAG_SESSION_SUMMARY).commit();
        mVideoLayout = (LinearLayout) findViewById(R.id.livestream_videolayout);
        mExtraLayout = (LinearLayout) findViewById(R.id.livestream_extralayout);
        mSummaryLayout = (FrameLayout) findViewById(R.id.livestream_summary);
    } else {
        // Handset UI specific views
        mTabsAdapter.addTab(getString(R.string.session_livestream_info), new SessionSummaryFragment(),
                TABNUM_SESSION_SUMMARY);
    }

    mTabsAdapter.addTab(getString(R.string.title_stream), new SocialStreamFragment(), TABNUM_SOCIAL_STREAM);
    mTabsAdapter.addTab(getString(R.string.session_livestream_captions), new SessionLiveCaptionsFragment(),
            TABNUM_LIVE_CAPTIONS);

    if (savedInstanceState != null) {
        mTabHost.setCurrentTabByTag(savedInstanceState.getString(EXTRA_TAB_STATE));
    }

    // Reload all other data in this activity
    reloadFromIntent(getIntent());

    // Update layout based on current configuration
    updateLayout(getResources().getConfiguration());

    // Set up action bar
    if (!mLoadFromExtras) {
        // Start sessions query to populate action bar navigation spinner
        getSupportLoaderManager().initLoader(SessionsQuery._TOKEN, null, this);

        // Set up action bar
        mLivestreamAdapter = new LivestreamAdapter(getSupportActionBar().getThemedContext());
        final ActionBar actionBar = getSupportActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        actionBar.setListNavigationCallbacks(mLivestreamAdapter, this);
        actionBar.setDisplayShowTitleEnabled(false);
    }

    // Media Router and Presentation set up
    if (UIUtils.hasJellyBeanMR1()) {
        mMediaRouterCallback = new MediaRouter.SimpleCallback() {
            @Override
            public void onRouteSelected(MediaRouter router, int type, MediaRouter.RouteInfo info) {
                LOGD(TAG, "onRouteSelected: type=" + type + ", info=" + info);
                updatePresentation();
            }

            @Override
            public void onRouteUnselected(MediaRouter router, int type, MediaRouter.RouteInfo info) {
                LOGD(TAG, "onRouteUnselected: type=" + type + ", info=" + info);
                updatePresentation();
            }

            @Override
            public void onRoutePresentationDisplayChanged(MediaRouter router, MediaRouter.RouteInfo info) {
                LOGD(TAG, "onRoutePresentationDisplayChanged: info=" + info);
                updatePresentation();
            }
        };

        mMediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE);
        final ImageButton playPauseButton = (ImageButton) findViewById(R.id.play_pause_button);
        playPauseButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mYouTubePlayer != null) {
                    if (mYouTubePlayer.isPlaying()) {
                        mYouTubePlayer.pause();
                        playPauseButton.setImageResource(R.drawable.ic_livestream_play);
                    } else {
                        mYouTubePlayer.play();
                        playPauseButton.setImageResource(R.drawable.ic_livestream_pause);
                    }
                }
            }
        });
        updatePresentation();
    }
}