mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
Merge pull request #274 from Aga-C/add-swipe-to-answer
Added swipe to answer an incoming call (#127)
This commit is contained in:
@ -11,7 +11,9 @@ import android.os.Handler
|
|||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import android.telecom.Call
|
import android.telecom.Call
|
||||||
import android.telecom.CallAudioState
|
import android.telecom.CallAudioState
|
||||||
|
import android.view.MotionEvent
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
|
import android.widget.ImageView
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.MINUTE_SECONDS
|
import com.simplemobiletools.commons.helpers.MINUTE_SECONDS
|
||||||
import com.simplemobiletools.commons.helpers.isOreoMr1Plus
|
import com.simplemobiletools.commons.helpers.isOreoMr1Plus
|
||||||
@ -45,6 +47,8 @@ class CallActivity : SimpleActivity() {
|
|||||||
private var callDuration = 0
|
private var callDuration = 0
|
||||||
private val callContactAvatarHelper by lazy { CallContactAvatarHelper(this) }
|
private val callContactAvatarHelper by lazy { CallContactAvatarHelper(this) }
|
||||||
private val callDurationHelper by lazy { (application as App).callDurationHelper }
|
private val callDurationHelper by lazy { (application as App).callDurationHelper }
|
||||||
|
private var dragDownX = 0f
|
||||||
|
private var stopAnimation = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
supportActionBar?.hide()
|
supportActionBar?.hide()
|
||||||
@ -94,13 +98,7 @@ class CallActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initButtons() {
|
private fun initButtons() {
|
||||||
call_decline.setOnClickListener {
|
handleSwipe()
|
||||||
endCall()
|
|
||||||
}
|
|
||||||
|
|
||||||
call_accept.setOnClickListener {
|
|
||||||
acceptCall()
|
|
||||||
}
|
|
||||||
|
|
||||||
call_toggle_microphone.setOnClickListener {
|
call_toggle_microphone.setOnClickListener {
|
||||||
toggleMicrophone()
|
toggleMicrophone()
|
||||||
@ -145,6 +143,115 @@ class CallActivity : SimpleActivity() {
|
|||||||
call_sim_id.setTextColor(config.textColor.getContrastColor())
|
call_sim_id.setTextColor(config.textColor.getContrastColor())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
private fun handleSwipe() {
|
||||||
|
var minDragX = 0f
|
||||||
|
var maxDragX = 0f
|
||||||
|
var initialDraggableX = 0f
|
||||||
|
var initialLeftArrowX = 0f
|
||||||
|
var initialRightArrowX = 0f
|
||||||
|
var initialLeftArrowScaleX = 0f
|
||||||
|
var initialLeftArrowScaleY = 0f
|
||||||
|
var initialRightArrowScaleX = 0f
|
||||||
|
var initialRightArrowScaleY = 0f
|
||||||
|
var leftArrowTranslation = 0f
|
||||||
|
var rightArrowTranslation = 0f
|
||||||
|
|
||||||
|
call_accept.onGlobalLayout {
|
||||||
|
minDragX = call_decline.left.toFloat()
|
||||||
|
maxDragX = call_accept.left.toFloat()
|
||||||
|
initialDraggableX = call_draggable.left.toFloat()
|
||||||
|
initialLeftArrowX = call_left_arrow.x
|
||||||
|
initialRightArrowX = call_right_arrow.x
|
||||||
|
initialLeftArrowScaleX = call_left_arrow.scaleX
|
||||||
|
initialLeftArrowScaleY = call_left_arrow.scaleY
|
||||||
|
initialRightArrowScaleX = call_right_arrow.scaleX
|
||||||
|
initialRightArrowScaleY = call_right_arrow.scaleY
|
||||||
|
leftArrowTranslation = -call_decline.x
|
||||||
|
rightArrowTranslation = call_decline.x
|
||||||
|
|
||||||
|
call_left_arrow.applyColorFilter(getColor(R.color.md_red_400))
|
||||||
|
call_right_arrow.applyColorFilter(getColor(R.color.md_green_400))
|
||||||
|
|
||||||
|
startArrowAnimation(call_left_arrow, initialLeftArrowX, initialLeftArrowScaleX, initialLeftArrowScaleY, leftArrowTranslation)
|
||||||
|
startArrowAnimation(call_right_arrow, initialRightArrowX, initialRightArrowScaleX, initialRightArrowScaleY, rightArrowTranslation)
|
||||||
|
}
|
||||||
|
|
||||||
|
var lock = false
|
||||||
|
call_draggable.setOnTouchListener { v, event ->
|
||||||
|
when (event.action) {
|
||||||
|
MotionEvent.ACTION_DOWN -> {
|
||||||
|
dragDownX = event.x
|
||||||
|
call_draggable_background.animate().alpha(0f)
|
||||||
|
stopAnimation = true
|
||||||
|
call_left_arrow.animate().alpha(0f)
|
||||||
|
call_right_arrow.animate().alpha(0f)
|
||||||
|
lock = false
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||||
|
dragDownX = 0f
|
||||||
|
call_draggable.animate().x(initialDraggableX).withEndAction {
|
||||||
|
call_draggable_background.animate().alpha(0.2f)
|
||||||
|
}
|
||||||
|
call_draggable.setImageDrawable(getDrawable(R.drawable.ic_phone_down_vector))
|
||||||
|
call_left_arrow.animate().alpha(1f)
|
||||||
|
call_right_arrow.animate().alpha(1f)
|
||||||
|
stopAnimation = false
|
||||||
|
startArrowAnimation(call_left_arrow, initialLeftArrowX, initialLeftArrowScaleX, initialLeftArrowScaleY, leftArrowTranslation)
|
||||||
|
startArrowAnimation(call_right_arrow, initialRightArrowX, initialRightArrowScaleX, initialRightArrowScaleY, rightArrowTranslation)
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_MOVE -> {
|
||||||
|
call_draggable.x = Math.min(maxDragX, Math.max(minDragX, event.rawX - dragDownX))
|
||||||
|
when {
|
||||||
|
call_draggable.x >= maxDragX - 50f -> {
|
||||||
|
if (!lock) {
|
||||||
|
lock = true
|
||||||
|
call_draggable.performHapticFeedback()
|
||||||
|
acceptCall()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
call_draggable.x <= minDragX + 50f -> {
|
||||||
|
if (!lock) {
|
||||||
|
lock = true
|
||||||
|
call_draggable.performHapticFeedback()
|
||||||
|
endCall()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
call_draggable.x > initialDraggableX -> {
|
||||||
|
lock = false
|
||||||
|
call_draggable.setImageDrawable(getDrawable(R.drawable.ic_phone_green_vector))
|
||||||
|
}
|
||||||
|
call_draggable.x <= initialDraggableX -> {
|
||||||
|
lock = false
|
||||||
|
call_draggable.setImageDrawable(getDrawable(R.drawable.ic_phone_down_red_vector))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startArrowAnimation(arrow: ImageView, initialX: Float, initialScaleX: Float, initialScaleY: Float, translation: Float) {
|
||||||
|
arrow.apply {
|
||||||
|
alpha = 1f
|
||||||
|
x = initialX
|
||||||
|
scaleX = initialScaleX
|
||||||
|
scaleY = initialScaleY
|
||||||
|
animate()
|
||||||
|
.alpha(0f)
|
||||||
|
.translationX(translation)
|
||||||
|
.scaleXBy(-0.5f)
|
||||||
|
.scaleYBy(-0.5f)
|
||||||
|
.setDuration(1000)
|
||||||
|
.withEndAction {
|
||||||
|
if (!stopAnimation) {
|
||||||
|
startArrowAnimation(this, initialX, initialScaleX, initialScaleY, translation)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun dialpadPressed(char: Char) {
|
private fun dialpadPressed(char: Char) {
|
||||||
CallManager.keypad(char)
|
CallManager.keypad(char)
|
||||||
dialpad_input.addCharacter(char)
|
dialpad_input.addCharacter(char)
|
||||||
|
12
app/src/main/res/drawable/pulsing_background.xml
Normal file
12
app/src/main/res/drawable/pulsing_background.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="oval">
|
||||||
|
|
||||||
|
<solid
|
||||||
|
android:color="@android:color/white"/>
|
||||||
|
|
||||||
|
<size
|
||||||
|
android:width="@dimen/incoming_call_button_size"
|
||||||
|
android:height="@dimen/incoming_call_button_size"/>
|
||||||
|
</shape>
|
@ -160,13 +160,15 @@
|
|||||||
android:id="@+id/call_decline"
|
android:id="@+id/call_decline"
|
||||||
android:layout_width="@dimen/incoming_call_button_size"
|
android:layout_width="@dimen/incoming_call_button_size"
|
||||||
android:layout_height="@dimen/incoming_call_button_size"
|
android:layout_height="@dimen/incoming_call_button_size"
|
||||||
|
android:clickable="false"
|
||||||
android:contentDescription="@string/decline_call"
|
android:contentDescription="@string/decline_call"
|
||||||
|
android:padding="@dimen/medium_margin"
|
||||||
android:src="@drawable/ic_call_decline"
|
android:src="@drawable/ic_call_decline"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="@+id/call_draggable"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toStartOf="@+id/call_draggable"
|
||||||
app:layout_constraintHorizontal_bias="0.15"
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="@+id/call_draggable"
|
||||||
app:layout_constraintVertical_bias="0.85" />
|
app:layout_constraintVertical_bias="0.85" />
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
@ -180,17 +182,78 @@
|
|||||||
app:layout_constraintStart_toStartOf="@+id/call_decline"
|
app:layout_constraintStart_toStartOf="@+id/call_decline"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/call_decline" />
|
app:layout_constraintTop_toBottomOf="@+id/call_decline" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/call_left_arrow"
|
||||||
|
android:layout_width="@dimen/incoming_call_arrow_size"
|
||||||
|
android:layout_height="@dimen/incoming_call_arrow_size"
|
||||||
|
android:layout_marginBottom="@dimen/activity_margin"
|
||||||
|
android:alpha="0.2"
|
||||||
|
android:padding="@dimen/medium_margin"
|
||||||
|
android:src="@drawable/ic_chevron_left_vector"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/call_accept"
|
||||||
|
app:layout_constraintHorizontal_bias="0.15"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/call_decline"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0.8375" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/call_draggable_background"
|
||||||
|
android:layout_width="@dimen/incoming_call_button_size"
|
||||||
|
android:layout_height="@dimen/incoming_call_button_size"
|
||||||
|
android:layout_marginBottom="@dimen/activity_margin"
|
||||||
|
android:alpha="0.2"
|
||||||
|
android:padding="@dimen/medium_margin"
|
||||||
|
android:src="@drawable/pulsing_background"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/call_accept"
|
||||||
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/call_decline"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0.85" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/call_draggable"
|
||||||
|
android:layout_width="@dimen/incoming_call_button_size"
|
||||||
|
android:layout_height="@dimen/incoming_call_button_size"
|
||||||
|
android:layout_marginBottom="@dimen/activity_margin"
|
||||||
|
android:padding="@dimen/activity_margin"
|
||||||
|
android:src="@drawable/ic_phone_down_vector"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/call_accept"
|
||||||
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/call_decline"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0.85" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/call_right_arrow"
|
||||||
|
android:layout_width="@dimen/incoming_call_arrow_size"
|
||||||
|
android:layout_height="@dimen/incoming_call_arrow_size"
|
||||||
|
android:layout_marginBottom="@dimen/activity_margin"
|
||||||
|
android:alpha="0.2"
|
||||||
|
android:padding="@dimen/medium_margin"
|
||||||
|
android:src="@drawable/ic_chevron_right_vector"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/call_accept"
|
||||||
|
app:layout_constraintHorizontal_bias="0.85"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/call_decline"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0.8375" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/call_accept"
|
android:id="@+id/call_accept"
|
||||||
android:layout_width="@dimen/incoming_call_button_size"
|
android:layout_width="@dimen/incoming_call_button_size"
|
||||||
android:layout_height="@dimen/incoming_call_button_size"
|
android:layout_height="@dimen/incoming_call_button_size"
|
||||||
|
android:clickable="false"
|
||||||
android:contentDescription="@string/accept_call"
|
android:contentDescription="@string/accept_call"
|
||||||
|
android:padding="@dimen/medium_margin"
|
||||||
android:src="@drawable/ic_call_accept"
|
android:src="@drawable/ic_call_accept"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="@+id/call_draggable"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.85"
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toEndOf="@+id/call_draggable"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="@+id/call_draggable"
|
||||||
app:layout_constraintVertical_bias="0.85" />
|
app:layout_constraintVertical_bias="0.85" />
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
@ -84,4 +84,4 @@
|
|||||||
Haven't found some strings? There's more at
|
Haven't found some strings? There's more at
|
||||||
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
||||||
-->
|
-->
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -61,4 +61,4 @@
|
|||||||
Haven't found some strings? There's more at
|
Haven't found some strings? There's more at
|
||||||
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
||||||
-->
|
-->
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -84,4 +84,4 @@
|
|||||||
Haven't found some strings? There's more at
|
Haven't found some strings? There's more at
|
||||||
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
||||||
-->
|
-->
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<string name="group_subsequent_calls">Oproepgeschiedenis: opeenvolgende items van hetzelfde nummer groeperen</string>
|
<string name="group_subsequent_calls">Oproepgeschiedenis: opeenvolgende items van hetzelfde nummer groeperen</string>
|
||||||
<string name="open_dialpad_by_default">Standaard het toetsenblok openen bij starten</string>
|
<string name="open_dialpad_by_default">Standaard het toetsenblok openen bij starten</string>
|
||||||
<string name="disable_proximity_sensor">Nabijheidssensor uitschakelen tijdens bellen</string>v
|
<string name="disable_proximity_sensor">Nabijheidssensor uitschakelen tijdens bellen</string>
|
||||||
|
|
||||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||||
<!-- App title has to have less than 50 characters. If you cannot squeeze it, just remove a part of it -->
|
<!-- App title has to have less than 50 characters. If you cannot squeeze it, just remove a part of it -->
|
||||||
|
@ -84,4 +84,4 @@
|
|||||||
Haven't found some strings? There's more at
|
Haven't found some strings? There's more at
|
||||||
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
||||||
-->
|
-->
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -84,4 +84,4 @@
|
|||||||
Haven't found some strings? There's more at
|
Haven't found some strings? There's more at
|
||||||
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
||||||
-->
|
-->
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -84,4 +84,4 @@
|
|||||||
Bazı dizeleri bulamadınız mı? Burada daha fazlası var:
|
Bazı dizeleri bulamadınız mı? Burada daha fazlası var:
|
||||||
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
||||||
-->
|
-->
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -84,4 +84,4 @@
|
|||||||
Haven't found some strings? There's more at
|
Haven't found some strings? There's more at
|
||||||
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
||||||
-->
|
-->
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="dialpad_button_size">60dp</dimen>
|
<dimen name="dialpad_button_size">60dp</dimen>
|
||||||
|
<dimen name="incoming_call_arrow_size">50dp</dimen>
|
||||||
<dimen name="incoming_call_button_size">72dp</dimen>
|
<dimen name="incoming_call_button_size">72dp</dimen>
|
||||||
<dimen name="call_notification_button_size">30dp</dimen>
|
<dimen name="call_notification_button_size">30dp</dimen>
|
||||||
<dimen name="incoming_call_avatar_size">120dp</dimen>
|
<dimen name="incoming_call_avatar_size">120dp</dimen>
|
||||||
|
Reference in New Issue
Block a user