mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
adding the DialerActivity
This commit is contained in:
@ -71,6 +71,19 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activities.DialerActivity"
|
||||
android:label="@string/dialer"
|
||||
android:theme="@style/Theme.Transparent">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.CALL" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<data android:scheme="tel" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity-alias
|
||||
android:name=".activities.SplashActivity.Red"
|
||||
android:enabled="false"
|
||||
|
@ -0,0 +1,71 @@
|
||||
package com.simplemobiletools.dialer.activities
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.telecom.TelecomManager
|
||||
import android.view.Menu
|
||||
import com.simplemobiletools.commons.extensions.isDefaultDialer
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import com.simplemobiletools.commons.extensions.telecomManager
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.helpers.REQUEST_CODE_SET_DEFAULT_DIALER
|
||||
import com.simplemobiletools.dialer.R
|
||||
import com.simplemobiletools.dialer.extensions.getHandleToUse
|
||||
|
||||
class DialerActivity : SimpleActivity() {
|
||||
private var callNumber: Uri? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
if (intent.action == Intent.ACTION_CALL && intent.data != null) {
|
||||
callNumber = intent.data
|
||||
|
||||
// make sure Simple Contacts is the default Phone app before initiating an outgoing call
|
||||
if (!isDefaultDialer()) {
|
||||
launchSetDefaultDialerIntent()
|
||||
} else {
|
||||
initOutgoingCall()
|
||||
}
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
updateMenuItemColors(menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun initOutgoingCall() {
|
||||
try {
|
||||
getHandleToUse(intent, callNumber.toString()) { handle ->
|
||||
Bundle().apply {
|
||||
putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle)
|
||||
putBoolean(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, false)
|
||||
putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, false)
|
||||
telecomManager.placeCall(callNumber, this)
|
||||
}
|
||||
finish()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, resultData)
|
||||
if (requestCode == REQUEST_CODE_SET_DEFAULT_DIALER) {
|
||||
if (!isDefaultDialer()) {
|
||||
finish()
|
||||
} else {
|
||||
initOutgoingCall()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user