Skip to content

Commit 01a26df

Browse files
android/tv-casting-app: Implemented commands and attributes using CHIPInteractionClient.jar
1 parent 6ba907e commit 01a26df

20 files changed

+808
-39
lines changed

examples/tv-casting-app/APIs.md

+148-7
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ func connect(selectedCastingPlayer: MCCastingPlayer?) {
830830
### Select an Endpoint on the Casting Player
831831
832832
_{Complete Endpoint selection examples: [Linux](linux/simple-app-helper.cpp) |
833-
[Android](android/App/app/src/main/java/com/matter/casting/ContentLauncherLaunchURLExampleFragment.java)
833+
[Android](android/App/app/src/main/java/com/matter/casting/EndpointSelectorExample.java)
834834
|
835835
[iOS](darwin/TvCasting/TvCasting/MCContentLauncherLaunchURLExampleViewModel.swift)}_
836836
@@ -905,18 +905,25 @@ Once the Casting Client has selected an `Endpoint`, it is ready to
905905
[issue commands](#issuing-commands) to it, [read](#read-operations) current
906906
playback state, and [subscribe](#subscriptions) to playback events.
907907
908-
On Linux refer to the following platform specific files:
908+
Refer to the following platform specific files, to find the list of clusters,
909+
commands and attributes, with their request/response types available for use
910+
with the Matter TV Casting library.
911+
912+
For Linux, refer to the following files:
909913
910-
1. For a list of clusters, commands and attributes supported by the Matter TV
911-
Casting library:
914+
1. For a list of supported clusters, commands and attributes:
912915
[tv-casting-common/clusters/Clusters.h](tv-casting-common/clusters/Clusters.h)
913916
2. For the IDs and request / response types to use with these APIs:
914917
[/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h](/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h)
915918
916-
On iOS refer to the following platform specific files:
919+
For Android, refer to the following files:
920+
921+
1. For a list of supported clusters, commands and attributes:
922+
[/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java](/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java)
917923
918-
1. For a list of clusters, commands and attributes supported by the Matter TV
919-
Casting library:
924+
On iOS, refer to the following files:
925+
926+
1. For a list of supported clusters, commands and attribute:
920927
[darwin/MatterTvCastingBridge/MatterTvCastingBridge/zap-generated/MCClusterObjects.h](darwin/MatterTvCastingBridge/MatterTvCastingBridge/zap-generated/MCClusterObjects.h)
921928
2. For the IDs and request / response types to use with the commands:
922929
[darwin/MatterTvCastingBridge/MatterTvCastingBridge/zap-generated/MCCommandObjects.h](darwin/MatterTvCastingBridge/MatterTvCastingBridge/zap-generated/MCCommandObjects.h)
@@ -929,6 +936,8 @@ On iOS refer to the following platform specific files:
929936
### Issuing Commands
930937
931938
_{Complete Command invocation examples: [Linux](linux/simple-app-helper.cpp) |
939+
[Android](android/App/app/src/main/java/com/matter/casting/ContentLauncherLaunchURLExampleFragment.java)
940+
|
932941
[iOS](darwin/TvCasting/TvCasting/MCContentLauncherLaunchURLExampleViewModel.swift)}_
933942
934943
The Casting Client can get a reference to an `Endpoint` on a `CastingPlayer`,
@@ -975,6 +984,51 @@ void InvokeContentLauncherLaunchURL(matter::casting::memory::Strong<matter::cast
975984
}
976985
```
977986
987+
On Android, given an `Endpoint`, it can send a `LaunchURL` command (part of the
988+
Content Launcher cluster) by calling the `launchURL` API on a
989+
`ChipClusters.ContentLauncherCluster` object.
990+
991+
```java
992+
// get ChipClusters.ContentLauncherCluster from the endpoint
993+
ChipClusters.ContentLauncherCluster cluster =
994+
endpoint.getCluster(ChipClusters.ContentLauncherCluster.class);
995+
if (cluster == null) {
996+
Log.e(TAG, "Could not get ContentLauncherCluster for endpoint with ID: " + endpoint.getId());
997+
return;
998+
}
999+
1000+
// call launchURL on the cluster object while passing in a
1001+
// ChipClusters.ContentLauncherCluster.LauncherResponseCallback and request parameters
1002+
cluster.launchURL(
1003+
new ChipClusters.ContentLauncherCluster.LauncherResponseCallback() {
1004+
@Override
1005+
public void onSuccess(Integer status, Optional<String> data) {
1006+
Log.d(TAG, "LaunchURL success. Status: " + status + ", Data: " + data);
1007+
new Handler(Looper.getMainLooper())
1008+
.post(
1009+
() -> {
1010+
TextView launcherResult = getView().findViewById(R.id.launcherResult);
1011+
launcherResult.setText(
1012+
"LaunchURL result\nStatus: " + status + ", Data: " + data);
1013+
});
1014+
}
1015+
1016+
@Override
1017+
public void onError(Exception error) {
1018+
Log.e(TAG, "LaunchURL failure " + error);
1019+
new Handler(Looper.getMainLooper())
1020+
.post(
1021+
() -> {
1022+
TextView launcherResult = getView().findViewById(R.id.launcherResult);
1023+
launcherResult.setText("LaunchURL result\nError: " + error);
1024+
});
1025+
}
1026+
},
1027+
contentUrl,
1028+
Optional.of(contentDisplayString),
1029+
Optional.empty());
1030+
```
1031+
9781032
On iOS, given an `MCEndpoint` endpoint, it can send a `LaunchURL` command (part
9791033
of the Content Launcher cluster) by calling the `invoke` API on a
9801034
`MCContentLauncherClusterLaunchURLCommand`
@@ -1033,6 +1087,8 @@ timedInvokeTimeoutMs: 5000) // time out after 5000ms
10331087
### Read Operations
10341088
10351089
_{Complete Attribute Read examples: [Linux](linux/simple-app-helper.cpp) |
1090+
[Android](android/App/app/src/main/java/com/matter/casting/ApplicationBasicReadVendorIDExampleFragment.java)
1091+
|
10361092
[iOS](darwin/TvCasting/TvCasting/MCApplicationBasicReadVendorIDExampleViewModel.swift)}_
10371093
10381094
The `CastingClient` may read an Attribute from the `Endpoint` on the
@@ -1080,6 +1136,45 @@ void ReadApplicationBasicVendorID(matter::casting::memory::Strong<matter::castin
10801136
}
10811137
```
10821138
1139+
On Android, given an `Endpoint`, the `VendorID` can be read, by calling
1140+
`readVendorIDAttribute` on the `ChipClusters.ApplicationBasicCluster` object.
1141+
1142+
```java
1143+
// get ChipClusters.ApplicationBasic from the endpoint
1144+
ChipClusters.ApplicationBasicCluster cluster = endpoint.getCluster(ChipClusters.ApplicationBasicCluster.class);
1145+
if (cluster == null) {
1146+
Log.e(TAG, "Could not get ApplicationBasicCluster for endpoint with ID: " + endpoint.getId());
1147+
return;
1148+
}
1149+
1150+
// call readVendorIDAttribute on the cluster object while passing in a
1151+
// ChipClusters.IntegerAttributeCallback
1152+
cluster.readVendorIDAttribute(new ChipClusters.IntegerAttributeCallback() {
1153+
@Override
1154+
public void onSuccess(int value) {
1155+
Log.d(TAG, "ReadVendorID success. Value: " + value);
1156+
new Handler(Looper.getMainLooper())
1157+
.post(
1158+
() -> {
1159+
TextView vendorIdResult = getView().findViewById(R.id.vendorIdResult);
1160+
vendorIdResult.setText(
1161+
"Read VendorID result\nValue: " + value );
1162+
});
1163+
}
1164+
1165+
@Override
1166+
public void onError(Exception error) {
1167+
Log.e(TAG, "ReadVendorID failure " + error);
1168+
new Handler(Looper.getMainLooper())
1169+
.post(
1170+
() -> {
1171+
TextView vendorIdResult = getView().findViewById(R.id.vendorIdResult);
1172+
vendorIdResult.setText("Read VendorID result\nError: " + error);
1173+
});
1174+
}
1175+
});
1176+
```
1177+
10831178
On iOS, given a `MCEndpoint`, the `VendorID` can be read similarly, by calling
10841179
the `read` API on the `MCApplicationBasicClusterVendorIDAttribute`
10851180
@@ -1138,6 +1233,9 @@ vendorIDAttribute!.read(nil) { context, before, after, err in
11381233
### Subscriptions
11391234
11401235
_{Complete Attribute subscription examples: [Linux](linux/simple-app-helper.cpp)
1236+
|
1237+
[Android](android/App/app/src/main/java/com/matter/casting/MediaPlaybackSubscribeToCurrentStateExampleFragment.java)
1238+
|
11411239
|[iOS](darwin/TvCasting/TvCasting/MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift)}_
11421240
11431241
A Casting Client may subscribe to an attribute on an `Endpoint` of the
@@ -1187,6 +1285,49 @@ void SubscribeToMediaPlaybackCurrentState(matter::casting::memory::Strong<matter
11871285
}
11881286
```
11891287
1288+
On Android, given an `Endpoint`, `CurrentState` can be subscribe to by calling
1289+
`subscribeCurrentStateAttribute` on a `ChipClusters.MediaPlaybackCluster`
1290+
object.
1291+
1292+
```java
1293+
// get ChipClusters.MediaPlaybackCluster from the endpoint
1294+
ChipClusters.MediaPlaybackCluster cluster =
1295+
endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class);
1296+
if (cluster == null) {
1297+
Log.e(
1298+
TAG,
1299+
"Could not get ApplicationBasicCluster for endpoint with ID: " + endpoint.getId());
1300+
return;
1301+
}
1302+
1303+
// call subscribeCurrentStateAttribute on the cluster object while passing in a
1304+
// ChipClusters.IntegerAttributeCallback and [0, 1] for min and max interval params
1305+
cluster.subscribeCurrentStateAttribute(new ChipClusters.IntegerAttributeCallback() {
1306+
@Override
1307+
public void onSuccess(int value) {
1308+
Log.d(TAG, "Read success on subscription. Value: " + value + " @ " + new Date());
1309+
new Handler(Looper.getMainLooper())
1310+
.post(
1311+
() -> {
1312+
TextView currentStateResult = getView().findViewById(R.id.currentStateResult);
1313+
currentStateResult.setText(
1314+
"Current State result\nValue: " + value );
1315+
});
1316+
}
1317+
1318+
@Override
1319+
public void onError(Exception error) {
1320+
Log.e(TAG, "Read failure on subscription: " + error);
1321+
new Handler(Looper.getMainLooper())
1322+
.post(
1323+
() -> {
1324+
TextView currentStateResult = getView().findViewById(R.id.currentStateResult);
1325+
currentStateResult.setText("Current State result\nError: " + error);
1326+
});
1327+
}
1328+
}, 0, 1);
1329+
```
1330+
11901331
On iOS, given a `MCEndpoint`, `CurrentState` can be subscribed to by calling the
11911332
`subscribe` API on the it can subscribe to the `CurrentState` (part of the Media
11921333
Playback Basic cluster) by calling the `Subscribe` API on the

examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MainActivity.java

+14
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
import com.chip.casting.TvCastingApp;
1212
import com.chip.casting.util.GlobalCastingConstants;
1313
import com.matter.casting.ActionSelectorFragment;
14+
import com.matter.casting.ApplicationBasicReadVendorIDExampleFragment;
1415
import com.matter.casting.ConnectionExampleFragment;
1516
import com.matter.casting.ContentLauncherLaunchURLExampleFragment;
1617
import com.matter.casting.DiscoveryExampleFragment;
1718
import com.matter.casting.InitializationExample;
19+
import com.matter.casting.MediaPlaybackSubscribeToCurrentStateExampleFragment;
1820
import com.matter.casting.PreferencesConfigurationManager;
1921
import com.matter.casting.core.CastingPlayer;
2022
import java.util.Random;
@@ -85,6 +87,18 @@ public void handleContentLauncherLaunchURLSelected(CastingPlayer selectedCasting
8587
showFragment(ContentLauncherLaunchURLExampleFragment.newInstance(selectedCastingPlayer));
8688
}
8789

90+
@Override
91+
public void handleApplicationBasicReadVendorIDSelected(CastingPlayer selectedCastingPlayer) {
92+
showFragment(ApplicationBasicReadVendorIDExampleFragment.newInstance(selectedCastingPlayer));
93+
}
94+
95+
@Override
96+
public void handleMediaPlaybackSubscribeToCurrentStateSelected(
97+
CastingPlayer selectedCastingPlayer) {
98+
showFragment(
99+
MediaPlaybackSubscribeToCurrentStateExampleFragment.newInstance(selectedCastingPlayer));
100+
}
101+
88102
@Override
89103
public void handleContentLauncherSelected() {
90104
showFragment(ContentLauncherFragment.newInstance(tvCastingApp));

examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/GlobalCastingConstants.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ public class GlobalCastingConstants {
66
public static final int SetupPasscode = 20202021;
77
public static final int Discriminator = 0xF00;
88
public static final boolean ChipCastingSimplified =
9-
false; // set this flag to true to demo simplified casting APIs
9+
true; // set this flag to true to demo simplified casting APIs
1010
}

examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/ActionSelectorFragment.java

+24
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class ActionSelectorFragment extends Fragment {
3333
private final CastingPlayer selectedCastingPlayer;
3434

3535
private View.OnClickListener selectContentLauncherButtonClickListener;
36+
private View.OnClickListener selectApplicationBasicButtonClickListener;
37+
private View.OnClickListener selectMediaPlaybackButtonClickListener;
3638
private View.OnClickListener disconnectButtonClickListener;
3739

3840
public ActionSelectorFragment(CastingPlayer selectedCastingPlayer) {
@@ -64,6 +66,16 @@ public View onCreateView(
6466
Log.d(TAG, "handle() called on selectContentLauncherButtonClickListener");
6567
callback.handleContentLauncherLaunchURLSelected(selectedCastingPlayer);
6668
};
69+
this.selectApplicationBasicButtonClickListener =
70+
v -> {
71+
Log.d(TAG, "handle() called on selectApplicationBasicButtonClickListener");
72+
callback.handleApplicationBasicReadVendorIDSelected(selectedCastingPlayer);
73+
};
74+
this.selectMediaPlaybackButtonClickListener =
75+
v -> {
76+
Log.d(TAG, "handle() called on selectMediaPlaybackButtonClickListener");
77+
callback.handleMediaPlaybackSubscribeToCurrentStateSelected(selectedCastingPlayer);
78+
};
6779

6880
this.disconnectButtonClickListener =
6981
v -> {
@@ -82,6 +94,12 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
8294
getView()
8395
.findViewById(R.id.selectContentLauncherLaunchURLButton)
8496
.setOnClickListener(selectContentLauncherButtonClickListener);
97+
getView()
98+
.findViewById(R.id.selectApplicationBasicReadVendorIDButton)
99+
.setOnClickListener(selectApplicationBasicButtonClickListener);
100+
getView()
101+
.findViewById(R.id.selectMediaPlaybackSubscribeToCurrentStateButton)
102+
.setOnClickListener(selectMediaPlaybackButtonClickListener);
85103

86104
getView().findViewById(R.id.disconnectButton).setOnClickListener(disconnectButtonClickListener);
87105
}
@@ -91,6 +109,12 @@ public interface Callback {
91109
/** Notifies listener to trigger transition on selection of Content Launcher cluster */
92110
void handleContentLauncherLaunchURLSelected(CastingPlayer selectedCastingPlayer);
93111

112+
/** Notifies listener to trigger transition on selection of Application Basic cluster */
113+
void handleApplicationBasicReadVendorIDSelected(CastingPlayer selectedCastingPlayer);
114+
115+
/** Notifies listener to trigger transition on selection of Media PLayback cluster */
116+
void handleMediaPlaybackSubscribeToCurrentStateSelected(CastingPlayer selectedCastingPlayer);
117+
94118
/** Notifies listener to trigger transition on click of the Disconnect button */
95119
void handleDisconnect();
96120
}

0 commit comments

Comments
 (0)