redirection delay selector
This commit is contained in:
parent
48a9998c26
commit
53708dc554
11 changed files with 64 additions and 11 deletions
|
@ -21,7 +21,7 @@ class CallRedirectionService : CallRedirectionService() {
|
|||
)
|
||||
}
|
||||
|
||||
private lateinit var prefs: Preferences
|
||||
lateinit var prefs: Preferences
|
||||
private lateinit var window: PopupWindow
|
||||
private var connectivityManager: ConnectivityManager? = null
|
||||
|
||||
|
@ -30,6 +30,11 @@ class CallRedirectionService : CallRedirectionService() {
|
|||
init()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
window.cancel()
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
prefs = Preferences(this)
|
||||
window = PopupWindow(this)
|
||||
|
|
|
@ -44,12 +44,19 @@ class MainActivity : AppCompatActivity() {
|
|||
prefs = Preferences(this)
|
||||
roleManager = getSystemService(RoleManager::class.java)
|
||||
binding.apply {
|
||||
redirectionDelay.value = (prefs.redirectionDelay / 1000).toFloat()
|
||||
toggle.isChecked = prefs.isServiceEnabled
|
||||
}
|
||||
}
|
||||
|
||||
private fun setup() {
|
||||
binding.apply {
|
||||
redirectionDelay.setLabelFormatter {
|
||||
String.format("%.1f", it)
|
||||
}
|
||||
redirectionDelay.addOnChangeListener { _, value, _ ->
|
||||
prefs.redirectionDelay = (value * 1000).toLong()
|
||||
}
|
||||
toggle.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked && !hasPermissions()) {
|
||||
toggle.isChecked = false
|
||||
|
|
|
@ -14,10 +14,6 @@ import java.util.*
|
|||
import kotlin.concurrent.timerTask
|
||||
|
||||
class PopupWindow(private val service: CallRedirectionService) {
|
||||
companion object {
|
||||
private const val CANCEL_DELAY = 2000L
|
||||
}
|
||||
|
||||
private val windowManager = service
|
||||
.applicationContext
|
||||
.getSystemService(WindowManager::class.java)
|
||||
|
@ -41,9 +37,8 @@ class PopupWindow(private val service: CallRedirectionService) {
|
|||
|
||||
init {
|
||||
view.setOnClickListener {
|
||||
timer?.cancel()
|
||||
cancel()
|
||||
service.placeCallUnmodified()
|
||||
remove()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,7 +65,7 @@ class PopupWindow(private val service: CallRedirectionService) {
|
|||
return@timerTask
|
||||
}
|
||||
service.cancelCall()
|
||||
}, CANCEL_DELAY)
|
||||
}, service.prefs.redirectionDelay)
|
||||
view.findViewById<TextView>(R.id.description).text = String.format(
|
||||
service.getString(R.string.popup),
|
||||
service.getString(destinationId),
|
||||
|
@ -104,4 +99,9 @@ class PopupWindow(private val service: CallRedirectionService) {
|
|||
} catch (exc: WindowManager.BadTokenException) { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
fun cancel() {
|
||||
timer?.cancel()
|
||||
remove()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import androidx.preference.PreferenceManager
|
|||
class Preferences(ctx: Context) {
|
||||
companion object {
|
||||
private const val SERVICE_ENABLED = "service_enabled"
|
||||
private const val REDIRECTION_DELAY = "redirection_delay"
|
||||
}
|
||||
|
||||
private val prefs = PreferenceManager.getDefaultSharedPreferences(ctx)
|
||||
|
@ -14,4 +15,8 @@ class Preferences(ctx: Context) {
|
|||
var isServiceEnabled: Boolean
|
||||
get() = prefs.getBoolean(SERVICE_ENABLED, false)
|
||||
set(value) = prefs.edit { putBoolean(SERVICE_ENABLED, value) }
|
||||
|
||||
var redirectionDelay: Long
|
||||
get() = prefs.getLong(REDIRECTION_DELAY, 2000L)
|
||||
set(value) = prefs.edit { putLong(REDIRECTION_DELAY, value) }
|
||||
}
|
||||
|
|
|
@ -16,6 +16,39 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginVertical="16dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/toggle"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/description">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.slider.Slider
|
||||
android:id="@+id/redirectionDelay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/redirection_delay_description"
|
||||
android:stepSize="0.5"
|
||||
android:valueFrom="2"
|
||||
android:valueTo="4" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/redirection_delay_description" />
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/toggle"
|
||||
android:layout_width="0dp"
|
||||
|
|
|
@ -5,4 +5,5 @@
|
|||
<string name="popup">Перенаправление в %1$s</string>
|
||||
<string name="signal">Signal</string>
|
||||
<string name="telegram">Telegram</string>
|
||||
<string name="redirection_delay_description">Задержка до того, как звонок будет перенаправлен.</string>
|
||||
</resources>
|
|
@ -5,4 +5,5 @@
|
|||
<string name="popup">Redirecting to %1$s</string>
|
||||
<string name="signal">Signal</string>
|
||||
<string name="telegram">Telegram</string>
|
||||
<string name="redirection_delay_description">Delay before a call will be redirected.</string>
|
||||
</resources>
|
Loading…
Add table
Add a link
Reference in a new issue