Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 1 | package com.android.launcher3; |
| 2 | |
| 3 | import android.content.Context; |
Sunny Goyal | 0abb36f | 2015-06-23 10:53:59 -0700 | [diff] [blame^] | 4 | import android.graphics.Canvas; |
| 5 | import android.graphics.Color; |
| 6 | import android.graphics.Paint; |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 7 | import android.graphics.Rect; |
| 8 | import android.util.AttributeSet; |
| 9 | |
| 10 | public class LauncherRootView extends InsettableFrameLayout { |
Sunny Goyal | 0abb36f | 2015-06-23 10:53:59 -0700 | [diff] [blame^] | 11 | |
| 12 | private final Paint mOpaquePaint; |
| 13 | private boolean mDrawRightInsetBar; |
| 14 | |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 15 | public LauncherRootView(Context context, AttributeSet attrs) { |
| 16 | super(context, attrs); |
Sunny Goyal | 0abb36f | 2015-06-23 10:53:59 -0700 | [diff] [blame^] | 17 | |
| 18 | mOpaquePaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 19 | mOpaquePaint.setColor(Color.BLACK); |
| 20 | mOpaquePaint.setStyle(Paint.Style.FILL); |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | @Override |
| 24 | protected boolean fitSystemWindows(Rect insets) { |
| 25 | setInsets(insets); |
Sunny Goyal | 0abb36f | 2015-06-23 10:53:59 -0700 | [diff] [blame^] | 26 | mDrawRightInsetBar = mInsets.right > 0 && LauncherAppState |
| 27 | .getInstance().getInvariantDeviceProfile().isRightInsetOpaque; |
| 28 | |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 29 | return true; // I'll take it from here |
| 30 | } |
Sunny Goyal | 0abb36f | 2015-06-23 10:53:59 -0700 | [diff] [blame^] | 31 | |
| 32 | @Override |
| 33 | protected void dispatchDraw(Canvas canvas) { |
| 34 | super.dispatchDraw(canvas); |
| 35 | |
| 36 | // If the right inset is opaque, draw a black rectangle to ensure that is stays opaque. |
| 37 | if (mDrawRightInsetBar) { |
| 38 | int width = getWidth(); |
| 39 | canvas.drawRect(width - mInsets.right, 0, width, getHeight(), mOpaquePaint); |
| 40 | } |
| 41 | } |
Adam Cohen | a6d0492 | 2014-10-23 17:28:30 -0700 | [diff] [blame] | 42 | } |