Skip to content

Commit 4a5bc9f

Browse files
TreeHugger RobotAndroid (Google) Code Review
TreeHugger Robot
authored and
Android (Google) Code Review
committed
Merge "Making CellLayout inflatable without LauncherActivtiy" into ub-launcher3-master
2 parents d2fe201 + ab770a1 commit 4a5bc9f

7 files changed

+46
-55
lines changed

src/com/android/launcher3/CellLayout.java

+10-26
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import com.android.launcher3.util.ParcelableSparseArray;
6363
import com.android.launcher3.util.Themes;
6464
import com.android.launcher3.util.Thunk;
65+
import com.android.launcher3.views.ActivityContext;
6566
import com.android.launcher3.widget.LauncherAppWidgetHostView;
6667

6768
import java.lang.annotation.Retention;
@@ -82,7 +83,7 @@ public class CellLayout extends ViewGroup {
8283
private static final String TAG = "CellLayout";
8384
private static final boolean LOGD = false;
8485

85-
private final Launcher mLauncher;
86+
protected final ActivityContext mActivity;
8687
@ViewDebug.ExportedProperty(category = "launcher")
8788
@Thunk int mCellWidth;
8889
@ViewDebug.ExportedProperty(category = "launcher")
@@ -106,7 +107,6 @@ public class CellLayout extends ViewGroup {
106107
private GridOccupancy mTmpOccupied;
107108

108109
private OnTouchListener mInterceptTouchListener;
109-
private final StylusEventHelper mStylusEventHelper;
110110

111111
private final ArrayList<PreviewBackground> mFolderBackgrounds = new ArrayList<>();
112112
final PreviewBackground mFolderLeaveBehind = new PreviewBackground();
@@ -201,9 +201,9 @@ public CellLayout(Context context, AttributeSet attrs, int defStyle) {
201201
// the user where a dragged item will land when dropped.
202202
setWillNotDraw(false);
203203
setClipToPadding(false);
204-
mLauncher = Launcher.getLauncher(context);
204+
mActivity = ActivityContext.lookupContext(context);
205205

206-
DeviceProfile grid = mLauncher.getDeviceProfile();
206+
DeviceProfile grid = mActivity.getDeviceProfile();
207207

208208
mCellWidth = mCellHeight = -1;
209209
mFixedCellWidth = mFixedCellHeight = -1;
@@ -286,8 +286,6 @@ public void onAnimationEnd(Animator animation) {
286286

287287
mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context, mContainerType);
288288
mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY);
289-
290-
mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this);
291289
addView(mShortcutsAndWidgets);
292290
}
293291

@@ -337,20 +335,6 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
337335
return false;
338336
}
339337

340-
@Override
341-
public boolean onTouchEvent(MotionEvent ev) {
342-
boolean handled = super.onTouchEvent(ev);
343-
// Stylus button press on a home screen should not switch between overview mode and
344-
// the home screen mode, however, once in overview mode stylus button press should be
345-
// enabled to allow rearranging the different home screens. So check what mode
346-
// the workspace is in, and only perform stylus button presses while in overview mode.
347-
if (mLauncher.isInState(LauncherState.OVERVIEW)
348-
&& mStylusEventHelper.onMotionEvent(ev)) {
349-
return true;
350-
}
351-
return handled;
352-
}
353-
354338
public void enableHardwareLayer(boolean hasLayer) {
355339
mShortcutsAndWidgets.setLayerType(hasLayer ? LAYER_TYPE_HARDWARE : LAYER_TYPE_NONE, sPaint);
356340
}
@@ -504,7 +488,7 @@ public void removeFolderBackground(PreviewBackground bg) {
504488

505489
public void setFolderLeaveBehindCell(int x, int y) {
506490
View child = getChildAt(x, y);
507-
mFolderLeaveBehind.setup(mLauncher, null,
491+
mFolderLeaveBehind.setup(getContext(), mActivity, null,
508492
child.getMeasuredWidth(), child.getPaddingTop());
509493

510494
mFolderLeaveBehind.delegateCellX = x;
@@ -945,7 +929,7 @@ void visualizeDropLocation(View v, DragPreviewProvider outlineProvider, int cell
945929
if (resize) {
946930
cellToRect(cellX, cellY, spanX, spanY, r);
947931
if (v instanceof LauncherAppWidgetHostView) {
948-
DeviceProfile profile = mLauncher.getDeviceProfile();
932+
DeviceProfile profile = mActivity.getDeviceProfile();
949933
Utilities.shrinkRect(r, profile.appWidgetScale.x, profile.appWidgetScale.y);
950934
}
951935
} else {
@@ -2047,7 +2031,7 @@ private void cancel() {
20472031
.translationY(initDeltaY)
20482032
.build(child)
20492033
.setDuration(REORDER_ANIMATION_DURATION);
2050-
mLauncher.getDragController().addFirstFrameAnimationHelper(a);
2034+
Launcher.cast(mActivity).getDragController().addFirstFrameAnimationHelper(a);
20512035
a.setInterpolator(DEACCEL_1_5);
20522036
a.start();
20532037
}
@@ -2063,7 +2047,7 @@ private void completeAndClearReorderPreviewAnimations() {
20632047
private void commitTempPlacement() {
20642048
mTmpOccupied.copyTo(mOccupied);
20652049

2066-
int screenId = mLauncher.getWorkspace().getIdForScreen(this);
2050+
int screenId = Launcher.cast(mActivity).getWorkspace().getIdForScreen(this);
20672051
int container = Favorites.CONTAINER_DESKTOP;
20682052

20692053
if (mContainerType == HOTSEAT) {
@@ -2089,8 +2073,8 @@ private void commitTempPlacement() {
20892073
info.spanY = lp.cellVSpan;
20902074

20912075
if (requiresDbUpdate) {
2092-
mLauncher.getModelWriter().modifyItemInDatabase(info, container, screenId,
2093-
info.cellX, info.cellY, info.spanX, info.spanY);
2076+
Launcher.cast(mActivity).getModelWriter().modifyItemInDatabase(info, container,
2077+
screenId, info.cellX, info.cellY, info.spanX, info.spanY);
20942078
}
20952079
}
20962080
}

src/com/android/launcher3/Hotseat.java

+3-16
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import android.graphics.Rect;
2121
import android.util.AttributeSet;
2222
import android.view.Gravity;
23-
import android.view.MotionEvent;
2423
import android.view.View;
2524
import android.view.ViewDebug;
2625
import android.view.ViewGroup;
@@ -32,8 +31,6 @@
3231

3332
public class Hotseat extends CellLayout implements LogContainerProvider, Insettable {
3433

35-
private final Launcher mLauncher;
36-
3734
@ViewDebug.ExportedProperty(category = "launcher")
3835
private boolean mHasVerticalHotseat;
3936

@@ -47,7 +44,6 @@ public Hotseat(Context context, AttributeSet attrs) {
4744

4845
public Hotseat(Context context, AttributeSet attrs, int defStyle) {
4946
super(context, attrs, defStyle);
50-
mLauncher = Launcher.getLauncher(context);
5147
}
5248

5349
/* Get the orientation specific coordinates given an invariant order in the hotseat. */
@@ -59,26 +55,17 @@ int getCellYFromOrder(int rank) {
5955
return mHasVerticalHotseat ? (getCountY() - (rank + 1)) : 0;
6056
}
6157

62-
void resetLayout(boolean hasVerticalHotseat) {
58+
public void resetLayout(boolean hasVerticalHotseat) {
6359
removeAllViewsInLayout();
6460
mHasVerticalHotseat = hasVerticalHotseat;
65-
InvariantDeviceProfile idp = mLauncher.getDeviceProfile().inv;
61+
InvariantDeviceProfile idp = mActivity.getDeviceProfile().inv;
6662
if (hasVerticalHotseat) {
6763
setGridSize(1, idp.numHotseatIcons);
6864
} else {
6965
setGridSize(idp.numHotseatIcons, 1);
7066
}
7167
}
7268

73-
@Override
74-
public boolean onInterceptTouchEvent(MotionEvent ev) {
75-
// We don't want any clicks to go through to the hotseat unless the workspace is in
76-
// the normal state or an accessible drag is in progress.
77-
return (!mLauncher.getWorkspace().workspaceIconsCanBeDragged()
78-
&& !mLauncher.getAccessibilityDelegate().isInAccessibleDrag())
79-
|| super.onInterceptTouchEvent(ev);
80-
}
81-
8269
@Override
8370
public void fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent) {
8471
target.gridX = info.cellX;
@@ -89,7 +76,7 @@ public void fillInLogContainerData(View v, ItemInfo info, Target target, Target
8976
@Override
9077
public void setInsets(Rect insets) {
9178
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
92-
DeviceProfile grid = mLauncher.getDeviceProfile();
79+
DeviceProfile grid = mActivity.getDeviceProfile();
9380

9481
if (grid.isVerticalBarLayout()) {
9582
lp.height = ViewGroup.LayoutParams.MATCH_PARENT;

src/com/android/launcher3/Launcher.java

+9
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
import com.android.launcher3.util.TraceHelper;
123123
import com.android.launcher3.util.UiThreadHelper;
124124
import com.android.launcher3.util.ViewOnDrawExecutor;
125+
import com.android.launcher3.views.ActivityContext;
125126
import com.android.launcher3.views.OptionsPopupView;
126127
import com.android.launcher3.widget.LauncherAppWidgetHostView;
127128
import com.android.launcher3.widget.PendingAddShortcutInfo;
@@ -940,6 +941,7 @@ private void setupViews() {
940941
mDropTargetBar.setup(mDragController);
941942

942943
mAllAppsController.setupViews(mAppsView);
944+
mHotseat.setOnInterceptTouchListener(mWorkspace::onInterceptHotseatTouch);
943945
}
944946

945947
/**
@@ -2391,6 +2393,13 @@ public static Launcher getLauncher(Context context) {
23912393
return (Launcher) fromContext(context);
23922394
}
23932395

2396+
/**
2397+
* Just a wrapper around the type cast to allow easier tracking of calls.
2398+
*/
2399+
public static <T extends Launcher> T cast(ActivityContext activityContext) {
2400+
return (T) activityContext;
2401+
}
2402+
23942403
/**
23952404
* Callback for listening for onResume
23962405
*/

src/com/android/launcher3/ShortcutAndWidgetContainer.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.view.ViewGroup;
2727

2828
import com.android.launcher3.CellLayout.ContainerType;
29+
import com.android.launcher3.views.ActivityContext;
2930
import com.android.launcher3.widget.LauncherAppWidgetHostView;
3031

3132
public class ShortcutAndWidgetContainer extends ViewGroup {
@@ -43,12 +44,12 @@ public class ShortcutAndWidgetContainer extends ViewGroup {
4344

4445
private int mCountX;
4546

46-
private Launcher mLauncher;
47+
private ActivityContext mActivity;
4748
private boolean mInvertIfRtl = false;
4849

4950
public ShortcutAndWidgetContainer(Context context, @ContainerType int containerType) {
5051
super(context);
51-
mLauncher = Launcher.getLauncher(context);
52+
mActivity = ActivityContext.lookupContext(context);
5253
mWallpaperManager = WallpaperManager.getInstance(context);
5354
mContainerType = containerType;
5455
}
@@ -92,7 +93,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
9293
public void setupLp(View child) {
9394
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
9495
if (child instanceof LauncherAppWidgetHostView) {
95-
DeviceProfile profile = mLauncher.getDeviceProfile();
96+
DeviceProfile profile = mActivity.getDeviceProfile();
9697
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX,
9798
profile.appWidgetScale.x, profile.appWidgetScale.y);
9899
} else {
@@ -107,12 +108,12 @@ public void setInvertIfRtl(boolean invert) {
107108

108109
public int getCellContentHeight() {
109110
return Math.min(getMeasuredHeight(),
110-
mLauncher.getDeviceProfile().getCellHeight(mContainerType));
111+
mActivity.getDeviceProfile().getCellHeight(mContainerType));
111112
}
112113

113114
public void measureChild(View child) {
114115
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
115-
final DeviceProfile profile = mLauncher.getDeviceProfile();
116+
final DeviceProfile profile = mActivity.getDeviceProfile();
116117

117118
if (child instanceof LauncherAppWidgetHostView) {
118119
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX,
@@ -149,7 +150,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
149150
LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) child;
150151

151152
// Scale and center the widget to fit within its cells.
152-
DeviceProfile profile = mLauncher.getDeviceProfile();
153+
DeviceProfile profile = mActivity.getDeviceProfile();
153154
float scaleX = profile.appWidgetScale.x;
154155
float scaleY = profile.appWidgetScale.y;
155156

src/com/android/launcher3/Workspace.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,13 @@ public void onViewAdded(View child) {
475475
super.onViewAdded(child);
476476
}
477477

478+
protected boolean onInterceptHotseatTouch(View v, MotionEvent ev) {
479+
// We don't want any clicks to go through to the hotseat unless the workspace is in
480+
// the normal state or an accessible drag is in progress.
481+
return !workspaceIconsCanBeDragged()
482+
&& !mLauncher.getAccessibilityDelegate().isInAccessibleDrag();
483+
}
484+
478485
/**
479486
* Initializes and binds the first page
480487
* @param qsb an existing qsb to recycle or null.
@@ -2442,7 +2449,7 @@ public FolderCreationAlarmListener(CellLayout layout, int cellX, int cellY) {
24422449
this.cellY = cellY;
24432450

24442451
BubbleTextView cell = (BubbleTextView) layout.getChildAt(cellX, cellY);
2445-
bg.setup(mLauncher, null, cell.getMeasuredWidth(), cell.getPaddingTop());
2452+
bg.setup(mLauncher, mLauncher, null, cell.getMeasuredWidth(), cell.getPaddingTop());
24462453

24472454
// The full preview background should appear behind the icon
24482455
bg.isClipping = false;

src/com/android/launcher3/folder/PreviewBackground.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.animation.AnimatorListenerAdapter;
2424
import android.animation.ObjectAnimator;
2525
import android.animation.ValueAnimator;
26+
import android.content.Context;
2627
import android.graphics.Canvas;
2728
import android.graphics.Color;
2829
import android.graphics.Matrix;
@@ -41,6 +42,7 @@
4142
import com.android.launcher3.Launcher;
4243
import com.android.launcher3.R;
4344
import com.android.launcher3.util.Themes;
45+
import com.android.launcher3.views.ActivityContext;
4446

4547
/**
4648
* This object represents a FolderIcon preview background. It stores drawing / measurement
@@ -121,20 +123,20 @@ public void set(PreviewBackground previewBackground, Integer alpha) {
121123
}
122124
};
123125

124-
public void setup(Launcher launcher, View invalidateDelegate,
126+
public void setup(Context context, ActivityContext activity, View invalidateDelegate,
125127
int availableSpaceX, int topPadding) {
126128
mInvalidateDelegate = invalidateDelegate;
127-
mBgColor = Themes.getAttrColor(launcher, android.R.attr.colorPrimary);
128-
mBadgeColor = Themes.getAttrColor(launcher, R.attr.folderBadgeColor);
129+
mBgColor = Themes.getAttrColor(context, android.R.attr.colorPrimary);
130+
mBadgeColor = Themes.getAttrColor(context, R.attr.folderBadgeColor);
129131

130-
DeviceProfile grid = launcher.getDeviceProfile();
132+
DeviceProfile grid = activity.getDeviceProfile();
131133
previewSize = grid.folderIconSizePx;
132134

133135
basePreviewOffsetX = (availableSpaceX - previewSize) / 2;
134136
basePreviewOffsetY = topPadding + grid.folderIconOffsetYPx;
135137

136138
// Stroke width is 1dp
137-
mStrokeWidth = launcher.getResources().getDisplayMetrics().density;
139+
mStrokeWidth = context.getResources().getDisplayMetrics().density;
138140

139141
float radius = getScaledRadius();
140142
float shadowRadius = radius + mStrokeWidth;

src/com/android/launcher3/folder/PreviewItemManager.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ private void computePreviewDrawingParams(int drawableSize, int totalSize) {
107107
mTotalWidth = totalSize;
108108
mPrevTopPadding = mIcon.getPaddingTop();
109109

110-
mIcon.mBackground.setup(mIcon.mLauncher, mIcon, mTotalWidth, mIcon.getPaddingTop());
110+
mIcon.mBackground.setup(mIcon.mLauncher, mIcon.mLauncher, mIcon, mTotalWidth,
111+
mIcon.getPaddingTop());
111112
mIcon.mPreviewLayoutRule.init(mIcon.mBackground.previewSize, mIntrinsicIconSize,
112113
Utilities.isRtl(mIcon.getResources()));
113114

0 commit comments

Comments
 (0)