From fa8499eedbab5fdd2c2c3df56f97392a54e0ada5 Mon Sep 17 00:00:00 2001 From: Marvin Rohrbach Date: Wed, 17 Jan 2024 01:56:05 +0100 Subject: [PATCH] Initial support for sim colors --- .../phone/activities/DialpadActivity.kt | 33 +++++++++++++------ .../phone/adapters/RecentCallsAdapter.kt | 8 +++-- .../org/fossify/phone/extensions/Context.kt | 2 +- .../fossify/phone/helpers/RecentsHelper.kt | 14 ++++---- .../org/fossify/phone/models/RecentCall.kt | 1 + .../org/fossify/phone/models/SIMAccount.kt | 2 +- app/src/main/res/layout/item_recent_call.xml | 1 + 7 files changed, 41 insertions(+), 20 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/phone/activities/DialpadActivity.kt b/app/src/main/kotlin/org/fossify/phone/activities/DialpadActivity.kt index a3dc6540..08210ed7 100644 --- a/app/src/main/kotlin/org/fossify/phone/activities/DialpadActivity.kt +++ b/app/src/main/kotlin/org/fossify/phone/activities/DialpadActivity.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.annotation.TargetApi import android.content.Intent import android.database.Cursor +import android.graphics.Color import android.net.Uri import android.os.Build import android.os.Bundle @@ -154,26 +155,38 @@ class DialpadActivity : SimpleActivity() { } val properPrimaryColor = getProperPrimaryColor() - val callIconId = if (areMultipleSIMsAvailable()) { - val callIcon = resources.getColoredDrawableWithColor(R.drawable.ic_phone_two_vector, properPrimaryColor.getContrastColor()) + val properBackgroundColor = getProperBackgroundColor() + val hsv = FloatArray(3) + Color.colorToHSV(properBackgroundColor, hsv) + if (areMultipleSIMsAvailable()) { + val simInfo = getAvailableSIMCardLabels() + var callColor1 = if (simInfo.size > 1) simInfo[0].color else properPrimaryColor + var callColor2 = if (simInfo.size > 1) simInfo[1].color else properPrimaryColor + if (hsv[2] < 0.5) { + callColor1 = callColor1.lightenColor(24) + callColor2 = callColor2.lightenColor(24) + } + val callIcon1 = resources.getColoredDrawableWithColor(R.drawable.ic_phone_one_vector, callColor1.getContrastColor()) + val callIcon2 = resources.getColoredDrawableWithColor(R.drawable.ic_phone_two_vector, callColor2.getContrastColor()) binding.apply { - dialpadCallTwoButton.setImageDrawable(callIcon) - dialpadCallTwoButton.background.applyColorFilter(properPrimaryColor) + dialpadCallButton.setImageDrawable(callIcon1) + dialpadCallButton.background.applyColorFilter(callColor1) + dialpadCallTwoButton.setImageDrawable(callIcon2) + dialpadCallTwoButton.background.applyColorFilter(callColor2) dialpadCallTwoButton.beVisible() dialpadCallTwoButton.setOnClickListener { initCall(dialpadInput.value, 1) } } - - R.drawable.ic_phone_one_vector } else { - R.drawable.ic_phone_vector + binding.apply { + val callIcon1 = resources.getColoredDrawableWithColor(R.drawable.ic_phone_vector, properPrimaryColor.getContrastColor()) + dialpadCallButton.setImageDrawable(callIcon1) + dialpadCallButton.background.applyColorFilter(properPrimaryColor) + } } binding.apply { - val callIcon = resources.getColoredDrawableWithColor(callIconId, properPrimaryColor.getContrastColor()) - dialpadCallButton.setImageDrawable(callIcon) - dialpadCallButton.background.applyColorFilter(properPrimaryColor) letterFastscroller.textColor = getProperTextColor().getColorStateList() letterFastscroller.pressedTextColor = properPrimaryColor diff --git a/app/src/main/kotlin/org/fossify/phone/adapters/RecentCallsAdapter.kt b/app/src/main/kotlin/org/fossify/phone/adapters/RecentCallsAdapter.kt index 9db09820..74919d24 100644 --- a/app/src/main/kotlin/org/fossify/phone/adapters/RecentCallsAdapter.kt +++ b/app/src/main/kotlin/org/fossify/phone/adapters/RecentCallsAdapter.kt @@ -1,6 +1,7 @@ package org.fossify.phone.adapters import android.content.Intent +import android.graphics.Color import android.graphics.drawable.Drawable import android.provider.CallLog.Calls import android.text.SpannableString @@ -330,8 +331,11 @@ class RecentCallsAdapter( itemRecentsSimImage.beVisibleIf(areMultipleSIMsAvailable && call.simID != -1) itemRecentsSimId.beVisibleIf(areMultipleSIMsAvailable && call.simID != -1) if (areMultipleSIMsAvailable && call.simID != -1) { - itemRecentsSimImage.applyColorFilter(textColor) - itemRecentsSimId.setTextColor(textColor.getContrastColor()) + val hsv = FloatArray(3) + Color.colorToHSV(backgroundColor, hsv) + val simColor = if (hsv[2] > 0.5) call.simColor else call.simColor.lightenColor(24) + itemRecentsSimImage.applyColorFilter(simColor) + itemRecentsSimId.setTextColor(backgroundColor) itemRecentsSimId.text = call.simID.toString() } diff --git a/app/src/main/kotlin/org/fossify/phone/extensions/Context.kt b/app/src/main/kotlin/org/fossify/phone/extensions/Context.kt index f9bbc2d8..ba243a2b 100644 --- a/app/src/main/kotlin/org/fossify/phone/extensions/Context.kt +++ b/app/src/main/kotlin/org/fossify/phone/extensions/Context.kt @@ -28,7 +28,7 @@ fun Context.getAvailableSIMCardLabels(): List { label += " ($address)" } - val SIM = SIMAccount(index + 1, phoneAccount.accountHandle, label, address.substringAfter("tel:")) + val SIM = SIMAccount(index + 1, phoneAccount.accountHandle, label, address.substringAfter("tel:"), phoneAccount.highlightColor) SIMAccounts.add(SIM) } } catch (ignored: Exception) { diff --git a/app/src/main/kotlin/org/fossify/phone/helpers/RecentsHelper.kt b/app/src/main/kotlin/org/fossify/phone/helpers/RecentsHelper.kt index 2e30f870..f082018b 100644 --- a/app/src/main/kotlin/org/fossify/phone/helpers/RecentsHelper.kt +++ b/app/src/main/kotlin/org/fossify/phone/helpers/RecentsHelper.kt @@ -11,6 +11,7 @@ import org.fossify.phone.R import org.fossify.phone.activities.SimpleActivity import org.fossify.phone.extensions.getAvailableSIMCardLabels import org.fossify.phone.models.RecentCall +import org.fossify.phone.models.SIMAccount class RecentsHelper(private val context: Context) { private val COMPARABLE_PHONE_NUMBER_LENGTH = 9 @@ -56,9 +57,9 @@ class RecentsHelper(private val context: Context) { Calls.PHONE_ACCOUNT_ID ) - val accountIdToSimIDMap = HashMap() + val accountIdToSimAccountMap = HashMap() context.getAvailableSIMCardLabels().forEach { - accountIdToSimIDMap[it.handle.id] = it.id + accountIdToSimAccountMap[it.handle.id] = it } val cursor = if (isNougatPlus()) { @@ -150,7 +151,7 @@ class RecentsHelper(private val context: Context) { val duration = cursor.getIntValue(Calls.DURATION) val type = cursor.getIntValue(Calls.TYPE) val accountId = cursor.getStringValue(Calls.PHONE_ACCOUNT_ID) - val simID = accountIdToSimIDMap[accountId] ?: -1 + val simAccount = accountIdToSimAccountMap[accountId] val neighbourIDs = mutableListOf() var specificNumber = "" var specificType = "" @@ -174,20 +175,21 @@ class RecentsHelper(private val context: Context) { duration = duration, type = type, neighbourIDs = neighbourIDs, - simID = simID, + simID = simAccount?.id ?: -1, + simColor = simAccount?.color ?: -1, specificNumber = specificNumber, specificType = specificType, isUnknownNumber = isUnknownNumber ) // if we have multiple missed calls from the same number, show it just once - if (!groupSubsequentCalls || "$number$name$simID" != previousRecentCallFrom) { + if (!groupSubsequentCalls || "$number$name${simAccount?.id ?: -1}" != previousRecentCallFrom) { recentCalls.add(recentCall) } else { recentCalls.lastOrNull()?.neighbourIDs?.add(id) } - previousRecentCallFrom = "$number$name$simID" + previousRecentCallFrom = "$number$name${simAccount?.id ?: -1}" } while (cursor.moveToNext() && recentCalls.size < maxSize) } diff --git a/app/src/main/kotlin/org/fossify/phone/models/RecentCall.kt b/app/src/main/kotlin/org/fossify/phone/models/RecentCall.kt index 0775bd70..bfe1baf2 100644 --- a/app/src/main/kotlin/org/fossify/phone/models/RecentCall.kt +++ b/app/src/main/kotlin/org/fossify/phone/models/RecentCall.kt @@ -18,6 +18,7 @@ data class RecentCall( val type: Int, val neighbourIDs: MutableList, val simID: Int, + val simColor: Int, val specificNumber: String, val specificType: String, val isUnknownNumber: Boolean, diff --git a/app/src/main/kotlin/org/fossify/phone/models/SIMAccount.kt b/app/src/main/kotlin/org/fossify/phone/models/SIMAccount.kt index 47dd7d3a..0074b3f1 100644 --- a/app/src/main/kotlin/org/fossify/phone/models/SIMAccount.kt +++ b/app/src/main/kotlin/org/fossify/phone/models/SIMAccount.kt @@ -2,4 +2,4 @@ package org.fossify.phone.models import android.telecom.PhoneAccountHandle -data class SIMAccount(val id: Int, val handle: PhoneAccountHandle, val label: String, val phoneNumber: String) +data class SIMAccount(val id: Int, val handle: PhoneAccountHandle, val label: String, val phoneNumber: String, val color: Int) diff --git a/app/src/main/res/layout/item_recent_call.xml b/app/src/main/res/layout/item_recent_call.xml index 219859e6..8fd9b651 100644 --- a/app/src/main/res/layout/item_recent_call.xml +++ b/app/src/main/res/layout/item_recent_call.xml @@ -65,6 +65,7 @@ android:gravity="center" android:textColor="@color/md_grey_black" android:textSize="@dimen/small_text_size" + android:textStyle="bold" android:visibility="gone" app:layout_constraintBottom_toBottomOf="@+id/item_recents_sim_image" app:layout_constraintEnd_toEndOf="@+id/item_recents_sim_image"