-
-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from KryptKode/feat/back-press
Feat/ handle back press for calls
- Loading branch information
Showing
7 changed files
with
249 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
app/src/main/kotlin/com/simplemobiletools/dialer/helpers/CallContactAvatarHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.simplemobiletools.dialer.helpers | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.graphics.* | ||
import android.net.Uri | ||
import android.provider.MediaStore | ||
import android.util.Size | ||
import com.simplemobiletools.commons.helpers.isQPlus | ||
import com.simplemobiletools.dialer.R | ||
import com.simplemobiletools.dialer.models.CallContact | ||
|
||
class CallContactAvatarHelper(private val context: Context) { | ||
@SuppressLint("NewApi") | ||
fun getCallContactAvatar(callContact: CallContact?): Bitmap? { | ||
var bitmap: Bitmap? = null | ||
if (callContact?.photoUri?.isNotEmpty() == true) { | ||
val photoUri = Uri.parse(callContact.photoUri) | ||
try { | ||
val contentResolver = context.contentResolver | ||
bitmap = if (isQPlus()) { | ||
val tmbSize = context.resources.getDimension(R.dimen.list_avatar_size).toInt() | ||
contentResolver.loadThumbnail(photoUri, Size(tmbSize, tmbSize), null) | ||
} else { | ||
MediaStore.Images.Media.getBitmap(contentResolver, photoUri) | ||
} | ||
bitmap = getCircularBitmap(bitmap!!) | ||
} catch (ignored: Exception) { | ||
return null | ||
} | ||
} | ||
return bitmap | ||
} | ||
|
||
fun getCircularBitmap(bitmap: Bitmap): Bitmap { | ||
val output = Bitmap.createBitmap(bitmap.width, bitmap.width, Bitmap.Config.ARGB_8888) | ||
val canvas = Canvas(output) | ||
val paint = Paint() | ||
val rect = Rect(0, 0, bitmap.width, bitmap.height) | ||
val radius = bitmap.width / 2.toFloat() | ||
|
||
paint.isAntiAlias = true | ||
canvas.drawARGB(0, 0, 0, 0) | ||
canvas.drawCircle(radius, radius, radius, paint) | ||
paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN) | ||
canvas.drawBitmap(bitmap, rect, rect, paint) | ||
return output | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/kotlin/com/simplemobiletools/dialer/helpers/CallDurationHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.simplemobiletools.dialer.helpers | ||
|
||
import java.util.Timer | ||
import java.util.TimerTask | ||
|
||
class CallDurationHelper { | ||
private var callTimer: Timer? = null | ||
private var callDuration = 0 | ||
private var callback: ((durationSecs: Int) -> Unit)? = null | ||
|
||
fun onDurationChange(callback: (durationSecs: Int) -> Unit) { | ||
this.callback = callback | ||
} | ||
|
||
fun start() { | ||
try { | ||
callDuration = 0 | ||
callTimer = Timer() | ||
callTimer?.scheduleAtFixedRate(getTimerUpdateTask(), 1000, 1000) | ||
} catch (ignored: Exception) { | ||
} | ||
} | ||
|
||
fun cancel() { | ||
callTimer?.cancel() | ||
} | ||
|
||
private fun getTimerUpdateTask() = object : TimerTask() { | ||
override fun run() { | ||
callDuration++ | ||
callback?.invoke(callDuration) | ||
} | ||
} | ||
} |
Oops, something went wrong.