Skip to content

Commit

Permalink
1.0.2+2
Browse files Browse the repository at this point in the history
  • Loading branch information
hiennguyen92 committed Aug 25, 2022
1 parent d4a9948 commit c231785
Show file tree
Hide file tree
Showing 20 changed files with 455 additions and 148 deletions.
9 changes: 0 additions & 9 deletions .idea/libraries/Flutter_Plugins.xml

This file was deleted.

11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
## 1.0.2+2

* Fix notification Android 12
* Fix sound notification
* Support `backgroundUrl` using path assets
* Fixed some bugs.

## 1.0.2+1

* Issue no audio when Accpet(iOS)
* Duplicate sound notificaiton(Android)
* Issue no audio when Accept(iOS)
* Duplicate sound notification(Android)
* Support Flutter 3
* Fixed some bugs.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
| **`isShowCallback`** | Show callback action from miss call notification. | `true` |
| **`ringtonePath`** | File name ringtone. put file into `/android/app/src/main/res/raw/ringtone_default.pm3` |`system_ringtone_default` <br>using ringtone default of the phone|
| **`backgroundColor`** | Incoming call screen background color. | `#0955fa` |
| **`backgroundUrl`** | Using image background for Incoming call screen. | _None_ |
| **`backgroundUrl`** | Using image background for Incoming call screen. example: http://... https://... or "assets/abc.png" | _None_ |
| **`actionColor`** | Color used in button/text on notification. | `#4CAF50` |

<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ class CallkitIncomingActivity : Activity() {
companion object {

const val ACTION_ENDED_CALL_INCOMING =
"com.hiennv.flutter_callkit_incoming.ACTION_ENDED_CALL_INCOMING"
"com.hiennv.flutter_callkit_incoming.ACTION_ENDED_CALL_INCOMING"

fun getIntent(data: Bundle) = Intent(ACTION_CALL_INCOMING).apply {
action = ACTION_CALL_INCOMING
putExtra(EXTRA_CALLKIT_INCOMING_DATA, data)
flags =
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
}

fun getIntentEnded() =
Intent(ACTION_ENDED_CALL_INCOMING)
Intent(ACTION_ENDED_CALL_INCOMING)

}

Expand Down Expand Up @@ -112,26 +112,26 @@ class CallkitIncomingActivity : Activity() {
initView()
incomingData(intent)
registerReceiver(
endedCallkitIncomingBroadcastReceiver,
IntentFilter(ACTION_ENDED_CALL_INCOMING)
endedCallkitIncomingBroadcastReceiver,
IntentFilter(ACTION_ENDED_CALL_INCOMING)
)
}

private fun wakeLockRequest(duration: Long) {

val pm = applicationContext.getSystemService(POWER_SERVICE) as PowerManager
val wakeLock = pm.newWakeLock(
PowerManager.SCREEN_BRIGHT_WAKE_LOCK or PowerManager.FULL_WAKE_LOCK or PowerManager.ACQUIRE_CAUSES_WAKEUP,
"Callkit:PowerManager"
PowerManager.SCREEN_BRIGHT_WAKE_LOCK or PowerManager.FULL_WAKE_LOCK or PowerManager.ACQUIRE_CAUSES_WAKEUP,
"Callkit:PowerManager"
)
wakeLock.acquire(duration)
}

private fun transparentStatusAndNavigation() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
setWindowFlag(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, true
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, true
)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Expand All @@ -141,8 +141,8 @@ class CallkitIncomingActivity : Activity() {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setWindowFlag(
(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION), false
(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION), false
)
window.statusBarColor = Color.TRANSPARENT
window.navigationBarColor = Color.TRANSPARENT
Expand Down Expand Up @@ -176,10 +176,10 @@ class CallkitIncomingActivity : Activity() {
ivAvatar.visibility = View.VISIBLE
val headers = data.getSerializable(EXTRA_CALLKIT_HEADERS) as HashMap<String, Any?>
getPicassoInstance(this@CallkitIncomingActivity, headers)
.load(avatarUrl)
.placeholder(R.drawable.ic_default_avatar)
.error(R.drawable.ic_default_avatar)
.into(ivAvatar)
.load(avatarUrl)
.placeholder(R.drawable.ic_default_avatar)
.error(R.drawable.ic_default_avatar)
.into(ivAvatar)
}

val callType = data?.getInt(EXTRA_CALLKIT_TYPE, 0) ?: 0
Expand All @@ -192,31 +192,34 @@ class CallkitIncomingActivity : Activity() {
finishTimeout(data, duration)

val textAccept = data?.getString(EXTRA_CALLKIT_TEXT_ACCEPT, "")
tvAccept.text = if(TextUtils.isEmpty(textAccept)) getString(R.string.text_accept) else textAccept
tvAccept.text = if (TextUtils.isEmpty(textAccept)) getString(R.string.text_accept) else textAccept
val textDecline = data?.getString(EXTRA_CALLKIT_TEXT_DECLINE, "")
tvDecline.text = if(TextUtils.isEmpty(textDecline)) getString(R.string.text_decline) else textDecline
tvDecline.text = if (TextUtils.isEmpty(textDecline)) getString(R.string.text_decline) else textDecline

val backgroundColor = data?.getString(EXTRA_CALLKIT_BACKGROUND_COLOR, "#0955fa")
try {
ivBackground.setBackgroundColor(Color.parseColor(backgroundColor))
} catch (error: Exception) {
}
val backgroundUrl = data?.getString(EXTRA_CALLKIT_BACKGROUND_URL, "")
var backgroundUrl = data?.getString(EXTRA_CALLKIT_BACKGROUND_URL, "")
if (backgroundUrl != null && backgroundUrl.isNotEmpty()) {
val headers = data.getSerializable(EXTRA_CALLKIT_HEADERS) as HashMap<String, Any?>
if (!backgroundUrl.startsWith("http://", true) && !backgroundUrl.startsWith("https://", true)){
backgroundUrl = String.format("file:///android_asset/flutter_assets/%s", backgroundUrl)
}
val headers = data?.getSerializable(EXTRA_CALLKIT_HEADERS) as HashMap<String, Any?>
getPicassoInstance(this@CallkitIncomingActivity, headers)
.load(backgroundUrl)
.placeholder(R.drawable.transparent)
.error(R.drawable.transparent)
.into(ivBackground)
.load(backgroundUrl)
.placeholder(R.drawable.transparent)
.error(R.drawable.transparent)
.into(ivBackground)
}
}

private fun finishTimeout(data: Bundle?, duration: Long) {
val currentSystemTime = System.currentTimeMillis()
val timeStartCall =
data?.getLong(CallkitNotificationManager.EXTRA_TIME_START_CALL, currentSystemTime)
?: currentSystemTime
data?.getLong(CallkitNotificationManager.EXTRA_TIME_START_CALL, currentSystemTime)
?: currentSystemTime

val timeOut = duration - abs(currentSystemTime - timeStartCall)
Handler(Looper.getMainLooper()).postDelayed({
Expand All @@ -234,7 +237,7 @@ class CallkitIncomingActivity : Activity() {
ivBackground = findViewById(R.id.ivBackground)
llBackgroundAnimation = findViewById(R.id.llBackgroundAnimation)
llBackgroundAnimation.layoutParams.height =
Utils.getScreenWidth() + Utils.getStatusBarHeight(this@CallkitIncomingActivity)
Utils.getScreenWidth() + Utils.getStatusBarHeight(this@CallkitIncomingActivity)
llBackgroundAnimation.startRippleAnimation()

tvNameCaller = findViewById(R.id.tvNameCaller)
Expand All @@ -245,7 +248,7 @@ class CallkitIncomingActivity : Activity() {
llAction = findViewById(R.id.llAction)

val params = llAction.layoutParams as MarginLayoutParams
params.setMargins(0,0,0,Utils.getNavigationBarHeight(this@CallkitIncomingActivity))
params.setMargins(0, 0, 0, Utils.getNavigationBarHeight(this@CallkitIncomingActivity))
llAction.layoutParams = params

ivAcceptCall = findViewById(R.id.ivAcceptCall)
Expand All @@ -264,7 +267,7 @@ class CallkitIncomingActivity : Activity() {

private fun animateAcceptCall() {
val shakeAnimation =
AnimationUtils.loadAnimation(this@CallkitIncomingActivity, R.anim.shake_anim)
AnimationUtils.loadAnimation(this@CallkitIncomingActivity, R.anim.shake_anim)
ivAcceptCall.animation = shakeAnimation
}

Expand Down Expand Up @@ -298,23 +301,23 @@ class CallkitIncomingActivity : Activity() {
private fun onDeclineClick() {
val data = intent.extras?.getBundle(EXTRA_CALLKIT_INCOMING_DATA)
val intent =
CallkitIncomingBroadcastReceiver.getIntentDecline(this@CallkitIncomingActivity, data)
CallkitIncomingBroadcastReceiver.getIntentDecline(this@CallkitIncomingActivity, data)
sendBroadcast(intent)
}

private fun getPicassoInstance(context: Context, headers: HashMap<String, Any?>): Picasso {
val client = OkHttpClient.Builder()
.addNetworkInterceptor { chain ->
val newRequestBuilder: okhttp3.Request.Builder = chain.request().newBuilder()
for ((key, value) in headers) {
newRequestBuilder.addHeader(key, value.toString())
.addNetworkInterceptor { chain ->
val newRequestBuilder: okhttp3.Request.Builder = chain.request().newBuilder()
for ((key, value) in headers) {
newRequestBuilder.addHeader(key, value.toString())
}
chain.proceed(newRequestBuilder.build())
}
chain.proceed(newRequestBuilder.build())
}
.build()
.build()
return Picasso.Builder(context)
.downloader(OkHttp3Downloader(client))
.build()
.downloader(OkHttp3Downloader(client))
.build()
}

override fun onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.media.RingtoneManager
Expand All @@ -16,7 +17,6 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.text.TextUtils
import android.util.TypedValue
import android.view.View
import android.widget.RemoteViews
import androidx.core.app.NotificationCompat
Expand Down Expand Up @@ -49,6 +49,7 @@ class CallkitNotificationManager(private val context: Context) {

private lateinit var notificationBuilder: NotificationCompat.Builder
private var notificationViews: RemoteViews? = null
private var notificationSmallViews: RemoteViews? = null
private var notificationId: Int = 9696

private var targetLoadAvatarDefault = object : Target {
Expand All @@ -57,19 +58,24 @@ class CallkitNotificationManager(private val context: Context) {
getNotificationManager().notify(notificationId, notificationBuilder.build())
}

override fun onBitmapFailed(e: Exception?, errorDrawable: Drawable?) {}
override fun onBitmapFailed(e: Exception?, errorDrawable: Drawable?) {
}

override fun onPrepareLoad(placeHolderDrawable: Drawable?) {}
override fun onPrepareLoad(placeHolderDrawable: Drawable?) {
}
}

private var targetLoadAvatarCustomize = object : Target {
override fun onBitmapLoaded(bitmap: Bitmap?, from: Picasso.LoadedFrom?) {
notificationViews?.setImageViewBitmap(R.id.ivAvatar, bitmap)
notificationViews?.setViewVisibility(R.id.ivAvatar, View.VISIBLE)
notificationSmallViews?.setImageViewBitmap(R.id.ivAvatar, bitmap)
notificationSmallViews?.setViewVisibility(R.id.ivAvatar, View.VISIBLE)
getNotificationManager().notify(notificationId, notificationBuilder.build())
}

override fun onBitmapFailed(e: Exception?, errorDrawable: Drawable?) {}
override fun onBitmapFailed(e: Exception?, errorDrawable: Drawable?) {
}

override fun onPrepareLoad(placeHolderDrawable: Drawable?) {
}
Expand Down Expand Up @@ -122,45 +128,23 @@ class CallkitNotificationManager(private val context: Context) {
if (isCustomNotification) {
notificationViews =
RemoteViews(context.packageName, R.layout.layout_custom_notification)
notificationViews?.setTextViewText(
R.id.tvNameCaller,
data.getString(EXTRA_CALLKIT_NAME_CALLER, "")
)
notificationViews?.setTextViewText(
R.id.tvNumber,
data.getString(EXTRA_CALLKIT_HANDLE, "")
)
notificationViews?.setOnClickPendingIntent(
R.id.llDecline,
getDeclinePendingIntent(notificationId, data)
)
val textDecline = data.getString(EXTRA_CALLKIT_TEXT_DECLINE, "")
notificationViews?.setTextViewText(
R.id.tvDecline,
if (TextUtils.isEmpty(textDecline)) context.getString(R.string.text_decline) else textDecline
)
notificationViews?.setOnClickPendingIntent(
R.id.llAccept,
getAcceptPendingIntent(notificationId, data)
)
val textAccept = data.getString(EXTRA_CALLKIT_TEXT_ACCEPT, "")
notificationViews?.setTextViewText(
R.id.tvAccept,
if (TextUtils.isEmpty(textAccept)) context.getString(R.string.text_accept) else textAccept
)
val avatarUrl = data.getString(EXTRA_CALLKIT_AVATAR, "")
if (avatarUrl != null && avatarUrl.isNotEmpty()) {
val headers =
data.getSerializable(CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_HEADERS) as HashMap<String, Any?>
getPicassoInstance(context, headers).load(avatarUrl)
.transform(CircleTransform())
.into(targetLoadAvatarCustomize)
initNotificationViews(notificationViews!!, data)


if (Build.MANUFACTURER.equals("Samsung", ignoreCase = true) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
notificationSmallViews =
RemoteViews(context.packageName, R.layout.layout_custom_small_ex_notification)
initNotificationViews(notificationSmallViews!!, data)
} else {
notificationSmallViews =
RemoteViews(context.packageName, R.layout.layout_custom_small_notification)
initNotificationViews(notificationSmallViews!!, data)
}

notificationBuilder.setStyle(NotificationCompat.DecoratedCustomViewStyle())
notificationBuilder.setCustomContentView(notificationViews)
notificationBuilder.setCustomContentView(notificationSmallViews)
notificationBuilder.setCustomBigContentView(notificationViews)
notificationBuilder.setCustomHeadsUpContentView(notificationViews)
notificationBuilder.setCustomHeadsUpContentView(notificationSmallViews)
} else {
val avatarUrl = data.getString(EXTRA_CALLKIT_AVATAR, "")
if (avatarUrl != null && avatarUrl.isNotEmpty()) {
Expand Down Expand Up @@ -191,6 +175,43 @@ class CallkitNotificationManager(private val context: Context) {
getNotificationManager().notify(notificationId, notification)
}

private fun initNotificationViews(remoteViews: RemoteViews, data: Bundle) {
remoteViews.setTextViewText(
R.id.tvNameCaller,
data.getString(EXTRA_CALLKIT_NAME_CALLER, "")
)
remoteViews.setTextViewText(
R.id.tvNumber,
data.getString(EXTRA_CALLKIT_HANDLE, "")
)
remoteViews.setOnClickPendingIntent(
R.id.llDecline,
getDeclinePendingIntent(notificationId, data)
)
val textDecline = data.getString(EXTRA_CALLKIT_TEXT_DECLINE, "")
remoteViews.setTextViewText(
R.id.tvDecline,
if (TextUtils.isEmpty(textDecline)) context.getString(R.string.text_decline) else textDecline
)
remoteViews.setOnClickPendingIntent(
R.id.llAccept,
getAcceptPendingIntent(notificationId, data)
)
val textAccept = data.getString(EXTRA_CALLKIT_TEXT_ACCEPT, "")
remoteViews.setTextViewText(
R.id.tvAccept,
if (TextUtils.isEmpty(textAccept)) context.getString(R.string.text_accept) else textAccept
)
val avatarUrl = data.getString(EXTRA_CALLKIT_AVATAR, "")
if (avatarUrl != null && avatarUrl.isNotEmpty()) {
val headers =
data.getSerializable(CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_HEADERS) as HashMap<String, Any?>
getPicassoInstance(context, headers).load(avatarUrl)
.transform(CircleTransform())
.into(targetLoadAvatarCustomize)
}
}

fun showMissCallNotification(data: Bundle) {
notificationId = data.getString(EXTRA_CALLKIT_ID, "callkit_incoming").hashCode() + 1
createNotificationChanel()
Expand Down Expand Up @@ -312,9 +333,9 @@ class CallkitNotificationManager(private val context: Context) {
private fun createNotificationChanel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
var channelCall = getNotificationManager().getNotificationChannel("callkit_incoming_channel_id")
if (channelCall != null){
if (channelCall != null) {
channelCall.setSound(null, null)
}else {
} else {
channelCall = NotificationChannel(
"callkit_incoming_channel_id",
"Incoming Call",
Expand Down
Loading

0 comments on commit c231785

Please sign in to comment.