2014-10-23 17:28:30 -07:00
|
|
|
package com.android.launcher3;
|
|
|
|
|
|
2015-11-23 11:47:50 -08:00
|
|
|
import android.annotation.TargetApi;
|
|
|
|
|
import android.app.ActivityManager;
|
2014-10-23 17:28:30 -07:00
|
|
|
import android.content.Context;
|
2015-06-23 10:53:59 -07:00
|
|
|
import android.graphics.Canvas;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.graphics.Paint;
|
2014-10-23 17:28:30 -07:00
|
|
|
import android.graphics.Rect;
|
|
|
|
|
import android.util.AttributeSet;
|
2015-11-23 11:47:50 -08:00
|
|
|
import android.view.View;
|
2016-02-09 11:28:52 -08:00
|
|
|
import android.view.ViewDebug;
|
2014-10-23 17:28:30 -07:00
|
|
|
|
|
|
|
|
public class LauncherRootView extends InsettableFrameLayout {
|
2015-06-23 10:53:59 -07:00
|
|
|
|
|
|
|
|
private final Paint mOpaquePaint;
|
2016-02-09 11:28:52 -08:00
|
|
|
@ViewDebug.ExportedProperty(category = "launcher")
|
2016-07-06 09:47:56 -07:00
|
|
|
private boolean mDrawSideInsetBar;
|
|
|
|
|
@ViewDebug.ExportedProperty(category = "launcher")
|
|
|
|
|
private int mLeftInsetBarWidth;
|
2016-02-09 11:28:52 -08:00
|
|
|
@ViewDebug.ExportedProperty(category = "launcher")
|
2016-01-12 10:35:32 -08:00
|
|
|
private int mRightInsetBarWidth;
|
2015-06-23 10:53:59 -07:00
|
|
|
|
2015-11-23 11:47:50 -08:00
|
|
|
private View mAlignedView;
|
|
|
|
|
|
2014-10-23 17:28:30 -07:00
|
|
|
public LauncherRootView(Context context, AttributeSet attrs) {
|
|
|
|
|
super(context, attrs);
|
2015-06-23 10:53:59 -07:00
|
|
|
|
|
|
|
|
mOpaquePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
|
mOpaquePaint.setColor(Color.BLACK);
|
|
|
|
|
mOpaquePaint.setStyle(Paint.Style.FILL);
|
2014-10-23 17:28:30 -07:00
|
|
|
}
|
|
|
|
|
|
2015-11-23 11:47:50 -08:00
|
|
|
@Override
|
|
|
|
|
protected void onFinishInflate() {
|
|
|
|
|
if (getChildCount() > 0) {
|
|
|
|
|
// LauncherRootView contains only one child, which should be aligned
|
|
|
|
|
// based on the horizontal insets.
|
|
|
|
|
mAlignedView = getChildAt(0);
|
|
|
|
|
}
|
|
|
|
|
super.onFinishInflate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@TargetApi(23)
|
2014-10-23 17:28:30 -07:00
|
|
|
@Override
|
|
|
|
|
protected boolean fitSystemWindows(Rect insets) {
|
2016-07-18 17:18:02 -07:00
|
|
|
boolean rawInsetsChanged = !mInsets.equals(insets);
|
2016-07-06 09:47:56 -07:00
|
|
|
mDrawSideInsetBar = (insets.right > 0 || insets.left > 0) &&
|
2015-11-23 11:47:50 -08:00
|
|
|
(!Utilities.ATLEAST_MARSHMALLOW ||
|
|
|
|
|
getContext().getSystemService(ActivityManager.class).isLowRamDevice());
|
2016-01-12 10:35:32 -08:00
|
|
|
mRightInsetBarWidth = insets.right;
|
2016-07-06 09:47:56 -07:00
|
|
|
mLeftInsetBarWidth = insets.left;
|
|
|
|
|
setInsets(mDrawSideInsetBar ? new Rect(0, insets.top, 0, insets.bottom) : insets);
|
2015-11-23 11:47:50 -08:00
|
|
|
|
2016-07-06 09:47:56 -07:00
|
|
|
if (mAlignedView != null && mDrawSideInsetBar) {
|
2015-11-23 11:47:50 -08:00
|
|
|
// Apply margins on aligned view to handle left/right insets.
|
|
|
|
|
MarginLayoutParams lp = (MarginLayoutParams) mAlignedView.getLayoutParams();
|
|
|
|
|
if (lp.leftMargin != insets.left || lp.rightMargin != insets.right) {
|
|
|
|
|
lp.leftMargin = insets.left;
|
|
|
|
|
lp.rightMargin = insets.right;
|
|
|
|
|
mAlignedView.setLayoutParams(lp);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-23 10:53:59 -07:00
|
|
|
|
2016-07-18 17:18:02 -07:00
|
|
|
if (rawInsetsChanged) {
|
|
|
|
|
// Update the grid again
|
|
|
|
|
Launcher launcher = Launcher.getLauncher(getContext());
|
|
|
|
|
launcher.onInsetsChanged(insets);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 17:28:30 -07:00
|
|
|
return true; // I'll take it from here
|
|
|
|
|
}
|
2015-06-23 10:53:59 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void dispatchDraw(Canvas canvas) {
|
|
|
|
|
super.dispatchDraw(canvas);
|
|
|
|
|
|
|
|
|
|
// If the right inset is opaque, draw a black rectangle to ensure that is stays opaque.
|
2016-07-06 09:47:56 -07:00
|
|
|
if (mDrawSideInsetBar) {
|
|
|
|
|
if (mRightInsetBarWidth > 0) {
|
|
|
|
|
int width = getWidth();
|
|
|
|
|
canvas.drawRect(width - mRightInsetBarWidth, 0, width, getHeight(), mOpaquePaint);
|
|
|
|
|
}
|
|
|
|
|
if (mLeftInsetBarWidth > 0) {
|
|
|
|
|
canvas.drawRect(0, 0, mLeftInsetBarWidth, getHeight(), mOpaquePaint);
|
|
|
|
|
}
|
2015-06-23 10:53:59 -07:00
|
|
|
}
|
|
|
|
|
}
|
2014-10-23 17:28:30 -07:00
|
|
|
}
|