Android4.4 應用分析——修改Launcher3應用以適應單屏壁紙

來源:互聯網
上載者:User

Android4.4 應用分析——修改Launcher3應用以適應單屏壁紙

Launcher3壁紙的規格預設是:壁紙高度=螢幕高度,壁紙寬頻=螢幕寬度*2倍

Android4.4的壁紙資訊存放在/data/system/users/0/目錄下,WallpaperManagerService啟動後,會產生如下兩個檔案在/data/system/users/0/目錄下:

 

    static final String WALLPAPER = wallpaper;   //設定的壁紙圖片,一般為jpeg格式    static final String WALLPAPER_INFO = wallpaper_info.xml;    //包含牆紙的規格資訊:高、寬

Wallpaper_info.xml的解析可以查看WallpaperManagerService的loadSettingsLocked()方法。下面是WallpaperManagerService的啟動時序圖,不解釋了,用的上朋友可以對著查看源碼:

 

下面我們就應該在Launcher3裡將壁紙的高、寬資訊寫入上面說的wallpaper_info.xml檔案中(當然時機寫入動作還是在Framework中),Launcher3隻是將其自身需要的牆紙高、寬寫入wallpaper_info.xml,你使用Go案頭,那肯定是在Go案頭設定高、寬了。

1. 找對位置後很簡單,就是Launcher3的WallpaperCropActivity.java檔案getDefaultWallpaperSize()。

 

    static protected Point getDefaultWallpaperSize(Resources res, WindowManager windowManager) {        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;        }        return new Point(defaultWidth, defaultHeight);    }

defaultWidth和defaultHeight分別賦值為螢幕的寬、高就行了。

 

 

2. cropImageAndSetWallpaper()方法,這個方法應該是設定牆紙時,按牆紙規格裁剪圖片用到的,該法與上面一樣。

 

3. 阻止Launcher3滑屏時,滑動牆紙:在Workspace.java中,注釋updateOffset()方法的調用(有兩處)。

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.