toolbar fix

This commit is contained in:
nuclearfog 2023-04-03 19:52:12 +02:00
parent 51a20283eb
commit 9a7b95408d
No known key found for this signature in database
GPG Key ID: 03488A185C476379
2 changed files with 28 additions and 18 deletions

View File

@ -289,24 +289,36 @@ public class AppStyles {
* @param toolbarBackground background image of the toolbar
*/
public static void setToolbarBackground(Activity activity, ImageView background, ImageView toolbarBackground) {
Point displaySize = new Point();
activity.getWindowManager().getDefaultDisplay().getSize(displaySize);
Drawable backgroundDrawable = background.getDrawable();
if (backgroundDrawable instanceof BitmapDrawable) {
Bitmap image = ((BitmapDrawable) backgroundDrawable).getBitmap().copy(ARGB_8888, true);
if (image.getWidth() > 1 && image.getHeight() > 1) {
if (background.getMeasuredHeight() > 0 && background.getMeasuredWidth() > 0) {
int height = image.getWidth() * background.getMeasuredHeight() / background.getMeasuredWidth();
CropTransformation crop = new CropTransformation(image.getWidth(), height, CropTransformation.GravityHorizontal.CENTER, CropTransformation.GravityVertical.CENTER);
image = crop.transform(image);
try {
Bitmap image = ((BitmapDrawable) backgroundDrawable).getBitmap().copy(ARGB_8888, true);
// check if image is valid
if (image.getWidth() > 1 && image.getHeight() > 1) {
// crop image to background size
if (background.getMeasuredHeight() > 0 && background.getMeasuredWidth() > 0) {
int height = image.getWidth() * background.getMeasuredHeight() / background.getMeasuredWidth();
// crop only if needed
if (height != image.getHeight()) {
CropTransformation crop = new CropTransformation(image.getWidth(), height, CropTransformation.GravityHorizontal.CENTER, CropTransformation.GravityVertical.CENTER);
image = crop.transform(image);
}
}
Point displaySize = new Point();
activity.getWindowManager().getDefaultDisplay().getSize(displaySize);
int blurRadius = Math.max(Math.round(displaySize.x * 10.0f / image.getWidth()), 10);
float toolbarRatio = activity.getResources().getDimension(R.dimen.profile_toolbar_height) / displaySize.x;
// do final transformations (crop first image to toolbar background size, then blur)
BlurTransformation blur = new BlurTransformation(activity.getApplicationContext(), blurRadius);
CropTransformation crop = new CropTransformation(image.getWidth(), (int) (image.getWidth() * toolbarRatio), CropTransformation.GravityHorizontal.CENTER, CropTransformation.GravityVertical.TOP);
image = blur.transform(crop.transform(image));
toolbarBackground.setImageBitmap(image);
}
float toolbarRatio = activity.getResources().getDimension(R.dimen.profile_toolbar_height) / displaySize.x;
int blurRadius = Math.max(Math.round(displaySize.x * 10.0f / image.getWidth()), 10);
BlurTransformation blur = new BlurTransformation(activity.getApplicationContext(), blurRadius);
CropTransformation crop = new CropTransformation(image.getWidth(), (int) (image.getWidth() * toolbarRatio), CropTransformation.GravityHorizontal.CENTER, CropTransformation.GravityVertical.TOP);
image = blur.transform(crop.transform(image));
toolbarBackground.setImageBitmap(image);
} catch (Exception e) {
// exception may occur when there is not enough free memory
// reset toolbar background
e.printStackTrace();
toolbarBackground.setImageResource(0);
}
}
}

View File

@ -46,8 +46,6 @@ public class ImageViewer extends MediaActivity implements AsyncCallback<ImageRes
*/
private static final String CACHE_FOLDER = "imagecache";
private static final int TOOLBAR_COLOR_MASK = 0xcfa0a0a0;
private ZoomView zoomImage;
private ProgressBar loadingCircle;
@ -71,7 +69,7 @@ public class ImageViewer extends MediaActivity implements AsyncCallback<ImageRes
settings = GlobalSettings.getInstance(this);
AppStyles.setProgressColor(loadingCircle, settings.getHighlightColor());
toolbar.setTitle("");
toolbar.setBackgroundColor(settings.getBackgroundColor() & TOOLBAR_COLOR_MASK);
toolbar.setBackgroundColor(settings.getBackgroundColor());
setSupportActionBar(toolbar);
cacheFolder = new File(getExternalCacheDir(), ImageViewer.CACHE_FOLDER);