summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
author Andrey Epin <ayepin@google.com> 2023-01-04 18:20:00 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-01-04 18:20:00 +0000
commitedde810a1add0eac7dbd2bcb544aedeb28312680 (patch)
tree9b98ff807b5a7a4e4d68332ae82dfed2317a8180 /java/src
parent50e07cf4d4589560d38a83c93b6d4ff64181c6ee (diff)
parent54f453056eb6be1613bf474ecb5b95346105c767 (diff)
Merge "Move EnterTransitionAnimationDelegate out of ChooserActivity" into tm-qpr-dev
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/intentresolver/ChooserActivity.java82
-rw-r--r--java/src/com/android/intentresolver/ChooserContentPreviewCoordinator.java2
-rw-r--r--java/src/com/android/intentresolver/EnterTransitionAnimationDelegate.kt107
3 files changed, 112 insertions, 79 deletions
diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java
index df71c7ff..ceab62b2 100644
--- a/java/src/com/android/intentresolver/ChooserActivity.java
+++ b/java/src/com/android/intentresolver/ChooserActivity.java
@@ -32,7 +32,6 @@ import android.annotation.Nullable;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityOptions;
-import android.app.SharedElementCallback;
import android.app.prediction.AppPredictor;
import android.app.prediction.AppTarget;
import android.app.prediction.AppTargetEvent;
@@ -249,9 +248,7 @@ public class ChooserActivity extends ResolverActivity implements
@VisibleForTesting
protected ChooserMultiProfilePagerAdapter mChooserMultiProfilePagerAdapter;
private final EnterTransitionAnimationDelegate mEnterTransitionAnimationDelegate =
- new EnterTransitionAnimationDelegate();
-
- private boolean mRemoveSharedElements = false;
+ new EnterTransitionAnimationDelegate(this, () -> mResolverDrawerLayout);
private View mContentView = null;
@@ -259,21 +256,6 @@ public class ChooserActivity extends ResolverActivity implements
public ChooserActivity() {}
- private void onSharedElementTransitionTargetReady(boolean runTransitionAnimation) {
- if (runTransitionAnimation && !mRemoveSharedElements && isActivityTransitionRunning()) {
- // Disable the window animations as it interferes with the transition animation.
- getWindow().setWindowAnimations(0);
- mEnterTransitionAnimationDelegate.markImagePreviewReady();
- } else {
- onSharedElementTransitionTargetMissing();
- }
- }
-
- private void onSharedElementTransitionTargetMissing() {
- mRemoveSharedElements = true;
- mEnterTransitionAnimationDelegate.markImagePreviewReady();
- }
-
@Override
protected void onCreate(Bundle savedInstanceState) {
final long intentReceivedTime = System.currentTimeMillis();
@@ -312,7 +294,7 @@ public class ChooserActivity extends ResolverActivity implements
mPreviewCoordinator = new ChooserContentPreviewCoordinator(
mBackgroundThreadPoolExecutor,
this,
- this::onSharedElementTransitionTargetMissing);
+ () -> mEnterTransitionAnimationDelegate.markImagePreviewReady(false));
super.onCreate(
savedInstanceState,
@@ -371,17 +353,6 @@ public class ChooserActivity extends ResolverActivity implements
mChooserRequest.getTargetAction()
);
- setEnterSharedElementCallback(new SharedElementCallback() {
- @Override
- public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
- if (mRemoveSharedElements) {
- names.remove(FIRST_IMAGE_PREVIEW_TRANSITION_NAME);
- sharedElements.remove(FIRST_IMAGE_PREVIEW_TRANSITION_NAME);
- }
- super.onMapSharedElements(names, sharedElements);
- mRemoveSharedElements = false;
- }
- });
mEnterTransitionAnimationDelegate.postponeTransition();
}
@@ -772,7 +743,7 @@ public class ChooserActivity extends ResolverActivity implements
R.layout.chooser_action_row,
parent,
previewCoordinator,
- this::onSharedElementTransitionTargetReady,
+ mEnterTransitionAnimationDelegate::markImagePreviewReady,
getContentResolver(),
this::isImageType);
@@ -780,7 +751,7 @@ public class ChooserActivity extends ResolverActivity implements
adjustPreviewWidth(getResources().getConfiguration().orientation, layout);
}
if (previewType != ChooserContentPreviewUi.CONTENT_PREVIEW_IMAGE) {
- mEnterTransitionAnimationDelegate.markImagePreviewReady();
+ mEnterTransitionAnimationDelegate.markImagePreviewReady(false);
}
return layout;
@@ -2191,51 +2162,6 @@ public class ChooserActivity extends ResolverActivity implements
}
/**
- * A helper class to track app's readiness for the scene transition animation.
- * The app is ready when both the image is laid out and the drawer offset is calculated.
- */
- private class EnterTransitionAnimationDelegate implements View.OnLayoutChangeListener {
- private boolean mPreviewReady = false;
- private boolean mOffsetCalculated = false;
-
- void postponeTransition() {
- postponeEnterTransition();
- }
-
- void markImagePreviewReady() {
- if (!mPreviewReady) {
- mPreviewReady = true;
- maybeStartListenForLayout();
- }
- }
-
- void markOffsetCalculated() {
- if (!mOffsetCalculated) {
- mOffsetCalculated = true;
- maybeStartListenForLayout();
- }
- }
-
- private void maybeStartListenForLayout() {
- if (mPreviewReady && mOffsetCalculated && mResolverDrawerLayout != null) {
- if (mResolverDrawerLayout.isInLayout()) {
- startPostponedEnterTransition();
- } else {
- mResolverDrawerLayout.addOnLayoutChangeListener(this);
- mResolverDrawerLayout.requestLayout();
- }
- }
- }
-
- @Override
- public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
- int oldTop, int oldRight, int oldBottom) {
- v.removeOnLayoutChangeListener(this);
- startPostponedEnterTransition();
- }
- }
-
- /**
* Used in combination with the scene transition when launching the image editor
*/
private static class FinishAnimation extends AlphaAnimation implements
diff --git a/java/src/com/android/intentresolver/ChooserContentPreviewCoordinator.java b/java/src/com/android/intentresolver/ChooserContentPreviewCoordinator.java
index 93552e31..0b8dbe35 100644
--- a/java/src/com/android/intentresolver/ChooserContentPreviewCoordinator.java
+++ b/java/src/com/android/intentresolver/ChooserContentPreviewCoordinator.java
@@ -58,7 +58,7 @@ public class ChooserContentPreviewCoordinator implements
// TODO: apparently this timeout is only used for not holding shared element transition
// animation for too long. If so, we already have a better place for it
- // ChooserActivity$EnterTransitionAnimationDelegate.
+ // EnterTransitionAnimationDelegate.
mHandler.postDelayed(this::onWatchdogTimeout, mImageLoadTimeoutMillis);
ListenableFuture<Bitmap> bitmapFuture = mBackgroundExecutor.submit(
diff --git a/java/src/com/android/intentresolver/EnterTransitionAnimationDelegate.kt b/java/src/com/android/intentresolver/EnterTransitionAnimationDelegate.kt
new file mode 100644
index 00000000..a0bf61b6
--- /dev/null
+++ b/java/src/com/android/intentresolver/EnterTransitionAnimationDelegate.kt
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.intentresolver
+
+import android.app.Activity
+import android.app.SharedElementCallback
+import android.view.View
+import com.android.intentresolver.widget.ResolverDrawerLayout
+import java.util.function.Supplier
+
+/**
+ * A helper class to track app's readiness for the scene transition animation.
+ * The app is ready when both the image is laid out and the drawer offset is calculated.
+ */
+internal class EnterTransitionAnimationDelegate(
+ private val activity: Activity,
+ private val resolverDrawerLayoutSupplier: Supplier<ResolverDrawerLayout?>
+) : View.OnLayoutChangeListener {
+ private var removeSharedElements = false
+ private var previewReady = false
+ private var offsetCalculated = false
+
+ init {
+ activity.setEnterSharedElementCallback(
+ object : SharedElementCallback() {
+ override fun onMapSharedElements(
+ names: MutableList<String>, sharedElements: MutableMap<String, View>
+ ) {
+ this@EnterTransitionAnimationDelegate.onMapSharedElements(
+ names, sharedElements
+ )
+ }
+ })
+ }
+
+ fun postponeTransition() = activity.postponeEnterTransition()
+
+ fun markImagePreviewReady(runTransitionAnimation: Boolean) {
+ if (!runTransitionAnimation) {
+ removeSharedElements = true
+ }
+ if (!previewReady) {
+ previewReady = true
+ maybeStartListenForLayout()
+ }
+ }
+
+ fun markOffsetCalculated() {
+ if (!offsetCalculated) {
+ offsetCalculated = true
+ maybeStartListenForLayout()
+ }
+ }
+
+ private fun onMapSharedElements(
+ names: MutableList<String>,
+ sharedElements: MutableMap<String, View>
+ ) {
+ if (removeSharedElements) {
+ names.remove(ChooserActivity.FIRST_IMAGE_PREVIEW_TRANSITION_NAME)
+ sharedElements.remove(ChooserActivity.FIRST_IMAGE_PREVIEW_TRANSITION_NAME)
+ }
+ removeSharedElements = false
+ }
+
+ private fun maybeStartListenForLayout() {
+ val drawer = resolverDrawerLayoutSupplier.get()
+ if (previewReady && offsetCalculated && drawer != null) {
+ if (drawer.isInLayout) {
+ startPostponedEnterTransition()
+ } else {
+ drawer.addOnLayoutChangeListener(this)
+ drawer.requestLayout()
+ }
+ }
+ }
+
+ override fun onLayoutChange(
+ v: View,
+ left: Int, top: Int, right: Int, bottom: Int,
+ oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int
+ ) {
+ v.removeOnLayoutChangeListener(this)
+ startPostponedEnterTransition()
+ }
+
+ private fun startPostponedEnterTransition() {
+ if (!removeSharedElements && activity.isActivityTransitionRunning) {
+ // Disable the window animations as it interferes with the transition animation.
+ activity.window.setWindowAnimations(0)
+ }
+ activity.startPostponedEnterTransition()
+ }
+}