Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
Also re-arrange codes

Signed-off-by: Shaka Huang <shaka@cs03.org>
  • Loading branch information
shakalaca committed Dec 4, 2011
1 parent c302f49 commit c8bbb2f
Showing 1 changed file with 13 additions and 30 deletions.
Expand Up @@ -36,7 +36,6 @@ public class WidgetService extends Service implements SharedPreferences.OnShared
private int mScreenWidth = 0;

private SharedPreferences mPrefs;
private File PictureFile = null;

private boolean mRegScreenBR = false;
private boolean mRegTimeBR = false;
Expand Down Expand Up @@ -141,7 +140,7 @@ private void unregisterTimeBroadcastReceiver() {
}
}

private Bitmap updateBeautyBitmap() {
private String getPicturePath() {
mTime.setToNow();
int hour = mTime.hour;
int minute = mTime.minute;
Expand All @@ -151,7 +150,6 @@ private Bitmap updateBeautyBitmap() {
// check SD card first
String fname = String.format("%s/%02d%02d.jpg", storePath, hour, minute);
File _f_sdcard = new File(fname);
PictureFile = _f_sdcard;
if (!_f_sdcard.exists()) {
fname = String.format("%s/%02d%02d.jpg", getCacheDir().getAbsolutePath(), hour, minute);
File _f_cache = new File(fname);
Expand All @@ -164,53 +162,36 @@ private Bitmap updateBeautyBitmap() {

return null;
}
PictureFile = _f_cache;
}

Log.d(TAG, fname);
return BitmapFactory.decodeFile(fname);
return fname;
}

private Bitmap ResizeBitmap(Bitmap bitmap) {
if (bitmap == null) {
Log.d(TAG, "null !");
Log.d(TAG, "NULL Bitmap !");
return null;
}

int width = bitmap.getWidth();
int height = bitmap.getHeight();
if (width == 0 || height == 0) {
Log.d(TAG, "Bitmap format error !");
return null;
}

if (width < mScreenWidth && height < mScreenHeight) {
return null;
}

int maxWidth = mScreenWidth;
int maxHeight = mScreenHeight;
/*
if (height > maxHeight) {
double ratio = (double) maxHeight / height;
height = maxHeight;
width = (int) (width * ratio);
bScaled = true;
}
if (width > maxWidth) {
double ratio = (double) maxWidth / width;
width = maxWidth;
height = (int) (height * ratio);
bScaled = true;
}
*/
if (height > width) {
double ratio = (double) maxHeight / height;
height = maxHeight;
double ratio = (double) mScreenHeight / height;
height = mScreenHeight;
width = (int) (width * ratio);
} else {
double ratio = (double) maxWidth / width;
width = maxWidth;
double ratio = (double) mScreenWidth / width;
width = mScreenWidth;
height = (int) (height * ratio);
}

Expand All @@ -231,12 +212,14 @@ private void updateWidget(Context context) {

remoteViews.setTextViewText(R.id.TimeTextView, String.format(DISPLAYTIME_FORMAT, mTime.hour, mTime.minute));
remoteViews.setOnClickPendingIntent(R.id.BeautyClockImageView, pendingIntent);
remoteViews.setViewVisibility(R.id.ShareIt, View.GONE);

Bitmap bitmap = updateBeautyBitmap();
if (bitmap == null) {
String fname = getPicturePath();
if (fname == null) {
remoteViews.setImageViewResource(R.id.BeautyClockImageView, R.drawable.beautyclock_retry);
remoteViews.setViewVisibility(R.id.ShareIt, View.GONE);
} else {
File PictureFile = new File(fname);
Bitmap bitmap = BitmapFactory.decodeFile(fname);
Bitmap bitmap_scaled = ResizeBitmap(bitmap);
if (bitmap_scaled != null) {
remoteViews.setImageViewBitmap(R.id.BeautyClockImageView, bitmap_scaled);
Expand Down

0 comments on commit c8bbb2f

Please sign in to comment.