• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

コミットメタ情報

リビジョン96c04f1974b69c3ad5621efcb113a3d56fa566d5 (tree)
日時2017-12-29 03:28:08
作者HMML <hmml3939@gmai...>
コミッターHMML

ログメッセージ

Dynamic resize of weather icon for small screen device to avoid memory limit error.

変更サマリ

差分

--- a/app/src/main/java/cloud/hmml/mmw/WeatherDispWidget.java
+++ b/app/src/main/java/cloud/hmml/mmw/WeatherDispWidget.java
@@ -5,8 +5,11 @@ import android.appwidget.AppWidgetManager;
55 import android.appwidget.AppWidgetProvider;
66 import android.content.Context;
77 import android.content.Intent;
8+import android.graphics.Bitmap;
9+import android.util.DisplayMetrics;
810 import android.util.Log;
911 import android.view.View;
12+import android.view.WindowManager;
1013 import android.widget.RemoteViews;
1114
1215 /**
@@ -38,6 +41,11 @@ public class WeatherDispWidget extends AppWidgetProvider {
3841 if (is_unit_f)
3942 temp_unit = "℉";
4043
44+
45+ DisplayMetrics metrics = new DisplayMetrics();
46+ ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics);
47+ Log.d("widget", "Current screen width: " + metrics.widthPixels);
48+
4149 if (theme.day_frame != null && theme.day_frame.equals("builtin/white")) {
4250 views.setImageViewResource(R.id.weather_background_today, R.drawable.day_frame_white);
4351 views.setImageViewResource(R.id.weather_background_tomorrow, R.drawable.day_frame_white);
@@ -50,7 +58,14 @@ public class WeatherDispWidget extends AppWidgetProvider {
5058 views.setTextViewText(tid, temp_unit);
5159
5260 if (conf.loadWeatherIdent(1) != null) {
53- views.setImageViewBitmap(R.id.weather_image_today, theme.getIconBitmap(conf.loadWeatherIdent(1)));
61+ Bitmap icon = theme.getIconBitmap(conf.loadWeatherIdent(1));
62+ if (metrics.widthPixels < icon.getWidth()) {
63+ // resize if icon is bigger than twice to avoid memory limit exception...
64+ views.setImageViewBitmap(R.id.weather_image_today,
65+ Bitmap.createScaledBitmap(icon, metrics.widthPixels/2, metrics.widthPixels * icon.getHeight() / icon.getWidth() / 2, true));
66+ } else {
67+ views.setImageViewBitmap(R.id.weather_image_today, icon);
68+ }
5469 views.setTextViewText(R.id.weather_name_today, conf.loadWeatherLabel(1));
5570 views.setTextViewText(R.id.txt_temp_min_today, toTempString(conf.loadTempMin(1), is_unit_f));
5671 views.setTextViewText(R.id.txt_temp_max_today, toTempString(conf.loadTempMax(1), is_unit_f));
@@ -66,7 +81,13 @@ public class WeatherDispWidget extends AppWidgetProvider {
6681 }
6782
6883 if (conf.loadWeatherIdent(2) != null) {
69- views.setImageViewBitmap(R.id.weather_image_tomorrow, theme.getIconBitmap(conf.loadWeatherIdent(2)));
84+ Bitmap icon = theme.getIconBitmap(conf.loadWeatherIdent(2));
85+ if (metrics.widthPixels < icon.getWidth()) {
86+ views.setImageViewBitmap(R.id.weather_image_tomorrow,
87+ Bitmap.createScaledBitmap(icon, metrics.widthPixels/2, metrics.widthPixels * icon.getHeight() / icon.getWidth() / 2, true));
88+ } else {
89+ views.setImageViewBitmap(R.id.weather_image_tomorrow, icon);
90+ }
7091 views.setTextViewText(R.id.weather_name_tomorrow, conf.loadWeatherLabel(2));
7192 views.setTextViewText(R.id.txt_temp_min_tomorrow, toTempString(conf.loadTempMin(2), is_unit_f));
7293 views.setTextViewText(R.id.txt_temp_max_tomorrow, toTempString(conf.loadTempMax(2), is_unit_f));