From ad2aa95e9bd7050553ae49c557d453fd6f7bd616 Mon Sep 17 00:00:00 2001 From: Cliff Chung <116232729+cliffamzn@users.noreply.github.com> Date: Thu, 2 Mar 2023 16:08:55 -0800 Subject: [PATCH] Making UI a bit nicer on Android TV Casting App (#116) This change fixes a bug in the layout of the commissioning page and also makes the list items look more like buttons --- .../app/CommissionerDiscoveryFragment.java | 62 ++++++++++--------- .../chip/casting/app/ConnectionFragment.java | 6 +- .../commissionable_player_list_item.xml | 8 +-- .../fragment_commissioner_discovery.xml | 9 +-- 4 files changed, 42 insertions(+), 43 deletions(-) diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CommissionerDiscoveryFragment.java b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CommissionerDiscoveryFragment.java index 1d26cade69324a..1a28cefcf7bcd2 100644 --- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CommissionerDiscoveryFragment.java +++ b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CommissionerDiscoveryFragment.java @@ -11,7 +11,6 @@ import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; -import android.widget.TextView; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import com.chip.casting.DiscoveredNodeData; @@ -76,18 +75,10 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { View.OnClickListener manualCommissioningButtonOnClickListener = v -> callback.handleCommissioningButtonClicked(null); manualCommissioningButton.setOnClickListener(manualCommissioningButtonOnClickListener); - ArrayAdapter arrayAdapter = - new VideoPlayerCommissionerAdapter(getActivity(), commissionerVideoPlayerList); + + ArrayAdapter arrayAdapter = new VideoPlayerCommissionerAdapter(getActivity(), commissionerVideoPlayerList); final ListView list = getActivity().findViewById(R.id.commissionerList); list.setAdapter(arrayAdapter); - list.setOnItemClickListener( - (parent, view1, position, id) -> { - DiscoveredNodeData discoveredNodeData = - (DiscoveredNodeData) parent.getItemAtPosition(position); - Log.d(TAG, "OnItemClickListener.onClick called for " + discoveredNodeData); - Callback callback1 = (Callback) getActivity(); - callback1.handleCommissioningButtonClicked(discoveredNodeData); - }); this.successCallback = new SuccessCallback() { @@ -156,24 +147,37 @@ public interface Callback { } class VideoPlayerCommissionerAdapter extends ArrayAdapter { - private final List playerList; - private LayoutInflater inflater; - - public VideoPlayerCommissionerAdapter( - Context applicationContext, List playerList) { - super(applicationContext, 0, playerList); - this.playerList = playerList; - inflater = (LayoutInflater.from(applicationContext)); - } - - @Override - public View getView(int i, View view, ViewGroup viewGroup) { - view = inflater.inflate(R.layout.commissionable_player_list_item, null); - String buttonText = getCommissionerButtonText(playerList.get(i)); - TextView playerDescription = view.findViewById(R.id.commissionable_player_description); - playerDescription.setText(buttonText); - return view; - } + private final List playerList; + private final Context context; + private LayoutInflater inflater; + private static final String TAG = VideoPlayerCommissionerAdapter.class.getSimpleName(); + + public VideoPlayerCommissionerAdapter(Context context, List playerList) { + super(context, 0, playerList); + this.context = context; + this.playerList = playerList; + inflater = (LayoutInflater.from(context)); + } + + @Override + public View getView(int i, View view, ViewGroup viewGroup) { + view = inflater.inflate(R.layout.commissionable_player_list_item, null); + String buttonText = getCommissionerButtonText(playerList.get(i)); + Button playerDescription = view.findViewById(R.id.commissionable_player_description); + playerDescription.setText(buttonText); + View.OnClickListener clickListener = v -> { + DiscoveredNodeData discoveredNodeData = playerList.get(i); + Log.d( + TAG, + "OnItemClickListener.onClick called for " + + discoveredNodeData); + CommissionerDiscoveryFragment.Callback callback1 = + (CommissionerDiscoveryFragment.Callback) context; + callback1.handleCommissioningButtonClicked(discoveredNodeData); + }; + playerDescription.setOnClickListener(clickListener); + return view; + } private String getCommissionerButtonText(DiscoveredNodeData commissioner) { String main = commissioner.getDeviceName() != null ? commissioner.getDeviceName() : ""; diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ConnectionFragment.java b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ConnectionFragment.java index c48b28974ef22e..4f090b20e9ef20 100644 --- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ConnectionFragment.java +++ b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ConnectionFragment.java @@ -25,7 +25,6 @@ public class ConnectionFragment extends Fragment { private final TvCastingApp tvCastingApp; private final DiscoveredNodeData selectedCommissioner; - private boolean verifyOrEstablishConnectionSuccess; private boolean openCommissioningWindowSuccess; private boolean sendUdcSuccess; @@ -83,9 +82,8 @@ public void handle(ContentApp contentApp) { if (selectedCommissioner != null && selectedCommissioner.isPreCommissioned()) { VideoPlayer videoPlayer = selectedCommissioner.toConnectableVideoPlayer(); Log.d(TAG, "Calling verifyOrEstablishConnectionSuccess with VideoPlayer: " + videoPlayer); - this.verifyOrEstablishConnectionSuccess = - tvCastingApp.verifyOrEstablishConnection( - videoPlayer, onConnectionSuccess, onConnectionFailure, onNewOrUpdatedEndpoints); + tvCastingApp.verifyOrEstablishConnection( + videoPlayer, onConnectionSuccess, onConnectionFailure, onNewOrUpdatedEndpoints); } else { Log.d(TAG, "Running commissioning"); this.openCommissioningWindowSuccess = diff --git a/examples/tv-casting-app/android/App/app/src/main/res/layout/commissionable_player_list_item.xml b/examples/tv-casting-app/android/App/app/src/main/res/layout/commissionable_player_list_item.xml index 979093e5efb8d8..a3adc515f19184 100644 --- a/examples/tv-casting-app/android/App/app/src/main/res/layout/commissionable_player_list_item.xml +++ b/examples/tv-casting-app/android/App/app/src/main/res/layout/commissionable_player_list_item.xml @@ -3,14 +3,10 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:padding="10dp" /> \ No newline at end of file diff --git a/examples/tv-casting-app/android/App/app/src/main/res/layout/fragment_commissioner_discovery.xml b/examples/tv-casting-app/android/App/app/src/main/res/layout/fragment_commissioner_discovery.xml index b9645a288d6449..7cfdf23b0b335b 100644 --- a/examples/tv-casting-app/android/App/app/src/main/res/layout/fragment_commissioner_discovery.xml +++ b/examples/tv-casting-app/android/App/app/src/main/res/layout/fragment_commissioner_discovery.xml @@ -7,8 +7,8 @@ + android:layout_width = "match_parent" + android:layout_height = "wrap_content" + android:fadeScrollbars = "false" />