Skip to content
Snippets Groups Projects
Commit 0efe17a0 authored by Lucas Silva's avatar Lucas Silva Committed by Automerger Merge Worker
Browse files

Merge "Update home controls activity to exit to dream" into tm-qpr-dev am: a8e2e554

parents 42127fba a8e2e554
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,8 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.os.RemoteException
import android.service.dreams.IDreamManager
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
......@@ -40,11 +42,13 @@ import javax.inject.Inject
*/
class ControlsActivity @Inject constructor(
private val uiController: ControlsUiController,
private val broadcastDispatcher: BroadcastDispatcher
private val broadcastDispatcher: BroadcastDispatcher,
private val dreamManager: IDreamManager,
) : ComponentActivity() {
private lateinit var parent: ViewGroup
private lateinit var broadcastReceiver: BroadcastReceiver
private var mExitToDream: Boolean = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -81,17 +85,36 @@ class ControlsActivity @Inject constructor(
parent = requireViewById<ViewGroup>(R.id.global_actions_controls)
parent.alpha = 0f
uiController.show(parent, { finish() }, this)
uiController.show(parent, { finishOrReturnToDream() }, this)
ControlsAnimations.enterAnimation(parent).start()
}
override fun onBackPressed() {
override fun onResume() {
super.onResume()
mExitToDream = intent.getBooleanExtra(ControlsUiController.EXIT_TO_DREAM, false)
}
fun finishOrReturnToDream() {
if (mExitToDream) {
try {
mExitToDream = false
dreamManager.dream()
return
} catch (e: RemoteException) {
// Fall through
}
}
finish()
}
override fun onBackPressed() {
finishOrReturnToDream()
}
override fun onStop() {
super.onStop()
mExitToDream = false
uiController.hide()
}
......@@ -106,7 +129,8 @@ class ControlsActivity @Inject constructor(
broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val action = intent.getAction()
if (Intent.ACTION_SCREEN_OFF.equals(action)) {
if (action == Intent.ACTION_SCREEN_OFF ||
action == Intent.ACTION_DREAMING_STARTED) {
finish()
}
}
......@@ -114,6 +138,7 @@ class ControlsActivity @Inject constructor(
val filter = IntentFilter()
filter.addAction(Intent.ACTION_SCREEN_OFF)
filter.addAction(Intent.ACTION_DREAMING_STARTED)
broadcastDispatcher.registerReceiver(broadcastReceiver, filter)
}
}
......@@ -27,6 +27,7 @@ interface ControlsUiController {
companion object {
public const val TAG = "ControlsUiController"
public const val EXTRA_ANIMATE = "extra_animate"
public const val EXIT_TO_DREAM = "extra_exit_to_dream"
}
fun show(parent: ViewGroup, onDismiss: Runnable, activityContext: Context)
......
......@@ -210,7 +210,8 @@ public class DreamHomeControlsComplication implements Complication {
final Intent intent = new Intent(mContext, ControlsActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(ControlsUiController.EXTRA_ANIMATE, true);
.putExtra(ControlsUiController.EXTRA_ANIMATE, true)
.putExtra(ControlsUiController.EXIT_TO_DREAM, true);
final ActivityLaunchAnimator.Controller controller =
v != null ? ActivityLaunchAnimator.Controller.fromView(v, null /* cujType */)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment