Making CellLayout inflatable without LauncherActivtiy
This will allow creating cellLayout with a different device profile
or a different activtiy which can be used when displaying multiple
activities in multi-display or generating a preview for changing
display properties.
Change-Id: I386731d95e33c48bdef270ce9c0d3e9feefb6262
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index 92404d4..a117cfd 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -62,6 +62,7 @@
import com.android.launcher3.util.ParcelableSparseArray;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.Thunk;
+import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.widget.LauncherAppWidgetHostView;
import java.lang.annotation.Retention;
@@ -82,7 +83,7 @@
private static final String TAG = "CellLayout";
private static final boolean LOGD = false;
- private final Launcher mLauncher;
+ protected final ActivityContext mActivity;
@ViewDebug.ExportedProperty(category = "launcher")
@Thunk int mCellWidth;
@ViewDebug.ExportedProperty(category = "launcher")
@@ -106,7 +107,6 @@
private GridOccupancy mTmpOccupied;
private OnTouchListener mInterceptTouchListener;
- private final StylusEventHelper mStylusEventHelper;
private final ArrayList<PreviewBackground> mFolderBackgrounds = new ArrayList<>();
final PreviewBackground mFolderLeaveBehind = new PreviewBackground();
@@ -201,9 +201,9 @@
// the user where a dragged item will land when dropped.
setWillNotDraw(false);
setClipToPadding(false);
- mLauncher = Launcher.getLauncher(context);
+ mActivity = ActivityContext.lookupContext(context);
- DeviceProfile grid = mLauncher.getDeviceProfile();
+ DeviceProfile grid = mActivity.getDeviceProfile();
mCellWidth = mCellHeight = -1;
mFixedCellWidth = mFixedCellHeight = -1;
@@ -286,8 +286,6 @@
mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context, mContainerType);
mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY);
-
- mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this);
addView(mShortcutsAndWidgets);
}
@@ -337,20 +335,6 @@
return false;
}
- @Override
- public boolean onTouchEvent(MotionEvent ev) {
- boolean handled = super.onTouchEvent(ev);
- // Stylus button press on a home screen should not switch between overview mode and
- // the home screen mode, however, once in overview mode stylus button press should be
- // enabled to allow rearranging the different home screens. So check what mode
- // the workspace is in, and only perform stylus button presses while in overview mode.
- if (mLauncher.isInState(LauncherState.OVERVIEW)
- && mStylusEventHelper.onMotionEvent(ev)) {
- return true;
- }
- return handled;
- }
-
public void enableHardwareLayer(boolean hasLayer) {
mShortcutsAndWidgets.setLayerType(hasLayer ? LAYER_TYPE_HARDWARE : LAYER_TYPE_NONE, sPaint);
}
@@ -504,7 +488,7 @@
public void setFolderLeaveBehindCell(int x, int y) {
View child = getChildAt(x, y);
- mFolderLeaveBehind.setup(mLauncher, null,
+ mFolderLeaveBehind.setup(getContext(), mActivity, null,
child.getMeasuredWidth(), child.getPaddingTop());
mFolderLeaveBehind.delegateCellX = x;
@@ -945,7 +929,7 @@
if (resize) {
cellToRect(cellX, cellY, spanX, spanY, r);
if (v instanceof LauncherAppWidgetHostView) {
- DeviceProfile profile = mLauncher.getDeviceProfile();
+ DeviceProfile profile = mActivity.getDeviceProfile();
Utilities.shrinkRect(r, profile.appWidgetScale.x, profile.appWidgetScale.y);
}
} else {
@@ -2047,7 +2031,7 @@
.translationY(initDeltaY)
.build(child)
.setDuration(REORDER_ANIMATION_DURATION);
- mLauncher.getDragController().addFirstFrameAnimationHelper(a);
+ Launcher.cast(mActivity).getDragController().addFirstFrameAnimationHelper(a);
a.setInterpolator(DEACCEL_1_5);
a.start();
}
@@ -2063,7 +2047,7 @@
private void commitTempPlacement() {
mTmpOccupied.copyTo(mOccupied);
- int screenId = mLauncher.getWorkspace().getIdForScreen(this);
+ int screenId = Launcher.cast(mActivity).getWorkspace().getIdForScreen(this);
int container = Favorites.CONTAINER_DESKTOP;
if (mContainerType == HOTSEAT) {
@@ -2089,8 +2073,8 @@
info.spanY = lp.cellVSpan;
if (requiresDbUpdate) {
- mLauncher.getModelWriter().modifyItemInDatabase(info, container, screenId,
- info.cellX, info.cellY, info.spanX, info.spanY);
+ Launcher.cast(mActivity).getModelWriter().modifyItemInDatabase(info, container,
+ screenId, info.cellX, info.cellY, info.spanX, info.spanY);
}
}
}