notification with timer and bug fixes

video-stream-floating
mosazaid 5 years ago
parent d0f1f9e17f
commit a1ab1e4f43

@ -292,7 +292,8 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
try { try {
notificationCompatBuilder.contentView.setChronometer(R.id.notify_timer, cmTimer.base, null, true) 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 // for change notification timer
if (mNotificationManagerCompat != null) { if (mNotificationManagerCompat != null) {
@ -1029,8 +1030,12 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
mRemoteViews.setTextViewText(R.id.notify_title, notificationData.mContentTitle) mRemoteViews.setTextViewText(R.id.notify_title, notificationData.mContentTitle)
// notification's content // notification's content
mRemoteViews.setTextViewText(R.id.notify_content, notificationData.mContentText) mRemoteViews.setTextViewText(R.id.notify_content, notificationData.mContentText)
mRemoteViews.setOnClickPendingIntent(R.id.btn_end, endCallPendingIntent) val mRemoteViewsExpand = RemoteViews(packageName, R.layout.notifi_video_view_expand)
mRemoteViews.setChronometer(R.id.notify_timer, SystemClock.elapsedRealtime(), null, false) 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 notificationCompatBuilder
// BIG_TEXT_STYLE sets title and content for API 16 (4.1 and after). // 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) .setCustomContentView(mRemoteViews)
.setCustomBigContentView(mRemoteViews) .setCustomBigContentView(mRemoteViewsExpand)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setDefaults(NotificationCompat.DEFAULT_ALL) // .setDefaults(NotificationCompat.DEFAULT_ALL)
// Set primary color (important for Wear 2.0 Notifications). // Set primary color (important for Wear 2.0 Notifications).
.setColor(ContextCompat.getColor(applicationContext, R.color.colorPrimary)) .setColor(ContextCompat.getColor(applicationContext, R.color.colorPrimary))
.setCategory(Notification.CATEGORY_SERVICE) .setCategory(Notification.CATEGORY_SERVICE)
@ -1059,6 +1064,7 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
.setUsesChronometer(true) .setUsesChronometer(true)
.setWhen(elapsedTime) .setWhen(elapsedTime)
.setOnlyAlertOnce(true) // This will ensure that updates to an existing notification won't sound/vibrate https://stackoverflow.com/a/52349466/6246772 .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 val notification = notificationCompatBuilder
.build() .build()

@ -12,8 +12,8 @@ class NotificationVideoModel constructor(
mChannelName: CharSequence, mChannelName: CharSequence,
mChannelDescription: String, mChannelDescription: String,
mPriority: Int = NotificationCompat.PRIORITY_DEFAULT, mPriority: Int = NotificationCompat.PRIORITY_DEFAULT,
mChannelImportance: Int = NotificationManager.IMPORTANCE_DEFAULT, mChannelImportance: Int = NotificationManager.IMPORTANCE_LOW,
mChannelEnableVibrate: Boolean = false, mChannelEnableVibrate: Boolean = true,
mChannelLockscreenVisibility: Int = NotificationCompat.VISIBILITY_PUBLIC, mChannelLockscreenVisibility: Int = NotificationCompat.VISIBILITY_PUBLIC,
// Unique data for this Notification.Style: // Unique data for this Notification.Style:
var mBigContentTitle: String = mContentTitle, var mBigContentTitle: String = mContentTitle,

@ -26,9 +26,11 @@ object NotificationUtil {
// Initializes NotificationChannel. // Initializes NotificationChannel.
val notificationChannel = NotificationChannel(channelId, channelName, channelImportance) val notificationChannel = NotificationChannel(channelId, channelName, channelImportance)
notificationChannel.description = channelDescription notificationChannel.description = channelDescription
notificationChannel.enableVibration(channelEnableVibrate)
notificationChannel.lightColor = Color.BLUE notificationChannel.lightColor = Color.BLUE
notificationChannel.lockscreenVisibility = channelLockscreenVisibility notificationChannel.lockscreenVisibility = channelLockscreenVisibility
// no vibration
notificationChannel.vibrationPattern = longArrayOf(0)
notificationChannel.enableVibration(channelEnableVibrate)
// Adds NotificationChannel to system. Attempting to create an existing notification // 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 // channel with its original values performs no operation, so it's safe to perform the

@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="88dp"
android:background="@android:color/holo_blue_dark" android:background="@android:color/holo_blue_dark"
android:orientation="vertical" android:orientation="vertical"
android:padding="@dimen/padding_space_medium"> android:padding="@dimen/padding_space_medium">
@ -48,20 +48,19 @@
<ImageView <ImageView
android:layout_width="22dp" android:layout_width="22dp"
android:layout_height="22dp" android:layout_height="22dp"
android:src="@drawable/ic_arrow_top" /> android:src="@drawable/ic_arrow_bottom" />
</LinearLayout> </LinearLayout>
<TextView <TextView
android:id="@+id/notify_title" android:id="@+id/notify_title"
style="@style/TextAppearance.Compat.Notification.Title" style="@style/TextAppearance.Compat.Notification.Title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_space_big" android:layout_marginTop="@dimen/padding_space_medium"
android:paddingStart="@dimen/padding_space_small" android:paddingStart="@dimen/padding_space_small"
android:paddingEnd="@dimen/padding_space_small" android:paddingEnd="@dimen/padding_space_small"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="@dimen/text_size_medium" android:textSize="@dimen/text_size_small"
android:textStyle="bold" android:textStyle="bold"
tools:text="Mosa zaid mosa abuzaid" /> tools:text="Mosa zaid mosa abuzaid" />
@ -73,20 +72,7 @@
android:paddingStart="@dimen/padding_space_small" android:paddingStart="@dimen/padding_space_small"
android:paddingEnd="@dimen/padding_space_small" android:paddingEnd="@dimen/padding_space_small"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="@dimen/text_size_medium" android:textSize="@dimen/text_size_small"
android:text="Tap to return to call" /> android:text="Tap to return to call" />
<TextView
android:id="@+id/btn_end"
style="@style/TextAppearance.Compat.Notification.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_space_medium"
android:paddingStart="@dimen/padding_space_small"
android:paddingEnd="@dimen/padding_space_small"
android:textColor="@color/white"
android:textSize="@dimen/text_size_medium"
android:textStyle="bold"
android:text="End call" />
</LinearLayout> </LinearLayout>

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:background="@android:color/holo_blue_dark"
android:orientation="vertical"
android:padding="@dimen/padding_space_medium">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/iv_icon"
android:layout_width="22dp"
android:layout_height="22dp"
android:src="@mipmap/ic_launcher" />
<TextView
style="@style/TextAppearance.Compat.Notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="@dimen/padding_space_small"
android:paddingEnd="@dimen/padding_space_small"
android:text="HMG Doctor"
android:textColor="@color/white"
android:textSize="@dimen/text_size_small" />
<Chronometer
android:id="@+id/notify_timer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/TextAppearance.Compat.Notification"
android:paddingStart="@dimen/padding_space_small"
android:paddingEnd="@dimen/padding_space_small"
android:textColor="@color/white"
android:textSize="@dimen/text_size_small"
android:format="MM:SS"
tools:text="25:45" />
<ImageView
android:layout_width="22dp"
android:layout_height="22dp"
android:src="@drawable/ic_arrow_top" />
</LinearLayout>
<TextView
android:id="@+id/notify_title"
style="@style/TextAppearance.Compat.Notification.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_space_big"
android:paddingStart="@dimen/padding_space_small"
android:paddingEnd="@dimen/padding_space_small"
android:textColor="@color/white"
android:textSize="@dimen/text_size_medium"
android:textStyle="bold"
tools:text="Mosa zaid mosa abuzaid" />
<TextView
android:id="@+id/notify_content"
style="@style/TextAppearance.Compat.Notification.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="@dimen/padding_space_small"
android:paddingEnd="@dimen/padding_space_small"
android:textColor="@color/white"
android:textSize="@dimen/text_size_medium"
android:text="Tap to return to call" />
<TextView
android:id="@+id/btn_end"
style="@style/TextAppearance.Compat.Notification.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_space_medium"
android:layout_marginBottom="@dimen/padding_space_medium"
android:paddingStart="@dimen/padding_space_small"
android:paddingEnd="@dimen/padding_space_small"
android:textColor="@color/white"
android:textSize="@dimen/text_size_medium"
android:textStyle="bold"
android:text="End call" />
</LinearLayout>
Loading…
Cancel
Save