-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TV Android app - Add commissioning User Prompter to TV android app (#…
…18926) * Initial commit * Update logic with callbacks * Minor fixes * restyle fix * Update examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MatterCommissioningPrompter.java Co-authored-by: chrisdecenzo <61757564+chrisdecenzo@users.noreply.github.com> * Update examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MatterCommissioningPrompter.java Co-authored-by: chrisdecenzo <61757564+chrisdecenzo@users.noreply.github.com> * Update examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MatterCommissioningPrompter.java Co-authored-by: chrisdecenzo <61757564+chrisdecenzo@users.noreply.github.com> * Update examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MatterCommissioningPrompter.java Co-authored-by: chrisdecenzo <61757564+chrisdecenzo@users.noreply.github.com> * Update examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MatterCommissioningPrompter.java Co-authored-by: chrisdecenzo <61757564+chrisdecenzo@users.noreply.github.com> * Update examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MatterCommissioningPrompter.java Co-authored-by: chrisdecenzo <61757564+chrisdecenzo@users.noreply.github.com> * Restyle fix * Converted the error to string * Fix activity * Restyle fix * Update examples/tv-app/android/java/src/com/tcl/chip/tvapp/UserPrompterResolver.java * Update examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MainActivity.java * Update examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MatterCommissioningPrompter.java * Update examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MatterCommissioningPrompter.java * Update examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MatterCommissioningPrompter.java * Update examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MatterCommissioningPrompter.java * Update examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MatterCommissioningPrompter.java * Restyle fix Co-authored-by: chrisdecenzo <61757564+chrisdecenzo@users.noreply.github.com>
- Loading branch information
Showing
19 changed files
with
635 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
...roid/App/platform-app/src/main/java/com/matter/tv/server/MatterCommissioningPrompter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package com.matter.tv.server; | ||
|
||
import static androidx.core.content.ContextCompat.getSystemService; | ||
|
||
import android.app.Activity; | ||
import android.app.NotificationChannel; | ||
import android.app.NotificationManager; | ||
import android.os.Build; | ||
import android.util.Log; | ||
import android.widget.EditText; | ||
import androidx.appcompat.app.AlertDialog; | ||
import androidx.core.app.NotificationCompat; | ||
import com.tcl.chip.tvapp.UserPrompter; | ||
import com.tcl.chip.tvapp.UserPrompterResolver; | ||
|
||
public class MatterCommissioningPrompter extends UserPrompterResolver implements UserPrompter { | ||
|
||
private Activity activity; | ||
private NotificationManager notificationManager; | ||
private final String CHANNEL_ID = "MatterCommissioningPrompter.CHANNEL"; | ||
private final int SUCCESS_ID = 0; | ||
private final int FAIL_ID = 1; | ||
|
||
public MatterCommissioningPrompter(Activity activity) { | ||
this.activity = activity; | ||
this.createNotificationChannel(); | ||
} | ||
|
||
public void promptForCommissionOkPermission( | ||
int vendorId, int productId, String commissioneeName) { | ||
// TODO: find app by vendorId and productId | ||
Log.d( | ||
TAG, | ||
"Received prompt for OK permission vendor id:" | ||
+ vendorId | ||
+ " productId:" | ||
+ productId | ||
+ ". Commissionee: " | ||
+ commissioneeName); | ||
AlertDialog.Builder builder = new AlertDialog.Builder(activity); | ||
|
||
builder | ||
.setMessage(commissioneeName + " is requesting permission to cast to this device, approve?") | ||
.setTitle("Allow access to " + commissioneeName) | ||
.setPositiveButton( | ||
"Ok", | ||
(dialog, which) -> { | ||
OnPromptAccepted(); | ||
}) | ||
.setNegativeButton( | ||
"Cancel", | ||
(dialog, which) -> { | ||
OnPromptDeclined(); | ||
}) | ||
.create() | ||
.show(); | ||
} | ||
|
||
@Override | ||
public void promptForCommissionPinCode(int vendorId, int productId, String commissioneeName) { | ||
// TODO: find app by vendorId and productId | ||
Log.d( | ||
TAG, | ||
"Received prompt for PIN code vendor id:" | ||
+ vendorId | ||
+ " productId:" | ||
+ productId | ||
+ ". Commissionee: " | ||
+ commissioneeName); | ||
EditText editText = new EditText(activity); | ||
AlertDialog.Builder builder = new AlertDialog.Builder(activity); | ||
|
||
builder | ||
.setMessage("Please enter PIN displayed in casting app.") | ||
.setTitle("Allow access to " + commissioneeName) | ||
.setView(editText) | ||
.setPositiveButton( | ||
"Ok", | ||
(dialog, which) -> { | ||
String pinCode = editText.getText().toString(); | ||
OnPinCodeEntered(Integer.parseInt(pinCode)); | ||
}) | ||
.setNegativeButton( | ||
"Cancel", | ||
(dialog, which) -> { | ||
OnPinCodeDeclined(); | ||
}) | ||
.create() | ||
.show(); | ||
} | ||
|
||
public void promptCommissioningSucceeded(int vendorId, int productId, String commissioneeName) { | ||
Log.d( | ||
TAG, | ||
"Received prompt for success vendor id:" | ||
+ vendorId | ||
+ " productId:" | ||
+ productId | ||
+ ". Commissionee: " | ||
+ commissioneeName); | ||
NotificationCompat.Builder builder = | ||
new NotificationCompat.Builder(activity, CHANNEL_ID) | ||
.setSmallIcon(R.drawable.ic_baseline_check_24) | ||
.setContentTitle("Connection Complete") | ||
.setContentText( | ||
"Success. " | ||
+ commissioneeName | ||
+ " can now cast to this device. Visit settings to manage access control for casting.") | ||
.setPriority(NotificationCompat.PRIORITY_DEFAULT); | ||
|
||
notificationManager.notify(SUCCESS_ID, builder.build()); | ||
} | ||
|
||
public void promptCommissioningFailed(String commissioneeName, String error) { | ||
Log.d( | ||
TAG, | ||
"Received prompt for failure vendor id:" | ||
+ vendorId | ||
+ " productId:" | ||
+ productId | ||
+ ". Commissionee: " | ||
+ commissioneeName); | ||
NotificationCompat.Builder builder = | ||
new NotificationCompat.Builder(activity, CHANNEL_ID) | ||
.setSmallIcon(R.drawable.ic_baseline_clear_24) | ||
.setContentTitle("Connection Failed") | ||
.setContentText("Failed. " + commissioneeName + " experienced error: " + error + ".") | ||
.setPriority(NotificationCompat.PRIORITY_DEFAULT); | ||
|
||
notificationManager.notify(FAIL_ID, builder.build()); | ||
} | ||
|
||
private void createNotificationChannel() { | ||
// Create the NotificationChannel, but only on API 26+ because | ||
// the NotificationChannel class is new and not in the support library | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
CharSequence name = "MatterPromptNotificationChannel"; | ||
String description = "Matter Channel for sending notifications"; | ||
int importance = NotificationManager.IMPORTANCE_DEFAULT; | ||
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance); | ||
channel.setDescription(description); | ||
// Register the channel with the system; you can't change the importance | ||
// or other notification behaviors after this | ||
this.notificationManager = getSystemService(activity, NotificationManager.class); | ||
notificationManager.createNotificationChannel(channel); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
examples/tv-app/android/App/platform-app/src/main/res/drawable/ic_baseline_check_24.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" | ||
android:tint="?attr/colorControlNormal"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/> | ||
</vector> |
10 changes: 10 additions & 0 deletions
10
examples/tv-app/android/App/platform-app/src/main/res/drawable/ic_baseline_clear_24.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" | ||
android:tint="?attr/colorControlNormal"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.