一.开机时出现问题:很抱歉,”启动器“已停止运行,源码级调试如下:
日志中Java调用栈如下:
8044 03-27 15:37:40.747 3023 3039 E AndroidRuntime: FATAL EXCEPTION: setWallpaperDimension
8045 03-27 15:37:40.747 3023 3039 E AndroidRuntime: Process: com.android.launcher, PID: 3023
8046 03-27 15:37:40.747 3023 3039 E AndroidRuntime: java.lang.IllegalArgumentException: width and height must be > 0
8047 03-27 15:37:40.747 3023 3039 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1544)
8048 03-27 15:37:40.747 3023 3039 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1493)
8049 03-27 15:37:40.747 3023 3039 E AndroidRuntime: at android.app.IWallpaperManager$Stub$Proxy.setDimensionHints(IWallpaperManager.java :361)
8050 03-27 15:37:40.747 3023 3039 E AndroidRuntime: at android.app.WallpaperManager.suggestDesiredDimensions(WallpaperManager.java:947)
8051 03-27 15:37:40.747 3023 3039 E AndroidRuntime: at com.android.launcher2.Workspace$2.run(Workspace.java:864)
在源码中添加打印信息,修改如下:
private float wallpaperTravelToScreenWidthRatio(int width, int height) {
// float aspectRatio = width / (float) height;
float h = (float) height;
float aspectRatio = width / h;
Log.d(TAG, "float height:" + h + " aspectRatio:" + aspectRatio);
final float ASPECT_RATIO_LANDSCAPE = 16/10f;
final float ASPECT_RATIO_PORTRAIT = 10/16f;
Log.d(TAG, "SCAPE:" + ASPECT_RATIO_LANDSCAPE + " TRAIT:" + ASPECT_RATIO_PORTRAIT );
final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
// final float x =
// (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
// (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
// final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
// Log.d(TAG, "x:" + x + " y:" + y + " aspectRatio:" + aspectRatio);
// return x * aspectRatio + y;
float lp = WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT;
float st = ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT;
final float x = lp / st;
Log.d(TAG, "LANDSCAPE - PORTRAIT:" + lp + " SCAPE - TRAIT:" + st + " x:" + x);
float t = x * ASPECT_RATIO_PORTRAIT;
final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - t;
float xt = x * aspectRatio;
Log.d(TAG, "t:" + t + " y
日志中Java调用栈如下:
8044 03-27 15:37:40.747 3023 3039 E AndroidRuntime: FATAL EXCEPTION: setWallpaperDimension
8045 03-27 15:37:40.747 3023 3039 E AndroidRuntime: Process: com.android.launcher, PID: 3023
8046 03-27 15:37:40.747 3023 3039 E AndroidRuntime: java.lang.IllegalArgumentException: width and height must be > 0
8047 03-27 15:37:40.747 3023 3039 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1544)
8048 03-27 15:37:40.747 3023 3039 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1493)
8049 03-27 15:37:40.747 3023 3039 E AndroidRuntime: at android.app.IWallpaperManager$Stub$Proxy.setDimensionHints(IWallpaperManager.java :361)
8050 03-27 15:37:40.747 3023 3039 E AndroidRuntime: at android.app.WallpaperManager.suggestDesiredDimensions(WallpaperManager.java:947)
8051 03-27 15:37:40.747 3023 3039 E AndroidRuntime: at com.android.launcher2.Workspace$2.run(Workspace.java:864)
在源码中添加打印信息,修改如下:
private float wallpaperTravelToScreenWidthRatio(int width, int height) {
// float aspectRatio = width / (float) height;
float h = (float) height;
float aspectRatio = width / h;
Log.d(TAG, "float height:" + h + " aspectRatio:" + aspectRatio);
final float ASPECT_RATIO_LANDSCAPE = 16/10f;
final float ASPECT_RATIO_PORTRAIT = 10/16f;
Log.d(TAG, "SCAPE:" + ASPECT_RATIO_LANDSCAPE + " TRAIT:" + ASPECT_RATIO_PORTRAIT );
final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
// final float x =
// (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
// (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
// final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
// Log.d(TAG, "x:" + x + " y:" + y + " aspectRatio:" + aspectRatio);
// return x * aspectRatio + y;
float lp = WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT;
float st = ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT;
final float x = lp / st;
Log.d(TAG, "LANDSCAPE - PORTRAIT:" + lp + " SCAPE - TRAIT:" + st + " x:" + x);
float t = x * ASPECT_RATIO_PORTRAIT;
final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - t;
float xt = x * aspectRatio;
Log.d(TAG, "t:" + t + " y