mirror of
				https://github.com/SimpleMobileTools/Simple-Contacts.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	show a timer at established calls
This commit is contained in:
		| @@ -10,6 +10,7 @@ import android.hardware.SensorEventListener | |||||||
| import android.hardware.SensorManager | import android.hardware.SensorManager | ||||||
| import android.net.Uri | import android.net.Uri | ||||||
| import android.os.Bundle | import android.os.Bundle | ||||||
|  | import android.os.Handler | ||||||
| import android.os.PowerManager | import android.os.PowerManager | ||||||
| import androidx.localbroadcastmanager.content.LocalBroadcastManager | import androidx.localbroadcastmanager.content.LocalBroadcastManager | ||||||
| import com.simplemobiletools.commons.extensions.* | import com.simplemobiletools.commons.extensions.* | ||||||
| @@ -27,9 +28,12 @@ class DialerActivity : SimpleActivity(), SensorEventListener { | |||||||
|  |  | ||||||
|     private var number = "" |     private var number = "" | ||||||
|     private var isIncomingCall = false |     private var isIncomingCall = false | ||||||
|  |     private var isCallActive = false | ||||||
|  |     private var callDuration = 0 | ||||||
|     private var sensorManager: SensorManager? = null |     private var sensorManager: SensorManager? = null | ||||||
|     private var proximity: Sensor? = null |     private var proximity: Sensor? = null | ||||||
|     private var proximityWakeLock: PowerManager.WakeLock? = null |     private var proximityWakeLock: PowerManager.WakeLock? = null | ||||||
|  |     private var timerHandler = Handler() | ||||||
|  |  | ||||||
|     override fun onCreate(savedInstanceState: Bundle?) { |     override fun onCreate(savedInstanceState: Bundle?) { | ||||||
|         super.onCreate(savedInstanceState) |         super.onCreate(savedInstanceState) | ||||||
| @@ -64,6 +68,11 @@ class DialerActivity : SimpleActivity(), SensorEventListener { | |||||||
|         sensorManager!!.unregisterListener(this) |         sensorManager!!.unregisterListener(this) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     override fun onDestroy() { | ||||||
|  |         super.onDestroy() | ||||||
|  |         timerHandler.removeCallbacksAndMessages(null) | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private val messageReceiver = object : BroadcastReceiver() { |     private val messageReceiver = object : BroadcastReceiver() { | ||||||
|         override fun onReceive(context: Context, intent: Intent) { |         override fun onReceive(context: Context, intent: Intent) { | ||||||
|             if (intent.extras?.containsKey(CALL_STATUS) == true) { |             if (intent.extras?.containsKey(CALL_STATUS) == true) { | ||||||
| @@ -121,13 +130,29 @@ class DialerActivity : SimpleActivity(), SensorEventListener { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun statusActive() { |     private fun statusActive() { | ||||||
|  |         isCallActive = true | ||||||
|  |         dialer_call_duration.beVisible() | ||||||
|  |         updateCallDuration() | ||||||
|  |  | ||||||
|         dialer_label.text = "" |         dialer_label.text = "" | ||||||
|         dialer_hangup_button.beVisible() |         dialer_hangup_button.beVisible() | ||||||
|         dialer_incoming_accept.beGone() |         dialer_incoming_accept.beGone() | ||||||
|         dialer_incoming_decline.beGone() |         dialer_incoming_decline.beGone() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private fun updateCallDuration() { | ||||||
|  |         dialer_call_duration.text = callDuration.getFormattedDuration() | ||||||
|  |         timerHandler.postDelayed({ | ||||||
|  |             if (isCallActive) { | ||||||
|  |                 callDuration++ | ||||||
|  |                 updateCallDuration() | ||||||
|  |             } | ||||||
|  |         }, 1000) | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private fun statusDisconnected() { |     private fun statusDisconnected() { | ||||||
|  |         isCallActive = false | ||||||
|  |         timerHandler.removeCallbacksAndMessages(null) | ||||||
|         dialer_hangup_button.beGone() |         dialer_hangup_button.beGone() | ||||||
|         dialer_hangup_button.postDelayed({ |         dialer_hangup_button.postDelayed({ | ||||||
|             finish() |             finish() | ||||||
|   | |||||||
| @@ -47,6 +47,21 @@ | |||||||
|         app:layout_constraintTop_toBottomOf="@+id/dialer_big_name_number" |         app:layout_constraintTop_toBottomOf="@+id/dialer_big_name_number" | ||||||
|         tools:text="123 456 789"/> |         tools:text="123 456 789"/> | ||||||
|  |  | ||||||
|  |     <com.simplemobiletools.commons.views.MyTextView | ||||||
|  |         android:id="@+id/dialer_call_duration" | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:layout_marginTop="@dimen/medium_margin" | ||||||
|  |         android:gravity="center_horizontal" | ||||||
|  |         android:paddingLeft="@dimen/activity_margin" | ||||||
|  |         android:paddingRight="@dimen/activity_margin" | ||||||
|  |         android:textSize="@dimen/big_text_size" | ||||||
|  |         android:visibility="gone" | ||||||
|  |         app:layout_constraintEnd_toEndOf="parent" | ||||||
|  |         app:layout_constraintStart_toStartOf="parent" | ||||||
|  |         app:layout_constraintTop_toBottomOf="@+id/dialer_number" | ||||||
|  |         tools:text="00:00"/> | ||||||
|  |  | ||||||
|     <ImageView |     <ImageView | ||||||
|         android:id="@+id/dialer_hangup_button" |         android:id="@+id/dialer_hangup_button" | ||||||
|         android:layout_width="@dimen/dialer_hangup_button_size" |         android:layout_width="@dimen/dialer_hangup_button_size" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user