From a1ab1e4f43e55ab56ad2ff055bd6bee6494a0733 Mon Sep 17 00:00:00 2001 From: mosazaid Date: Wed, 7 Jul 2021 16:59:33 +0300 Subject: [PATCH] notification with timer and bug fixes --- .../VideoStreamFloatingWidgetService.kt | 16 +++- .../hmg/hmgDr/model/NotificationVideoModel.kt | 4 +- .../com/hmg/hmgDr/util/NotificationUtil.kt | 4 +- .../src/main/res/layout/notifi_video_view.xml | 24 +---- .../res/layout/notifi_video_view_expand.xml | 93 +++++++++++++++++++ 5 files changed, 114 insertions(+), 27 deletions(-) create mode 100644 android/app/src/main/res/layout/notifi_video_view_expand.xml diff --git a/android/app/src/main/kotlin/com/hmg/hmgDr/Service/VideoStreamFloatingWidgetService.kt b/android/app/src/main/kotlin/com/hmg/hmgDr/Service/VideoStreamFloatingWidgetService.kt index 96f0ce1f..02413827 100644 --- a/android/app/src/main/kotlin/com/hmg/hmgDr/Service/VideoStreamFloatingWidgetService.kt +++ b/android/app/src/main/kotlin/com/hmg/hmgDr/Service/VideoStreamFloatingWidgetService.kt @@ -292,7 +292,8 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener, try { notificationCompatBuilder.contentView.setChronometer(R.id.notify_timer, cmTimer.base, null, true) - }catch (e : Exception){} + notificationCompatBuilder.bigContentView.setChronometer(R.id.notify_timer, cmTimer.base, null, true) + } catch (e : Exception){} // for change notification timer if (mNotificationManagerCompat != null) { @@ -1029,8 +1030,12 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener, mRemoteViews.setTextViewText(R.id.notify_title, notificationData.mContentTitle) // notification's content mRemoteViews.setTextViewText(R.id.notify_content, notificationData.mContentText) - mRemoteViews.setOnClickPendingIntent(R.id.btn_end, endCallPendingIntent) - mRemoteViews.setChronometer(R.id.notify_timer, SystemClock.elapsedRealtime(), null, false) + val mRemoteViewsExpand = RemoteViews(packageName, R.layout.notifi_video_view_expand) + mRemoteViewsExpand.setImageViewResource(R.id.iv_icon, R.mipmap.ic_launcher) + mRemoteViewsExpand.setTextViewText(R.id.notify_title, notificationData.mContentTitle) + mRemoteViewsExpand.setTextViewText(R.id.notify_content, notificationData.mContentText) + mRemoteViewsExpand.setOnClickPendingIntent(R.id.btn_end, endCallPendingIntent) + mRemoteViewsExpand.setChronometer(R.id.notify_timer, SystemClock.elapsedRealtime(), null, false) notificationCompatBuilder // BIG_TEXT_STYLE sets title and content for API 16 (4.1 and after). @@ -1047,9 +1052,9 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener, ) ) .setCustomContentView(mRemoteViews) - .setCustomBigContentView(mRemoteViews) + .setCustomBigContentView(mRemoteViewsExpand) .setContentIntent(pendingIntent) - .setDefaults(NotificationCompat.DEFAULT_ALL) +// .setDefaults(NotificationCompat.DEFAULT_ALL) // Set primary color (important for Wear 2.0 Notifications). .setColor(ContextCompat.getColor(applicationContext, R.color.colorPrimary)) .setCategory(Notification.CATEGORY_SERVICE) @@ -1059,6 +1064,7 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener, .setUsesChronometer(true) .setWhen(elapsedTime) .setOnlyAlertOnce(true) // This will ensure that updates to an existing notification won't sound/vibrate https://stackoverflow.com/a/52349466/6246772 + .setSound(null) val notification = notificationCompatBuilder .build() diff --git a/android/app/src/main/kotlin/com/hmg/hmgDr/model/NotificationVideoModel.kt b/android/app/src/main/kotlin/com/hmg/hmgDr/model/NotificationVideoModel.kt index 6b6d9217..9a0835f3 100644 --- a/android/app/src/main/kotlin/com/hmg/hmgDr/model/NotificationVideoModel.kt +++ b/android/app/src/main/kotlin/com/hmg/hmgDr/model/NotificationVideoModel.kt @@ -12,8 +12,8 @@ class NotificationVideoModel constructor( mChannelName: CharSequence, mChannelDescription: String, mPriority: Int = NotificationCompat.PRIORITY_DEFAULT, - mChannelImportance: Int = NotificationManager.IMPORTANCE_DEFAULT, - mChannelEnableVibrate: Boolean = false, + mChannelImportance: Int = NotificationManager.IMPORTANCE_LOW, + mChannelEnableVibrate: Boolean = true, mChannelLockscreenVisibility: Int = NotificationCompat.VISIBILITY_PUBLIC, // Unique data for this Notification.Style: var mBigContentTitle: String = mContentTitle, diff --git a/android/app/src/main/kotlin/com/hmg/hmgDr/util/NotificationUtil.kt b/android/app/src/main/kotlin/com/hmg/hmgDr/util/NotificationUtil.kt index 13d6bd19..1c55e1b2 100644 --- a/android/app/src/main/kotlin/com/hmg/hmgDr/util/NotificationUtil.kt +++ b/android/app/src/main/kotlin/com/hmg/hmgDr/util/NotificationUtil.kt @@ -26,9 +26,11 @@ object NotificationUtil { // Initializes NotificationChannel. val notificationChannel = NotificationChannel(channelId, channelName, channelImportance) notificationChannel.description = channelDescription - notificationChannel.enableVibration(channelEnableVibrate) notificationChannel.lightColor = Color.BLUE notificationChannel.lockscreenVisibility = channelLockscreenVisibility + // no vibration + notificationChannel.vibrationPattern = longArrayOf(0) + notificationChannel.enableVibration(channelEnableVibrate) // Adds NotificationChannel to system. Attempting to create an existing notification // channel with its original values performs no operation, so it's safe to perform the diff --git a/android/app/src/main/res/layout/notifi_video_view.xml b/android/app/src/main/res/layout/notifi_video_view.xml index cdc87a4b..a2a81be1 100644 --- a/android/app/src/main/res/layout/notifi_video_view.xml +++ b/android/app/src/main/res/layout/notifi_video_view.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="wrap_content" + android:layout_height="88dp" android:background="@android:color/holo_blue_dark" android:orientation="vertical" android:padding="@dimen/padding_space_medium"> @@ -48,20 +48,19 @@ + android:src="@drawable/ic_arrow_bottom" /> - @@ -73,20 +72,7 @@ android:paddingStart="@dimen/padding_space_small" android:paddingEnd="@dimen/padding_space_small" android:textColor="@color/white" - android:textSize="@dimen/text_size_medium" + android:textSize="@dimen/text_size_small" android:text="Tap to return to call" /> - - \ No newline at end of file diff --git a/android/app/src/main/res/layout/notifi_video_view_expand.xml b/android/app/src/main/res/layout/notifi_video_view_expand.xml new file mode 100644 index 00000000..c06aa9ac --- /dev/null +++ b/android/app/src/main/res/layout/notifi_video_view_expand.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file