Merge "Add task layer drawable class for Recents Go." into ub-launcher3-master

This commit is contained in:
TreeHugger Robot
2019-04-09 20:52:59 +00:00
committed by Android (Google) Code Review
2 changed files with 113 additions and 0 deletions
@@ -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>
@@ -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();
}
}