1 调节bitmap大小以覆盖指定大小区域
static Bitmap generateBitmap(Context context, Bitmap bm, int width, int height) {
if (bm == null) {
return bm;
}
bm.setDensity(DisplayMetrics.DENSITY_DEVICE);
// This is the final bitmap we want to return.
// XXX We should get the pixel depth from the system (to match the
// physical display depth), when there is a way.
Bitmap newbm = Bitmap.createBitmap(width, height,
Bitmap.Config.RGB_565);
newbm.setDensity(DisplayMetrics.DENSITY_DEVICE);
Canvas c = new Canvas(newbm);
c.setDensity(DisplayMetrics.DENSITY_DEVICE);
Rect targetRect = new Rect();
targetRect.left = targetRect.top = 0;
targetRect.right = bm.getWidth();
targetRect.bottom = bm.getHeight();
int deltaw = width - targetRect.right;
int deltah = height - targetRect.bottom;
if (deltaw > 0 || deltah > 0) {
// We need to scale up so it covers the entire
// area.
float scale = 1.0f;
if (deltaw > deltah) {
scale = width / (float)targetRect.right;
} else {
scale = height / (float)targetRect.bottom;
}
targetRect.right = (int)(targetRect.right*scale);
targetRect.bottom = (int)(targetRect.bottom*scale);
deltaw = width - targetRect.right;
deltah = height - targetRect.bottom;
}
targetRect.offset(deltaw/2, deltah/2);
Paint paint = new Paint();
paint.setFilterBitmap(true);
paint.setDither(true);
c.drawBitmap(bm, null, targetRect, paint);
bm.recycle();
return newbm;
}
2 把wallpaper设置为大于屏幕宽度(如需要划屏)
private void setWallpaperDimension() {
WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
Display display = getWindowManager().getDefaultDisplay();
boolean isPortrait = display.getWidth() < display.getHeight();
final int width = isPortrait ? display.getWidth() : display.getHeight();
final int height = isPortrait ? display.getHeight() : display.getWidth();
wpm.suggestDesiredDimensions(width * WALLPAPER_SCREENS_SPAN, height);
}
3 屏蔽home键
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(KeyEvent.KEYCODE_HOME==keyCode)
Log.i("lds", "HOme") ;
return super.onKeyDown(keyCode, event);
}
@Override
public void onAttachedToWindow() {
// TODO Auto-generated method stub
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
添加权限:
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>