Launcher3桌面壁纸被拉伸模糊的修改

最近很忙,记录一下,Launcher3壁纸的修改。免得忘记。花了我近半天的时间。

环境:RK3288 + AndroidLL

步骤:进入Launcher3,长按桌面空白部分,设置一个内置的壁纸。

现象:发现模糊了,因为被拉伸了。



第一篇这样的文章。讲下解决思路。

思路:这种一看就比较简单的问题。从UI入手。(适合经验不足的人)。问题不在Launcher3上,就在WallpaperManagerService上。从Launcher3入手。。。。。。。
通过字符串就可以找到layout: actionbar_set_wallpaper。。。

见代码WallpaperCropActivity.java中。

<strong>protected void init() {
        。。。。。。

        // Action bar
        // Show the custom action bar view
        final ActionBar actionBar = getActionBar();
        actionBar.setCustomView(R.layout.actionbar_set_wallpaper);
        actionBar.getCustomView().setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        boolean finishActivityWhenDone = true;
                        cropImageAndSetWallpaper(imageUri, null, finishActivityWhenDone);
                    }
                });
        。。。。。。
}
</strong>


继续看cropImageAndSetWallpaper

<strong>protected void cropImageAndSetWallpaper(
            Resources res, int resId, final boolean finishActivityWhenDone) {
        // crop this image and scale it down to the default wallpaper size for
        // this device
        int rotation = getRotationFromExif(res, resId);
        Point inSize = mCropView.getSourceDimensions();
        Point outSize = getDefaultWallpaperSize(getResources(),
                getWindowManager());
        RectF crop = getMaxCropRect(
                inSize.x, inSize.y, outSize.x, outSize.y, false);
        Runnable onEndCrop = new Runnable() {
            public void run() {
                // Passing 0, 0 will cause launcher to revert to using the
                // default wallpaper size
                updateWallpaperDimensions(0, 0);
                if (finishActivityWhenDone) {
                    setResult(Activity.RESULT_OK);
                    finish();
                }
            }
        };
        BitmapCropTask cropTask = new BitmapCropTask(this, res, resId,
                crop, rotation, outSize.x, outSize.y, true, false, onEndCrop);
        cropTask.execute();
    }

</strong>

这里讲一下,BitmapCropTask是实际设置的地方。就不贴代码了。

这里的outSize才是被拉伸的关键点。这里肯定要查的。

后来发现打了log。发现确实尺寸跟实际的尺寸对不上号。


getDefaultWallpaperSize

看这段代码。

<strong>static protected Point getDefaultWallpaperSize(Resources res, WindowManager windowManager) {
        if (sDefaultWallpaperSize == null) {
            Point minDims = new Point();
            Point maxDims = new Point();
            windowManager.getDefaultDisplay().getCurrentSizeRange(minDims, maxDims);

            int maxDim = Math.max(maxDims.x, maxDims.y);
            int minDim = Math.max(minDims.x, minDims.y);

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
                Point realSize = new Point();
                windowManager.getDefaultDisplay().getRealSize(realSize);
                maxDim = Math.max(realSize.x, realSize.y);
                minDim = Math.min(realSize.x, realSize.y);
            }

            // We need to ensure that there is enough extra space in the wallpaper
            // for the intended parallax effects
            final int defaultWidth, defaultHeight;
            if (isScreenLarge(res)) {
                defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
                defaultHeight = maxDim;
            } else {
                defaultWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim);
                defaultHeight = maxDim;
            }
            sDefaultWallpaperSize = new Point(defaultWidth, defaultHeight);
        }
        return sDefaultWallpaperSize;
    }

</strong>

看一下这里,打个log,发现defaultHeightdefaultWidth这两个值不对。尺寸很大。那肯定是妥妥的被拉伸了。符合对现象的分析。


修改方法:搞个真实的尺寸就搞定了

<strong>            Point realSize = new Point();
            windowManager.getDefaultDisplay().getRealSize(realSize);
            final int defaultWidth, defaultHeight;
            if (/*isScreenLarge(res)*/false) {
                defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
                defaultHeight = maxDim;
            } else {
                //defaultWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim);
                //defaultHeight = maxDim;
                defaultWidth = realSize.x;
                defaultHeight = realSize.y;
            }
</strong>


修改完毕。就这样。壁纸不被拉伸的话。就不需要继续看WallpaperManagerService了


小结。以前觉得很简单的代码,找到改了之后还是会忘。算了。还是记下来靠谱。。。

方案公司出来的人,没什么产品,也没什么代码,但是阅读framework阅读application阅读外文文档 的能力 还是有的。

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值