Skip to content

Commit

Permalink
Android tv-casting-app v1.3 Commissioner-Generated passcode flow (pro…
Browse files Browse the repository at this point in the history
…ject-chip#33680)

* Android tv-casting-app v1.3 Commissioner-Generated passcode flow

* Fixing style issues

* Fixing style issues 2

* Addressed comments by sharadb-amazon

* Fixing style issue

* Addressed comments by sharadb-amazon part 2

* Addressed comments by sharadb-amazon part3

* Addressed comments by sharadb-amazon and fix Darwin compile issue
  • Loading branch information
pgregorr-amazon authored Jun 5, 2024
1 parent 2005be9 commit d3cac0c
Show file tree
Hide file tree
Showing 37 changed files with 1,642 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ public void handleCommissioningButtonClicked(DiscoveredNodeData commissioner) {
}

@Override
public void handleConnectionButtonClicked(CastingPlayer castingPlayer) {
Log.i(TAG, "MainActivity.handleConnectionButtonClicked() called");
showFragment(ConnectionExampleFragment.newInstance(castingPlayer));
public void handleConnectionButtonClicked(
CastingPlayer castingPlayer, boolean useCommissionerGeneratedPasscode) {
Log.i(TAG, "MainActivity.handleConnectionButtonClicked()");
showFragment(
ConnectionExampleFragment.newInstance(castingPlayer, useCommissionerGeneratedPasscode));
}

@Override
Expand All @@ -77,26 +79,35 @@ public void handleCommissioningComplete() {
}

@Override
public void handleConnectionComplete(CastingPlayer castingPlayer) {
Log.i(TAG, "MainActivity.handleConnectionComplete() called ");
showFragment(ActionSelectorFragment.newInstance(castingPlayer));
public void handleConnectionComplete(
CastingPlayer castingPlayer, boolean useCommissionerGeneratedPasscode) {
Log.i(TAG, "MainActivity.handleConnectionComplete()");
showFragment(
ActionSelectorFragment.newInstance(castingPlayer, useCommissionerGeneratedPasscode));
}

@Override
public void handleContentLauncherLaunchURLSelected(CastingPlayer selectedCastingPlayer) {
showFragment(ContentLauncherLaunchURLExampleFragment.newInstance(selectedCastingPlayer));
public void handleContentLauncherLaunchURLSelected(
CastingPlayer selectedCastingPlayer, boolean useCommissionerGeneratedPasscode) {
showFragment(
ContentLauncherLaunchURLExampleFragment.newInstance(
selectedCastingPlayer, useCommissionerGeneratedPasscode));
}

@Override
public void handleApplicationBasicReadVendorIDSelected(CastingPlayer selectedCastingPlayer) {
showFragment(ApplicationBasicReadVendorIDExampleFragment.newInstance(selectedCastingPlayer));
public void handleApplicationBasicReadVendorIDSelected(
CastingPlayer selectedCastingPlayer, boolean useCommissionerGeneratedPasscode) {
showFragment(
ApplicationBasicReadVendorIDExampleFragment.newInstance(
selectedCastingPlayer, useCommissionerGeneratedPasscode));
}

@Override
public void handleMediaPlaybackSubscribeToCurrentStateSelected(
CastingPlayer selectedCastingPlayer) {
CastingPlayer selectedCastingPlayer, boolean useCommissionerGeneratedPasscode) {
showFragment(
MediaPlaybackSubscribeToCurrentStateExampleFragment.newInstance(selectedCastingPlayer));
MediaPlaybackSubscribeToCurrentStateExampleFragment.newInstance(
selectedCastingPlayer, useCommissionerGeneratedPasscode));
}

@Override
Expand Down Expand Up @@ -148,7 +159,10 @@ private boolean initJni() {
private void showFragment(Fragment fragment, boolean showOnBack) {
Log.d(
TAG,
"showFragment() called with " + fragment.getClass().getSimpleName() + " and " + showOnBack);
"showFragment() called with: "
+ fragment.getClass().getSimpleName()
+ ", and showOnBack: "
+ showOnBack);
FragmentTransaction fragmentTransaction =
getSupportFragmentManager()
.beginTransaction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,31 @@ public class ActionSelectorFragment extends Fragment {
private static final String TAG = ActionSelectorFragment.class.getSimpleName();

private final CastingPlayer selectedCastingPlayer;
private final boolean useCommissionerGeneratedPasscode;

private View.OnClickListener selectContentLauncherButtonClickListener;
private View.OnClickListener selectApplicationBasicButtonClickListener;
private View.OnClickListener selectMediaPlaybackButtonClickListener;
private View.OnClickListener disconnectButtonClickListener;

public ActionSelectorFragment(CastingPlayer selectedCastingPlayer) {
public ActionSelectorFragment(
CastingPlayer selectedCastingPlayer, boolean useCommissionerGeneratedPasscode) {
this.selectedCastingPlayer = selectedCastingPlayer;
this.useCommissionerGeneratedPasscode = useCommissionerGeneratedPasscode;
}

/**
* Use this factory method to create a new instance of this fragment using the provided
* parameters.
*
* @param selectedCastingPlayer CastingPlayer that the casting app connected to
* @param useCommissionerGeneratedPasscode Boolean indicating whether this CastingPlayer was
* commissioned using the Commissioner-Generated passcode commissioning flow.
* @return A new instance of fragment SelectActionFragment.
*/
public static ActionSelectorFragment newInstance(CastingPlayer selectedCastingPlayer) {
return new ActionSelectorFragment(selectedCastingPlayer);
public static ActionSelectorFragment newInstance(
CastingPlayer selectedCastingPlayer, boolean useCommissionerGeneratedPasscode) {
return new ActionSelectorFragment(selectedCastingPlayer, useCommissionerGeneratedPasscode);
}

@Override
Expand All @@ -64,17 +70,20 @@ public View onCreateView(
this.selectContentLauncherButtonClickListener =
v -> {
Log.d(TAG, "handle() called on selectContentLauncherButtonClickListener");
callback.handleContentLauncherLaunchURLSelected(selectedCastingPlayer);
callback.handleContentLauncherLaunchURLSelected(
selectedCastingPlayer, useCommissionerGeneratedPasscode);
};
this.selectApplicationBasicButtonClickListener =
v -> {
Log.d(TAG, "handle() called on selectApplicationBasicButtonClickListener");
callback.handleApplicationBasicReadVendorIDSelected(selectedCastingPlayer);
callback.handleApplicationBasicReadVendorIDSelected(
selectedCastingPlayer, useCommissionerGeneratedPasscode);
};
this.selectMediaPlaybackButtonClickListener =
v -> {
Log.d(TAG, "handle() called on selectMediaPlaybackButtonClickListener");
callback.handleMediaPlaybackSubscribeToCurrentStateSelected(selectedCastingPlayer);
callback.handleMediaPlaybackSubscribeToCurrentStateSelected(
selectedCastingPlayer, useCommissionerGeneratedPasscode);
};

this.disconnectButtonClickListener =
Expand Down Expand Up @@ -107,13 +116,16 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
/** Interface for notifying the host. */
public interface Callback {
/** Notifies listener to trigger transition on selection of Content Launcher cluster */
void handleContentLauncherLaunchURLSelected(CastingPlayer selectedCastingPlayer);
void handleContentLauncherLaunchURLSelected(
CastingPlayer selectedCastingPlayer, boolean useCommissionerGeneratedPasscode);

/** Notifies listener to trigger transition on selection of Application Basic cluster */
void handleApplicationBasicReadVendorIDSelected(CastingPlayer selectedCastingPlayer);
void handleApplicationBasicReadVendorIDSelected(
CastingPlayer selectedCastingPlayer, boolean useCommissionerGeneratedPasscode);

/** Notifies listener to trigger transition on selection of Media PLayback cluster */
void handleMediaPlaybackSubscribeToCurrentStateSelected(CastingPlayer selectedCastingPlayer);
void handleMediaPlaybackSubscribeToCurrentStateSelected(
CastingPlayer selectedCastingPlayer, boolean useCommissionerGeneratedPasscode);

/** Notifies listener to trigger transition on click of the Disconnect button */
void handleDisconnect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,32 @@
public class ApplicationBasicReadVendorIDExampleFragment extends Fragment {
private static final String TAG =
ApplicationBasicReadVendorIDExampleFragment.class.getSimpleName();
private static final int DEFAULT_ENDPOINT_ID_FOR_CGP_FLOW = 1;

private final CastingPlayer selectedCastingPlayer;
private final boolean useCommissionerGeneratedPasscode;

private View.OnClickListener readButtonClickListener;

public ApplicationBasicReadVendorIDExampleFragment(CastingPlayer selectedCastingPlayer) {
public ApplicationBasicReadVendorIDExampleFragment(
CastingPlayer selectedCastingPlayer, boolean useCommissionerGeneratedPasscode) {
this.selectedCastingPlayer = selectedCastingPlayer;
this.useCommissionerGeneratedPasscode = useCommissionerGeneratedPasscode;
}

/**
* Use this factory method to create a new instance of this fragment using the provided
* parameters.
*
* @param selectedCastingPlayer CastingPlayer that the casting app connected to
* @param selectedCastingPlayer CastingPlayer that the casting app connected to.
* @param useCommissionerGeneratedPasscode Boolean indicating whether this CastingPlayer was
* commissioned using the Commissioner-Generated Passcode (CGP) commissioning flow.
* @return A new instance of fragment ApplicationBasicReadVendorIDExampleFragment.
*/
public static ApplicationBasicReadVendorIDExampleFragment newInstance(
CastingPlayer selectedCastingPlayer) {
return new ApplicationBasicReadVendorIDExampleFragment(selectedCastingPlayer);
CastingPlayer selectedCastingPlayer, boolean useCommissionerGeneratedPasscode) {
return new ApplicationBasicReadVendorIDExampleFragment(
selectedCastingPlayer, useCommissionerGeneratedPasscode);
}

@Override
Expand All @@ -68,8 +75,14 @@ public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
this.readButtonClickListener =
v -> {
Endpoint endpoint =
EndpointSelectorExample.selectFirstEndpointByVID(selectedCastingPlayer);
Endpoint endpoint;
if (useCommissionerGeneratedPasscode) {
endpoint =
EndpointSelectorExample.selectEndpointById(
selectedCastingPlayer, DEFAULT_ENDPOINT_ID_FOR_CGP_FLOW);
} else {
endpoint = EndpointSelectorExample.selectFirstEndpointByVID(selectedCastingPlayer);
}
if (endpoint == null) {
Log.e(TAG, "No Endpoint with sample vendorID found on CastingPlayer");
return;
Expand Down
Loading

0 comments on commit d3cac0c

Please sign in to comment.