负一屏整体框架

目录

负一屏整体框架

负一屏创建时机

1、workspace页面顺序

2、负一屏的加入和view的填充


负一屏创建时机

负一屏的创建在Launcher.java的bindScreens中,该方法:

1、bindAddScreens传入一个界面列表,循环往workspace中添加需要的界面

2、判断是否需要添加左屏(也就是负一屏),如果需要则在workspace.java的createCustomContentContainer中完成该页面的添加。

populateCustomContentContainer中完成页面内容的填充。

    @Overridepublic void bindScreens(ArrayList<Long> orderedScreenIds) {bindAddScreens(orderedScreenIds);// If there are no screens, we need to have an empty screenif (orderedScreenIds.size() == 0) {mWorkspace.addExtraEmptyScreen();}// Create the custom content page (this call updates mDefaultScreen which calls// setCurrentPage() so ensure that all pages are added before calling this).if (needCustomContentToLeft()) {mWorkspace.createCustomContentContainer();populateCustomContentContainer();}}

1、workspace页面顺序

bindAddScreens中,循环添加页面

@Overridepublic void bindAddScreens(ArrayList<Long> orderedScreenIds) {int count = orderedScreenIds.size();for (int i = 0; i < count; i++) {mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));}}
public long insertNewWorkspaceScreenBeforeEmptyScreen(long screenId) {// Find the index to insert this view into.  If the empty screen exists, then// insert it before that.int insertIndex = mScreenOrder.indexOf(EXTRA_EMPTY_SCREEN_ID);if (insertIndex < 0) {insertIndex = mScreenOrder.size();}return insertNewWorkspaceScreen(screenId, insertIndex);}
public long insertNewWorkspaceScreen(long screenId, int insertIndex) {if (mWorkspaceScreens.containsKey(screenId)) {throw new RuntimeException("Screen id " + screenId + " already exists!");}// Inflate the cell layout, but do not add it automatically so that we can get the newly// created CellLayout.CellLayout newScreen = (CellLayout) mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, this, false /* attachToRoot */);//Added by ****** in 2017-6-26 for drag icon InOverviewMode(bug)if (isInOverviewMode() && !mLauncher.isEditing()) {newScreen.getPageSetting().setVisibility(VISIBLE);}//Added by ****** in 2017-6-26for drag icon InOverviewMode(bug)newScreen.setOnLongClickListener(mLongClickListener);newScreen.setOnClickListener(mLauncher);newScreen.setSoundEffectsEnabled(false);mWorkspaceScreens.put(screenId, newScreen);mScreenOrder.add(insertIndex, screenId);addView(newScreen, insertIndex);//添加view到指定的下标changePageSettingColor();LauncherAccessibilityDelegate delegate =LauncherAppState.getInstance().getAccessibilityDelegate();if (delegate != null && delegate.isInAccessibleDrag()) {newScreen.enableAccessibleDrag(true, CellLayout.WORKSPACE_ACCESSIBILITY_DRAG);}return screenId;}

这样就完成了workspace的页面添加。

2、负一屏的加入和view的填充

负一屏页面的添加:mWorkspace.createCustomContentContainer();

public void createCustomContentContainer() {CellLayout customScreen = (CellLayout)mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, this, false);customScreen.disableDragTarget();customScreen.disableJailContent();mWorkspaceScreens.put(CUSTOM_CONTENT_SCREEN_ID, customScreen);mScreenOrder.add(0, CUSTOM_CONTENT_SCREEN_ID);// We want no padding on the custom contentcustomScreen.setPadding(0, 0, 0, 0);//负一屏边距if (mLauncher!=null&&mLauncher.needCustomContentToLeft()){CustomPageManager.getInstance(mLauncher).setInsets(insetsRealSize);}addFullScreenPage(customScreen);//添加到workspace// Ensure that the current page and default page are maintained.// Added by huanghaihao in 2017-6-26 for screen setting startint pageIndex = getPageIndexForScreenId(mDefaultPageScreenId);if (-1 != pageIndex) {mDefaultPage = pageIndex;} else {mDefaultPage = mOriginalDefaultPage + 1;}// Added by huanghaihao in 2017-6-26 for screen setting end// Update the custom content hintif (mRestorePage != INVALID_RESTORE_PAGE) {mRestorePage = mRestorePage + 1;} else {setCurrentPage(getCurrentPage() + 1);}}

以上可以看出,addFullScreenPage方法决定了添加动作。方法体内部,固定的把负一屏添加到了首位:

public void addFullScreenPage(View page) {LayoutParams lp = generateDefaultLayoutParams();lp.isFullScreenPage = true;super.addView(page, 0, lp);//添加view到指定的下标}

负一屏view的填充:populateCustomContentContainer();

protected void populateCustomContentContainer() {//if (mLauncherCallbacks != null) {//    mLauncherCallbacks.populateCustomContentContainer();//}//负一屏viewView customView = CustomPageManager.getInstance(null).getCustomPageView();Log.i(TAG, "populateCustomContentContainer customView="+customView);addToCustomContentPage(customView,null,"");}

以上,添加view到负一屏的页面,可以看出,view的实现根据产品的界面。最简单的 new情况,一个textview也能看到效果。负一屏的本质其实就是一个view。

public void addToCustomContentPage(View customContent, Launcher.CustomContentCallbacks callbacks,String description) {if (getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID) < 0) {throw new RuntimeException("Expected custom content screen to exist");}// Add the custom content to the full screen custom pageCellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID);int spanX = customScreen.getCountX();int spanY = customScreen.getCountY();CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, spanX, spanY);lp.canReorder = false;lp.isFullscreen = true;if (customContent instanceof Insettable) {((Insettable) customContent).setInsets(mInsets,insetsRealSize);}// Verify that the child is removed from any existing parent.if (customContent.getParent() instanceof ViewGroup) {ViewGroup parent = (ViewGroup) customContent.getParent();parent.removeView(customContent);}customScreen.removeAllViews();customContent.setFocusable(true);customContent.setOnKeyListener(new FullscreenKeyEventListener());//delete by linhai remove focusChange start 31/8/2017
//        customContent.setOnFocusChangeListener(mLauncher.mFocusHandler
//                .getHideIndicatorOnFocusListener());//delete by linhai remove focusChange start 31/8/2017customScreen.addViewToCellLayout(customContent, 0, 0, lp, true);mCustomContentDescription = description;mCustomContentCallbacks = callbacks;if (mLauncher != null && mLauncher.needCustomContentToLeft()){CustomPageManager.getInstance(mLauncher).addCustomPageComplete();}}

至于一层一层add,workspace中add Celllayout,Celllayout中add ShortcutAndWidgetContainer,ShortcutAndWidgetContainer最后addCustompageView。

都是Launcher结构的套路。其本质就是viewGroup的addView,因为workspace、Celllayout、ShortcutAndWidgetContainer都是viewGroup的子类。

Launcher负一屏---创建和添加流程相关推荐

  1. Launcher负一屏(二)----引入其它资源替换Google原生负一屏界面

    负一屏有两种实现方式 1.Launcher自行开发,往Workspace中插入一个自定义的CellLayout来作为负一屏的容器. 具体请参考之前的文章:https://blog.csdn.net/a ...

  2. Launcher桌面负一屏实现 第一章

    Android Launcher负一屏实现 负一屏的实现主流有两种方式 Launcher自行开发,往Workspace中插入一个自定义的CellLayout来作为负一屏的容器. 这种方式是最常用的方案 ...

  3. Android桌面负一屏实现.md

    Android桌面负一屏实现 负一屏的实现主流有两种方式 Launcher自行开发,往Workspace中插入一个自定义的CellLayout来作为负一屏的容器. 这种方式是最常用的方案. 利用Goo ...

  4. Activity启动窗口(StartingWindow)的添加流程

    本篇基于Android Q分析 在Activity启动的时候,Android系统会为它添加一个启动窗口,作用是在应用程序主Activity还没有显示出来的时候,它作为一个预览窗口先让用户能看到一个画面 ...

  5. 3个超实用功能,华为手机负一屏应该这么用

    现在越来越多人使用华为手机,但是你知道华为手机的负一屏吗?华为手机负一屏有哪些功能?华为手机的负一屏有以下3个超实用的功能,以后打开手机,你就可以快速找到自己想查看的东西了! 你可能会问华为手机的负一 ...

  6. android负一屏类似苹果,Find X3、苹果12负一屏体验对比,谁才是真正的效率神器?...

    如今不论是iOS还是安卓系统手机,绝大部分手机都设计了负一屏功能,目的就是为了把最直接的路径和最快捷的方式带给用户.而各大手机厂商也都从不同的角度出发,设计出了各具特色的负一屏界面,但是哪个牌子的手机 ...

  7. 【学以致用】android功能实现9---Launcher之AS中,在Launcher源码中增加google负一屏的实现方法

    负一屏是相对于正常屏幕而言,正常屏幕是指桌面上用户用于摆放图标(也可以编辑图标位置)的屏幕,根据用户喜欢可以有一个或多个屏幕.在一些手机当中,包括苹果和安卓,在正常屏幕的最左边一屏,我们再往左滑,会出 ...

  8. Launcher 谷歌负一屏集成(基于Android 9.0)

    谷歌负一屏集成(基于Android 9.0) 步骤一:Launcher3中导入并编译launcher_client.jar(此jar包存在与谷歌的serarchLauncher中) 在Android. ...

  9. android 9.0 10.0 Launcher3添加负一屏(左一屏)功能

    1.概述 在10.0的系统产品开发中,要实现负一屏功能,而在8.1以前的版本中,都带有负一屏功能,但是在9.0以后就被取消掉了,由于客户需要只能参考8.1来实现负一屏功能了 效果图: 2.Launch ...

最新文章

  1. 单链表中一个插入操作的分析
  2. Linux文本三剑客之sed
  3. CCF关于暂停NOIP竞赛的公告
  4. jquery对json的各种遍历
  5. 清华计算机接口原理,微机原理与接口技术课后习题答案清华大学
  6. hertz接触理论_角接触轴承的组配和预紧技术及影响
  7. python非法的_在下列Python语句中非法的是________。
  8. WPF中两个窗口的互斥
  9. jquery+ajax验证不通过也提交表单问题处理
  10. java工厂模式和抽象工厂_Java中的抽象工厂设计模式
  11. tensorflow 中的 array_ops
  12. POJ 3862 POJ 3528 HDU 3662 HDU 4273 三维凸包问题解决模板
  13. 关于DCMM评估模型的全面解析
  14. 水晶苍蝇拍-微薄投资感悟
  15. Python脚本操作Excel实现批量替换
  16. CRM系统的价值效益
  17. golang的乐观锁与悲观锁
  18. 华为OD机试题 - 找出重复代码(JavaScript)| 包含代码编写思路
  19. Browser Security Plus 企业网络过滤工具
  20. 中国蚁剑安装使用教程

热门文章

  1. jaff decyptor system新型勒索病毒
  2. STM32F429/STM32F439最小系统微控制器介绍
  3. 打工是不可能打工的,2021电商新机遇,抖音小店无货源店群
  4. EMC VNX 图形管理界面Unisphere Java环境配置
  5. 【推荐两款神器】不限速下载、追剧神器
  6. 硬贴“科技”标签,折射出家电企业从To C到To B的转型尴尬
  7. 别再光靠工资过日子,外国程序员教你如何通过副业赚钱
  8. 什么是标准输入、标准输出(stdin、stdout)?
  9. Spring事务管理四大特性
  10. sqlserver2012错误问题