1. 程式人生 > >預設鎖屏桌布及鎖屏桌布被拉伸顯示不全的問題

預設鎖屏桌布及鎖屏桌布被拉伸顯示不全的問題

RK 7.1,增加預設鎖屏桌布:

frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
 private static final boolean ENABLE_LOCKSCREEN_WALLPAPER = true;
要設定出廠預設鎖屏桌布,修改如下程式碼即可實現: 
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockscreenWallpaper.java

 public Bitmap getBitmap() {
        if (mCached) {
            return mCache;
        }
        if (!mWallpaperManager.isWallpaperSupported()) {
            mCached = true;
            mCache = null;
            return null;
        }

        LoaderResult result = loadBitmap(mCurrentUserId, mSelectedUser);
        if (result.success) {
            mCached = true;
            mUpdateMonitor.setHasLockscreenWallpaper(result.bitmap != null);
            mCache = result.bitmap;
        }

    //add begin : 第一次開機載入失敗,嘗試讀取系統資源default_lock_wallpaper.jpg,然後寫入到鎖屏桌布檔案中,並重新loadBitmap
        if (mCache == null) {
            try {
                mWallpaperManager.setStream(
                        mContext.getResources().openRawResource(com.android.internal.R.drawable.default_lock_wallpaper),
                        null,
                        true,
                        WallpaperManager.FLAG_LOCK);

                result = loadBitmap(mCurrentUserId, mSelectedUser);
                if (result.success) {
                    mCached = true;
                    mUpdateMonitor.setHasLockscreenWallpaper(result.bitmap != null);
                    mCache = result.bitmap;
                }
            } catch (IOException e) {
                Log.e(TAG, "can not set default lockscreen wallpaper");
            }
        }
    //add end
        return mCache;
    }



frameworks/base/core/res/res/values/config.xml
-    <item name="default_lock_wallpaper" type="drawable">@null</item>
+    <!--<item name="default_lock_wallpaper" type="drawable">@null</item>-->

然後放入系統資源圖片default_lock_wallpaper即可。

桌布顯示不全是因為dwidth 和dheight 的值不對,要改成螢幕尺寸解析度大小的

frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockscreenWallpaper.java
             protected void onBoundsChange(Rect bounds) {
                 int vwidth = getBounds().width();
                 int vheight = getBounds().height();
    -            int dwidth = mState.mBackground.getWidth();
    -            int dheight = mState.mBackground.getHeight();
    +            int dwidth = getBounds().width();
    +            int dheight = getBounds().height();