|
50 | 50 | * whenever the activity itself is paused or resumed. |
51 | 51 | * </p> |
52 | 52 | * |
| 53 | + * <h3>Choosing a presentation display</h3> |
| 54 | + * <p> |
| 55 | + * Before showing a {@link Presentation} it's important to choose the {@link Display} |
| 56 | + * on which it will appear. Choosing a presentation display is sometimes difficult |
| 57 | + * because there may be multiple displays attached. Rather than trying to guess |
| 58 | + * which display is best, an application should let the system choose a suitable |
| 59 | + * presentation display. |
| 60 | + * </p><p> |
| 61 | + * There are two main ways to choose a {@link Display}. |
| 62 | + * </p> |
| 63 | + * |
| 64 | + * <h4>Using the media router to choose a presentation display</h4> |
| 65 | + * <p> |
| 66 | + * The easiest way to choose a presentation display is to use the |
| 67 | + * {@link android.media.MediaRouter MediaRouter} API. The media router service keeps |
| 68 | + * track of which audio and video routes are available on the system. |
| 69 | + * The media router sends notifications whenever routes are selected or unselected |
| 70 | + * or when the preferred presentation display of a route changes. |
| 71 | + * So an application can simply watch for these notifications and show or dismiss |
| 72 | + * a presentation on the preferred presentation display automatically. |
| 73 | + * </p><p> |
| 74 | + * The preferred presentation display is the display that the media router recommends |
| 75 | + * that the application should use if it wants to show content on the secondary display. |
| 76 | + * Sometimes there may not be a preferred presentation display in which |
| 77 | + * case the application should show its content locally without using a presentation. |
| 78 | + * </p><p> |
| 79 | + * Here's how to use the media router to create and show a presentation on the preferred |
| 80 | + * presentation display using {@link android.media.MediaRouter.RouteInfo#getPresentationDisplay()}. |
| 81 | + * </p> |
| 82 | + * {@samplecode |
| 83 | + * MediaRouter mediaRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE); |
| 84 | + * MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute(); |
| 85 | + * if (route != null) ${ |
| 86 | + * Display presentationDisplay = route.getPresentationDisplay(); |
| 87 | + * if (presentationDisplay != null) ${ |
| 88 | + * Presentation presentation = new MyPresentation(context, presentationDisplay); |
| 89 | + * presentation.show(); |
| 90 | + * $} |
| 91 | + * $} |
| 92 | + * } |
| 93 | + * <p> |
| 94 | + * The following sample code from <code>ApiDemos</code> demonstrates how to use the media |
| 95 | + * router to automatically switch between showing content in the main activity and showing |
| 96 | + * the content in a presentation when a presentation display is available. |
| 97 | + * </p> |
| 98 | + * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/PresentationWithMediaRouterActivity.java |
| 99 | + * activity} |
| 100 | + * |
| 101 | + * <h4>Using the display manager to choose a presentation display</h4> |
| 102 | + * <p> |
| 103 | + * Another way to choose a presentation display is to use the {@link DisplayManager} API |
| 104 | + * directly. The display manager service provides functions to enumerate and describe all |
| 105 | + * displays that are attached to the system including displays that may be used |
| 106 | + * for presentations. |
| 107 | + * </p><p> |
| 108 | + * The display manager keeps track of all displays in the system. However, not all |
| 109 | + * displays are appropriate for showing presentations. For example, if an activity |
| 110 | + * attempted to show a presentation on the main display it might obscure its own content |
| 111 | + * (it's like opening a dialog on top of your activity). |
| 112 | + * </p><p> |
| 113 | + * Here's how to identify suitable displays for showing presentations using |
| 114 | + * {@link DisplayManager#getDisplays(String)} and the |
| 115 | + * {@link DisplayManager#DISPLAY_CATEGORY_PRESENTATION} category. |
| 116 | + * </p> |
| 117 | + * {@samplecode |
| 118 | + * DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); |
| 119 | + * Display[] presentationDisplays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION); |
| 120 | + * if (presentationDisplays.length > 0) ${ |
| 121 | + * // If there is more than one suitable presentation display, then we could consider |
| 122 | + * // giving the user a choice. For this example, we simply choose the first display |
| 123 | + * // which is the one the system recommends as the preferred presentation display. |
| 124 | + * Display display = presentationDisplays[0]; |
| 125 | + * Presentation presentation = new MyPresentation(context, presentationDisplay); |
| 126 | + * presentation.show(); |
| 127 | + * $} |
| 128 | + * } |
| 129 | + * <p> |
| 130 | + * The following sample code from <code>ApiDemos</code> demonstrates how to use the display |
| 131 | + * manager to enumerate displays and show content on multiple presentation displays |
| 132 | + * simultaneously. |
| 133 | + * </p> |
| 134 | + * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/PresentationActivity.java |
| 135 | + * activity} |
| 136 | + * |
| 137 | + * @see android.media.MediaRouter#ROUTE_TYPE_LIVE_VIDEO for information on about live |
| 138 | + * video routes and how to obtain the preferred presentation display for the |
| 139 | + * current media route. |
53 | 140 | * @see DisplayManager for information on how to enumerate displays and receive |
54 | 141 | * notifications when displays are added or removed. |
55 | 142 | */ |
@@ -121,7 +208,7 @@ public Resources getResources() { |
121 | 208 | @Override |
122 | 209 | protected void onStart() { |
123 | 210 | super.onStart(); |
124 | | - mDisplayManager.registerDisplayListener(mDisplayListener, null); |
| 211 | + mDisplayManager.registerDisplayListener(mDisplayListener, mHandler); |
125 | 212 |
|
126 | 213 | // Since we were not watching for display changes until just now, there is a |
127 | 214 | // chance that the display metrics have changed. If so, we will need to |
|
0 commit comments