diff options
author | George Chang <georgekgchang@google.com> | 2020-06-16 15:59:36 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-06-16 15:59:36 +0000 |
commit | 68800697a16f7e919c50e010fb4bf72d4e7d7a40 (patch) | |
tree | 54922f5ade12df18a34ff525218ed2e21296cd19 | |
parent | a91a94b0453a107cda52a64e413a6cb4f756f938 (diff) | |
parent | 2edd8c10b46361da196e8da1f1f6738a217c1934 (diff) | |
download | Nfc-68800697a16f7e919c50e010fb4bf72d4e7d7a40.tar.gz |
Refine NfcBlockedNotification am: 2edd8c10b4
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Nfc/+/11867586
Change-Id: I81767f36eab8889874cae99bfbc7840a07de343e
-rwxr-xr-x | AndroidManifest.xml | 9 | ||||
-rw-r--r-- | src/com/android/nfc/NfcBlockedNotification.java | 54 | ||||
-rw-r--r-- | src/com/android/nfc/NfcService.java | 5 |
3 files changed, 34 insertions, 34 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index edb445cc..f6a07166 100755 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -115,15 +115,6 @@ android:noHistory="true" android:configChanges="orientation|keyboardHidden|screenSize" /> - - <activity android:name=".NfcBlockedNotification" - android:finishOnCloseSystemDialogs="true" - android:excludeFromRecents="true" - android:theme="@android:style/Theme.Translucent.NoTitleBar" - android:noHistory="true" - android:configChanges="orientation|keyboardHidden|screenSize" - /> - <activity android:name=".BeamShareActivity" android:finishOnCloseSystemDialogs="true" android:theme="@android:style/Theme.Translucent" diff --git a/src/com/android/nfc/NfcBlockedNotification.java b/src/com/android/nfc/NfcBlockedNotification.java index 34421cc8..9db74f65 100644 --- a/src/com/android/nfc/NfcBlockedNotification.java +++ b/src/com/android/nfc/NfcBlockedNotification.java @@ -16,49 +16,61 @@ package com.android.nfc; -import android.app.Activity; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; -import android.content.IntentFilter; -import android.content.res.Resources; import android.net.Uri; -import android.os.Bundle; import android.text.TextUtils; + import com.android.nfc.R; -public class NfcBlockedNotification extends Activity { +/** + * This class handles the Notification Manager for the antenna blocked notification + */ + +public class NfcBlockedNotification { private static final String NFC_NOTIFICATION_CHANNEL = "nfc_notification_channel"; private NotificationChannel mNotificationChannel; public static final int NOTIFICATION_ID_NFC = -1000001; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + Context mContext; + + /** + * Constructor + * + * @param ctx The context to use to obtain access to the resources + */ + public NfcBlockedNotification(Context ctx) { + mContext = ctx; + } + + /** + * Start the notification. + */ + public void startNotification() { Intent infoIntent; - if (TextUtils.isEmpty(getString(R.string.antenna_blocked_alert_link))) { + if (TextUtils.isEmpty(mContext.getString(R.string.antenna_blocked_alert_link))) { // Do nothing after user click the notification if antenna_blocked_alert_link is empty infoIntent = new Intent(); } else { // Open the link after user click the notification infoIntent = new Intent(Intent.ACTION_VIEW); - infoIntent.setData(Uri.parse(getString(R.string.antenna_blocked_alert_link))); + infoIntent.setData(Uri.parse(mContext.getString(R.string.antenna_blocked_alert_link))); } - Notification.Builder builder = new Notification.Builder(this, NFC_NOTIFICATION_CHANNEL); - builder.setContentTitle(getString(R.string.nfc_blocking_alert_title)) - .setContentText(getString(R.string.nfc_blocking_alert_message)) - .setSmallIcon(android.R.drawable.stat_sys_warning) - .setPriority(NotificationManager.IMPORTANCE_DEFAULT) - .setAutoCancel(true) - .setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, infoIntent, - PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE)); + Notification.Builder builder = new Notification.Builder(mContext, NFC_NOTIFICATION_CHANNEL); + builder.setContentTitle(mContext.getString(R.string.nfc_blocking_alert_title)) + .setContentText(mContext.getString(R.string.nfc_blocking_alert_message)) + .setSmallIcon(android.R.drawable.stat_sys_warning) + .setPriority(NotificationManager.IMPORTANCE_DEFAULT) + .setAutoCancel(true) + .setContentIntent(PendingIntent.getActivity(mContext, 0, infoIntent, + PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE)); mNotificationChannel = new NotificationChannel(NFC_NOTIFICATION_CHANNEL, - getString(R.string.nfcUserLabel), NotificationManager.IMPORTANCE_DEFAULT); + mContext.getString(R.string.nfcUserLabel), NotificationManager.IMPORTANCE_DEFAULT); NotificationManager notificationManager = - getApplicationContext().getSystemService(NotificationManager.class); + mContext.getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(mNotificationChannel); notificationManager.notify(NOTIFICATION_ID_NFC, builder.build()); } diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java index f4dbca83..0116142e 100644 --- a/src/com/android/nfc/NfcService.java +++ b/src/com/android/nfc/NfcService.java @@ -2750,10 +2750,7 @@ public class NfcService implements DeviceHostListener { playSound(SOUND_ERROR); } if (!mAntennaBlockedMessageShown && mDispatchFailedCount++ > mDispatchFailedMax) { - Intent dialogIntent = new Intent(mContext, NfcBlockedNotification.class); - dialogIntent.setFlags( - Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - mContext.startActivity(dialogIntent); + new NfcBlockedNotification(mContext).startNotification(); mPrefsEditor.putBoolean(PREF_ANTENNA_BLOCKED_MESSAGE_SHOWN, true); mPrefsEditor.apply(); mBackupManager.dataChanged(); |