diff options
Diffstat (limited to 'src/main')
5 files changed, 66 insertions, 28 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index fb5df34d6..9f434a626 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -153,7 +153,7 @@ android:name="android.support.PARENT_ACTIVITY" android:value="eu.siacs.conversations.ui.SettingsActivity"/> </activity> - + <activity android:name="com.soundcloud.android.crop.CropImageActivity" /> <service android:name=".services.ExportLogsService"/> </application> diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 35b836a7a..febb09705 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -486,7 +486,7 @@ public class FileBackend { return calcSampleSize(options, size); } - private int calcSampleSize(File image, int size) { + private static int calcSampleSize(File image, int size) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(image.getAbsolutePath(), options); diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index abd42f4c4..b54e54826 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -234,8 +234,13 @@ public class NotificationService { if (messages.size() > 0) { conversation = messages.get(0).getConversation(); final String name = conversation.getName(); - style.addLine(Html.fromHtml("<b>" + name + "</b> " - + UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first)); + if (Config.PARANOID_MODE) { + int count = messages.size(); + style.addLine(Html.fromHtml("<b>"+name+"</b> "+mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages,count,count))); + } else { + style.addLine(Html.fromHtml("<b>" + name + "</b> " + + UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first)); + } names.append(name); names.append(", "); } @@ -264,25 +269,30 @@ public class NotificationService { mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService() .get(conversation, getPixel(64))); mBuilder.setContentTitle(conversation.getName()); - Message message; - if ((message = getImage(messages)) != null) { - modifyForImage(mBuilder, message, messages, notify); + if (Config.PARANOID_MODE) { + int count = messages.size(); + mBuilder.setContentText(mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages,count,count)); } else { - modifyForTextOnly(mBuilder, messages, notify); - } - if ((message = getFirstDownloadableMessage(messages)) != null) { - mBuilder.addAction( - Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? - R.drawable.ic_file_download_white_24dp : R.drawable.ic_action_download, - mXmppConnectionService.getResources().getString(R.string.download_x_file, - UIHelper.getFileDescriptionString(mXmppConnectionService, message)), - createDownloadIntent(message) - ); - } - if ((message = getFirstLocationMessage(messages)) != null) { - mBuilder.addAction(R.drawable.ic_room_white_24dp, - mXmppConnectionService.getString(R.string.show_location), - createShowLocationIntent(message)); + Message message; + if ((message = getImage(messages)) != null) { + modifyForImage(mBuilder, message, messages, notify); + } else { + modifyForTextOnly(mBuilder, messages, notify); + } + if ((message = getFirstDownloadableMessage(messages)) != null) { + mBuilder.addAction( + Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? + R.drawable.ic_file_download_white_24dp : R.drawable.ic_action_download, + mXmppConnectionService.getResources().getString(R.string.download_x_file, + UIHelper.getFileDescriptionString(mXmppConnectionService, message)), + createDownloadIntent(message) + ); + } + if ((message = getFirstLocationMessage(messages)) != null) { + mBuilder.addAction(R.drawable.ic_room_white_24dp, + mXmppConnectionService.getString(R.string.show_location), + createShowLocationIntent(message)); + } } mBuilder.setContentIntent(createContentIntent(conversation)); } diff --git a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java index e01490f90..542c27432 100644 --- a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java @@ -3,6 +3,7 @@ package eu.siacs.conversations.ui; import android.app.PendingIntent; import android.content.Intent; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.view.View; @@ -13,9 +14,15 @@ import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; +import com.soundcloud.android.crop.Crop; + +import java.io.File; +import java.io.FileNotFoundException; + import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.utils.PhoneHelper; import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; @@ -32,6 +39,7 @@ public class PublishProfilePictureActivity extends XmppActivity { private Button cancelButton; private Button publishButton; + final static int REQUEST_CROP_PICTURE = 92374; private Uri avatarUri; private Uri defaultUri; private OnLongClickListener backToDefaultListener = new OnLongClickListener() { @@ -147,11 +155,14 @@ public class PublishProfilePictureActivity extends XmppActivity { if (resultCode == RESULT_OK) { if (requestCode == REQUEST_CHOOSE_FILE) { this.avatarUri = data.getData(); - if (xmppConnectionServiceBound) { - loadImageIntoPreview(this.avatarUri); - } + Uri destination = Uri.fromFile(new File(getCacheDir(), "croppedAvatar")); + Crop.of(this.avatarUri, destination).asSquare().start(PublishProfilePictureActivity.this); } } + if (requestCode == Crop.REQUEST_CROP) { + this.avatarUri = Uri.fromFile(new File(getCacheDir(), "croppedAvatar")); + loadImageIntoPreview(this.avatarUri); + } } @Override @@ -217,9 +228,22 @@ public class PublishProfilePictureActivity extends XmppActivity { } } + private Bitmap loadScaledBitmap(Uri uri, int reqSize) throws FileNotFoundException { + final BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeStream(getContentResolver().openInputStream(uri)); + options.inSampleSize = FileBackend.calcSampleSize(options, reqSize); + options.inJustDecodeBounds = false; + return BitmapFactory.decodeStream(getContentResolver().openInputStream(uri)); + } protected void loadImageIntoPreview(Uri uri) { - Bitmap bm = xmppConnectionService.getFileBackend().cropCenterSquare( - uri, 384); + Bitmap bm = null; + try{ + bm = loadScaledBitmap(uri, Config.AVATAR_SIZE); + } catch (Exception e) { + e.printStackTrace(); + } + if (bm == null) { disablePublishButton(); this.hintOrWarning.setTextColor(getWarningTextColor()); @@ -261,5 +285,4 @@ public class PublishProfilePictureActivity extends XmppActivity { public void refreshUiReal() { //nothing to do. This Activity doesn't implement any listeners } - } diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 5b3ef186f..0726375d6 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -314,6 +314,7 @@ \n\nhttps://github.com/kyleduo/SwitchButton\n(Apache License, Version 2.0) \n\nhttps://github.com/WhisperSystems/libaxolotl-java\n(GPLv3) \n\nhttps://github.com/vinc3m1/RoundedImageView\n(Apache License, Version 2.0) + \n\nhttps://github.com/jdamcd/android-crop\n(Apache License, Version 2.0) </string> <string name="title_pref_quiet_hours">Quiet Hours</string> <string name="title_pref_quiet_hours_start_time">Start time</string> @@ -549,4 +550,8 @@ <string name="not_a_valid_port">This is not a valid port number</string> <string name="not_valid_hostname">This is not a valid hostname</string> <string name="connected_accounts">%1$d of %2$d accounts connected</string> + <plurals name="x_messages"> + <item quantity="one">%d message</item> + <item quantity="other">%d messages</item> + </plurals> </resources> |