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
|
|
|
|
2018-01-18 11:35:10 -08:00
|
|
|
import com.android.launcher3.util.Themes;
|
|
|
|
|
|
2017-08-18 00:35:52 -07:00
|
|
|
import static com.android.launcher3.util.SystemUiController.FLAG_DARK_NAV;
|
|
|
|
|
import static com.android.launcher3.util.SystemUiController.UI_STATE_ROOT_VIEW;
|
|
|
|
|
|
2014-10-23 17:28:30 -07:00
|
|
|
public class LauncherRootView extends InsettableFrameLayout {
|
2015-06-23 10:53:59 -07:00
|
|
|
|
2018-01-08 14:19:34 -08:00
|
|
|
private final Launcher mLauncher;
|
|
|
|
|
|
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);
|
2018-01-08 14:19:34 -08:00
|
|
|
|
|
|
|
|
mLauncher = Launcher.getLauncher(context);
|
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-06 09:47:56 -07:00
|
|
|
mDrawSideInsetBar = (insets.right > 0 || insets.left > 0) &&
|
2015-11-23 11:47:50 -08:00
|
|
|
(!Utilities.ATLEAST_MARSHMALLOW ||
|
2017-08-18 00:35:52 -07:00
|
|
|
getContext().getSystemService(ActivityManager.class).isLowRamDevice());
|
|
|
|
|
if (mDrawSideInsetBar) {
|
|
|
|
|
mLeftInsetBarWidth = insets.left;
|
|
|
|
|
mRightInsetBarWidth = insets.right;
|
|
|
|
|
insets = new Rect(0, insets.top, 0, insets.bottom);
|
|
|
|
|
} else {
|
|
|
|
|
mLeftInsetBarWidth = mRightInsetBarWidth = 0;
|
|
|
|
|
}
|
2018-01-08 14:19:34 -08:00
|
|
|
mLauncher.getSystemUiController().updateUiState(
|
2017-08-18 00:35:52 -07:00
|
|
|
UI_STATE_ROOT_VIEW, mDrawSideInsetBar ? FLAG_DARK_NAV : 0);
|
|
|
|
|
|
2018-01-08 14:19:34 -08:00
|
|
|
// Update device profile before notifying th children.
|
|
|
|
|
mLauncher.getDeviceProfile().updateInsets(insets);
|
2018-01-18 14:02:47 -08:00
|
|
|
boolean resetState = !insets.equals(mInsets);
|
2017-08-18 00:35:52 -07:00
|
|
|
setInsets(insets);
|
2015-11-23 11:47:50 -08:00
|
|
|
|
2017-08-18 00:35:52 -07:00
|
|
|
if (mAlignedView != null) {
|
2015-11-23 11:47:50 -08:00
|
|
|
// Apply margins on aligned view to handle left/right insets.
|
|
|
|
|
MarginLayoutParams lp = (MarginLayoutParams) mAlignedView.getLayoutParams();
|
2017-08-18 00:35:52 -07:00
|
|
|
if (lp.leftMargin != mLeftInsetBarWidth || lp.rightMargin != mRightInsetBarWidth) {
|
|
|
|
|
lp.leftMargin = mLeftInsetBarWidth;
|
|
|
|
|
lp.rightMargin = mRightInsetBarWidth;
|
2015-11-23 11:47:50 -08:00
|
|
|
mAlignedView.setLayoutParams(lp);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-18 14:02:47 -08:00
|
|
|
if (resetState) {
|
|
|
|
|
mLauncher.getStateManager().reapplyState();
|
|
|
|
|
}
|
2015-06-23 10:53:59 -07:00
|
|
|
|
2014-10-23 17:28:30 -07:00
|
|
|
return true; // I'll take it from here
|
|
|
|
|
}
|
2015-06-23 10:53:59 -07:00
|
|
|
|
2018-01-18 11:35:10 -08:00
|
|
|
@Override
|
|
|
|
|
public void setInsets(Rect insets) {
|
|
|
|
|
super.setInsets(insets);
|
|
|
|
|
setBackground(insets.top == 0 ? null
|
|
|
|
|
: Themes.getAttrDrawable(getContext(), R.attr.workspaceStatusBarScrim));
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 14:19:34 -08:00
|
|
|
public void dispatchInsets() {
|
|
|
|
|
fitSystemWindows(mInsets);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|