修改Launcher

来源:互联网 发布:高维空间 知乎 编辑:程序博客网 时间:2024/05/17 03:22

1.左滑切换到显示所有apps

PageView.java->onTouchEvent->case MotionEvent.ACTION_UP->if (mTouchState == TOUCH_STATE_SCROLLING)->else { snapToDestination();->后添加

if(((isSignificantMove && deltaX > 0 && !isFling) ||
                            (isFling && velocityX > 0)) && mCurrentPage == 0)
                    {
                        snapToLeftDestination();
                    }

并在Workspace.java中重写函数

    protected void snapToLeftDestination() {
        mLauncher.showAllApps(true);
    }


2.静态添加屏幕和屏幕上的快捷键

http://blog.csdn.net/the01hierarch/article/details/7641521

android1.6的版本有3个屏 需要把它改为5个屏 需要修改的地方 如下 

1、Launcher.java

Java代码  收藏代码
  1. static final int SCREEN_COUNT = 5;  
  2. static final int DEFAULT_SCREN = 2;  


2、launcher.xml

Java代码  收藏代码
  1. <com.lp.launcher.Workspace  
  2.         android:id="@+id/workspace"  
  3.         android:layout_width="fill_parent"  
  4.         android:layout_height="fill_parent"  
  5.   
  6.         launcher:defaultScreen="2">//从0开始  
  7.   
  8.         <include android:id="@+id/cell1" layout="@layout/workspace_screen" />  
  9.         <include android:id="@+id/cell2" layout="@layout/workspace_screen" />  
  10.         <include android:id="@+id/cell3" layout="@layout/workspace_screen" />  
  11.         <include android:id="@+id/cell4" layout="@layout/workspace_screen" />  
  12.         <include android:id="@+id/cell5" layout="@layout/workspace_screen" />  
  13.   
  14. </com.lp.launcher.Workspace>  


defaultScreen 修改为2 然后 加两个<include />

然后 修改默认显示的屏 

3、Workspace.java

修改构造方法里面的
Java代码  收藏代码
  1. mDefaultScreen = a.getInt(R.styleable.Workspace_defaultScreen, 2);//从0开始  


这时 基本上已经可以显示5个屏幕了 默认的屏也是第三个屏了 但是进去后 默认显示的屏什么也没有 我们需要把组建都挪到默认屏上去

4、default_workspace.xml

修改所有的 launcher:screen 为 2  

Java代码  收藏代码
  1. launcher:screen="2"  


3.桌面最下方显示3个指定快捷方式

方法一:在launcher.xml中删除    

<include
        android:id="@+id/hotseat"
        android:layout_width="match_parent"
        android:layout_height="@dimen/button_bar_height_plus_padding"
        android:layout_gravity="bottom"
        layout="@layout/hotseat"/>

并添加相应的按钮

方法二:修改default_workspace.xml

方法三:如果是定死热键,不可改变的话不推荐

重写LauncherModel->loadWorkspace中获得的数据方法,其中sWorkspaceItems.add(info);就是添加快捷方式(包括桌面widget和下面的热键)

在Hotseat->resetLayout->删除mContent.addViewToCellLayout(allAppsButton, -1, 0, new CellLayout.LayoutParams(x,y,1,1), true);




4.动态添加屏幕

在launcher.java中添加两个按键事件---------之后可以将这两个按钮作为appwidget加到默认的桌面上,和launcher交互用动态(内部注册)广播

    public void addScreen(View view)
    {
        LayoutInflater  mInflater = LayoutInflater.from(this);
        CellLayout mCelllayout =(CellLayout)mInflater.inflate(R.layout.workspace_screen,null);
        mWorkspace.addView(mCelllayout);
        mWorkspace.requestLayout();
    }

    
    public void removeScreen(View view)
    {
        int currentPage = mWorkspace.getCurrentPage();
        int countPage = mWorkspace.getChildCount();
        if(countPage > 1)
        {
            if(currentPage == (countPage - 1))
            {
                currentPage--;
            }
            mWorkspace.removeViewAt(countPage - 1);
        }
        mWorkspace.requestLayout();
        mWorkspace.snapToPage(currentPage);
    }