Launcher3源码分析(Workspace)

Workspace主要功能:完成多个屏幕的以及壁纸的显示,多个屏幕之间的切换和壁纸的添加。

    /**
     * Used to inflate the Workspace from XML.
     */
    public Workspace(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        //获取绘制轮廓的辅助类对象
        mOutlineHelper = HolographicOutlineHelper.obtain(context);

        mLauncher = (Launcher) context;
        mStateTransitionAnimation = new WorkspaceStateTransitionAnimation(mLauncher, this);
        final Resources res = getResources();
        DeviceProfile grid = mLauncher.getDeviceProfile();
        mWorkspaceFadeInAdjacentScreens = grid.shouldFadeAdjacentWorkspaceScreens();
        mFadeInAdjacentScreens = false;
        //获取Wallpaper管理器
        mWallpaperManager = WallpaperManager.getInstance(context);
        //获取自定义属性
        TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.Workspace, defStyle, 0);
        //在allapp 应用程序菜单里拖动app时workspace的缩放比例
        mSpringLoadedShrinkFactor =
            res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
        //长按桌面进入预览模式时的缩放比例
        mOverviewModeShrinkFactor = grid.getOverviewModeScale(mIsRtl);
        //开机时的屏幕
        mOriginalDefaultPage = mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1);
        a.recycle();
        //监听view层次的变化
        setOnHierarchyChangeListener(this);
        //打开触摸反馈
        setHapticFeedbackEnabled(false);
        //初始化workspace
        initWorkspace();

        // Disable multitouch across the workspace/all apps/customize tray
        setMotionEventSplittingEnabled(true);
    }

初始化workspace

/**
     * Initializes various states for this workspace.
     */
    protected void initWorkspace() {
        //默认页
        mCurrentPage = mDefaultPage;
        LauncherAppState app = LauncherAppState.getInstance();
        DeviceProfile grid = mLauncher.getDeviceProfile();
        //保存应用图片的缓存
        mIconCache = app.getIconCache();
        setWillNotDraw(false);
        setClipChildren(false);
        setClipToPadding(false);
        //设置子view绘图缓存开始
        setChildrenDrawnWithCacheEnabled(true);

        setMinScale(mOverviewModeShrinkFactor);
        setupLayoutTransition();
        //wallpaper偏移
        mWallpaperOffset = new WallpaperOffsetInterpolator();
        //获取屏幕大小
        Display display = mLauncher.getWindowManager().getDefaultDisplay();
        display.getSize(mDisplaySize);

        mMaxDistanceForFolderCreation = (0.55f * grid.iconSizePx);

        // Set the wallpaper dimensions when Launcher starts up
        setWallpaperDimension();

        setEdgeGlowColor(getResources().getColor(R.color.workspace_edge_effect_color));
    }

workspace实现了DragSource和Dragtarget,说明它即是一个拖动的容器也是一个拖动的源,分析开始拖动方法:

public void startDrag(CellLayout.CellInfo cellInfo){
    startDrag(cellInfo,false);
}
public void startDrag(CellLayout.CellInfo cellInfo,boolean accessible){
    View child = cellInfo.cell;

        // Make sure the drag was started by a long press as opposed to a long click.
        if (!child.isInTouchMode()) {
            return;
        }

        mDragInfo = cellInfo;
        //原位置的item设置为不可见
        child.setVisibility(INVISIBLE);
        CellLayout layout = (CellLayout) child.getParent().getParent();
        layout.prepareChildForDrag(child);

        beginDragShared(child, this, accessible);
}

public void beginDragShared(View child, DragSource source,boolean accessible){
    beginDragShared(child, new Point(), source, accessible);
}

public void beginDragShared(View child, Point relativeTouchPos,DragSource source, boolean accessible){
    child.clearFocus();
    child.setPressed(false);
    
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值