今天我们学习打卡的内容是:Android 10.0 Launcher3 禁止首屏时钟AppWidget拖动到其他屏这个知识。
当然此次学习的文章链接将会放置文章末尾,有需要的朋友自行查看。
那直接进入分享:
知识Android 10.0 Launcher3 禁止首屏时钟AppWidget拖动到其他屏:
在日常开发中,有时屏幕第一屏默认会放一个时钟AppWidget,但是这个时钟可以被任意拖动到其他屏,这样拖动到其他屏显得很不好看,所以我们根据需求改成不能拖动时钟去其他屏,这就需要去分析拖拽整个流程。
这也是禁止拖动的实现,相关实现还有播放在线音频时,需求是不能拖动进度条,让音频自然播放。以及英语听力考试时要求自然播放不得倒放等。
要了解Android的触摸机制。
直接监听SeekBar 的 OnTouchListener,就可以实现禁止拖动。
相关代码:
packages/apps/Launcher3/src/com/android/launcher3/Workspace.java @Override public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) { if (TestProtocol.sDebugTracing) { android.util.Log.d(TestProtocol.NO_DRAG_TAG, "onDragStart 1"); } if (ENFORCE_DRAG_EVENT_ORDER) { enforceDragParity("onDragStart", 0, 0); } if (mDragInfo != null && mDragInfo.cell != null && mDragInfo.cell.getParent() != null) { CellLayout layout = (CellLayout) mDragInfo.cell.getParent().getParent(); if (layout != null) layout.markCellsAsUnoccupiedForView(mDragInfo.cell); } if (mOutlineProvider != null) { if (dragObject.dragView != null) { Bitmap preview = dragObject.dragView.getPreviewBitmap(); // The outline is used to visualize where the item will land if dropped mOutlineProvider.generateDragOutline(preview); } } updateChildrenLayersEnabled(); // Do not add a new page if it is a accessible drag which was not started by the workspace. // We do not support accessibility drag from other sources and instead provide a direct // action for move/add to homescreen. // When a accessible drag is started by the folder, we only allow rearranging withing the // folder. boolean addNewPage = !(options.isAccessibleDrag && dragObject.dragSource != this); if (addNewPage) { mDeferRemoveExtraEmptyScreen = false; addExtraEmptyScreenOnDrag(); if (dragObject.dragInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET && dragObject.dragSource != this) { // When dragging a widget from different source, move to a page which has // enough space to place this widget (after rearranging/resizing). We special case // widgets as they cannot be placed inside a folder. // Start at the current page and search right (on LTR) until finding a page with // enough space. Since an empty screen is the furthest right, a page must be found. int currentPage = getPageNearestToCenterOfScreen(); for (int pageIndex = currentPage; pageIndex < getPageCount(); pageIndex++) { CellLayout page = (CellLayout) getPageAt(pageIndex); if (page.hasReorderSolution(dragObject.dragInfo)) { setCurrentPage(pageIndex); break; } } } } // Always enter the spring loaded mode if (TestProtocol.sDebugTracing) { android.util.Log.d(TestProtocol.NO_DRAG_TAG, "onDragStart 2"); } mLauncher.getStateManager().goToState(SPRING_LOADED); }
学习收获:
学习是人这一生永远离不开的主题,然而学什么、怎样学也始终在拷问着每一位在人生旅途中奋力前行的行进者,本次活动中让我对学习有了新的认识。珍惜CSDN的这个打卡活动,去努力的多学习相关自己感兴趣的知识,通过这个平台去不断的提升自己,这样才能在以后的工作中脱颖而出。,只要自己愿意努力,就一定会成功的。