/** * Used to inflate the Workspace from XML. * * @param context The application's context. * @param attrs The attribtues set containing the Workspace's customization values. */ public Folder(Context context, AttributeSet attrs) { super(context, attrs); setAlwaysDrawnWithCacheEnabled(false); mInflater = LayoutInflater.from(context); mIconCache = ((LauncherApplication) context.getApplicationContext()).getIconCache(); Resources res = getResources(); mMaxCountX = res.getInteger(R.integer.folder_max_count_x); mMaxCountY = res.getInteger(R.integer.folder_max_count_y); mMaxNumItems = res.getInteger(R.integer.folder_max_num_items); if (mMaxCountX < 0 || mMaxCountY < 0 || mMaxNumItems < 0) { mMaxCountX = LauncherModel.getCellCountX(); mMaxCountY = LauncherModel.getCellCountY(); mMaxNumItems = mMaxCountX * mMaxCountY; } mInputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); mExpandDuration = res.getInteger(R.integer.config_folderAnimDuration); if (sDefaultFolderName == null) { sDefaultFolderName = res.getString(R.string.folder_name); } if (sHintText == null) { sHintText = res.getString(R.string.folder_hint_text); } mLauncher = (Launcher) context; // We need this view to be focusable in touch mode so that when text editing of the folder // name is complete, we have something to focus on, thus hiding the cursor and giving // reliable behvior when clicking the text field (since it will always gain focus on click). setFocusableInTouchMode(true); mAM = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); }
@Override public void onClick(View v) { int id = v.getId(); if (id == R.id.cling_dismiss_migration_use_default) { // Disable the migration cling dismissMigrationCling(); } else if (id == R.id.cling_dismiss_migration_copy_apps) { // Copy the shortcuts from the old database LauncherModel model = mLauncher.getModel(); model.resetLoadedState(false, true); model.startLoader( false, PagedView.INVALID_RESTORE_PAGE, LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS); // Set the flag to skip the folder cling String spKey = LauncherAppState.getSharedPreferencesKey(); SharedPreferences sp = mLauncher.getSharedPreferences(spKey, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sp.edit(); editor.putBoolean(Launcher.USER_HAS_MIGRATED, true); editor.apply(); // Disable the migration cling dismissMigrationCling(); } else if (id == R.id.cling_dismiss_longpress_info) { dismissLongPressCling(); } }
private void completeDrop(DragObject d) { ItemInfo item = (ItemInfo) d.dragInfo; if (LauncherLog.DEBUG) { LauncherLog.d( DragController.TAG, "DeleteDropTarget completeDrop: item = " + item + ",d = " + d); } if (isAllAppsApplication(d.dragSource, item)) { // Uninstall the application if it is being dragged from AppsCustomize mLauncher.startApplicationUninstallActivity((ApplicationInfo) item); } else if (isWorkspaceOrFolderApplication(d)) { LauncherModel.deleteItemFromDatabase(mLauncher, item); } else if (isWorkspaceFolder(d)) { // Remove the folder from the workspace and delete the contents from launcher model FolderInfo folderInfo = (FolderInfo) item; mLauncher.removeFolder(folderInfo); LauncherModel.deleteFolderContentsFromDatabase(mLauncher, folderInfo); } else if (isWorkspaceOrFolderWidget(d)) { // Remove the widget from the workspace mLauncher.removeAppWidget((LauncherAppWidgetInfo) item); LauncherModel.deleteItemFromDatabase(mLauncher, item); final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item; final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost(); if (appWidgetHost != null) { // Deleting an app widget ID is a void call but writes to disk before returning // to the caller... new Thread("deleteAppWidgetId") { public void run() { appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId); } }.start(); } } }
@Override public void onStop() { super.onStop(); final LauncherModel model = Launcher.getModel(); model.loadApplications(false, activeLauncher, false); }
@Override protected void onFinishInflate() { super.onFinishInflate(); if (mCellCountX < 0) mCellCountX = LauncherModel.getCellCountX(); if (mCellCountY < 0) mCellCountY = LauncherModel.getCellCountY(); mContent = (CellLayout) findViewById(R.id.layout); mContent.setGridSize(mCellCountX, mCellCountY); mContent.setIsHotseat(true); resetLayout(); }
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); }
@Override public void setTag(Object tag) { if (tag != null) { LauncherModel.checkItemInfo((ItemInfo) tag); } super.setTag(tag); }
void addAllAppsFolder( IconCache iconCache, ArrayList<AppInfo> allApps, ArrayList<ComponentName> onWorkspace, Launcher launcher, Workspace workspace) { if (AppsCustomizePagedView.DISABLE_ALL_APPS) { FolderInfo fi = new FolderInfo(); fi.cellX = getCellXFromOrder(mAllAppsButtonRank); fi.cellY = getCellYFromOrder(mAllAppsButtonRank); fi.spanX = 1; fi.spanY = 1; fi.container = LauncherSettings.Favorites.CONTAINER_HOTSEAT; fi.screenId = mAllAppsButtonRank; fi.itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER; fi.title = "More Apps"; LauncherModel.addItemToDatabase( launcher, fi, fi.container, fi.screenId, fi.cellX, fi.cellY, false); FolderIcon folder = FolderIcon.fromXml(R.layout.folder_icon, launcher, getLayout(), fi, iconCache); workspace.addInScreen( folder, fi.container, fi.screenId, fi.cellX, fi.cellY, fi.spanX, fi.spanY); for (AppInfo info : allApps) { ComponentName cn = info.intent.getComponent(); if (!onWorkspace.contains(cn)) { Log.d(TAG, "Adding to 'more apps': " + info.intent); ShortcutInfo si = info.makeShortcut(); fi.add(si); } } } }
public void applyFromAppWidgetProviderInfo( AppWidgetProviderInfo info, int maxWidth, int[] cellSpan) { mIsAppWidget = true; final ImageView image = (ImageView) findViewById(R.id.widget_preview); if (maxWidth > -1) { image.setMaxWidth(maxWidth); } image.setContentDescription(info.label); final TextView name = (TextView) findViewById(R.id.widget_name); name.setText(info.label); final TextView dims = (TextView) findViewById(R.id.widget_dims); if (dims != null) { int hSpan = Math.min(cellSpan[0], LauncherModel.getCellCountX()); int vSpan = Math.min(cellSpan[1], LauncherModel.getCellCountY()); dims.setText(String.format(mDimensionsFormatString, hSpan, vSpan)); } }
public void addItemLocationsInDatabase() { ArrayList<View> list = getItemsInReadingOrder(); for (int i = 0; i < list.size(); i++) { View v = list.get(i); ItemInfo info = (ItemInfo) v.getTag(); LauncherModel.addItemToDatabase(mLauncher, info, mInfo.id, 0, info.cellX, info.cellY, false); } }
private void updateItemLocationsInDatabase() { ArrayList<View> list = getItemsInReadingOrder(); for (int i = 0; i < list.size(); i++) { View v = list.get(i); ItemInfo info = (ItemInfo) v.getTag(); LauncherModel.moveItemInDatabase(mLauncher, info, mInfo.id, 0, info.cellX, info.cellY); } }
private void updateItemLocationsInDatabaseBatch() { ArrayList<View> list = getItemsInReadingOrder(); ArrayList<ItemInfo> items = new ArrayList<ItemInfo>(); for (int i = 0; i < list.size(); i++) { View v = list.get(i); ItemInfo info = (ItemInfo) v.getTag(); items.add(info); } LauncherModel.moveItemsInDatabase(mLauncher, items, mInfo.id, 0); }
static void flushInstallQueue(Context context) { String spKey = LauncherAppState.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp, context); if (!installQueue.isEmpty()) { Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator(); ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>(); while (iter.hasNext()) { final PendingInstallShortcutInfo pendingInfo = iter.next(); final Intent intent = pendingInfo.launchIntent; if (LauncherAppState.isDisableAllApps() && !isValidShortcutLaunchIntent(intent)) { if (DBG) Log.d(TAG, "Ignoring shortcut with launchIntent:" + intent); continue; } // If the intent specifies a package, make sure the package exists String packageName = pendingInfo.getTargetPackage(); if (!TextUtils.isEmpty(packageName)) { UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle(); if (!LauncherModel.isValidPackage(context, packageName, myUserHandle)) { if (DBG) Log.d(TAG, "Ignoring shortcut for absent package:" + intent); continue; } } final boolean exists = LauncherModel.shortcutExists(context, pendingInfo.label, intent, pendingInfo.user); if (!exists) { // Generate a shortcut info to add into the model addShortcuts.add(pendingInfo.getShortcutInfo()); } } // Add the new apps to the model and bind them if (!addShortcuts.isEmpty()) { LauncherAppState app = LauncherAppState.getInstance(); app.getModel().addAndBindAddedWorkspaceApps(context, addShortcuts); } } }
private void completeDrop(DragObject d) { ItemInfo item = (ItemInfo) d.dragInfo; switch (mMode) { case MODE_DELETE: if (isWorkspaceOrFolderApplication(d.dragSource, item)) { LauncherModel.deleteItemFromDatabase(mLauncher, item); } else if (isWorkspaceFolder(d.dragSource, d.dragInfo)) { // Remove the folder from the workspace and delete the contents from launcher model FolderInfo folderInfo = (FolderInfo) item; mLauncher.removeFolder(folderInfo); LauncherModel.deleteFolderContentsFromDatabase(mLauncher, folderInfo); } else if (isWorkspaceWidget(d.dragSource, item)) { // Remove the widget from the workspace mLauncher.removeAppWidget((LauncherAppWidgetInfo) item); LauncherModel.deleteItemFromDatabase(mLauncher, item); final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item; final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost(); if (appWidgetHost != null) { // Deleting an app widget ID is a void call but writes to disk before returning // to the caller... new Thread("deleteAppWidgetId") { public void run() { appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId); } }.start(); } } break; case MODE_UNINSTALL: if (isAllAppsApplication(d.dragSource, item)) { // Uninstall the application mLauncher.startApplicationUninstallActivity((ApplicationInfo) item); } else if (isWorkspaceOrFolderApplication(d.dragSource, item)) { // Uninstall the shortcut mLauncher.startShortcutUninstallActivity((ShortcutInfo) item); } break; } }
public void onAdd(ShortcutInfo item) { mItemsInvalidated = true; // If the item was dropped onto this open folder, we have done the work associated // with adding the item to the folder, as indicated by mSuppressOnAdd being set if (mSuppressOnAdd) return; if (!findAndSetEmptyCells(item)) { // The current layout is full, can we expand it? setupContentForNumItems(getItemCount() + 1); findAndSetEmptyCells(item); } createAndAddShortcut(item); LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, item.cellX, item.cellY); }
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); } }
public void onDrop( DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo) { final ItemInfo item = (ItemInfo) dragInfo; if (item.container == -1) return; if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { if (item instanceof LauncherAppWidgetInfo) { mLauncher.removeAppWidget((LauncherAppWidgetInfo) item); } } else { if (source instanceof UserFolder) { final UserFolder userFolder = (UserFolder) source; final UserFolderInfo userFolderInfo = (UserFolderInfo) userFolder.getInfo(); // Item must be a ShortcutInfo otherwise it couldn't have been in the folder // in the first place. userFolderInfo.remove((ShortcutInfo) item); } } if (item instanceof UserFolderInfo) { final UserFolderInfo userFolderInfo = (UserFolderInfo) item; 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); } } LauncherModel.deleteItemFromDatabase(mLauncher, item); }
public void onAdd(ShortcutInfo item) { mItemsInvalidated = true; // If the item was dropped onto this open folder, we have done the work // associated // with adding the item to the folder, as indicated by mSuppressOnAdd // being set if (mSuppressOnAdd) return; // 如果当前item不在Layout中,添加进来,如果需要,扩张一下Folder if (!findAndSetEmptyCells(item)) { setupContentForNumItems(getItemCount() + 1); findAndSetEmptyCells(item); } createAndAddShortcut(item); LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, item.cellX, item.cellY); }
void bind(FolderInfo info) { mInfo = info; ArrayList<ShortcutInfo> children = info.contents; ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>(); setupContentForNumItems(children.size()); placeInReadingOrder(children); int count = 0; for (int i = 0; i < children.size(); i++) { ShortcutInfo child = (ShortcutInfo) children.get(i); if (createAndAddShortcut(child) == null) { overflow.add(child); } else { count++; } } // We rearrange the items in case there are any empty gaps setupContentForNumItems(count); // If our folder has too many items we prune them from the list. This is an issue // when upgrading from the old Folders implementation which could contain an unlimited // number of items. for (ShortcutInfo item : overflow) { mInfo.remove(item); LauncherModel.deleteItemFromDatabase(mLauncher, item); } mItemsInvalidated = true; updateTextViewFocus(); mInfo.addListener(this); if (!sDefaultFolderName.contentEquals(mInfo.title)) { mFolderName.setText(mInfo.title); } else { mFolderName.setText(""); } updateItemLocationsInDatabase(); // In case any children didn't come across during loading, clean up the folder accordingly mFolderIcon.post( new Runnable() { public void run() { if (getItemCount() <= 1) { replaceFolderWithFinalItem(); } } }); }
public IconCache(Context context, InvariantDeviceProfile inv) { mContext = context; mPackageManager = context.getPackageManager(); mUserManager = UserManagerCompat.getInstance(mContext); mLauncherApps = LauncherAppsCompat.getInstance(mContext); mIconDpi = inv.fillResIconDpi; mIconDb = new IconDB(context); mWorkerHandler = new Handler(LauncherModel.getWorkerLooper()); mActivityBgColor = context.getResources().getColor(R.color.quantum_panel_bg_color); mPackageBgColor = context.getResources().getColor(R.color.quantum_panel_bg_color_dark); mLowResOptions = new BitmapFactory.Options(); // Always prefer RGB_565 config for low res. If the bitmap has transparency, it will // automatically be loaded as ALPHA_8888. mLowResOptions.inPreferredConfig = Bitmap.Config.RGB_565; updateSystemStateString(); }
void bind(FolderInfo info) { mInfo = info; ArrayList<ShortcutInfo> children = info.contents; ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>(); // 超出数量的item setupContentForNumItems(children.size()); placeInReadingOrder(children); int count = 0; for (int i = 0; i < children.size(); i++) { ShortcutInfo child = (ShortcutInfo) children.get(i); if (!createAndAddShortcut(child)) { overflow.add(child); } else { count++; } } // 重新排序以防止有空的间隔。应该是防止万一数据有不对。 setupContentForNumItems(count); // If our folder has too many items we prune them from the list. This is // an issue // when upgrading from the old Folders implementation which could // contain an unlimited // number of items. // 如果文件夹里面有太多项目的话,我们把他们从list里面删掉。 // 因为从以前版本的数据库升级的时候有可能会出现许许多多的item(以前没有限制?) for (ShortcutInfo item : overflow) { mInfo.remove(item); LauncherModel.deleteItemFromDatabase(mLauncher, item); } mItemsInvalidated = true; updateTextViewFocus(); mInfo.addListener(this); if (!sDefaultFolderName.contentEquals(mInfo.title)) { mFolderName.setText(mInfo.title); } else { mFolderName.setText(""); } updateItemLocationsInDatabase(); // 更新数据库里面的位置,万一以前里面的有错误(也太小心了……) }
public void doneEditingFolderName(boolean commit) { mFolderName.setHint(sHintText); // Convert to a string here to ensure that no other state associated with the text field // gets saved. String newTitle = mFolderName.getText().toString(); mInfo.setTitle(newTitle); LauncherModel.updateItemInDatabase(mLauncher, mInfo); if (commit) { sendCustomAccessibilityEvent( AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, String.format(getContext().getString(R.string.folder_renamed), newTitle)); } // In order to clear the focus from the text field, we set the focus on ourself. This // ensures that every time the field is clicked, focus is gained, giving reliable behavior. requestFocus(); Selection.setSelection((Spannable) mFolderName.getText(), 0, 0); mIsEditingName = false; }
public void onDrop(DragObject d) { ShortcutInfo item; if (d.dragInfo instanceof ApplicationInfo) { // Came from all apps -- make a copy item = ((ApplicationInfo) d.dragInfo).makeShortcut(); } else if (d.dragInfo instanceof FolderInfo) { FolderInfo folder = (FolderInfo) d.dragInfo; mFolder.notifyDrop(); for (ShortcutInfo fItem : folder.contents) { onDrop(fItem, d.dragView, null, 1.0f, mInfo.contents.size(), d.postAnimationRunnable); } mLauncher.removeFolder(folder); LauncherModel.deleteItemFromDatabase(mLauncher, folder); return; } else { item = (ShortcutInfo) d.dragInfo; } mFolder.notifyDrop(); onDrop(item, d.dragView, null, 1.0f, mInfo.contents.size(), d.postAnimationRunnable); }
private void arrangeChildren(ArrayList<View> list) { int[] vacant = new int[2]; if (list == null) { list = getItemsInReadingOrder(); } mContent.removeAllViews(); for (int i = 0; i < list.size(); i++) { View v = list.get(i); mContent.getVacantCell(vacant, 1, 1); CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams(); lp.cellX = vacant[0]; lp.cellY = vacant[1]; ItemInfo info = (ItemInfo) v.getTag(); if (info.cellX != vacant[0] || info.cellY != vacant[1]) { info.cellX = vacant[0]; info.cellY = vacant[1]; LauncherModel.addOrMoveItemInDatabase(mLauncher, info, mInfo.id, 0, info.cellX, info.cellY); } boolean insert = false; mContent.addViewToCellLayout(v, insert ? 0 : -1, (int) info.id, lp, true); } mItemsInvalidated = true; }
void bind(FolderInfo info) { mInfo = info; ArrayList<ShortcutInfo> children = info.contents; ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>(); setupContentForNumItems(children.size()); int count = 0; for (int i = 0; i < children.size(); i++) { ShortcutInfo child = (ShortcutInfo) children.get(i); if (!createAndAddShortcut(child)) { overflow.add(child); } else { count++; } } // We rearrange the items in case there are any empty gaps setupContentForNumItems(count); // If our folder has too many items we prune them from the list. This is an issue // when upgrading from the old Folders implementation which could contain an unlimited // number of items. for (ShortcutInfo item : overflow) { mInfo.remove(item); LauncherModel.deleteItemFromDatabase(mLauncher, item); } mItemsInvalidated = true; updateStyledTextFooFocus(); mInfo.addListener(this); if (!sDefaultFolderName.contentEquals(mInfo.title)) { mFolderName.setText(mInfo.title); } else { mFolderName.setText(""); } }
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); }
@Override public void onChange(boolean selfChange) { mModel.startLoader(LauncherApplication.this, false); }
public void addItem(ShortcutInfo item) { mInfo.add(item); LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, item.cellX, item.cellY); }
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; }
LauncherModel setLauncher(Launcher launcher) { mModel.initialize(launcher); return mModel; }