diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c6b76294..2076d5b8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -224,9 +224,7 @@ + android:label="@string/dialer"> @@ -246,32 +244,6 @@ android:resource="@xml/provider_paths"/> - - - - - - - - - - - - - - - - - statusActive() - Call.STATE_DISCONNECTED -> statusDisconnected() - } - } - - private fun statusActive() { - callingDotsHandler.removeCallbacksAndMessages(null) - dialer_label_dots.beGone() - startNotificationService() - isCallActive = true - dialer_call_duration.beVisible() - updateCallDuration() - - dialer_label.setText(R.string.ongoing_call) - dialer_hangup_button.beVisible() - dialer_incoming_accept.beGone() - dialer_incoming_decline.beGone() - } - - private fun updateCallDuration() { - dialer_call_duration.text = callDuration.getFormattedDuration() - timerHandler.postDelayed({ - if (isCallActive) { - callDuration++ - updateCallDuration() - } - }, 1000) - } - - private fun statusDisconnected() { - callingDotsHandler.removeCallbacksAndMessages(null) - timerHandler.removeCallbacksAndMessages(null) - dialer_label_dots.beGone() - stopNotificationService() - dialer_hangup_button.beGone() - dialer_label.setText(R.string.disconnected) - if (isCallActive) { - dialer_hangup_button.postDelayed({ - finish() - }, DISCONNECT_DELAY) - } else { - finish() - } - isCallActive = false - } - - private fun updateOtherParticipant(contact: Contact?) { - if (contact != null) { - dialer_big_name_number.text = contact.getNameToDisplay() - dialer_number.text = callNumber - } else { - dialer_big_name_number.text = callNumber - dialer_number.beGone() - } - } - - override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {} - - override fun onSensorChanged(event: SensorEvent) { - if (event.sensor.type == Sensor.TYPE_PROXIMITY) { - if (event.values[0] >= -SENSOR_SENSITIVITY && event.values[0] <= SENSOR_SENSITIVITY) { - turnOffScreen() - } else { - turnOnScreen() - } - } - } - - @SuppressLint("WakelockTimeout") - private fun turnOffScreen() { - if (proximityWakeLock?.isHeld == false) { - proximityWakeLock!!.acquire() - } - } - - private fun turnOnScreen() { - if (proximityWakeLock?.isHeld == true) { - proximityWakeLock!!.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY) - } - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt index 596a33c1..458256b1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt @@ -32,16 +32,6 @@ const val FIRST_GROUP_ID = 10000L const val KEY_PHONE = "phone" const val KEY_NAME = "name" -// Dialer -const val INCOMING_CALL = "incoming_call" -const val RESUME_DIALER = "resume_dialer" -const val CALL_NUMBER = "call_number" -const val CALL_STATUS = "call_status" -const val IS_INCOMING_CALL = "is_incoming_call" -const val DIALER_INTENT_FILTER = "dialer_intent_filter" -const val DECLINE_CALL = "decline_call" -const val ANSWER_CALL = "answer_call" - const val LOCATION_CONTACTS_TAB = 0 const val LOCATION_FAVORITES_TAB = 1 const val LOCATION_RECENTS_TAB = 2 diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt index ac2312a9..9aa917ba 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt @@ -93,31 +93,6 @@ class ContactsHelper(val context: Context) { }.start() } - fun getContactWithNumber(number: String, callback: (contact: Contact?) -> Unit) { - Thread { - val uri = CommonDataKinds.Phone.CONTENT_URI - val projection = arrayOf(ContactsContract.Data.RAW_CONTACT_ID) - val selection = "${CommonDataKinds.Phone.NUMBER} = ? OR ${CommonDataKinds.Phone.NORMALIZED_NUMBER} = ?" - val selectionArgs = arrayOf(number, number.normalizeNumber()) - - var cursor: Cursor? = null - try { - cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null) - if (cursor?.moveToFirst() == true) { - val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID) - callback(getContactWithId(id, false)) - return@Thread - } - } catch (e: Exception) { - context.showErrorToast(e) - } finally { - cursor?.close() - } - - callback(LocalContactsHelper(context).getContactWithNumber(number)) - }.start() - } - private fun getContentResolverAccounts(): HashSet { val uri = ContactsContract.Data.CONTENT_URI val projection = arrayOf( diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt index f1f4caa5..54045fa3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt @@ -19,15 +19,6 @@ class LocalContactsHelper(val context: Context) { fun getContactWithId(id: Int) = convertLocalContactToContact(context.contactsDB.getContactWithId(id)) - fun getContactWithNumber(number: String): Contact? { - context.contactsDB.getContacts().forEach { - if (it.phoneNumbers.map { it.value }.contains(number)) { - return convertLocalContactToContact(it) - } - } - return null - } - fun insertOrUpdateContact(contact: Contact): Boolean { val localContact = convertContactToLocalContact(contact) return context.contactsDB.insertOrUpdate(localContact) > 0 diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/MyConnection.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/MyConnection.kt deleted file mode 100644 index 419ece65..00000000 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/MyConnection.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.simplemobiletools.contacts.pro.helpers - -import android.annotation.TargetApi -import android.content.Context -import android.os.Build -import android.telecom.Connection -import android.telecom.DisconnectCause - -@TargetApi(Build.VERSION_CODES.M) -class MyConnection(val context: Context) : Connection() { - override fun onAnswer() { - super.onAnswer() - setActive() - } - - override fun onReject() { - super.onReject() - setDisconnected(DisconnectCause(DisconnectCause.REJECTED)) - destroy() - } - - override fun onAbort() { - super.onAbort() - setDisconnected(DisconnectCause(DisconnectCause.REMOTE)) - destroy() - } - - override fun onDisconnect() { - super.onDisconnect() - setDisconnected(DisconnectCause(DisconnectCause.CANCELED)) - destroy() - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/objects/CallManager.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/objects/CallManager.kt deleted file mode 100644 index bfb7b9cb..00000000 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/objects/CallManager.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.simplemobiletools.contacts.pro.objects - -import android.annotation.TargetApi -import android.os.Build -import android.telecom.Call - -@TargetApi(Build.VERSION_CODES.M) -object CallManager { - private var currentCall: Call? = null - - fun updateCall(call: Call?) { - currentCall = call - } - - fun declineCall() { - currentCall?.apply { - when (state) { - Call.STATE_RINGING -> reject(false, "") - else -> disconnect() - } - } - } - - fun answerCall() { - currentCall?.apply { - answer(details.videoState) - } - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/DialerCallService.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/DialerCallService.kt deleted file mode 100644 index 12c95806..00000000 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/DialerCallService.kt +++ /dev/null @@ -1,161 +0,0 @@ -package com.simplemobiletools.contacts.pro.services - -import android.annotation.TargetApi -import android.app.NotificationChannel -import android.app.NotificationManager -import android.app.PendingIntent -import android.app.Service -import android.content.Context -import android.content.Intent -import android.os.Build -import android.os.Handler -import android.telecom.Call -import android.widget.RemoteViews -import androidx.core.app.NotificationCompat -import com.simplemobiletools.commons.extensions.getColoredBitmap -import com.simplemobiletools.commons.extensions.setText -import com.simplemobiletools.commons.extensions.setVisibleIf -import com.simplemobiletools.commons.helpers.isOreoPlus -import com.simplemobiletools.contacts.pro.R -import com.simplemobiletools.contacts.pro.activities.DialerActivity -import com.simplemobiletools.contacts.pro.helpers.* -import com.simplemobiletools.contacts.pro.objects.CallManager - -class DialerCallService : Service() { - private val REFRESH_REMINDER_PERIOD = 3000L - private val CALL_NOTIFICATION_ID = 1 - private val LAUNCH_DIALER_INTENT_ID = 1 - private val DISMISS_CALL_INTENT_ID = 2 - private val ANSWER_CALL_INTENT_ID = 3 - - private var callNumber = "" - private var callStatus = Call.STATE_NEW - private var isIncomingCall = false - private var otherParticipantName: String? = null - private var reminderRefreshHandler = Handler() - - override fun onBind(intent: Intent?) = null - - override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { - super.onStartCommand(intent, flags, startId) - when { - intent.getBooleanExtra(DECLINE_CALL, false) -> { - CallManager.declineCall() - stopForeground(true) - stopSelf() - } - intent.extras?.containsKey(CALL_STATUS) == true -> { - callNumber = intent.getStringExtra(CALL_NUMBER) - callStatus = intent.getIntExtra(CALL_STATUS, Call.STATE_NEW) - isIncomingCall = intent.getBooleanExtra(IS_INCOMING_CALL, false) - getOtherParticipantsName() - } - } - return START_STICKY - } - - override fun onDestroy() { - super.onDestroy() - stopForeground(true) - reminderRefreshHandler.removeCallbacksAndMessages(null) - } - - private fun getOtherParticipantsName() { - ContactsHelper(this).getContactWithNumber(callNumber) { - otherParticipantName = it?.getNameToDisplay() ?: callNumber - setupNotification() - } - } - - @TargetApi(Build.VERSION_CODES.O) - private fun setupNotification() { - val channelId = "call_channel" - if (isOreoPlus()) { - val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - val name = resources.getString(R.string.app_name) - val importance = if (callStatus == Call.STATE_RINGING) NotificationManager.IMPORTANCE_HIGH else NotificationManager.IMPORTANCE_DEFAULT - NotificationChannel(channelId, name, importance).apply { - enableLights(false) - enableVibration(false) - setSound(null, null) - notificationManager.createNotificationChannel(this) - } - } - - val notificationLayout = RemoteViews(packageName, R.layout.incoming_call_notification).apply { - setText(R.id.incoming_call_caller, otherParticipantName!!) - setText(R.id.incoming_call_status, getCallStatusString()) - - val resources = applicationContext.resources - setImageViewBitmap(R.id.call_decline, resources.getColoredBitmap(R.drawable.ic_phone_down, resources.getColor(R.color.theme_dark_red_primary_color))) - setImageViewBitmap(R.id.call_answer, resources.getColoredBitmap(R.drawable.ic_phone, resources.getColor(R.color.md_green_700))) - - setVisibleIf(R.id.call_answer, callStatus == Call.STATE_RINGING) - - setOnClickPendingIntent(R.id.call_decline, getDeclineCallIntent()) - setOnClickPendingIntent(R.id.call_answer, getAnswerCallIntent()) - } - - val notification = NotificationCompat.Builder(applicationContext, channelId) - .setSmallIcon(R.drawable.ic_phone) - .setContentIntent(getLaunchDialerIntent()) - .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - .setPriority(NotificationCompat.PRIORITY_MAX) - .setCustomContentView(notificationLayout) - .setCustomHeadsUpContentView(notificationLayout) - .setCustomBigContentView(notificationLayout) - .setOngoing(true) - .setCategory(NotificationCompat.CATEGORY_CALL) - .setChannelId(channelId) - .setSound(null) - .setOnlyAlertOnce(false) - .setUsesChronometer(callStatus == Call.STATE_ACTIVE) - - startForeground(CALL_NOTIFICATION_ID, notification.build()) - - reminderRefreshHandler.postDelayed({ - if (callStatus == Call.STATE_RINGING) { - setupNotification() - } - }, REFRESH_REMINDER_PERIOD) - } - - private fun getLaunchDialerIntent(): PendingIntent { - val intent = Intent(this, DialerActivity::class.java).apply { - action = RESUME_DIALER - putExtra(CALL_NUMBER, callNumber) - putExtra(CALL_STATUS, callStatus) - putExtra(IS_INCOMING_CALL, isIncomingCall) - } - return PendingIntent.getActivity(this, LAUNCH_DIALER_INTENT_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT) - } - - private fun getDeclineCallIntent(): PendingIntent { - Intent(this, DialerCallService::class.java).apply { - putExtra(DECLINE_CALL, true) - return PendingIntent.getService(this@DialerCallService, DISMISS_CALL_INTENT_ID, this, PendingIntent.FLAG_UPDATE_CURRENT) - } - } - - private fun getAnswerCallIntent(): PendingIntent { - val intent = Intent(this, DialerActivity::class.java).apply { - action = RESUME_DIALER - putExtra(CALL_NUMBER, callNumber) - putExtra(CALL_STATUS, callStatus) - putExtra(IS_INCOMING_CALL, isIncomingCall) - putExtra(ANSWER_CALL, true) - } - return PendingIntent.getActivity(this, ANSWER_CALL_INTENT_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT) - } - - private fun getCallStatusString(): String { - val id = when (callStatus) { - Call.STATE_DIALING -> R.string.calling - Call.STATE_RINGING -> R.string.incoming_call - Call.STATE_ACTIVE -> R.string.ongoing_call - else -> if (isIncomingCall) R.string.incoming_call else R.string.calling - } - - return applicationContext.getString(id) - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/MyIncomingCallService.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/MyIncomingCallService.kt deleted file mode 100644 index 15652cb4..00000000 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/MyIncomingCallService.kt +++ /dev/null @@ -1,76 +0,0 @@ -package com.simplemobiletools.contacts.pro.services - -import android.annotation.TargetApi -import android.app.KeyguardManager -import android.content.Context -import android.content.Intent -import android.net.Uri -import android.os.Build -import android.os.Bundle -import android.telecom.Call -import android.telecom.InCallService -import androidx.localbroadcastmanager.content.LocalBroadcastManager -import com.simplemobiletools.contacts.pro.activities.DialerActivity -import com.simplemobiletools.contacts.pro.helpers.* -import com.simplemobiletools.contacts.pro.objects.CallManager - -@TargetApi(Build.VERSION_CODES.M) -class MyIncomingCallService : InCallService() { - override fun onCallAdded(call: Call) { - super.onCallAdded(call) - call.registerCallback(callCallback) - - val handle = Uri.decode(call.details.handle.toString()) - val callerNumber = if (handle.contains("tel:")) { - handle.substringAfter("tel:") - } else { - handle - } - - val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager - if (keyguardManager.isKeyguardLocked) { - Intent(this, DialerActivity::class.java).apply { - action = RESUME_DIALER - flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK - putExtra(CALL_NUMBER, callerNumber) - putExtra(CALL_STATUS, call.state) - putExtra(IS_INCOMING_CALL, true) - startActivity(this) - } - } else { - Intent(this, DialerCallService::class.java).apply { - putExtra(CALL_STATUS, call.state) - putExtra(CALL_NUMBER, callerNumber) - putExtra(IS_INCOMING_CALL, true) - startService(this) - } - } - - CallManager.updateCall(call) - } - - override fun onCallRemoved(call: Call) { - super.onCallRemoved(call) - call.unregisterCallback(callCallback) - CallManager.updateCall(null) - } - - private val callCallback = object : Call.Callback() { - override fun onStateChanged(call: Call, state: Int) { - CallManager.updateCall(call) - sendCallToActivity(call) - if (state == Call.STATE_DISCONNECTED) { - Intent(applicationContext, DialerCallService::class.java).apply { - stopService(this) - } - } - } - } - - private fun sendCallToActivity(call: Call) { - Intent(DIALER_INTENT_FILTER).apply { - putExtra(CALL_STATUS, call.state) - LocalBroadcastManager.getInstance(applicationContext).sendBroadcast(this) - } - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/MyOutgoingCallService.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/MyOutgoingCallService.kt deleted file mode 100644 index 9e8427fa..00000000 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/MyOutgoingCallService.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.simplemobiletools.contacts.pro.services - -import android.annotation.TargetApi -import android.net.Uri -import android.os.Build -import android.telecom.* -import com.simplemobiletools.contacts.pro.helpers.MyConnection - -@TargetApi(Build.VERSION_CODES.M) -class MyOutgoingCallService : ConnectionService() { - override fun onCreateIncomingConnection(connectionManagerPhoneAccount: PhoneAccountHandle, request: ConnectionRequest): Connection { - val connection = MyConnection(applicationContext) - val phoneNumber = request.extras.get(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS) as Uri - connection.setAddress(phoneNumber, TelecomManager.PRESENTATION_ALLOWED) - connection.setRinging() - return connection - } -} diff --git a/app/src/main/res/drawable-hdpi/ic_phone_down.png b/app/src/main/res/drawable-hdpi/ic_phone_down.png deleted file mode 100755 index 94547825..00000000 Binary files a/app/src/main/res/drawable-hdpi/ic_phone_down.png and /dev/null differ diff --git a/app/src/main/res/drawable-xhdpi/ic_phone_down.png b/app/src/main/res/drawable-xhdpi/ic_phone_down.png deleted file mode 100644 index a0c8b0cb..00000000 Binary files a/app/src/main/res/drawable-xhdpi/ic_phone_down.png and /dev/null differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_phone_down.png b/app/src/main/res/drawable-xxhdpi/ic_phone_down.png deleted file mode 100644 index 79f71efe..00000000 Binary files a/app/src/main/res/drawable-xxhdpi/ic_phone_down.png and /dev/null differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_phone_down.png b/app/src/main/res/drawable-xxxhdpi/ic_phone_down.png deleted file mode 100644 index 60c9a533..00000000 Binary files a/app/src/main/res/drawable-xxxhdpi/ic_phone_down.png and /dev/null differ diff --git a/app/src/main/res/drawable/circle_green_background.xml b/app/src/main/res/drawable/circle_green_background.xml deleted file mode 100644 index 03bb39d3..00000000 --- a/app/src/main/res/drawable/circle_green_background.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - diff --git a/app/src/main/res/drawable/circle_red_background.xml b/app/src/main/res/drawable/circle_red_background.xml deleted file mode 100644 index 4371db18..00000000 --- a/app/src/main/res/drawable/circle_red_background.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - diff --git a/app/src/main/res/drawable/ripple.xml b/app/src/main/res/drawable/ripple.xml deleted file mode 100644 index 4538babe..00000000 --- a/app/src/main/res/drawable/ripple.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - diff --git a/app/src/main/res/layout/activity_dialer.xml b/app/src/main/res/layout/activity_dialer.xml deleted file mode 100644 index 3fbf37e2..00000000 --- a/app/src/main/res/layout/activity_dialer.xml +++ /dev/null @@ -1,118 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/incoming_call_notification.xml b/app/src/main/res/layout/incoming_call_notification.xml deleted file mode 100644 index ece53f06..00000000 --- a/app/src/main/res/layout/incoming_call_notification.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml deleted file mode 100644 index b8d2ac37..00000000 --- a/app/src/main/res/values/colors.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - #55000000 - diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 06eb1258..e5a33be5 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -7,9 +7,6 @@ 56dp 68dp 60dp - 70dp - 140dp - 40dp 34sp