Skip to content

Commit b932800

Browse files
chrisdecenzorestyled-io[bot]restyled-commits
authored andcommitted
TV Android Sample App: Dialogs for new commissioning feedback and message cluster (project-chip#32281)
* Dialogs for new commissioning feedback and message cluster * Address comments * Restyle TV Android Sample App: Dialogs for new commissioning feedback and message cluster (project-chip#32282) * Restyled by whitespace * Restyled by google-java-format --------- Co-authored-by: Restyled.io <commits@restyled.io> --------- Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 3786192 commit b932800

File tree

10 files changed

+507
-90
lines changed

10 files changed

+507
-90
lines changed

examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MatterCommissioningPrompter.java

+253-58
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import androidx.appcompat.app.AlertDialog;
1313
import androidx.core.app.NotificationCompat;
1414
import com.matter.tv.server.service.MatterServant;
15+
import com.matter.tv.server.tvapp.Message;
1516
import com.matter.tv.server.tvapp.UserPrompter;
1617
import com.matter.tv.server.tvapp.UserPrompterResolver;
1718

@@ -26,6 +27,7 @@ public class MatterCommissioningPrompter extends UserPrompterResolver implements
2627
public MatterCommissioningPrompter(Context context) {
2728
this.context = context;
2829
this.createNotificationChannel();
30+
setUserPrompter(this);
2931
}
3032

3133
private Activity getActivity() {
@@ -34,7 +36,6 @@ private Activity getActivity() {
3436

3537
public void promptForCommissionOkPermission(
3638
int vendorId, int productId, String commissioneeName) {
37-
// TODO: find app by vendorId and productId
3839
Log.d(
3940
TAG,
4041
"Received prompt for OK permission vendor id:"
@@ -43,28 +44,33 @@ public void promptForCommissionOkPermission(
4344
+ productId
4445
+ ". Commissionee: "
4546
+ commissioneeName);
46-
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
47-
48-
builder
49-
.setMessage(commissioneeName + " is requesting permission to cast to this device, approve?")
50-
.setTitle("Allow access to " + commissioneeName)
51-
.setPositiveButton(
52-
"Ok",
53-
(dialog, which) -> {
54-
OnPromptAccepted();
55-
})
56-
.setNegativeButton(
57-
"Cancel",
58-
(dialog, which) -> {
59-
OnPromptDeclined();
60-
})
61-
.create()
62-
.show();
47+
48+
getActivity()
49+
.runOnUiThread(
50+
() -> {
51+
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
52+
builder
53+
.setMessage(
54+
commissioneeName
55+
+ " is requesting permission to cast to this device, approve?")
56+
.setTitle("Allow access to " + commissioneeName)
57+
.setPositiveButton(
58+
"Ok",
59+
(dialog, which) -> {
60+
OnPromptAccepted();
61+
})
62+
.setNegativeButton(
63+
"Cancel",
64+
(dialog, which) -> {
65+
OnPromptDeclined();
66+
})
67+
.create()
68+
.show();
69+
});
6370
}
6471

6572
@Override
6673
public void promptForCommissionPinCode(int vendorId, int productId, String commissioneeName) {
67-
// TODO: find app by vendorId and productId
6874
Log.d(
6975
TAG,
7076
"Received prompt for PIN code vendor id:"
@@ -73,26 +79,143 @@ public void promptForCommissionPinCode(int vendorId, int productId, String commi
7379
+ productId
7480
+ ". Commissionee: "
7581
+ commissioneeName);
76-
EditText editText = new EditText(getActivity());
77-
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
78-
79-
builder
80-
.setMessage("Please enter PIN displayed in casting app.")
81-
.setTitle("Allow access to " + commissioneeName)
82-
.setView(editText)
83-
.setPositiveButton(
84-
"Ok",
85-
(dialog, which) -> {
86-
String pinCode = editText.getText().toString();
87-
OnPinCodeEntered(Integer.parseInt(pinCode));
88-
})
89-
.setNegativeButton(
90-
"Cancel",
91-
(dialog, which) -> {
92-
OnPinCodeDeclined();
93-
})
94-
.create()
95-
.show();
82+
83+
getActivity()
84+
.runOnUiThread(
85+
() -> {
86+
EditText editText = new EditText(getActivity());
87+
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
88+
89+
builder
90+
.setMessage("Please enter PIN displayed in casting app.")
91+
.setTitle("Allow access to " + commissioneeName)
92+
.setView(editText)
93+
.setPositiveButton(
94+
"Ok",
95+
(dialog, which) -> {
96+
String pinCode = editText.getText().toString();
97+
OnPinCodeEntered(Integer.parseInt(pinCode));
98+
})
99+
.setNegativeButton(
100+
"Cancel",
101+
(dialog, which) -> {
102+
OnPinCodeDeclined();
103+
})
104+
.create()
105+
.show();
106+
});
107+
}
108+
109+
public void hidePromptsOnCancel(int vendorId, int productId, String commissioneeName) {
110+
Log.d(
111+
TAG,
112+
"Received Cancel from vendor id:"
113+
+ vendorId
114+
+ " productId:"
115+
+ productId
116+
+ ". Commissionee: "
117+
+ commissioneeName);
118+
119+
getActivity()
120+
.runOnUiThread(
121+
() -> {
122+
AlertDialog.Builder abuilder = new AlertDialog.Builder(getActivity());
123+
abuilder
124+
.setMessage("Cancelled connection to " + commissioneeName)
125+
.setTitle("Connection Cancelled")
126+
.create()
127+
.show();
128+
129+
NotificationCompat.Builder builder =
130+
new NotificationCompat.Builder(getActivity(), CHANNEL_ID)
131+
.setSmallIcon(R.drawable.ic_baseline_check_24)
132+
.setContentTitle("Connection Cancelled")
133+
.setContentText("Cancelled connection to " + commissioneeName)
134+
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
135+
136+
notificationManager.notify(SUCCESS_ID, builder.build());
137+
});
138+
}
139+
140+
public void promptWithCommissionerPasscode(
141+
int vendorId,
142+
int productId,
143+
String commissioneeName,
144+
long passcode,
145+
int pairingHint,
146+
String pairingInstruction) {
147+
Log.d(
148+
TAG,
149+
"Received prompt for Commissioner Passcode:"
150+
+ passcode
151+
+ " vendor id:"
152+
+ vendorId
153+
+ " productId:"
154+
+ productId
155+
+ ". Commissionee: "
156+
+ commissioneeName);
157+
158+
getActivity()
159+
.runOnUiThread(
160+
() -> {
161+
EditText editText = new EditText(getActivity());
162+
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
163+
164+
builder
165+
.setMessage(
166+
"Please enter "
167+
+ passcode
168+
+ " in "
169+
+ commissioneeName
170+
+ " app. "
171+
+ pairingInstruction
172+
+ " ["
173+
+ pairingHint
174+
+ "]")
175+
.setTitle("Passcode" + passcode)
176+
.setPositiveButton(
177+
"Ok",
178+
(dialog, which) -> {
179+
OnCommissionerPasscodeOK();
180+
})
181+
.setNegativeButton(
182+
"Cancel",
183+
(dialog, which) -> {
184+
OnCommissionerPasscodeCancel();
185+
})
186+
.create()
187+
.show();
188+
});
189+
}
190+
191+
public void promptCommissioningStarted(int vendorId, int productId, String commissioneeName) {
192+
Log.d(
193+
TAG,
194+
"Received prompt for started vendor id:"
195+
+ vendorId
196+
+ " productId:"
197+
+ productId
198+
+ ". Commissionee: "
199+
+ commissioneeName);
200+
getActivity()
201+
.runOnUiThread(
202+
() -> {
203+
AlertDialog.Builder abuilder = new AlertDialog.Builder(getActivity());
204+
abuilder
205+
.setMessage("Starting connection to " + commissioneeName)
206+
.setTitle("Connection Starting")
207+
.create()
208+
.show();
209+
210+
NotificationCompat.Builder builder =
211+
new NotificationCompat.Builder(getActivity(), CHANNEL_ID)
212+
.setSmallIcon(R.drawable.ic_baseline_check_24)
213+
.setContentTitle("Connection Starting")
214+
.setContentText("Starting connection to " + commissioneeName)
215+
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
216+
217+
notificationManager.notify(SUCCESS_ID, builder.build());
218+
});
96219
}
97220

98221
public void promptCommissioningSucceeded(int vendorId, int productId, String commissioneeName) {
@@ -104,35 +227,105 @@ public void promptCommissioningSucceeded(int vendorId, int productId, String com
104227
+ productId
105228
+ ". Commissionee: "
106229
+ commissioneeName);
107-
NotificationCompat.Builder builder =
108-
new NotificationCompat.Builder(getActivity(), CHANNEL_ID)
109-
.setSmallIcon(R.drawable.ic_baseline_check_24)
110-
.setContentTitle("Connection Complete")
111-
.setContentText(
112-
"Success. "
113-
+ commissioneeName
114-
+ " can now cast to this device. Visit settings to manage access control for casting.")
115-
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
116-
117-
notificationManager.notify(SUCCESS_ID, builder.build());
230+
getActivity()
231+
.runOnUiThread(
232+
() -> {
233+
AlertDialog.Builder abuilder = new AlertDialog.Builder(getActivity());
234+
abuilder
235+
.setMessage(
236+
"Success. "
237+
+ commissioneeName
238+
+ " can now cast to this device. Visit settings to manage access control for casting.")
239+
.setTitle("Connection Complete")
240+
.create()
241+
.show();
242+
243+
NotificationCompat.Builder builder =
244+
new NotificationCompat.Builder(getActivity(), CHANNEL_ID)
245+
.setSmallIcon(R.drawable.ic_baseline_check_24)
246+
.setContentTitle("Connection Complete")
247+
.setContentText(
248+
"Success. "
249+
+ commissioneeName
250+
+ " can now cast to this device. Visit settings to manage access control for casting.")
251+
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
252+
253+
notificationManager.notify(SUCCESS_ID, builder.build());
254+
});
118255
}
119256

120257
public void promptCommissioningFailed(String commissioneeName, String error) {
121258
Log.d(TAG, "Received prompt for failure Commissionee: " + commissioneeName);
122-
NotificationCompat.Builder builder =
123-
new NotificationCompat.Builder(getActivity(), CHANNEL_ID)
124-
.setSmallIcon(R.drawable.ic_baseline_clear_24)
125-
.setContentTitle("Connection Failed")
126-
.setContentText("Failed. " + commissioneeName + " experienced error: " + error + ".")
127-
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
128-
129-
notificationManager.notify(FAIL_ID, builder.build());
259+
getActivity()
260+
.runOnUiThread(
261+
() -> {
262+
AlertDialog.Builder abuilder = new AlertDialog.Builder(getActivity());
263+
abuilder
264+
.setMessage("Failed. " + commissioneeName + " experienced error: " + error + ".")
265+
.setTitle("Connection Failed")
266+
.create()
267+
.show();
268+
269+
NotificationCompat.Builder builder =
270+
new NotificationCompat.Builder(getActivity(), CHANNEL_ID)
271+
.setSmallIcon(R.drawable.ic_baseline_clear_24)
272+
.setContentTitle("Connection Failed")
273+
.setContentText(
274+
"Failed. " + commissioneeName + " experienced error: " + error + ".")
275+
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
276+
277+
notificationManager.notify(FAIL_ID, builder.build());
278+
});
279+
}
280+
281+
public void promptWithMessage(Message message) {
282+
Log.d(TAG, "Received message prompt for " + message.messageText);
283+
getActivity()
284+
.runOnUiThread(
285+
() -> {
286+
if (message.responseOptions.length != 2) {
287+
AlertDialog.Builder abuilder = new AlertDialog.Builder(getActivity());
288+
abuilder
289+
.setMessage("" + message.messageId + ":" + message.messageText)
290+
.setTitle("New Message from Test")
291+
.setPositiveButton(
292+
"Ok",
293+
(dialog, which) -> {
294+
OnMessageResponse(message.messageId, 0); // ack
295+
})
296+
.setNegativeButton(
297+
"Ignore",
298+
(dialog, which) -> {
299+
OnMessageResponse(message.messageId, -1); // ignore
300+
})
301+
.create()
302+
.show();
303+
} else {
304+
AlertDialog.Builder abuilder = new AlertDialog.Builder(getActivity());
305+
abuilder
306+
.setMessage("" + message.messageId + ":" + message.messageText)
307+
.setTitle("New Message from Test")
308+
.setPositiveButton(
309+
message.responseOptions[0].label,
310+
(dialog, which) -> {
311+
OnMessageResponse(message.messageId, message.responseOptions[0].id);
312+
})
313+
.setNegativeButton(
314+
message.responseOptions[1].label,
315+
(dialog, which) -> {
316+
OnMessageResponse(message.messageId, message.responseOptions[1].id);
317+
})
318+
.create()
319+
.show();
320+
}
321+
});
130322
}
131323

132324
private void createNotificationChannel() {
133325
// Create the NotificationChannel, but only on API 26+ because
134326
// the NotificationChannel class is new and not in the support library
135327
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
328+
Log.d(TAG, " ------------- createNotificationChannel");
136329
CharSequence name = "MatterPromptNotificationChannel";
137330
String description = "Matter Channel for sending notifications";
138331
int importance = NotificationManager.IMPORTANCE_DEFAULT;
@@ -142,6 +335,8 @@ private void createNotificationChannel() {
142335
// or other notification behaviors after this
143336
this.notificationManager = getSystemService(context, NotificationManager.class);
144337
notificationManager.createNotificationChannel(channel);
338+
} else {
339+
Log.d(TAG, " ------------- NOT createNotificationChannel");
145340
}
146341
}
147342
}

examples/tv-app/android/java/MessagesManager.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,11 @@ CHIP_ERROR MessagesManager::HandlePresentMessagesRequest(
382382
return CHIP_ERROR_INTERNAL;
383383
}
384384

385-
jobject jlong = env->NewObject(longClass, longCtor, response.messageResponseID.Value());
386-
VerifyOrReturnError(jlong != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Could not create Long"));
385+
jobject jlongobj = env->NewObject(longClass, longCtor, static_cast<uint64_t>(response.messageResponseID.Value()));
386+
VerifyOrReturnError(jlongobj != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Could not create Long"));
387387

388388
// add to HashMap
389-
env->CallObjectMethod(joptions, hashMapPut, jlong, jlabel);
389+
env->CallObjectMethod(joptions, hashMapPut, jlongobj, jlabel);
390390
if (env->ExceptionCheck())
391391
{
392392
ChipLogError(DeviceLayer, "Java exception in MessagesManager::HandlePresentMessagesRequest");

0 commit comments

Comments
 (0)