Skip to content

Commit

Permalink
Android tv-casting-app v1.3 Commissioner-Generated passcode flow
Browse files Browse the repository at this point in the history
  • Loading branch information
pgregorr-amazon committed May 31, 2024
1 parent 174f2a0 commit 8513ebe
Show file tree
Hide file tree
Showing 35 changed files with 1,379 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ 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() useCommissionerGeneratedPasscode: "
+ useCommissionerGeneratedPasscode);
showFragment(
ConnectionExampleFragment.newInstance(castingPlayer, useCommissionerGeneratedPasscode));
}

@Override
Expand All @@ -77,26 +82,38 @@ 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() useCommissionerGeneratedPasscode: "
+ useCommissionerGeneratedPasscode);
showFragment(
ActionSelectorFragment.newInstance(castingPlayer, useCommissionerGeneratedPasscode));
}

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

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

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

@Override
Expand Down Expand Up @@ -148,7 +165,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 commissionerGeneratedPasscodeExample;

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 commissionerGeneratedPasscodeExample) {
this.selectedCastingPlayer = selectedCastingPlayer;
this.commissionerGeneratedPasscodeExample = commissionerGeneratedPasscodeExample;
}

/**
* 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 commissionerGeneratedPasscodeExample 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 commissionerGeneratedPasscodeExample) {
return new ActionSelectorFragment(selectedCastingPlayer, commissionerGeneratedPasscodeExample);
}

@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, commissionerGeneratedPasscodeExample);
};
this.selectApplicationBasicButtonClickListener =
v -> {
Log.d(TAG, "handle() called on selectApplicationBasicButtonClickListener");
callback.handleApplicationBasicReadVendorIDSelected(selectedCastingPlayer);
callback.handleApplicationBasicReadVendorIDSelected(
selectedCastingPlayer, commissionerGeneratedPasscodeExample);
};
this.selectMediaPlaybackButtonClickListener =
v -> {
Log.d(TAG, "handle() called on selectMediaPlaybackButtonClickListener");
callback.handleMediaPlaybackSubscribeToCurrentStateSelected(selectedCastingPlayer);
callback.handleMediaPlaybackSubscribeToCurrentStateSelected(
selectedCastingPlayer, commissionerGeneratedPasscodeExample);
};

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 commissionerGeneratedPasscodeExample);

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

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

/** 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 @@ -39,11 +39,14 @@ public class ApplicationBasicReadVendorIDExampleFragment extends Fragment {
ApplicationBasicReadVendorIDExampleFragment.class.getSimpleName();

private final CastingPlayer selectedCastingPlayer;
private final Boolean commissionerGeneratedPasscodeExample;

private View.OnClickListener readButtonClickListener;

public ApplicationBasicReadVendorIDExampleFragment(CastingPlayer selectedCastingPlayer) {
public ApplicationBasicReadVendorIDExampleFragment(
CastingPlayer selectedCastingPlayer, Boolean commissionerGeneratedPasscodeExample) {
this.selectedCastingPlayer = selectedCastingPlayer;
this.commissionerGeneratedPasscodeExample = commissionerGeneratedPasscodeExample;
}

/**
Expand All @@ -54,8 +57,9 @@ public ApplicationBasicReadVendorIDExampleFragment(CastingPlayer selectedCasting
* @return A new instance of fragment ApplicationBasicReadVendorIDExampleFragment.
*/
public static ApplicationBasicReadVendorIDExampleFragment newInstance(
CastingPlayer selectedCastingPlayer) {
return new ApplicationBasicReadVendorIDExampleFragment(selectedCastingPlayer);
CastingPlayer selectedCastingPlayer, Boolean commissionerGeneratedPasscodeExample) {
return new ApplicationBasicReadVendorIDExampleFragment(
selectedCastingPlayer, commissionerGeneratedPasscodeExample);
}

@Override
Expand All @@ -68,8 +72,12 @@ public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
this.readButtonClickListener =
v -> {
Endpoint endpoint =
EndpointSelectorExample.selectFirstEndpointByVID(selectedCastingPlayer);
Endpoint endpoint;
if (commissionerGeneratedPasscodeExample) {
endpoint = EndpointSelectorExample.selectFirstEndpoint(selectedCastingPlayer);
} 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 8513ebe

Please sign in to comment.