Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Karthi/updated with custom UI #1

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.dart_tool/
*/.idea/*

.packages
.pub/
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 2.0.4+2
* add func `requestFullIntentPermission` (Android 14+) thank @Spyspyspy https://github.com/hiennguyen92/flutter_callkit_incoming/pull/584
* set Notification call style (Android) thank @AAkira https://github.com/hiennguyen92/flutter_callkit_incoming/pull/553
* Many other issues
1. add prop `accepted` in activeCalls (iOS) thank @vasilich6107
2.

## 2.0.4+1
* Removed `Telecom Framework` (Android)

Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Flutter Callkit Incoming

## Custom UI -

![](images/newUI.png)

## How to update the to plugin to latest version

1. Create a new branch from the latest version tag on [our flutter_callkit_incoming repo clone](https://github.com/famedly/flutter_callkit_incoming/) - `git fetch origin && git checkout -b <new-branch-name> tags/vX.Y.Z`
2. Set remote "upstream" to the actual repo - `git remote add upstream https://github.com/hiennguyen92/flutter_callkit_incoming.git`
3. Now rebase the branch on the upstream's latest version tag - `git fetch upstream && git rebase upstream/vX.Y.Z`
4. Push the branch to your repo - `git push origin <new-branch-name>`
5. Once it is approved, create a tag from it - `git tag vX.Y.Z`
6. Push the tag to your repo - `git push origin vX.Y.Z`

**IMPORTANT**
- Make sure to only do minimal changes to the code so it is always easy to maintain. The allowed changes are the ones specific to the custom UI.
- Always look for whitespace changes and remove them before committing. These changes are not needed and make the diffs harder to read when rebasing later.
- If you're doing a bug fix, please do it first in the original repo. Once it's merged there and a new release is done, follow the steps above to update the plugin in our fork.

A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Callkit for iOS).

[![pub package](https://img.shields.io/pub/v/flutter_callkit_incoming.svg)](https://pub.dev/packages/flutter_callkit_incoming)
Expand Down Expand Up @@ -147,6 +165,12 @@ Our top sponsors are shown below!
});
```

* request permission for full intent Notification/full screen locked screen Android 14+
For Android 14+, please `requestFullIntentPermission`
```dart
await FlutterCallkitIncoming.requestFullIntentPermission();
```

* Show miss call notification
```dart
this._currentUuid = _uuid.v4();
Expand Down Expand Up @@ -504,7 +528,7 @@ Our top sponsors are shown below!
| **`incomingCallNotificationChannelName`** | Notification channel name of incoming call. | `Incoming call` |
| **`missedCallNotificationChannelName`** | Notification channel name of missed call. | `Missed call` |
| **`isShowCallID`** | Show call id app inside full screen/notification. | false |
| **`isShowFullLockedScreen`** | Show full screen on Locked Screen. | true |
| **`isShowFullLockedScreen`** | Show full screen on Locked Screen(please make sure call `requestFullIntentPermission` for android 14+). | true |

<br>

Expand Down
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ dependencies {
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0'
implementation 'com.fasterxml.jackson.core:jackson-core:2.11.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.11.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.5.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ data class Data(val args: Map<String, Any?>) {
@JsonProperty("isShowFullLockedScreen")
var isShowFullLockedScreen: Boolean = true

@JsonProperty("isImportant")
var isImportant: Boolean = false
@JsonProperty("isBot")
var isBot: Boolean = false

init {
var android: Map<String, Any?>? = args["android"] as? HashMap<String, Any?>?
android = android ?: args
Expand All @@ -101,6 +106,8 @@ data class Data(val args: Map<String, Any?>) {
android["incomingCallNotificationChannelName"] as? String
missedCallNotificationChannelName = android["missedCallNotificationChannelName"] as? String
isShowFullLockedScreen = android["isShowFullLockedScreen"] as? Boolean ?: true
isImportant = android["isImportant"] as? Boolean ?: false
isBot = android["isBot"] as? Boolean ?: false

val missedNotification: Map<String, Any?>? =
args["missedCallNotification"] as? Map<String, Any?>?
Expand Down Expand Up @@ -214,6 +221,14 @@ data class Data(val args: Map<String, Any?>) {
CallkitConstants.EXTRA_CALLKIT_IS_SHOW_FULL_LOCKED_SCREEN,
isShowFullLockedScreen
)
bundle.putBoolean(
CallkitConstants.EXTRA_CALLKIT_IS_IMPORTANT,
isImportant,
)
bundle.putBoolean(
CallkitConstants.EXTRA_CALLKIT_IS_BOT,
isBot,
)
return bundle
}

Expand All @@ -237,6 +252,10 @@ data class Data(val args: Map<String, Any?>) {
bundle.getString(CallkitConstants.EXTRA_CALLKIT_TEXT_ACCEPT, "")
data.textDecline =
bundle.getString(CallkitConstants.EXTRA_CALLKIT_TEXT_DECLINE, "")
data.isImportant =
bundle.getBoolean(CallkitConstants.EXTRA_CALLKIT_IS_IMPORTANT, false)
data.isBot =
bundle.getBoolean(CallkitConstants.EXTRA_CALLKIT_IS_BOT, false)

data.missedNotificationId =
bundle.getInt(CallkitConstants.EXTRA_CALLKIT_MISSED_CALL_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ object CallkitConstants {
const val EXTRA_CALLKIT_ACTION_FROM = "EXTRA_CALLKIT_ACTION_FROM"

const val EXTRA_CALLKIT_IS_SHOW_FULL_LOCKED_SCREEN = "EXTRA_CALLKIT_IS_SHOW_FULL_LOCKED_SCREEN"
const val EXTRA_CALLKIT_IS_IMPORTANT = "EXTRA_CALLKIT_IS_IMPORTANT"
const val EXTRA_CALLKIT_IS_BOT = "EXTRA_CALLKIT_IS_BOT"
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
package com.hiennv.flutter_callkit_incoming

import android.app.Activity
import android.app.ActivityManager
import android.app.KeyguardManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.ActivityInfo
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.*
import android.view.View
import android.view.ViewGroup.MarginLayoutParams
import android.view.Window
import android.view.WindowManager
import android.view.animation.AnimationUtils
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.hiennv.flutter_callkit_incoming.widgets.RippleRelativeLayout
import com.squareup.picasso.OkHttp3Downloader
import com.squareup.picasso.Picasso
import de.hdodenhof.circleimageview.CircleImageView
import kotlin.math.abs
import okhttp3.OkHttpClient
import com.squareup.picasso.OkHttp3Downloader
import android.view.ViewGroup.MarginLayoutParams
import android.os.PowerManager
import android.text.TextUtils
import android.util.Log

import kotlin.math.abs

class CallkitIncomingActivity : Activity() {

Expand Down Expand Up @@ -68,20 +58,17 @@ class CallkitIncomingActivity : Activity() {
private var endedCallkitIncomingBroadcastReceiver = EndedCallkitIncomingBroadcastReceiver()

private lateinit var ivBackground: ImageView
private lateinit var llBackgroundAnimation: RippleRelativeLayout

private lateinit var tvNameCaller: TextView
private lateinit var tvNumber: TextView
private lateinit var ivLogo: ImageView
private lateinit var ivAvatar: CircleImageView

private lateinit var ivAvatar: ImageView
private lateinit var llAction: LinearLayout
private lateinit var ivAcceptCall: ImageView
private lateinit var tvAccept: TextView

private lateinit var ivDeclineCall: ImageView
private lateinit var tvDecline: TextView

private lateinit var tvCallerOrganization: TextView
private lateinit var ivAvatarPlaceholder: TextView

@Suppress("DEPRECATION")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -179,6 +166,10 @@ class CallkitIncomingActivity : Activity() {
tvNumber.text = data?.getString(CallkitConstants.EXTRA_CALLKIT_HANDLE, "")
tvNumber.visibility = if (isShowCallID == true) View.VISIBLE else View.INVISIBLE

// To show the caller's organization
val extra = data?.getSerializable(CallkitConstants.EXTRA_CALLKIT_EXTRA) as HashMap<String, Any?>
tvCallerOrganization.text = extra?.get("callerOrganization") as String?

try {
tvNameCaller.setTextColor(Color.parseColor(textColor))
tvNumber.setTextColor(Color.parseColor(textColor))
Expand All @@ -189,36 +180,27 @@ class CallkitIncomingActivity : Activity() {
ivLogo.visibility = if (isShowLogo == true) View.VISIBLE else View.INVISIBLE

val avatarUrl = data?.getString(CallkitConstants.EXTRA_CALLKIT_AVATAR, "")
if (avatarUrl != null && avatarUrl.isNotEmpty()) {
var temp = data?.getString(CallkitConstants.EXTRA_CALLKIT_NAME_CALLER, "")?.split(' ')
?.mapNotNull { it.firstOrNull()?.toString() }
?.reduce { acc, s -> acc + s }
if (temp?.length!! < 2) temp =
data?.getString(CallkitConstants.EXTRA_CALLKIT_NAME_CALLER, "")?.substring(0, 2)
ivAvatarPlaceholder.text = temp
if (avatarUrl != null && avatarUrl.isNotEmpty() && avatarUrl != "null") {
ivAvatar.visibility = View.VISIBLE
val headers = data.getSerializable(CallkitConstants.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)
}

val callType = data?.getInt(CallkitConstants.EXTRA_CALLKIT_TYPE, 0) ?: 0
if (callType > 0) {
ivAcceptCall.setImageResource(R.drawable.ic_video)
}
val duration = data?.getLong(CallkitConstants.EXTRA_CALLKIT_DURATION, 0L) ?: 0L
wakeLockRequest(duration)

finishTimeout(data, duration)

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

try {
tvAccept.setTextColor(Color.parseColor(textColor))
tvDecline.setTextColor(Color.parseColor(textColor))
} catch (error: Exception) {
}

val backgroundColor = data?.getString(CallkitConstants.EXTRA_CALLKIT_BACKGROUND_COLOR, "#0955fa")
try {
ivBackground.setBackgroundColor(Color.parseColor(backgroundColor))
Expand Down Expand Up @@ -254,27 +236,23 @@ class CallkitIncomingActivity : Activity() {

private fun initView() {
ivBackground = findViewById(R.id.ivBackground)
llBackgroundAnimation = findViewById(R.id.llBackgroundAnimation)
llBackgroundAnimation.layoutParams.height =
Utils.getScreenWidth() + Utils.getStatusBarHeight(this@CallkitIncomingActivity)
llBackgroundAnimation.startRippleAnimation()

tvNameCaller = findViewById(R.id.tvNameCaller)
tvNumber = findViewById(R.id.tvNumber)
ivLogo = findViewById(R.id.ivLogo)
ivAvatar = findViewById(R.id.ivAvatar)

tvCallerOrganization = findViewById(R.id.tvCallerOrganization)
ivAvatarPlaceholder = findViewById(R.id.ivAvatarPlaceholder)

llAction = findViewById(R.id.llAction)

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

ivAcceptCall = findViewById(R.id.ivAcceptCall)
tvAccept = findViewById(R.id.tvAccept)
ivDeclineCall = findViewById(R.id.ivDeclineCall)
tvDecline = findViewById(R.id.tvDecline)
animateAcceptCall()

ivAcceptCall.setOnClickListener {
onAcceptClick()
Expand All @@ -284,12 +262,6 @@ class CallkitIncomingActivity : Activity() {
}
}

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


private fun onAcceptClick() {
val data = intent.extras?.getBundle(CallkitConstants.EXTRA_CALLKIT_INCOMING_DATA)
Expand Down
Loading