지난번의 소스를 잘 사용했었는데.
일부폰(엘지폰)에서는 홈화면에서 배경이미지가 좌우로 스크롤되는 현상이 있었다.
이건 그 버그를 수정한 버젼이다.
지난번 소스와 다 꼭같고, try 안에만 수정되었다.
h = new Handler()
{
public void handleMessage(Message msg)
{
progressDialog.dismiss();
Toast.makeText(skin_book_image_activity.this, "배경화면으로 설정하였습니다", Toast.LENGTH_SHORT).show();
}
};
Thread t = new Thread
(
new Runnable()
{
@Override public void run()
{
skin_book_image_activity.this.runOnUiThread
(
new Runnable()
{
@Override public void run()
{
progressDialog = ProgressDialog.show(skin_book_image_activity.this, "", "배경화면 설정중...", true);
progressDialog.show();
}
}
);
String s = aryImage.get(iCurrentImageIndex);
Point p = lib_image.getImageSizeFromFile(sImageDir + "/" + s.split(":")[1]);
try
{
WallpaperManager wpm = WallpaperManager.getInstance(getApplicationContext());
Bitmap b = BitmapFactory.decodeFile(sImageDir + "/" + s.split(":")[1]);
int letterboxedWidth = wpm.getDesiredMinimumWidth();
int letterboxedHeight = wpm.getDesiredMinimumHeight();
// 안드로이드는 바탕화면이 2종류가 있다(홈화면, 배경화면)
// 일부폰(LG) 에서는 홈화면의 넓이가 굉장히 넓고, 홈화면 이미지가 좌우로 스크롤된다.
// 홈화면 이미지의 스크롤을 방지하기 위해서 아래의 코드 추가함
if(letterboxedWidth > letterboxedHeight)
{
letterboxedWidth = lib_device.getDeviceWidth(getApplicationContext());
}
final float resizeRatio = (float) letterboxedHeight / p.y;
final int resizedWidth = (int) Math.ceil(p.x * resizeRatio);
final Bitmap letterboxedBitmap = Bitmap.createBitmap(letterboxedWidth, letterboxedHeight, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(letterboxedBitmap);
canvas.drawRGB(0, 0, 0);
final Matrix transformations = new Matrix();
transformations.postScale(resizeRatio, resizeRatio);
transformations.postTranslate(Math.round(((float) letterboxedWidth - resizedWidth)/2), 0);
canvas.drawBitmap(b, transformations, null);
wpm.setBitmap(letterboxedBitmap);
//Point p1 = new Point(wpm.getDesiredMinimumWidth(), wpm.getDesiredMinimumHeight());
//Point p2 = new Point(lib_device.getDeviceWidth(getApplicationContext()), lib_device.getDeviceHeight(getApplicationContext()));
//lib_common.Log("*** p1.x=["+p1.x+"] p1.y=["+p1.y+"]");
//lib_common.Log("*** p2.x=["+p2.x+"] p2.y=["+p2.y+"]");
}
catch(IOException exp)
{
lib_common.Log("*** SKIN_BOOK_IMAGE_ACTIVITY... "+exp.toString());
}
h.sendEmptyMessage(0);
}
}
);
t.start();
'Android 초보' 카테고리의 다른 글
android. 구글맵 (0) | 2015.08.11 |
---|---|
leftmargin 애니메이션 (0) | 2015.01.06 |
adb shell run-as (0) | 2014.12.12 |
안드로이드, 배경화면 이미지 (0) | 2014.07.14 |
안드로이드, runOnUiThread, 배경화면설정 (0) | 2014.07.04 |