mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-19 02:38:20 +00:00
Using a custom view instead of ImageView to avoid relayout when the icon changes
Bug: 78585335 Change-Id: I078aec5b80ec45933ba4974df68cab23ac4a0ca0
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="@dimen/task_thumbnail_top_margin" />
|
||||
|
||||
<ImageView
|
||||
<com.android.quickstep.views.IconView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="@dimen/task_thumbnail_icon_size"
|
||||
android:layout_height="@dimen/task_thumbnail_icon_size"
|
||||
|
||||
@@ -21,7 +21,7 @@ import android.graphics.ColorFilter;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.FloatProperty;
|
||||
import android.widget.ImageView;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.quickstep.views.RecentsView;
|
||||
@@ -47,7 +47,7 @@ public class TaskViewDrawable extends Drawable {
|
||||
(t) -> (Math.max(t, 0.3f) - 0.3f) / 0.7f;
|
||||
|
||||
private final RecentsView mParent;
|
||||
private final ImageView mIconView;
|
||||
private final View mIconView;
|
||||
private final int[] mIconPos;
|
||||
|
||||
private final TaskThumbnailView mThumbnailView;
|
||||
|
||||
91
quickstep/src/com/android/quickstep/views/IconView.java
Normal file
91
quickstep/src/com/android/quickstep/views/IconView.java
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* A view which draws a drawable stretched to fit its size. Unlike ImageView, it avoids relayout
|
||||
* when the drawable changes.
|
||||
*/
|
||||
public class IconView extends View {
|
||||
|
||||
private Drawable mDrawable;
|
||||
|
||||
public IconView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public IconView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public IconView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public void setDrawable(Drawable d) {
|
||||
if (mDrawable != null) {
|
||||
mDrawable.setCallback(null);
|
||||
}
|
||||
mDrawable = d;
|
||||
if (mDrawable != null) {
|
||||
mDrawable.setCallback(this);
|
||||
mDrawable.setBounds(0, 0, getWidth(), getHeight());
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
if (mDrawable != null) {
|
||||
mDrawable.setBounds(0, 0, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean verifyDrawable(Drawable who) {
|
||||
return super.verifyDrawable(who) || who == mDrawable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawableStateChanged() {
|
||||
super.drawableStateChanged();
|
||||
|
||||
final Drawable drawable = mDrawable;
|
||||
if (drawable != null && drawable.isStateful()
|
||||
&& drawable.setState(getDrawableState())) {
|
||||
invalidateDrawable(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
if (mDrawable != null) {
|
||||
mDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOverlappingRendering() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class TaskView extends FrameLayout implements TaskCallbacks, PageCallback
|
||||
|
||||
private Task mTask;
|
||||
private TaskThumbnailView mSnapshotView;
|
||||
private ImageView mIconView;
|
||||
private IconView mIconView;
|
||||
private float mCurveScale;
|
||||
private float mCurveDimAlpha;
|
||||
private Animator mDimAlphaAnim;
|
||||
@@ -133,7 +133,7 @@ public class TaskView extends FrameLayout implements TaskCallbacks, PageCallback
|
||||
return mSnapshotView;
|
||||
}
|
||||
|
||||
public ImageView getIconView() {
|
||||
public IconView getIconView() {
|
||||
return mIconView;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public class TaskView extends FrameLayout implements TaskCallbacks, PageCallback
|
||||
@Override
|
||||
public void onTaskDataLoaded(Task task, ThumbnailData thumbnailData) {
|
||||
mSnapshotView.setThumbnail(task, thumbnailData);
|
||||
mIconView.setImageDrawable(task.icon);
|
||||
mIconView.setDrawable(task.icon);
|
||||
mIconView.setOnClickListener(icon -> TaskMenuView.showForTask(this));
|
||||
mIconView.setOnLongClickListener(icon -> {
|
||||
requestDisallowInterceptTouchEvent(true);
|
||||
@@ -174,7 +174,7 @@ public class TaskView extends FrameLayout implements TaskCallbacks, PageCallback
|
||||
@Override
|
||||
public void onTaskDataUnloaded() {
|
||||
mSnapshotView.setThumbnail(null, null);
|
||||
mIconView.setImageDrawable(null);
|
||||
mIconView.setDrawable(null);
|
||||
mIconView.setOnLongClickListener(null);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user