Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
BasicMediaRouter / src / com.example.android.basicmediarouter /

SamplePresentation.java

       
        1
       
       
        /*
       
       
        2
       
       
        * Copyright 2013 The Android Open Source Project
       
       
        3
       
       
        *
       
       
        4
       
       
        * Licensed under the Apache License, Version 2.0 (the "License");
       
       
        5
       
       
        * you may not use this file except in compliance with the License.
       
       
        6
       
       
        * You may obtain a copy of the License at
       
       
        7
       
       
        *
       
       
        8
       
       
        *       http://www.apache.org/licenses/LICENSE-2.0
       
       
        9
       
       
        *
       
       
        10
       
       
        * Unless required by applicable law or agreed to in writing, software
       
       
        11
       
       
        * distributed under the License is distributed on an "AS IS" BASIS,
       
       
        12
       
       
        * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
       
        13
       
       
        * See the License for the specific language governing permissions and
       
       
        14
       
       
        * limitations under the License.
       
       
        15
       
       
        */
       
       
        16
       
       
       
       
        17
       
       
        package com.example.android.basicmediarouter;
       
       
        18
       
       
       
       
        19
       
       
        import android.app.Presentation;
       
       
        20
       
       
        import android.content.Context;
       
       
        21
       
       
        import android.os.Bundle;
       
       
        22
       
       
        import android.view.Display;
       
       
        23
       
       
        import android.widget.LinearLayout;
       
       
        24
       
       
        import android.widget.TextView;
       
       
        25
       
       
       
       
        26
       
       
        /**
       
       
        27
       
       
        * <p>
       
       
        28
       
       
        * A {@link android.app.Presentation} used to demonstrate interaction between primary and
       
       
        29
       
       
        * secondary screens.
       
       
        30
       
       
        * </p>
       
       
        31
       
       
        * <p>
       
       
        32
       
       
        * It displays the name of the display in which it has been embedded (see
       
       
        33
       
       
        * {@link android.app.Presentation#getDisplay()}) and exposes a facility to change its
       
       
        34
       
       
        * background color and display its text.
       
       
        35
       
       
        * </p>
       
       
        36
       
       
        */
       
       
        37
       
       
        public class SamplePresentation extends Presentation {
       
       
        38
       
       
       
       
        39
       
       
        private LinearLayout mLayout;
       
       
        40
       
       
        private TextView mText;
       
       
        41
       
       
       
       
        42
       
       
        public SamplePresentation(Context outerContext, Display display) {
       
       
        43
       
       
        super(outerContext, display);
       
       
        44
       
       
        }
       
       
        45
       
       
       
       
        46
       
       
        @Override
       
       
        47
       
       
        protected void onCreate(Bundle savedInstanceState) {
       
       
        48
       
       
        super.onCreate(savedInstanceState);
       
       
        49
       
       
       
       
        50
       
       
        // Set the content view to the custom layout
       
       
        51
       
       
        setContentView(R.layout.display);
       
       
        52
       
       
       
       
        53
       
       
        // Get the Views
       
       
        54
       
       
        mLayout = (LinearLayout) findViewById(R.id.display_layout);
       
       
        55
       
       
        mText = (TextView) findViewById(R.id.display_text);
       
       
        56
       
       
       
       
        57
       
       
        /*
       
       
        58
       
       
        * Show the name of the display this presentation was embedded in.
       
       
        59
       
       
        */
       
       
        60
       
       
        TextView smallText = (TextView) findViewById(R.id.display_smalltext);
       
       
        61
       
       
        final String name = getDisplay().getName();
       
       
        62
       
       
        smallText.setText(getResources().getString(R.string.display_name, name));
       
       
        63
       
       
        }
       
       
        64
       
       
       
       
        65
       
       
        /**
       
       
        66
       
       
        * Set the background color of the layout and display the color as a String.
       
       
        67
       
       
        *
       
       
        68
       
       
        * @param color The background color
       
       
        69
       
       
        */
       
       
        70
       
       
        public void setColor(int color) {
       
       
        71
       
       
        mLayout.setBackgroundColor(color);
       
       
        72
       
       
       
       
        73
       
       
        // Display the color as a string on screen
       
       
        74
       
       
        String s = getResources().getString(R.string.display_color, color);
       
       
        75
       
       
        mText.setText(s);
       
       
        76
       
       
        }
       
       
        77
       
       
       
       
        78
       
       
        }