From fa8499eedbab5fdd2c2c3df56f97392a54e0ada5 Mon Sep 17 00:00:00 2001 From: Marvin Rohrbach Date: Wed, 17 Jan 2024 01:56:05 +0100 Subject: [PATCH 1/6] 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 a3dc65408..08210ed77 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 9db098203..74919d244 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 f9bbc2d80..ba243a2b1 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 2e30f8702..f082018bf 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 0775bd702..bfe1baf29 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 47dd7d3a4..0074b3f15 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 219859e6d..8fd9b6514 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" From d8ba4faa66a5116290637dad9913920bc6a2935f Mon Sep 17 00:00:00 2001 From: Marvin Rohrbach Date: Mon, 22 Jan 2024 22:37:37 +0100 Subject: [PATCH 2/6] Move color conversion to extension function --- .../org/fossify/phone/activities/DialpadActivity.kt | 11 ++--------- .../fossify/phone/adapters/RecentCallsAdapter.kt | 6 +----- .../main/kotlin/org/fossify/phone/extensions/Int.kt | 13 +++++++++++++ 3 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 app/src/main/kotlin/org/fossify/phone/extensions/Int.kt 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 08210ed77..0c830358f 100644 --- a/app/src/main/kotlin/org/fossify/phone/activities/DialpadActivity.kt +++ b/app/src/main/kotlin/org/fossify/phone/activities/DialpadActivity.kt @@ -4,7 +4,6 @@ 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 @@ -156,16 +155,10 @@ class DialpadActivity : SimpleActivity() { val properPrimaryColor = getProperPrimaryColor() 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 callColor1 = if (simInfo.size > 1) simInfo[0].color.adjustSimColorForBackground(properBackgroundColor) else properPrimaryColor + val callColor2 = if (simInfo.size > 1) simInfo[1].color.adjustSimColorForBackground(properBackgroundColor) else properPrimaryColor 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 { 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 74919d244..046a340cc 100644 --- a/app/src/main/kotlin/org/fossify/phone/adapters/RecentCallsAdapter.kt +++ b/app/src/main/kotlin/org/fossify/phone/adapters/RecentCallsAdapter.kt @@ -1,7 +1,6 @@ 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 @@ -331,10 +330,7 @@ class RecentCallsAdapter( itemRecentsSimImage.beVisibleIf(areMultipleSIMsAvailable && call.simID != -1) itemRecentsSimId.beVisibleIf(areMultipleSIMsAvailable && call.simID != -1) if (areMultipleSIMsAvailable && call.simID != -1) { - 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) + itemRecentsSimImage.applyColorFilter(call.simColor.adjustSimColorForBackground(backgroundColor)) itemRecentsSimId.setTextColor(backgroundColor) itemRecentsSimId.text = call.simID.toString() } diff --git a/app/src/main/kotlin/org/fossify/phone/extensions/Int.kt b/app/src/main/kotlin/org/fossify/phone/extensions/Int.kt new file mode 100644 index 000000000..ab651845b --- /dev/null +++ b/app/src/main/kotlin/org/fossify/phone/extensions/Int.kt @@ -0,0 +1,13 @@ +package org.fossify.phone.extensions + +import android.graphics.Color +import org.fossify.commons.extensions.lightenColor + +fun Int.adjustSimColorForBackground(bg: Int): Int { + val hsv = FloatArray(3) + Color.colorToHSV(bg, hsv) + if (hsv[2] < 0.5) { + return this.lightenColor(24) + } + return this +} From ec0403083cdc7b7c2d896f113f50b520ae6d6f54 Mon Sep 17 00:00:00 2001 From: Marvin Rohrbach Date: Mon, 22 Jan 2024 22:37:50 +0100 Subject: [PATCH 3/6] Implement sim color support in call activity --- .../org/fossify/phone/activities/CallActivity.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/phone/activities/CallActivity.kt b/app/src/main/kotlin/org/fossify/phone/activities/CallActivity.kt index da4c0fc31..505414a3b 100644 --- a/app/src/main/kotlin/org/fossify/phone/activities/CallActivity.kt +++ b/app/src/main/kotlin/org/fossify/phone/activities/CallActivity.kt @@ -585,14 +585,15 @@ class CallActivity : SimpleActivity() { @SuppressLint("MissingPermission") private fun checkCalledSIMCard() { try { - val accounts = telecomManager.callCapablePhoneAccounts - if (accounts.size > 1) { - accounts.forEachIndexed { index, account -> - if (account == CallManager.getPrimaryCall()?.details?.accountHandle) { + val simLabels = getAvailableSIMCardLabels() + if (simLabels.size > 1) { + simLabels.forEachIndexed { index, sim -> + if (sim.handle == CallManager.getPrimaryCall()?.details?.accountHandle) { binding.apply { - callSimId.text = "${index + 1}" + callSimId.text = sim.id.toString() callSimId.beVisible() callSimImage.beVisible() + callSimImage.applyColorFilter(sim.color.adjustSimColorForBackground(getProperBackgroundColor())) } val acceptDrawableId = when (index) { From 7b9b095aab8e51310df2fcb316fe095a4132ad3a Mon Sep 17 00:00:00 2001 From: Naveen Singh Date: Thu, 5 Jun 2025 15:52:45 +0530 Subject: [PATCH 4/6] style: add empty line --- app/src/main/kotlin/org/fossify/phone/helpers/RecentsHelper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ffa501485..7d7d63d44 100644 --- a/app/src/main/kotlin/org/fossify/phone/helpers/RecentsHelper.kt +++ b/app/src/main/kotlin/org/fossify/phone/helpers/RecentsHelper.kt @@ -317,4 +317,4 @@ class RecentsHelper(private val context: Context) { } } } -} \ No newline at end of file +} From efb9bbeb96c1cb5e61c0b906f614cd4217b6bbdf Mon Sep 17 00:00:00 2001 From: Naveen Singh Date: Thu, 5 Jun 2025 15:56:42 +0530 Subject: [PATCH 5/6] style: put parameters on separate lines --- .../main/kotlin/org/fossify/phone/models/SIMAccount.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 0074b3f15..f004e64a1 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,10 @@ package org.fossify.phone.models import android.telecom.PhoneAccountHandle -data class SIMAccount(val id: Int, val handle: PhoneAccountHandle, val label: String, val phoneNumber: String, val color: Int) +data class SIMAccount( + val id: Int, + val handle: PhoneAccountHandle, + val label: String, + val phoneNumber: String, + val color: Int, +) From c0e87452571fe7c5f02205220004817a2ebcc00f Mon Sep 17 00:00:00 2001 From: Naveen Singh Date: Thu, 5 Jun 2025 16:52:47 +0530 Subject: [PATCH 6/6] revert: undo dialpad button changes The primary/secondary buttons will be removed to keep things simple: https://github.com/FossifyOrg/Phone/issues/50 --- .../phone/activities/DialpadActivity.kt | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 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 610eff8ab..e3710d47d 100644 --- a/app/src/main/kotlin/org/fossify/phone/activities/DialpadActivity.kt +++ b/app/src/main/kotlin/org/fossify/phone/activities/DialpadActivity.kt @@ -150,32 +150,26 @@ class DialpadActivity : SimpleActivity() { } val properPrimaryColor = getProperPrimaryColor() - val properBackgroundColor = getProperBackgroundColor() - if (areMultipleSIMsAvailable()) { - val simInfo = getAvailableSIMCardLabels() - val callColor1 = if (simInfo.size > 1) simInfo[0].color.adjustSimColorForBackground(properBackgroundColor) else properPrimaryColor - val callColor2 = if (simInfo.size > 1) simInfo[1].color.adjustSimColorForBackground(properBackgroundColor) else properPrimaryColor - val callIcon1 = resources.getColoredDrawableWithColor(R.drawable.ic_phone_one_vector, callColor1.getContrastColor()) - val callIcon2 = resources.getColoredDrawableWithColor(R.drawable.ic_phone_two_vector, callColor2.getContrastColor()) + val callIconId = if (areMultipleSIMsAvailable()) { + val callIcon = resources.getColoredDrawableWithColor(R.drawable.ic_phone_two_vector, properPrimaryColor.getContrastColor()) binding.apply { - dialpadCallButton.setImageDrawable(callIcon1) - dialpadCallButton.background.applyColorFilter(callColor1) - dialpadCallTwoButton.setImageDrawable(callIcon2) - dialpadCallTwoButton.background.applyColorFilter(callColor2) + dialpadCallTwoButton.setImageDrawable(callIcon) + dialpadCallTwoButton.background.applyColorFilter(properPrimaryColor) dialpadCallTwoButton.beVisible() dialpadCallTwoButton.setOnClickListener { initCall(dialpadInput.value, 1) } } + + R.drawable.ic_phone_one_vector } else { - binding.apply { - val callIcon1 = resources.getColoredDrawableWithColor(R.drawable.ic_phone_vector, properPrimaryColor.getContrastColor()) - dialpadCallButton.setImageDrawable(callIcon1) - dialpadCallButton.background.applyColorFilter(properPrimaryColor) - } + R.drawable.ic_phone_vector } binding.apply { + val callIcon = resources.getColoredDrawableWithColor(callIconId, properPrimaryColor.getContrastColor()) + dialpadCallButton.setImageDrawable(callIcon) + dialpadCallButton.background.applyColorFilter(properPrimaryColor) letterFastscroller.textColor = getProperTextColor().getColorStateList() letterFastscroller.pressedTextColor = properPrimaryColor