Add task layer drawable class for Recents Go.

Add a custom drawable class that provides a hook to the caller to
control a crossfade animation between two drawables. This will be
helpful going forward to sync up all the animations to the controller.

Note that this CL only adds the class and does not replace the current
implementation.

Bug: 114136250
Test: Builds
Change-Id: I3cc6be79cb2ca5d64c8cc2945ff7f2ebd49632b6
(cherry picked from commit bb956bd028)
This commit is contained in:
Kevin 2019-04-08 16:34:19 -07:00 committed by Kevin Han
parent 736982d74b
commit e6e1463ed2
2 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2019 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.
-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/transparent"/>
<stroke android:color="@android:color/white" android:width="4px"/>
<corners android:radius="2dp"/>
</shape>

View File

@ -0,0 +1,90 @@
/*
* Copyright (C) 2019 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.quickstep.views;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import androidx.annotation.NonNull;
import com.android.launcher3.R;
/**
* A layer drawable for task content that transitions between two drawables by crossfading. Similar
* to {@link android.graphics.drawable.TransitionDrawable} but allows callers to control transition
* progress and provides a default, empty drawable.
*/
public final class TaskLayerDrawable extends LayerDrawable {
private final Drawable mEmptyDrawable;
public TaskLayerDrawable(Context context) {
super(new Drawable[0]);
// Use empty drawable for both layers initially.
mEmptyDrawable = context.getResources().getDrawable(
R.drawable.empty_content_box, context.getTheme());
addLayer(mEmptyDrawable);
addLayer(mEmptyDrawable);
setTransitionProgress(1.0f);
}
/**
* Immediately set the front-most drawable layer.
*
* @param drawable drawable to set
*/
public void setCurrentDrawable(@NonNull Drawable drawable) {
setDrawable(0, drawable);
}
/**
* Immediately reset the drawable to showing the empty drawable.
*/
public void resetDrawable() {
setCurrentDrawable(mEmptyDrawable);
}
/**
* Prepare to start animating the transition by pushing the current drawable to the back and
* setting a new drawable to the front layer and making it invisible.
*
* @param endDrawable drawable to animate to
*/
public void startNewTransition(@NonNull Drawable endDrawable) {
Drawable oldDrawable = getDrawable(0);
setDrawable(1, oldDrawable);
setDrawable(0, endDrawable);
setTransitionProgress(0.0f);
}
/**
* Set the progress of the transition animation to crossfade the two drawables.
*
* @param progress current transition progress between 0 (front view invisible) and 1
* (front view visible)
*/
public void setTransitionProgress(float progress) {
if (progress > 1 || progress < 0) {
throw new IllegalArgumentException("Transition progress should be between 0 and 1");
}
int drawableAlpha = (int) (progress * 255);
getDrawable(0).setAlpha(drawableAlpha);
getDrawable(1).setAlpha(255 - drawableAlpha);
invalidateSelf();
}
}