Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c8f42b4 authored by Satish Yalla's avatar Satish Yalla Committed by Android (Google) Code Review
Browse files

Merge "Revert "Animate caption showing/hiding"" into main

parents a2af1593 7a8a0f0f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -445,4 +445,9 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
    private static int getCaptionHeightIdStatic(@WindowingMode int windowingMode) {
        return R.dimen.freeform_decor_caption_height;
    }

    @Override
    int getCaptionViewId() {
        return R.id.caption;
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -108,6 +108,11 @@ public class CarWindowDecoration extends WindowDecoration<WindowDecorLinearLayou
        return new Rect();
    }

    @Override
    int getCaptionViewId() {
        return R.id.caption;
    }

    private void updateRelayoutParams(
            RelayoutParams relayoutParams,
            ActivityManager.RunningTaskInfo taskInfo,
+5 −0
Original line number Diff line number Diff line
@@ -1776,6 +1776,11 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        return loadDimensionPixelSize(mContext.getResources(), getCaptionHeightId(windowingMode));
    }

    @Override
    int getCaptionViewId() {
        return R.id.desktop_mode_caption;
    }

    void setAnimatingTaskResizeOrReposition(boolean animatingTaskResizeOrReposition) {
        if (mRelayoutParams.mLayoutResId == R.layout.desktop_mode_app_handle) return;
        final boolean inFullImmersive =
+16 −0
Original line number Diff line number Diff line
@@ -629,16 +629,32 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
     */
    private void updateCaptionVisibility(View rootView, @NonNull RelayoutParams params) {
        mIsCaptionVisible = params.mIsCaptionVisible;
        setCaptionVisibility(rootView, mIsCaptionVisible);
    }

    void setTaskDragResizer(TaskDragResizer taskDragResizer) {
        mTaskDragResizer = taskDragResizer;
    }

    // TODO(b/346441962): Move these three methods closer to implementing or View-level classes to
    //  keep implementation details more encapsulated.
    private void setCaptionVisibility(View rootView, boolean visible) {
        if (rootView == null) {
            return;
        }
        final int v = visible ? View.VISIBLE : View.GONE;
        final View captionView = rootView.findViewById(getCaptionViewId());
        captionView.setVisibility(v);
    }

    int getCaptionHeightId(@WindowingMode int windowingMode) {
        return Resources.ID_NULL;
    }

    int getCaptionViewId() {
        return Resources.ID_NULL;
    }

    /**
     * Obtains the {@link Display} instance for the display ID in {@link #mTaskInfo} if it exists or
     * registers {@link #mOnDisplaysChangedListener} if it doesn't.
+0 −101
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.wm.shell.windowdecor

import android.animation.ObjectAnimator
import android.view.View
import android.view.View.Visibility
import android.view.animation.PathInterpolator
import android.widget.ImageButton
import androidx.core.animation.doOnEnd
import com.android.wm.shell.shared.animation.Interpolators

/**
 * Animates the Desktop View's app handle.
 */
class AppHandleAnimator(
    private val appHandleView: View,
    private val captionHandle: ImageButton,
) {
    companion object {
        //  Constants for animating the whole caption
        private const val APP_HANDLE_ALPHA_FADE_IN_ANIMATION_DURATION_MS: Long = 275L
        private const val APP_HANDLE_ALPHA_FADE_OUT_ANIMATION_DURATION_MS: Long = 340
        private val APP_HANDLE_ANIMATION_INTERPOLATOR = PathInterpolator(
            0.4f,
            0f,
            0.2f,
            1f
        )

        // Constants for animating the caption's handle
        private const val HANDLE_ANIMATION_DURATION: Long = 100
        private val HANDLE_ANIMATION_INTERPOLATOR = Interpolators.FAST_OUT_SLOW_IN
    }

    private var animator: ObjectAnimator? = null

    /** Animates the given caption view to the given visibility after a visibility change. */
    fun animateVisibilityChange(@Visibility visible: Int) {
        when (visible) {
            View.VISIBLE -> animateShowAppHandle()
            else -> animateHideAppHandle()
        }
    }

    /** Animate appearance/disappearance of caption's handle. */
    fun animateCaptionHandleAlpha(startValue: Float, endValue: Float) {
        cancel()
        animator = ObjectAnimator.ofFloat(captionHandle, View.ALPHA, startValue, endValue).apply {
            duration = HANDLE_ANIMATION_DURATION
            interpolator = HANDLE_ANIMATION_INTERPOLATOR
            start()
        }
    }

    private fun animateShowAppHandle() {
        cancel()
        appHandleView.alpha = 0f
        appHandleView.visibility = View.VISIBLE
        animator = ObjectAnimator.ofFloat(appHandleView, View.ALPHA, 1f).apply {
            duration = APP_HANDLE_ALPHA_FADE_IN_ANIMATION_DURATION_MS
            interpolator = APP_HANDLE_ANIMATION_INTERPOLATOR
            start()
        }
    }

    private fun animateHideAppHandle() {
        cancel()
        animator = ObjectAnimator.ofFloat(appHandleView, View.ALPHA, 0f).apply {
            duration = APP_HANDLE_ALPHA_FADE_OUT_ANIMATION_DURATION_MS
            interpolator = APP_HANDLE_ANIMATION_INTERPOLATOR
            doOnEnd {
                appHandleView.visibility = View.GONE
            }
            start()
        }
    }

    /**
     * Cancels any active animations.
     */
    fun cancel() {
        animator?.removeAllListeners()
        animator?.cancel()
        animator = null
    }
}
Loading