Skip to content

Commit 3fca9af

Browse files
eldainosorPMS22
authored andcommitted
base: Let's shrink file headers bigger than the device size
Custom headers and new cameras with bigger resolution sizes aren't a good match. This might put a stop to those who put a 4K image as their header and complains about SysUI struggling :) Change-Id: I4a9ade0008f532d84160f44c57efdaa3e1fdeb30 Signed-off-by: NurKeinNeid <mralexman3000@gmail.com>
1 parent 867bdb2 commit 3fca9af

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

core/java/com/android/internal/util/fh/ImageHelper.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@
5555
import android.renderscript.Allocation;
5656
import android.renderscript.ScriptIntrinsicBlur;
5757
import android.renderscript.RenderScript;
58+
import android.util.DisplayMetrics;
5859
import android.util.AttributeSet;
5960
import android.util.Log;
6061
import android.util.TypedValue;
6162
import android.util.Xml;
63+
import android.view.WindowManager;
6264

6365
public class ImageHelper {
6466
private static final int VECTOR_WIDTH = 512;
@@ -174,6 +176,42 @@ public static Drawable resize(Context context, Drawable image, int size) {
174176
}
175177
}
176178

179+
public static Bitmap resizeMaxDeviceSize(Context context, Drawable image) {
180+
Bitmap i2b = ((BitmapDrawable) image).getBitmap();
181+
return resizeMaxDeviceSize(context, i2b);
182+
}
183+
184+
public static Bitmap resizeMaxDeviceSize(Context context, Bitmap image) {
185+
Bitmap imageToBitmap;
186+
DisplayMetrics metrics = new DisplayMetrics();
187+
WindowManager wm = context.getSystemService(WindowManager.class);
188+
wm.getDefaultDisplay().getRealMetrics(metrics);
189+
int maxHeight = metrics.heightPixels;
190+
int maxWidth = metrics.widthPixels;
191+
try {
192+
imageToBitmap = RGB565toARGB888(image);
193+
if (maxHeight > 0 && maxWidth > 0) {
194+
int width = imageToBitmap.getWidth();
195+
int height = imageToBitmap.getHeight();
196+
float ratioBitmap = (float) width / (float) height;
197+
float ratioMax = (float) maxWidth / (float) maxHeight;
198+
199+
int finalWidth = maxWidth;
200+
int finalHeight = maxHeight;
201+
if (ratioMax > ratioBitmap) {
202+
finalWidth = (int) ((float)maxHeight * ratioBitmap);
203+
} else {
204+
finalHeight = (int) ((float)maxWidth / ratioBitmap);
205+
}
206+
imageToBitmap = Bitmap.createScaledBitmap(imageToBitmap, finalWidth, finalHeight, true);
207+
return imageToBitmap;
208+
}
209+
} catch (Exception e) {
210+
e.printStackTrace();
211+
}
212+
return image;
213+
}
214+
177215
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
178216
if (bitmap == null) {
179217
return null;

packages/SystemUI/src/com/android/systemui/fh/header/FileHeaderProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.io.InputStream;
3838
import java.util.Calendar;
3939

40+
import com.android.internal.util.fh.ImageHelper;
4041
import com.android.systemui.R;
4142

4243
public class FileHeaderProvider implements
@@ -115,7 +116,7 @@ private void loadHeaderImage() {
115116
if (file.exists()) {
116117
if (DEBUG) Log.i(TAG, "Load header image");
117118
final Bitmap image = BitmapFactory.decodeFile(file.getAbsolutePath());
118-
mImage = new BitmapDrawable(mContext.getResources(), image);
119+
mImage = new BitmapDrawable(mContext.getResources(), ImageHelper.resizeMaxDeviceSize(mContext, image));
119120
}
120121
}
121122

0 commit comments

Comments
 (0)