2525import android .app .MediaRouteButton ;
2626import android .content .Context ;
2727import android .graphics .drawable .Drawable ;
28- import android .media . AudioManager ;
28+ import android .hardware . display . DisplayManager ;
2929import android .media .MediaRouter ;
3030import android .media .MediaRouter .RouteCategory ;
3131import android .media .MediaRouter .RouteGroup ;
@@ -70,6 +70,7 @@ public class MediaRouteChooserDialogFragment extends DialogFragment {
7070 };
7171
7272 MediaRouter mRouter ;
73+ DisplayManager mDisplayService ;
7374 private int mRouteTypes ;
7475
7576 private LayoutInflater mInflater ;
@@ -97,6 +98,7 @@ public void setLauncherListener(LauncherListener listener) {
9798 public void onAttach (Activity activity ) {
9899 super .onAttach (activity );
99100 mRouter = (MediaRouter ) activity .getSystemService (Context .MEDIA_ROUTER_SERVICE );
101+ mDisplayService = (DisplayManager ) activity .getSystemService (Context .DISPLAY_SERVICE );
100102 }
101103
102104 @ Override
@@ -119,6 +121,15 @@ public void setExtendedSettingsClickListener(View.OnClickListener listener) {
119121
120122 public void setRouteTypes (int types ) {
121123 mRouteTypes = types ;
124+ if ((mRouteTypes & MediaRouter .ROUTE_TYPE_LIVE_VIDEO ) != 0 && mDisplayService == null ) {
125+ final Context activity = getActivity ();
126+ if (activity != null ) {
127+ mDisplayService = (DisplayManager ) activity .getSystemService (
128+ Context .DISPLAY_SERVICE );
129+ }
130+ } else {
131+ mDisplayService = null ;
132+ }
122133 }
123134
124135 void updateVolume () {
@@ -194,6 +205,9 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
194205 @ Override
195206 public void onResume () {
196207 super .onResume ();
208+ if (mDisplayService != null ) {
209+ mDisplayService .scanWifiDisplays ();
210+ }
197211 }
198212
199213 private static class ViewHolder {
@@ -253,7 +267,9 @@ void update() {
253267 final RouteCategory cat = mRouter .getCategoryAt (i );
254268 routes = cat .getRoutes (mCatRouteList );
255269
256- mItems .add (cat );
270+ if (!cat .isSystem ()) {
271+ mItems .add (cat );
272+ }
257273
258274 if (cat == mCategoryEditingGroups ) {
259275 addGroupEditingCategoryRoutes (routes );
@@ -370,6 +386,7 @@ public boolean areAllItemsEnabled() {
370386 public boolean isEnabled (int position ) {
371387 switch (getItemViewType (position )) {
372388 case VIEW_ROUTE :
389+ return ((RouteInfo ) mItems .get (position )).isEnabled ();
373390 case VIEW_GROUPING_ROUTE :
374391 case VIEW_GROUPING_DONE :
375392 return true ;
@@ -434,6 +451,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
434451 }
435452
436453 convertView .setActivated (position == mSelectedItemPosition );
454+ convertView .setEnabled (isEnabled (position ));
437455
438456 return convertView ;
439457 }
0 commit comments