• 修改Launcher源码之快速启动


      最近在写一个快速拨号的App,应用很简单,主要要突出一个快速的特点,启动要快,最好能从Home Screen启动,当然第一个反应是在桌面上新建一个快捷方式,不过我决定用另一种特别的方式,即:当用户在Home Screen中上下触屏时,启动此应用,左右触屏是切换桌面的。废话不多说,看怎样实现:

      1、编译运行Launcher源码,具体可参照网上相关介绍,本来打算附上修改后的源码,不过文件太大,需要的话可以找我,建议参考网络资料自己动手编译。

      2、修改Launcher源码,只要改一处,修改Workspace类的onInterceptTouchEvent方法女装品牌排行榜

    Workspace相当于你看到的一个桌面,触屏事件在到达onTouchEvent之前会先执行onInterceptTouchEvent方法。

    如果你想通过在桌面空白处用触屏事件来启动你的应用的话,可以用此方法,不过用户不一定接受你的定制Launcher。

    public boolean onInterceptTouchEvent(MotionEvent ev) {

            /*****************省略相关代码***********/

            final float x = ev.getX();
            final float y = ev.getY();
            Log.d("Workspace", "enter onInterceptTouchEvent");
            switch (action) {
                case MotionEvent.ACTION_MOVE:
                    /*
                     * mIsBeingDragged == false, otherwise the shortcut would have caught it.
                     * Check
                     * whether the user has moved far enough from his original down touch.
                     */

                    /*
                     * Locally do absolute value. mLastMotionX is set to the y value
                     * of the down event.
                     */
                    final int xDiff = (int) Math.abs(x - mLastMotionX);
                    final int yDiff = (int) Math.abs(y - mLastMotionY);

                    final int touchSlop = mTouchSlop;
                    boolean xMoved = xDiff > touchSlop;
                    boolean yMoved = yDiff > touchSlop;
                   
                    if (xMoved || yMoved) {
                       
                        if (xMoved) {
                            // Scroll if the user moved far enough along the X axis
                            mTouchState = TOUCH_STATE_SCROLLING;
                            enableChildrenCache();
                        }
       /*********************************添加的代码****************************************/
                        if(yMoved) {            //纵向移动
                            Log.d("workspace", "在这启动你的应用程序!");
                           
                            Intent intent = new Intent();                   
                            //设置应用的包名,类名
                            intent.setClassName("com.tek.qd", "com.tek.qd.QuickDialer");
                            //启动应用
                            mContext.startActivity(intent);

                            mTouchState = TOUCH_STATE_SCROLLING;
                            enableChildrenCache();
                        }
      /*********************************代码结束****************************************/
                        // Either way, cancel any pending longpress
                        if (mAllowLongPress) {
                            mAllowLongPress = false;
                            // Try canceling the long press. It could also have been scheduled
                            // by a distant descendant, so use the mAllowLongPress flag to
                            //block
                            // everything
                            final View currentScreen = getChildAt(mCurrentScreen);
                            currentScreen.cancelLongPress();
                        }
                    }
                    break;

                case MotionEvent.ACTION_DOWN:
                    // Remember location of down touch
                    mLastMotionX = x;
                    mLastMotionY = y;
                    mAllowLongPress = true;
                   
                    /*
                     * If being flinged and user touches the screen, initiate drag;
                     * otherwise don't.  mScroller.isFinished should be false when
                     * being flinged.
                     */
                   
                    mTouchState = mScroller.isFinished() ?
                                   TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;
                    break;

                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_UP:

                    if (mTouchState != TOUCH_STATE_SCROLLING) {
                        final CellLayout currentScreen = (CellLayout) getChildAt(
                                                          mCurrentScreen);
                        if (!currentScreen.lastDownOnOccupiedCell()) {
                            getLocationOnScreen(mTempCell);
                            // Send a tap to the wallpaper if the last down was on
                            //empty space
                            mWallpaperManager.sendWallpaperCommand(getWindowToken(),
                                    "android.wallpaper.tap",
                                    mTempCell[0] + (int) ev.getX(),
                                    mTempCell[1] + (int) ev.getY(), 0, null);
                        }
                    }
                   
                    // Release the drag
                    clearChildrenCache();
                    mTouchState = TOUCH_STATE_REST;
                    mAllowLongPress = false;
                    break;
            }

            /*
             * The only time we want to intercept motion events is if we are in the
             * drag mode.
             */
            return mTouchState != TOUCH_STATE_REST;
        }风之境地 java-javascript 蘑菇街女装

  • 相关阅读:
    一致性哈希算法
    Discourse 的标签(Tag)只能是小写的原因
    JIRA 链接 bitbucket 提示错误 Invalid OAuth credentials
    JIRA 如何连接到云平台的 bitbucket
    Apache Druid 能够支持即席查询
    如何在 Discourse 中配置使用 GitHub 登录和创建用户
    Apache Druid 是什么
    Xshell 如何导入 PuTTYgen 生成的 key
    windows下配置Nginx支持php
    laravel连接数据库提示mysql_connect() :Connection refused...
  • 原文地址:https://www.cnblogs.com/sky7034/p/2015622.html
Copyright © 2020-2023  润新知