默认锁屏壁纸及锁屏壁纸被拉伸显示不全的问题

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();

猜你喜欢

转载自blog.csdn.net/m1126125223/article/details/85093588