Removing ViewScrim and cutom drawing code
Bug: 109828640 Change-Id: I2cab0215a32c2ca6bc331d48083fcc00ada05c3b
This commit is contained in:
parent
194f58525a
commit
1642f7173f
|
@ -101,9 +101,6 @@
|
|||
<!-- View ID used by cell layout to jail its content -->
|
||||
<item type="id" name="cell_layout_jail_id" />
|
||||
|
||||
<!-- Tag id used for view scrim -->
|
||||
<item type="id" name="view_scrim" />
|
||||
|
||||
<!-- View IDs to store item highlight information -->
|
||||
<item type="id" name="view_unhighlight_background" />
|
||||
<item type="id" name="view_highlighted" />
|
||||
|
|
|
@ -68,7 +68,7 @@ public class InsettableFrameLayout extends FrameLayout implements Insettable {
|
|||
}
|
||||
|
||||
public static class LayoutParams extends FrameLayout.LayoutParams {
|
||||
boolean ignoreInsets = false;
|
||||
public boolean ignoreInsets = false;
|
||||
|
||||
public LayoutParams(Context c, AttributeSet attrs) {
|
||||
super(c, attrs);
|
||||
|
|
|
@ -47,7 +47,6 @@ import com.android.launcher3.Workspace;
|
|||
import com.android.launcher3.anim.Interpolators;
|
||||
import com.android.launcher3.folder.Folder;
|
||||
import com.android.launcher3.folder.FolderIcon;
|
||||
import com.android.launcher3.graphics.ViewScrim;
|
||||
import com.android.launcher3.graphics.WorkspaceAndHotseatScrim;
|
||||
import com.android.launcher3.keyboard.ViewGroupFocusHelper;
|
||||
import com.android.launcher3.uioverrides.UiFactory;
|
||||
|
@ -124,15 +123,6 @@ public class DragLayer extends BaseDragLayer<Launcher> {
|
|||
return mDragController.dispatchKeyEvent(event) || super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
|
||||
ViewScrim scrim = ViewScrim.get(child);
|
||||
if (scrim != null) {
|
||||
scrim.draw(canvas, getWidth(), getHeight());
|
||||
}
|
||||
return super.drawChild(canvas, child, drawingTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean findActiveController(MotionEvent ev) {
|
||||
if (mActivity.getStateManager().getState().disableInteraction) {
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* 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.launcher3.graphics;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.anim.Interpolators;
|
||||
import com.android.launcher3.uioverrides.WallpaperColorInfo;
|
||||
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
|
||||
/**
|
||||
* Simple scrim which draws a color
|
||||
*/
|
||||
public class ColorScrim extends ViewScrim {
|
||||
|
||||
private final int mColor;
|
||||
private final Interpolator mInterpolator;
|
||||
private int mCurrentColor;
|
||||
|
||||
public ColorScrim(View view, int color, Interpolator interpolator) {
|
||||
super(view);
|
||||
mColor = color;
|
||||
mInterpolator = interpolator;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressChanged() {
|
||||
mCurrentColor = ColorUtils.setAlphaComponent(mColor,
|
||||
Math.round(mInterpolator.getInterpolation(mProgress) * Color.alpha(mColor)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas, int width, int height) {
|
||||
if (mProgress > 0) {
|
||||
canvas.drawColor(mCurrentColor);
|
||||
}
|
||||
}
|
||||
|
||||
public static ColorScrim createExtractedColorScrim(View view) {
|
||||
WallpaperColorInfo colors = WallpaperColorInfo.getInstance(view.getContext());
|
||||
int alpha = view.getResources().getInteger(R.integer.extracted_color_gradient_alpha);
|
||||
ColorScrim scrim = new ColorScrim(view, ColorUtils.setAlphaComponent(
|
||||
colors.getSecondaryColor(), alpha), Interpolators.LINEAR);
|
||||
scrim.attach();
|
||||
return scrim;
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* 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.launcher3.graphics;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.util.Property;
|
||||
import android.view.View;
|
||||
import android.view.ViewParent;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
|
||||
/**
|
||||
* A utility class that can be used to draw a scrim behind a view
|
||||
*/
|
||||
public abstract class ViewScrim<T extends View> {
|
||||
|
||||
public static Property<ViewScrim, Float> PROGRESS =
|
||||
new Property<ViewScrim, Float>(Float.TYPE, "progress") {
|
||||
@Override
|
||||
public Float get(ViewScrim viewScrim) {
|
||||
return viewScrim.mProgress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(ViewScrim object, Float value) {
|
||||
object.setProgress(value);
|
||||
}
|
||||
};
|
||||
|
||||
protected final T mView;
|
||||
protected float mProgress = 0;
|
||||
|
||||
public ViewScrim(T view) {
|
||||
mView = view;
|
||||
}
|
||||
|
||||
public void attach() {
|
||||
mView.setTag(R.id.view_scrim, this);
|
||||
}
|
||||
|
||||
public void setProgress(float progress) {
|
||||
if (mProgress != progress) {
|
||||
mProgress = progress;
|
||||
onProgressChanged();
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void draw(Canvas canvas, int width, int height);
|
||||
|
||||
protected void onProgressChanged() { }
|
||||
|
||||
public void invalidate() {
|
||||
ViewParent parent = mView.getParent();
|
||||
if (parent != null) {
|
||||
((View) parent).invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public static ViewScrim get(View view) {
|
||||
return (ViewScrim) view.getTag(R.id.view_scrim);
|
||||
}
|
||||
}
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package com.android.launcher3.widget;
|
||||
|
||||
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
|
||||
import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -31,13 +33,16 @@ import com.android.launcher3.ItemInfo;
|
|||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.dragndrop.DragOptions;
|
||||
import com.android.launcher3.graphics.ColorScrim;
|
||||
import com.android.launcher3.touch.ItemLongClickListener;
|
||||
import com.android.launcher3.uioverrides.WallpaperColorInfo;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
|
||||
import com.android.launcher3.util.SystemUiController;
|
||||
import com.android.launcher3.util.Themes;
|
||||
import com.android.launcher3.views.AbstractSlideInView;
|
||||
import com.android.launcher3.views.BaseDragLayer;
|
||||
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
|
||||
/**
|
||||
* Base class for various widgets popup
|
||||
|
@ -49,11 +54,11 @@ abstract class BaseWidgetSheet extends AbstractSlideInView
|
|||
/* Touch handling related member variables. */
|
||||
private Toast mWidgetInstructionToast;
|
||||
|
||||
protected final ColorScrim mColorScrim;
|
||||
protected final View mColorScrim;
|
||||
|
||||
public BaseWidgetSheet(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
mColorScrim = ColorScrim.createExtractedColorScrim(this);
|
||||
mColorScrim = createColorScrim(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,9 +85,14 @@ abstract class BaseWidgetSheet extends AbstractSlideInView
|
|||
return true;
|
||||
}
|
||||
|
||||
protected void attachToContainer() {
|
||||
getPopupContainer().addView(mColorScrim);
|
||||
getPopupContainer().addView(this);
|
||||
}
|
||||
|
||||
protected void setTranslationShift(float translationShift) {
|
||||
super.setTranslationShift(translationShift);
|
||||
mColorScrim.setProgress(1 - mTranslationShift);
|
||||
mColorScrim.setAlpha(1 - mTranslationShift);
|
||||
}
|
||||
|
||||
private boolean beginDraggingWidget(WidgetCell v) {
|
||||
|
@ -115,6 +125,7 @@ abstract class BaseWidgetSheet extends AbstractSlideInView
|
|||
|
||||
protected void onCloseComplete() {
|
||||
super.onCloseComplete();
|
||||
getPopupContainer().removeView(mColorScrim);
|
||||
clearNavBarColor();
|
||||
}
|
||||
|
||||
|
@ -148,4 +159,19 @@ abstract class BaseWidgetSheet extends AbstractSlideInView
|
|||
protected SystemUiController getSystemUiController() {
|
||||
return mLauncher.getSystemUiController();
|
||||
}
|
||||
|
||||
private static View createColorScrim(Context context) {
|
||||
View view = new View(context);
|
||||
view.forceHasOverlappingRendering(false);
|
||||
|
||||
WallpaperColorInfo colors = WallpaperColorInfo.getInstance(context);
|
||||
int alpha = context.getResources().getInteger(R.integer.extracted_color_gradient_alpha);
|
||||
view.setBackgroundColor(ColorUtils.setAlphaComponent(colors.getSecondaryColor(), alpha));
|
||||
|
||||
BaseDragLayer.LayoutParams lp = new BaseDragLayer.LayoutParams(MATCH_PARENT, MATCH_PARENT);
|
||||
lp.ignoreInsets = true;
|
||||
view.setLayoutParams(lp);
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,8 +70,7 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable {
|
|||
R.string.widgets_bottom_sheet_title, mOriginalItemInfo.title));
|
||||
|
||||
onWidgetsBound();
|
||||
|
||||
getPopupContainer().addView(this);
|
||||
attachToContainer();
|
||||
mIsOpen = false;
|
||||
animateOpen();
|
||||
}
|
||||
|
|
|
@ -220,8 +220,8 @@ public class WidgetsFullSheet extends BaseWidgetSheet
|
|||
public static WidgetsFullSheet show(Launcher launcher, boolean animate) {
|
||||
WidgetsFullSheet sheet = (WidgetsFullSheet) launcher.getLayoutInflater()
|
||||
.inflate(R.layout.widgets_full_sheet, launcher.getDragLayer(), false);
|
||||
sheet.attachToContainer();
|
||||
sheet.mIsOpen = true;
|
||||
sheet.getPopupContainer().addView(sheet);
|
||||
sheet.open(animate);
|
||||
return sheet;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue