fixes #466. Setting the background image provides for a image that is sufficiently large to fit portrait and landscape orientations. When displayed the shorter side is scaled to fit, the larger is then centered and cropped.

This commit is contained in:
Angelo Fuchs 2020-05-20 12:35:04 +02:00 committed by B. Petersen
parent bfa08887e2
commit 16f5c6d889
No known key found for this signature in database
GPG key ID: 3B88E92DEA8E9AFC
3 changed files with 18 additions and 8 deletions

View file

@ -1,10 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent" android:layout_width="match_parent"> android:layout_height="match_parent" android:layout_width="match_parent">
<ImageView
android:id="@+id/conversation_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="ContentDescription"
android:scaleType="centerCrop" />
<org.thoughtcrime.securesms.components.InputAwareLayout <org.thoughtcrime.securesms.components.InputAwareLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_container" android:id="@+id/layout_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">

View file

@ -175,6 +175,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private InputAwareLayout container; private InputAwareLayout container;
private View composePanel; private View composePanel;
protected Stub<ReminderView> reminderView; protected Stub<ReminderView> reminderView;
private ImageView backgroundView;
private AttachmentTypeSelector attachmentTypeSelector; private AttachmentTypeSelector attachmentTypeSelector;
private AttachmentManager attachmentManager; private AttachmentManager attachmentManager;
@ -798,6 +799,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
quickAttachmentDrawer = ViewUtil.findById(this, R.id.quick_attachment_drawer); quickAttachmentDrawer = ViewUtil.findById(this, R.id.quick_attachment_drawer);
quickAttachmentToggle = ViewUtil.findById(this, R.id.quick_attachment_toggle); quickAttachmentToggle = ViewUtil.findById(this, R.id.quick_attachment_toggle);
inputPanel = ViewUtil.findById(this, R.id.bottom_panel); inputPanel = ViewUtil.findById(this, R.id.bottom_panel);
backgroundView = ViewUtil.findById(this, R.id.conversation_background);
ImageButton quickCameraToggle = ViewUtil.findById(this, R.id.quick_camera_toggle); ImageButton quickCameraToggle = ViewUtil.findById(this, R.id.quick_camera_toggle);
@ -842,13 +844,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
String backgroundImagePath = Prefs.getBackgroundImagePath(this); String backgroundImagePath = Prefs.getBackgroundImagePath(this);
if(!backgroundImagePath.isEmpty()) { if(!backgroundImagePath.isEmpty()) {
Drawable image = Drawable.createFromPath(backgroundImagePath); Drawable image = Drawable.createFromPath(backgroundImagePath);
getWindow().setBackgroundDrawable(image); backgroundView.setImageDrawable(image);
} }
else if(dynamicTheme.isDarkTheme(this)) { else if(dynamicTheme.isDarkTheme(this)) {
getWindow().setBackgroundDrawableResource(R.drawable.background_hd_dark); backgroundView.setImageResource(R.drawable.background_hd_dark);
} }
else { else {
getWindow().setBackgroundDrawableResource(R.drawable.background_hd); backgroundView.setImageResource(R.drawable.background_hd);
} }
} }

View file

@ -136,13 +136,15 @@ public class ChatBackgroundActivity extends PassphraseRequiredActionBarActivity
Display display = ServiceUtil.getWindowManager(context).getDefaultDisplay(); Display display = ServiceUtil.getWindowManager(context).getDefaultDisplay();
Point size = new Point(); Point size = new Point();
display.getSize(size); display.getSize(size);
// resize so that the larger side fits the screen accurately
int largerSide = (size.x > size.y ? size.x : size.y);
Bitmap scaledBitmap = GlideApp.with(context) Bitmap scaledBitmap = GlideApp.with(context)
.asBitmap() .asBitmap()
.load(imageUri) .load(imageUri)
.centerCrop() .fitCenter()
.skipMemoryCache(true) .skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE) .diskCacheStrategy(DiskCacheStrategy.NONE)
.submit(size.x, size.y) .submit(largerSide, largerSide)
.get(); .get();
FileOutputStream outStream = new FileOutputStream(destinationPath); FileOutputStream outStream = new FileOutputStream(destinationPath);
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 85, outStream); scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 85, outStream);