/** 以图标为中心,中心对齐,比如缩放时要以中心对齐 */ private void centerAboutIcon() { DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); int height = getPaddingTop() + getPaddingBottom() + mContent.getDesiredHeight() + mFolderNameHeight; DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer); float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect); int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2); int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2); int centeredLeft = centerX - width / 2; int centeredTop = centerY - height / 2; int currentPage = mLauncher.getWorkspace().getCurrentPage(); // In case the workspace is scrolling, we need to use the final scroll // to compute // the folders bounds. // 如果workspace正在滚动,就强制滚动到最后以计算最终的位置 mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage); // We first fetch the currently visible CellLayoutChildren // 首先获取可见CellLayoutChildren CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage); ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets(); Rect bounds = new Rect(); parent.getDescendantRectRelativeToSelf(boundingLayout, bounds); // We reset the workspaces scroll // 强制重置workspace的滚动状态 mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage); // 重新调整folder的边界,如果有需要的话,比如实际内容比folder要更大或者更小 int left = Math.min(Math.max(bounds.left, centeredLeft), bounds.left + bounds.width() - width); int top = Math.min(Math.max(bounds.top, centeredTop), bounds.top + bounds.height() - height); // 如果实际内容比folder要更大或者更小,那么调整为实际大小 if (width >= bounds.width()) { left = bounds.left + (bounds.width() - width) / 2; } if (height >= bounds.height()) { top = bounds.top + (bounds.height() - height) / 2; } int folderPivotX = width / 2 + (centeredLeft - left); int folderPivotY = height / 2 + (centeredTop - top); // 设置Folder的锚点 setPivotX(folderPivotX); setPivotY(folderPivotY); mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width)); mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height)); lp.width = width; lp.height = height; lp.x = left; lp.y = top; }
private void centerAboutIcon() { DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer); int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); int height = getFolderHeight(); float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect); LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2); int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2); int centeredLeft = centerX - width / 2; int centeredTop = centerY - height / 2; int currentPage = mLauncher.getWorkspace().getNextPage(); // In case the workspace is scrolling, we need to use the final scroll to compute // the folders bounds. mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage); // We first fetch the currently visible CellLayoutChildren CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage); ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets(); Rect bounds = new Rect(); parent.getDescendantRectRelativeToSelf(boundingLayout, bounds); // We reset the workspaces scroll mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage); // We need to bound the folder to the currently visible CellLayoutChildren int left = Math.min(Math.max(bounds.left, centeredLeft), bounds.left + bounds.width() - width); int top = Math.min(Math.max(bounds.top, centeredTop), bounds.top + bounds.height() - height); if (grid.isPhone() && (grid.availableWidthPx - width) < grid.iconSizePx) { // Center the folder if it is full (on phones only) left = (grid.availableWidthPx - width) / 2; } else if (width >= bounds.width()) { // If the folder doesn't fit within the bounds, center it about the desired bounds left = bounds.left + (bounds.width() - width) / 2; } if (height >= bounds.height()) { top = bounds.top + (bounds.height() - height) / 2; } int folderPivotX = width / 2 + (centeredLeft - left); int folderPivotY = height / 2 + (centeredTop - top); setPivotX(folderPivotX); setPivotY(folderPivotY); mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width)); mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height)); lp.width = width; lp.height = height; lp.x = left; lp.y = top; }
private void deleteFromWorkspace(DragSource source, ItemInfo item) { // TODO Auto-generated method stub if (item.container == Favorites.CONTAINER_DESKTOP) { if (item instanceof LauncherAppWidgetInfo) { mLauncher.removeAppWidget((LauncherAppWidgetInfo) item); } else if (item instanceof CustomAppWidgetInfo) { if (((CustomAppWidgetInfo) item).itemType == Favorites.ITEM_TYPE_WIDGET_LOCK_SCREEN) { final ContentResolver cr = mLauncher.getContentResolver(); final String where = BaseLauncherColumns.ITEM_TYPE + "=" + Favorites.ITEM_TYPE_WIDGET_LOCK_SCREEN; Cursor c = cr.query(Favorites.CONTENT_URI, null, where, null, null); // should remove administration when no more LOCK_SCREEN // widget displayed in launcher if (c.getCount() <= 1) { LockScreenUtil.getInstance(mLauncher).removeAdmin(); } } } } else { if (source instanceof UserFolder) { final UserFolder userFolder = (UserFolder) source; final FolderInfo folderInfo = userFolder.getInfo(); if (folderInfo instanceof UserFolderInfo) { // Item must be a ShortcutInfo otherwise it couldn't have // been in the folder // in the first place. if (item instanceof ShortcutInfo && item.container == folderInfo.id) { mLauncher.removeItemFromFolder((ShortcutInfo) item); } } } } if (item instanceof UserFolderInfo) { final UserFolderInfo userFolderInfo = (UserFolderInfo) item; if (userFolderInfo.contents.size() > 0) { Toast.makeText(mLauncher, R.string.folder_is_not_empty, Toast.LENGTH_SHORT).show(); return; } LauncherModel.deleteUserFolderContentsFromDatabase(mLauncher, userFolderInfo); mLauncher.removeFolder(userFolderInfo); } else if (item instanceof LauncherAppWidgetInfo) { final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item; final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost(); if (appWidgetHost != null) { appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId); } mLauncher.getWorkspace().forceToDeleteWidget((long) launcherAppWidgetInfo.appWidgetId); } else if (item instanceof CustomAppWidgetInfo) { mLauncher.getWorkspace().forceToDeleteWidget(((CustomAppWidgetInfo) item).id); } LauncherModel.deleteItemFromDatabase(mLauncher, item); }
private boolean handleTouchDown(MotionEvent ev, boolean intercept) { Rect hitRect = new Rect(); int x = (int) ev.getX(); int y = (int) ev.getY(); for (AppWidgetResizeFrame child : mResizeFrames) { child.getHitRect(hitRect); if (hitRect.contains(x, y)) { if (child.beginResizeIfPointInRegion(x - child.getLeft(), y - child.getTop())) { mCurrentResizeFrame = child; mXDown = x; mYDown = y; requestDisallowInterceptTouchEvent(true); return true; } } } Folder currentFolder = mLauncher.getWorkspace().getOpenFolder(); if (currentFolder != null && !mLauncher.isFolderClingVisible() && intercept) { if (currentFolder.isEditingName()) { if (!isEventOverFolderTextRegion(currentFolder, ev)) { currentFolder.dismissEditingName(); return true; } } getDescendantRectRelativeToSelf(currentFolder, hitRect); if (!isEventOverFolder(currentFolder, ev)) { mLauncher.closeFolder(); return true; } } return false; }
public boolean onLongClick(View v) { // 返回是否全局拖动被禁止,如果是,则不执行下面的动作 if (!mLauncher.isDraggingEnabled()) return true; Object tag = v.getTag(); if (tag instanceof ShortcutInfo) { ShortcutInfo item = (ShortcutInfo) tag; if (!v.isInTouchMode()) { return false; } mLauncher.dismissFolderCling(null); mLauncher.getWorkspace().onDragStartedWithItem(v); mLauncher.getWorkspace().beginDragShared(v, this); // 此处发起拖动 mIconDrawable = ((TextView) v).getCompoundDrawables()[1]; mCurrentDragInfo = item; mEmptyCell[0] = item.cellX; mEmptyCell[1] = item.cellY; mCurrentDragView = v; mContent.removeView(mCurrentDragView); mInfo.remove(mCurrentDragInfo); mDragInProgress = true; mItemAddedBackToSelfViaIcon = false; } return true; }
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (mInScrollArea && !LauncherApplication.isScreenLarge()) { Workspace workspace = mLauncher.getWorkspace(); int width = workspace.getWidth(); Rect childRect = new Rect(); getDescendantRectRelativeToSelf(workspace.getChildAt(0), childRect); int page = workspace.getNextPage(); final boolean isRtl = isLayoutDirectionRtl(); CellLayout leftPage = (CellLayout) workspace.getChildAt(isRtl ? page + 1 : page - 1); CellLayout rightPage = (CellLayout) workspace.getChildAt(isRtl ? page - 1 : page + 1); if (leftPage != null && leftPage.getIsDragOverlapping()) { mLeftHoverDrawable.setBounds( 0, childRect.top, mLeftHoverDrawable.getIntrinsicWidth(), childRect.bottom); mLeftHoverDrawable.draw(canvas); } else if (rightPage != null && rightPage.getIsDragOverlapping()) { mRightHoverDrawable.setBounds( width - mRightHoverDrawable.getIntrinsicWidth(), childRect.top, width, childRect.bottom); mRightHoverDrawable.draw(canvas); } } }
public boolean onLongClick(View v) { // Return if workspace is locked if (mLauncher.getLockWorkspace()) return false; // Return if global dragging is not enabled if (!mLauncher.isDraggingEnabled()) return true; Object tag = v.getTag(); if (tag instanceof ShortcutInfo) { ShortcutInfo item = (ShortcutInfo) tag; if (!v.isInTouchMode()) { return false; } mLauncher.getWorkspace().beginDragShared(v, this); mCurrentDragInfo = item; mEmptyCell[0] = item.cellX; mEmptyCell[1] = item.cellY; mCurrentDragView = v; mContent.removeView(mCurrentDragView); mInfo.remove(mCurrentDragInfo); mDragInProgress = true; mItemAddedBackToSelfViaIcon = false; } return true; }
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { // We don't want any clicks to go through to the hotseat unless the workspace is in // the normal state. if (mLauncher.getWorkspace().isSmall()) { return true; } return false; }
@Override public boolean onInterceptHoverEvent(MotionEvent ev) { Log.d("DragLayer", "onInterceptHoverEvent"); if (mLauncher == null || mLauncher.getWorkspace() == null) { return false; } Folder currentFolder = mLauncher.getWorkspace().getOpenFolder(); if (currentFolder == null) { return false; } else { AccessibilityManager accessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); if (accessibilityManager.isTouchExplorationEnabled()) { final int action = ev.getAction(); boolean isOverFolder; switch (action) { case MotionEvent.ACTION_HOVER_ENTER: isOverFolder = isEventOverFolder(currentFolder, ev); if (!isOverFolder) { sendTapOutsideFolderAccessibilityEvent(currentFolder.isEditingName()); mHoverPointClosesFolder = true; return true; } else if (isOverFolder) { mHoverPointClosesFolder = false; } else { return true; } case MotionEvent.ACTION_HOVER_MOVE: isOverFolder = isEventOverFolder(currentFolder, ev); if (!isOverFolder && !mHoverPointClosesFolder) { sendTapOutsideFolderAccessibilityEvent(currentFolder.isEditingName()); mHoverPointClosesFolder = true; return true; } else if (isOverFolder) { mHoverPointClosesFolder = false; } else { return true; } } } } return false; }
@Override public void addChildrenForAccessibility(ArrayList<View> childrenForAccessibility) { Folder currentFolder = mLauncher.getWorkspace().getOpenFolder(); if (currentFolder != null) { // Only add the folder as a child for accessibility when it is open childrenForAccessibility.add(currentFolder); } else { super.addChildrenForAccessibility(childrenForAccessibility); } }
public void onDragEnd() { if (mTrashMode) { mTrashMode = false; mDragLayer.setDeleteRegion(null); startAnimation(mOutAnimation); setVisibility(INVISIBLE); mLauncher.getWorkspace().setPadding(0, 0, 0, 0); mLauncher.setDockPadding(0); if (mPosition == POSITION_BOTTOM_SHRINK || mPosition == POSITION_TOP_SHRINK) { mLauncher.fullScreenRestore(); } mLauncher.getWorkspace().requestLayout(); } if (mShouldUninstall && mUninstallPkg != null) { try { Intent intent = new Intent(); final int apiLevel = Build.VERSION.SDK_INT; if (apiLevel >= 9) { // above 2.3 intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); Uri uri = Uri.fromParts("package", mUninstallPkg, null); intent.setData(uri); } else { // below 2.3 final String appPkgName = (apiLevel == 8 ? "pkg" : "com.android.settings.ApplicationPkgName"); intent.setAction(Intent.ACTION_VIEW); intent.setClassName( Launcher.ANDROID_SETTINGS_PACKAGE, "com.android.settings.InstalledAppDetails"); intent.putExtra(appPkgName, mUninstallPkg); } DeleteZone.this.getContext().startActivity(intent); } catch (Exception e) { // failed to start app info } // actually uninstall /* Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, Uri.parse("package:"+mUninstallPkg)); DeleteZone.this.getContext().startActivity(uninstallIntent); */ } }
@Override public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) { Folder currentFolder = mLauncher.getWorkspace().getOpenFolder(); if (currentFolder != null) { if (child == currentFolder) { return super.onRequestSendAccessibilityEvent(child, event); } // Skip propagating onRequestSendAccessibilityEvent all for other children // when a folder is open return false; } return super.onRequestSendAccessibilityEvent(child, event); }
private void dismissLongPressCling() { Runnable dismissCb = new Runnable() { public void run() { dismissCling( mLauncher.findViewById(R.id.longpress_cling), null, WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); } }; mLauncher.getWorkspace().post(dismissCb); }
private void centerAboutIcon() { DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); int height = getPaddingTop() + getPaddingBottom() + mContent.getDesiredHeight() + mFolderNameHeight; DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer); parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect); int centerX = mTempRect.centerX(); int centerY = mTempRect.centerY(); int centeredLeft = centerX - width / 2; int centeredTop = centerY - height / 2; // We first fetch the currently visible CellLayoutChildren CellLayout currentPage = mLauncher.getWorkspace().getCurrentDropLayout(); CellLayoutChildren boundingLayout = currentPage.getChildrenLayout(); Rect bounds = new Rect(); parent.getDescendantRectRelativeToSelf(boundingLayout, bounds); // We need to bound the folder to the currently visible CellLayoutChildren int left = Math.min(Math.max(bounds.left, centeredLeft), bounds.left + bounds.width() - width); int top = Math.min(Math.max(bounds.top, centeredTop), bounds.top + bounds.height() - height); // If the folder doesn't fit within the bounds, center it about the desired bounds if (width >= bounds.width()) { left = bounds.left + (bounds.width() - width) / 2; } if (height >= bounds.height()) { top = bounds.top + (bounds.height() - height) / 2; } int folderPivotX = width / 2 + (centeredLeft - left); int folderPivotY = height / 2 + (centeredTop - top); setPivotX(folderPivotX); setPivotY(folderPivotY); int folderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width)); int folderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height)); mFolderIcon.setPivotX(folderIconPivotX); mFolderIcon.setPivotY(folderIconPivotY); if (mMode == PARTIAL_GROW) { lp.width = width; lp.height = height; lp.x = left; lp.y = top; } else { mNewSize.set(left, top, left + width, top + height); } }
private void dismissMigrationCling() { mLauncher.showWorkspaceSearchAndHotseat(); Runnable dismissCb = new Runnable() { public void run() { Runnable cb = new Runnable() { public void run() { // Show the longpress cling next showLongPressCling(false); } }; dismissCling( mLauncher.findViewById(R.id.migration_cling), cb, MIGRATION_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); } }; mLauncher.getWorkspace().post(dismissCb); }
private void replaceFolderWithFinalItem() { ItemInfo finalItem = null; if (getItemCount() == 1) { finalItem = mInfo.contents.get(0); } // Remove the folder completely CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screen); cellLayout.removeView(mFolderIcon); if (mFolderIcon instanceof DropTarget) { mDragController.removeDropTarget((DropTarget) mFolderIcon); } mLauncher.removeFolder(mInfo); if (finalItem != null) { LauncherModel.addOrMoveItemInDatabase( mLauncher, finalItem, mInfo.container, mInfo.screen, mInfo.cellX, mInfo.cellY); } LauncherModel.deleteItemFromDatabase(mLauncher, mInfo); // Add the last remaining child to the workspace in place of the folder if (finalItem != null) { View child = mLauncher.createShortcut(R.layout.application, cellLayout, (ShortcutInfo) finalItem); mLauncher .getWorkspace() .addInScreen( child, mInfo.container, mInfo.screen, mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY); } }
@Override protected int getChildDrawingOrder(int childCount, int i) { // TODO: We have turned off this custom drawing order because it now effects touch // dispatch order. We need to sort that issue out and then decide how to go about this. if (true || LauncherApplication.isScreenLandscape(getContext()) || mWorkspaceIndex == -1 || mQsbIndex == -1 || mLauncher.getWorkspace().isDrawingBackgroundGradient()) { return i; } // This ensures that the workspace is drawn above the hotseat and qsb, // except when the workspace is drawing a background gradient, in which // case we want the workspace to stay behind these elements. if (i == mQsbIndex) { return mWorkspaceIndex; } else if (i == mWorkspaceIndex) { return mQsbIndex; } else { return i; } }
public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) { final ItemInfo item = (ItemInfo) dragInfo; // dismiss popup to avoid an ugly bug when the qaw is triggered directly on top of the delete // zone mLauncher.dismissQuickActionWindow(); if (item.container == -1) return; final LauncherModel model = Launcher.getLauncherModel(); if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { if (item instanceof LauncherAppWidgetInfo) { model.removeDesktopAppWidget((LauncherAppWidgetInfo) item); } else { model.removeDesktopItem(item); } } else { if (source instanceof UserFolder) { final UserFolder userFolder = (UserFolder) source; final UserFolderInfo userFolderInfo = (UserFolderInfo) userFolder.getInfo(); model.removeUserFolderItem(userFolderInfo, item); } } if (item instanceof UserFolderInfo) { final UserFolderInfo userFolderInfo = (UserFolderInfo) item; LauncherModel.deleteUserFolderContentsFromDatabase(mLauncher, userFolderInfo); model.removeUserFolder(userFolderInfo); } else if (item instanceof LauncherAppWidgetInfo) { final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item; final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost(); mLauncher.getWorkspace().unbindWidgetScrollableId(launcherAppWidgetInfo.appWidgetId); if (appWidgetHost != null) { appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId); } } LauncherModel.deleteItemFromDatabase(mLauncher, item); }
public void onDrop(DragObject d) { Runnable cleanUpRunnable = null; // If we are coming from All Apps space, we defer removing the extra empty screen // until the folder closes if (d.dragSource != mLauncher.getWorkspace() && !(d.dragSource instanceof Folder)) { cleanUpRunnable = new Runnable() { @Override public void run() { mLauncher.exitSpringLoadedDragModeDelayed( true, Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); } }; } View currentDragView; ShortcutInfo si = mCurrentDragInfo; if (mIsExternalDrag) { si.cellX = mEmptyCell[0]; si.cellY = mEmptyCell[1]; // Actually move the item in the database if it was an external drag. Call this // before creating the view, so that ShortcutInfo is updated appropriately. LauncherModel.addOrMoveItemInDatabase(mLauncher, si, mInfo.id, 0, si.cellX, si.cellY); // We only need to update the locations if it doesn't get handled in #onDropCompleted. if (d.dragSource != this) { updateItemLocationsInDatabaseBatch(); } mIsExternalDrag = false; currentDragView = createAndAddShortcut(si); } else { currentDragView = mCurrentDragView; CellLayout.LayoutParams lp = (CellLayout.LayoutParams) currentDragView.getLayoutParams(); si.cellX = lp.cellX = mEmptyCell[0]; si.cellX = lp.cellY = mEmptyCell[1]; mContent.addViewToCellLayout(currentDragView, -1, (int) si.id, lp, true); } if (d.dragView.hasDrawn()) { // Temporarily reset the scale such that the animation target gets calculated correctly. float scaleX = getScaleX(); float scaleY = getScaleY(); setScaleX(1.0f); setScaleY(1.0f); mLauncher .getDragLayer() .animateViewIntoPosition(d.dragView, currentDragView, cleanUpRunnable, null); setScaleX(scaleX); setScaleY(scaleY); } else { d.deferDragViewCleanupPostAnimation = false; currentDragView.setVisibility(VISIBLE); } mItemsInvalidated = true; setupContentDimensions(getItemCount()); // Temporarily suppress the listener, as we did all the work already here. mSuppressOnAdd = true; mInfo.add(si); mSuppressOnAdd = false; // Clear the drag info, as it is no longer being dragged. mCurrentDragInfo = null; }
private void updateChildIndices() { if (mLauncher != null) { mWorkspaceIndex = indexOfChild(mLauncher.getWorkspace()); mQsbIndex = indexOfChild(mLauncher.getSearchBar()); } }
public void onDragStart(View v, DragSource source, Object info, int dragAction) { if (mPosition == -1) { int position = MyLauncherSettingsHelper.getDeletezoneStyle(getContext()); setPosition(position); } if (mPosition == POSITION_NONE) return; final ItemInfo item = (ItemInfo) info; mUninstallPkg = null; if (item != null) { mTrashMode = true; createAnimations(); final int[] location = mLocation; getLocationOnScreen(location); if (mPosition == POSITION_BOTTOM_SHRINK) { mLauncher.getWorkspace().setPadding(0, 0, 0, mStatusBarHeight); mLauncher.setDockPadding(mStatusBarHeight); mLauncher.fullScreenTemporary(true); } else if (mPosition == POSITION_TOP_SHRINK) { mLauncher.getWorkspace().setPadding(0, mStatusBarHeight, 0, 0); mLauncher.fullScreenTemporary(true); if (mLauncher.isScreenLandscape()) { mLauncher.setDockPadding(-mStatusBarHeight); } else { mLauncher.setDockPadding(0); } } mLauncher.getWorkspace().requestLayout(); mRegion.set( location[0], location[1], location[0] + getRight() - getLeft(), location[1] + getBottom() - getTop()); mDragLayer.setDeleteRegion(mRegion); mTransition.resetTransition(); startAnimation(mInAnimation); setVisibility(VISIBLE); // ADW Store app data for uninstall if its an Application // ADW Thanks to irrenhaus@xda & Rogro82@xda :) if (item instanceof ApplicationInfo) { try { final ApplicationInfo appInfo = (ApplicationInfo) item; if (appInfo.iconResource != null) mUninstallPkg = appInfo.iconResource.packageName; else { PackageManager mgr = DeleteZone.this.getContext().getPackageManager(); ResolveInfo res = mgr.resolveActivity(appInfo.intent, 0); mUninstallPkg = res.activityInfo.packageName; } // Dont uninstall ADW ;-) if (this.getClass().getPackage().getName().equals(mUninstallPkg)) mUninstallPkg = null; } catch (Exception e) { Log.w(LOG_TAG, "Could not load shortcut icon: " + item); mUninstallPkg = null; } } else if (item instanceof LauncherAppWidgetInfo) { LauncherAppWidgetInfo appwidget = (LauncherAppWidgetInfo) item; final AppWidgetProviderInfo aw = AppWidgetManager.getInstance(mLauncher).getAppWidgetInfo(appwidget.appWidgetId); if (aw != null) mUninstallPkg = aw.provider.getPackageName(); } } }
private void onDrop( final ShortcutInfo item, View animateView, Rect finalRect, float scaleRelativeToDragLayer, int index, Runnable postAnimationRunnable) { item.cellX = -1; item.cellY = -1; // Typically, the animateView corresponds to the DragView; however, if this is being done // after a configuration activity (ie. for a Shortcut being dragged from AllApps) we // will not have a view to animate if (animateView != null) { DragLayer dragLayer = mLauncher.getDragLayer(); Rect from = new Rect(); dragLayer.getViewRectRelativeToSelf(animateView, from); Rect to = finalRect; if (to == null) { to = new Rect(); Workspace workspace = mLauncher.getWorkspace(); // Set cellLayout and this to it's final state to compute final animation locations workspace.setFinalTransitionTransform((CellLayout) getParent().getParent()); float scaleX = getScaleX(); float scaleY = getScaleY(); setScaleX(1.0f); setScaleY(1.0f); scaleRelativeToDragLayer = dragLayer.getDescendantRectRelativeToSelf(this, to); // Finished computing final animation locations, restore current state setScaleX(scaleX); setScaleY(scaleY); workspace.resetTransitionTransform((CellLayout) getParent().getParent()); } int[] center = new int[2]; float scale = getLocalCenterForIndex(index, center); center[0] = Math.round(scaleRelativeToDragLayer * center[0]); center[1] = Math.round(scaleRelativeToDragLayer * center[1]); to.offset( center[0] - animateView.getMeasuredWidth() / 2, center[1] - animateView.getMeasuredHeight() / 2); float finalAlpha = index < NUM_ITEMS_IN_PREVIEW ? 0.5f : 0f; dragLayer.animateView( animateView, from, to, finalAlpha, scale * scaleRelativeToDragLayer, DROP_IN_ANIMATION_DURATION, new DecelerateInterpolator(2), new AccelerateInterpolator(2), postAnimationRunnable, false); postDelayed( new Runnable() { public void run() { addItem(item); } }, DROP_IN_ANIMATION_DURATION); } else { addItem(item); } }