Loading core/java/com/android/internal/app/MediaRouteChooserContentManager.java 0 → 100644 +56 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2025 The Android Open Source Project * * 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 com.android.internal.app; import android.content.Context; import android.view.Gravity; import android.view.View; import android.widget.LinearLayout; import android.widget.ListView; import com.android.internal.R; public class MediaRouteChooserContentManager { Context mContext; private final boolean mShowProgressBarWhenEmpty; public MediaRouteChooserContentManager(Context context, boolean showProgressBarWhenEmpty) { mContext = context; mShowProgressBarWhenEmpty = showProgressBarWhenEmpty; } /** * Starts binding all the views (list view, empty view, etc.) using the * given container view. */ public void bindViews(View containerView) { View emptyView = containerView.findViewById(android.R.id.empty); ListView listView = containerView.findViewById(R.id.media_route_list); listView.setEmptyView(emptyView); if (!mShowProgressBarWhenEmpty) { containerView.findViewById(R.id.media_route_progress_bar).setVisibility(View.GONE); // Center the empty view when the progress bar is not shown. LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) emptyView.getLayoutParams(); params.gravity = Gravity.CENTER; emptyView.setLayoutParams(params); } } } core/java/com/android/internal/app/MediaRouteChooserDialog.java +13 −24 Original line number Original line Diff line number Diff line Loading @@ -23,14 +23,12 @@ import android.media.MediaRouter.RouteInfo; import android.os.Bundle; import android.os.Bundle; import android.text.TextUtils; import android.text.TextUtils; import android.util.TypedValue; import android.util.TypedValue; import android.view.Gravity; import android.view.LayoutInflater; import android.view.LayoutInflater; import android.view.View; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.ListView; import android.widget.TextView; import android.widget.TextView; Loading @@ -52,15 +50,15 @@ import java.util.Comparator; public class MediaRouteChooserDialog extends AlertDialog { public class MediaRouteChooserDialog extends AlertDialog { private final MediaRouter mRouter; private final MediaRouter mRouter; private final MediaRouterCallback mCallback; private final MediaRouterCallback mCallback; private final boolean mShowProgressBarWhenEmpty; private int mRouteTypes; private int mRouteTypes; private View.OnClickListener mExtendedSettingsClickListener; private View.OnClickListener mExtendedSettingsClickListener; private RouteAdapter mAdapter; private RouteAdapter mAdapter; private ListView mListView; private Button mExtendedSettingsButton; private Button mExtendedSettingsButton; private boolean mAttachedToWindow; private boolean mAttachedToWindow; private final MediaRouteChooserContentManager mContentManager; public MediaRouteChooserDialog(Context context, int theme) { public MediaRouteChooserDialog(Context context, int theme) { this(context, theme, true); this(context, theme, true); } } Loading @@ -70,7 +68,7 @@ public class MediaRouteChooserDialog extends AlertDialog { mRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE); mRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE); mCallback = new MediaRouterCallback(); mCallback = new MediaRouterCallback(); mShowProgressBarWhenEmpty = showProgressBarWhenEmpty; mContentManager = new MediaRouteChooserContentManager(context, showProgressBarWhenEmpty); } } /** /** Loading Loading @@ -128,8 +126,9 @@ public class MediaRouteChooserDialog extends AlertDialog { @Override @Override protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) { // Note: setView must be called before super.onCreate(). // Note: setView must be called before super.onCreate(). setView(LayoutInflater.from(getContext()).inflate(R.layout.media_route_chooser_dialog, View containerView = LayoutInflater.from(getContext()).inflate( null)); R.layout.media_route_chooser_dialog, null); setView(containerView); setTitle(mRouteTypes == MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY setTitle(mRouteTypes == MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY ? R.string.media_route_chooser_title_for_remote_display ? R.string.media_route_chooser_title_for_remote_display Loading @@ -140,25 +139,15 @@ public class MediaRouteChooserDialog extends AlertDialog { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); View emptyView = findViewById(android.R.id.empty); mAdapter = new RouteAdapter(getContext()); mAdapter = new RouteAdapter(getContext()); mListView = (ListView) findViewById(R.id.media_route_list); ListView listView = findViewById(R.id.media_route_list); mListView.setAdapter(mAdapter); listView.setAdapter(mAdapter); mListView.setOnItemClickListener(mAdapter); listView.setOnItemClickListener(mAdapter); mListView.setEmptyView(emptyView); mExtendedSettingsButton = (Button) findViewById(R.id.media_route_extended_settings_button); mExtendedSettingsButton = findViewById(R.id.media_route_extended_settings_button); updateExtendedSettingsButton(); updateExtendedSettingsButton(); if (!mShowProgressBarWhenEmpty) { mContentManager.bindViews(containerView); findViewById(R.id.media_route_progress_bar).setVisibility(View.GONE); // Center the empty view when the progress bar is not shown. LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) emptyView.getLayoutParams(); params.gravity = Gravity.CENTER; emptyView.setLayoutParams(params); } } } private void updateExtendedSettingsButton() { private void updateExtendedSettingsButton() { Loading Loading @@ -240,8 +229,8 @@ public class MediaRouteChooserDialog extends AlertDialog { view = mInflater.inflate(R.layout.media_route_list_item, parent, false); view = mInflater.inflate(R.layout.media_route_list_item, parent, false); } } MediaRouter.RouteInfo route = getItem(position); MediaRouter.RouteInfo route = getItem(position); TextView text1 = (TextView)view.findViewById(android.R.id.text1); TextView text1 = view.findViewById(android.R.id.text1); TextView text2 = (TextView)view.findViewById(android.R.id.text2); TextView text2 = view.findViewById(android.R.id.text2); text1.setText(route.getName()); text1.setText(route.getName()); CharSequence description = route.getDescription(); CharSequence description = route.getDescription(); if (TextUtils.isEmpty(description)) { if (TextUtils.isEmpty(description)) { Loading Loading
core/java/com/android/internal/app/MediaRouteChooserContentManager.java 0 → 100644 +56 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2025 The Android Open Source Project * * 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 com.android.internal.app; import android.content.Context; import android.view.Gravity; import android.view.View; import android.widget.LinearLayout; import android.widget.ListView; import com.android.internal.R; public class MediaRouteChooserContentManager { Context mContext; private final boolean mShowProgressBarWhenEmpty; public MediaRouteChooserContentManager(Context context, boolean showProgressBarWhenEmpty) { mContext = context; mShowProgressBarWhenEmpty = showProgressBarWhenEmpty; } /** * Starts binding all the views (list view, empty view, etc.) using the * given container view. */ public void bindViews(View containerView) { View emptyView = containerView.findViewById(android.R.id.empty); ListView listView = containerView.findViewById(R.id.media_route_list); listView.setEmptyView(emptyView); if (!mShowProgressBarWhenEmpty) { containerView.findViewById(R.id.media_route_progress_bar).setVisibility(View.GONE); // Center the empty view when the progress bar is not shown. LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) emptyView.getLayoutParams(); params.gravity = Gravity.CENTER; emptyView.setLayoutParams(params); } } }
core/java/com/android/internal/app/MediaRouteChooserDialog.java +13 −24 Original line number Original line Diff line number Diff line Loading @@ -23,14 +23,12 @@ import android.media.MediaRouter.RouteInfo; import android.os.Bundle; import android.os.Bundle; import android.text.TextUtils; import android.text.TextUtils; import android.util.TypedValue; import android.util.TypedValue; import android.view.Gravity; import android.view.LayoutInflater; import android.view.LayoutInflater; import android.view.View; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.ListView; import android.widget.TextView; import android.widget.TextView; Loading @@ -52,15 +50,15 @@ import java.util.Comparator; public class MediaRouteChooserDialog extends AlertDialog { public class MediaRouteChooserDialog extends AlertDialog { private final MediaRouter mRouter; private final MediaRouter mRouter; private final MediaRouterCallback mCallback; private final MediaRouterCallback mCallback; private final boolean mShowProgressBarWhenEmpty; private int mRouteTypes; private int mRouteTypes; private View.OnClickListener mExtendedSettingsClickListener; private View.OnClickListener mExtendedSettingsClickListener; private RouteAdapter mAdapter; private RouteAdapter mAdapter; private ListView mListView; private Button mExtendedSettingsButton; private Button mExtendedSettingsButton; private boolean mAttachedToWindow; private boolean mAttachedToWindow; private final MediaRouteChooserContentManager mContentManager; public MediaRouteChooserDialog(Context context, int theme) { public MediaRouteChooserDialog(Context context, int theme) { this(context, theme, true); this(context, theme, true); } } Loading @@ -70,7 +68,7 @@ public class MediaRouteChooserDialog extends AlertDialog { mRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE); mRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE); mCallback = new MediaRouterCallback(); mCallback = new MediaRouterCallback(); mShowProgressBarWhenEmpty = showProgressBarWhenEmpty; mContentManager = new MediaRouteChooserContentManager(context, showProgressBarWhenEmpty); } } /** /** Loading Loading @@ -128,8 +126,9 @@ public class MediaRouteChooserDialog extends AlertDialog { @Override @Override protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) { // Note: setView must be called before super.onCreate(). // Note: setView must be called before super.onCreate(). setView(LayoutInflater.from(getContext()).inflate(R.layout.media_route_chooser_dialog, View containerView = LayoutInflater.from(getContext()).inflate( null)); R.layout.media_route_chooser_dialog, null); setView(containerView); setTitle(mRouteTypes == MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY setTitle(mRouteTypes == MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY ? R.string.media_route_chooser_title_for_remote_display ? R.string.media_route_chooser_title_for_remote_display Loading @@ -140,25 +139,15 @@ public class MediaRouteChooserDialog extends AlertDialog { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); View emptyView = findViewById(android.R.id.empty); mAdapter = new RouteAdapter(getContext()); mAdapter = new RouteAdapter(getContext()); mListView = (ListView) findViewById(R.id.media_route_list); ListView listView = findViewById(R.id.media_route_list); mListView.setAdapter(mAdapter); listView.setAdapter(mAdapter); mListView.setOnItemClickListener(mAdapter); listView.setOnItemClickListener(mAdapter); mListView.setEmptyView(emptyView); mExtendedSettingsButton = (Button) findViewById(R.id.media_route_extended_settings_button); mExtendedSettingsButton = findViewById(R.id.media_route_extended_settings_button); updateExtendedSettingsButton(); updateExtendedSettingsButton(); if (!mShowProgressBarWhenEmpty) { mContentManager.bindViews(containerView); findViewById(R.id.media_route_progress_bar).setVisibility(View.GONE); // Center the empty view when the progress bar is not shown. LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) emptyView.getLayoutParams(); params.gravity = Gravity.CENTER; emptyView.setLayoutParams(params); } } } private void updateExtendedSettingsButton() { private void updateExtendedSettingsButton() { Loading Loading @@ -240,8 +229,8 @@ public class MediaRouteChooserDialog extends AlertDialog { view = mInflater.inflate(R.layout.media_route_list_item, parent, false); view = mInflater.inflate(R.layout.media_route_list_item, parent, false); } } MediaRouter.RouteInfo route = getItem(position); MediaRouter.RouteInfo route = getItem(position); TextView text1 = (TextView)view.findViewById(android.R.id.text1); TextView text1 = view.findViewById(android.R.id.text1); TextView text2 = (TextView)view.findViewById(android.R.id.text2); TextView text2 = view.findViewById(android.R.id.text2); text1.setText(route.getName()); text1.setText(route.getName()); CharSequence description = route.getDescription(); CharSequence description = route.getDescription(); if (TextUtils.isEmpty(description)) { if (TextUtils.isEmpty(description)) { Loading