Reusing LayoutListener instead of creating a new one everytime

Bug: 122345781
Change-Id: Ica43849030afb497b0444e9ce474e7c3bdb9ee73
This commit is contained in:
Sunny Goyal 2019-01-09 11:20:29 -08:00
parent 55a32272be
commit 8304c32077
3 changed files with 32 additions and 3 deletions

View File

@ -154,7 +154,7 @@ public interface ActivityControlHelper<T extends BaseDraggingActivity> {
@Override
public LayoutListener createLayoutListener(Launcher activity) {
return new LauncherLayoutListener(activity);
return LauncherLayoutListener.resetAndGet(activity);
}
@Override

View File

@ -40,17 +40,35 @@ import com.android.quickstep.WindowTransformSwipeHandler;
public class LauncherLayoutListener extends AbstractFloatingView
implements Insettable, LayoutListener {
public static LauncherLayoutListener resetAndGet(Launcher launcher) {
LauncherRecentsView lrv = launcher.getOverviewPanel();
LauncherLayoutListener listener = lrv.mLauncherLayoutListener;
if (listener.isOpen()) {
listener.close(false);
}
listener.setHandler(null);
return listener;
}
private final Launcher mLauncher;
private final Paint mPaint = new Paint();
private WindowTransformSwipeHandler mHandler;
private RectF mCurrentRect;
private float mCornerRadius;
public LauncherLayoutListener(Launcher launcher) {
private boolean mWillNotDraw;
/**
* package private
*/
LauncherLayoutListener(Launcher launcher) {
super(launcher, null);
mLauncher = launcher;
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
setLayoutParams(new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
mWillNotDraw = willNotDraw();
super.setWillNotDraw(false);
}
@Override
@ -68,6 +86,12 @@ public class LauncherLayoutListener extends AbstractFloatingView
invalidate();
}
@Override
public void setWillNotDraw(boolean willNotDraw) {
// Prevent super call as that causes additional relayout.
mWillNotDraw = willNotDraw;
}
@Override
public void setHandler(WindowTransformSwipeHandler handler) {
mHandler = handler;
@ -125,6 +149,8 @@ public class LauncherLayoutListener extends AbstractFloatingView
@Override
protected void onDraw(Canvas canvas) {
canvas.drawRoundRect(mCurrentRect, mCornerRadius, mCornerRadius, mPaint);
if (!mWillNotDraw) {
canvas.drawRoundRect(mCurrentRect, mCornerRadius, mCornerRadius, mPaint);
}
}
}

View File

@ -35,6 +35,7 @@ import android.view.View;
import android.view.ViewDebug;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
@ -70,6 +71,7 @@ public class LauncherRecentsView extends RecentsView<Launcher> {
private float mTranslationYFactor;
private final TransformParams mTransformParams = new TransformParams();
final LauncherLayoutListener mLauncherLayoutListener;
public LauncherRecentsView(Context context) {
this(context, null);
@ -82,6 +84,7 @@ public class LauncherRecentsView extends RecentsView<Launcher> {
public LauncherRecentsView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setContentAlpha(0);
mLauncherLayoutListener = new LauncherLayoutListener(BaseActivity.fromContext(context));
}
@Override