summaryrefslogtreecommitdiffstats
path: root/src/com/android/messaging/ui/mediapicker/GalleryGridItemView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/messaging/ui/mediapicker/GalleryGridItemView.java')
-rw-r--r--src/com/android/messaging/ui/mediapicker/GalleryGridItemView.java71
1 files changed, 68 insertions, 3 deletions
diff --git a/src/com/android/messaging/ui/mediapicker/GalleryGridItemView.java b/src/com/android/messaging/ui/mediapicker/GalleryGridItemView.java
index 2006f57..eb66b80 100644
--- a/src/com/android/messaging/ui/mediapicker/GalleryGridItemView.java
+++ b/src/com/android/messaging/ui/mediapicker/GalleryGridItemView.java
@@ -18,7 +18,9 @@ package com.android.messaging.ui.mediapicker;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Rect;
+import androidx.appcompat.mms.CarrierConfigValuesLoader;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.MotionEvent;
import android.view.TouchDelegate;
import android.view.View;
@@ -26,11 +28,16 @@ import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.ImageView.ScaleType;
+import android.widget.Toast;
import com.android.messaging.R;
import com.android.messaging.datamodel.DataModel;
+import com.android.messaging.datamodel.data.DraftMessageData;
import com.android.messaging.datamodel.data.GalleryGridItemData;
+import com.android.messaging.datamodel.data.ParticipantData;
+import com.android.messaging.sms.MmsConfig;
import com.android.messaging.ui.AsyncImageView;
import com.android.messaging.ui.ConversationDrawables;
+import com.android.messaging.util.UriUtil;
import com.google.common.annotations.VisibleForTesting;
import java.util.concurrent.TimeUnit;
@@ -39,6 +46,7 @@ import java.util.concurrent.TimeUnit;
* Shows an item in the gallery picker grid view. Hosts an FileImageView with a checkbox.
*/
public class GalleryGridItemView extends FrameLayout {
+ private static final String TAG = GalleryGridItemView.class.getSimpleName();
/**
* Implemented by the owner of this GalleryGridItemView instance to communicate on media
* picking and selection events.
@@ -47,6 +55,7 @@ public class GalleryGridItemView extends FrameLayout {
void onItemClicked(View view, GalleryGridItemData data, boolean longClick);
boolean isItemSelected(GalleryGridItemData data);
boolean isMultiSelectEnabled();
+ int getSubscriptionProviderSubId();
}
@VisibleForTesting
@@ -55,10 +64,65 @@ public class GalleryGridItemView extends FrameLayout {
private AsyncImageView mImageView;
private CheckBox mCheckBox;
private HostInterface mHostInterface;
+ private static long mTotalContentSize = 0;
+ private static long mMaxMessageSize = 0;
+
+ private boolean checkSize() {
+ if (mData.isDocumentPickerItem()) {
+ return true;
+ }
+ // only perform the check for videos, since they are not being compressed
+ // images will be compressed, so exclude them from this check
+
+ // determine the maximum message size, this will be computed only once per this class
+ if (mMaxMessageSize == 0) {
+ int subId = mHostInterface.getSubscriptionProviderSubId();
+ mMaxMessageSize = MmsConfig.get(subId).getMaxMessageSize();
+ }
+
+ long contentSize = mData.getContentSize();
+ if (mHostInterface.isMultiSelectEnabled()) {
+ if (mData.isVideoItem()) {
+ if (mHostInterface.isItemSelected(mData)) {
+ // un-selecting
+ mTotalContentSize -= contentSize;
+ if (mTotalContentSize < 0) {
+ mTotalContentSize = 0;
+ }
+ } else {
+ // selecting
+ mTotalContentSize += contentSize;
+ }
+ }
+ } else {
+ // short click or first long click
+ if (mData.isVideoItem()) {
+ mTotalContentSize = contentSize;
+ } else {
+ mTotalContentSize = 0;
+ }
+ }
+
+ if (mTotalContentSize > mMaxMessageSize) {
+ mTotalContentSize -= contentSize;
+ if (mTotalContentSize < 0) {
+ mTotalContentSize = 0;
+ }
+
+ Toast.makeText(getContext(), getContext().
+ getString(R.string.mediapicker_gallery_image_item_attachment_too_large),
+ Toast.LENGTH_LONG).show();
+ return false;
+ }
+
+ return true;
+ }
private final OnClickListener mOnClickListener = new OnClickListener() {
@Override
public void onClick(final View v) {
- mHostInterface.onItemClicked(GalleryGridItemView.this, mData, false /*longClick*/);
+ if (checkSize()) {
+ mHostInterface.onItemClicked(GalleryGridItemView.this, mData, false /*longClick*/);
+ }
}
};
@@ -78,7 +142,9 @@ public class GalleryGridItemView extends FrameLayout {
final OnLongClickListener longClickListener = new OnLongClickListener() {
@Override
public boolean onLongClick(final View v) {
- mHostInterface.onItemClicked(v, mData, true /* longClick */);
+ if (checkSize()) {
+ mHostInterface.onItemClicked(v, mData, true /* longClick */);
+ }
return true;
}
};
@@ -159,7 +225,6 @@ public class GalleryGridItemView extends FrameLayout {
dateSeconds * TimeUnit.SECONDS.toMillis(1));
mImageView.setContentDescription(contentDescription);
} else {
- hideVideoPlayButtonOverlay();
mImageView.setScaleType(ScaleType.CENTER_CROP);
setBackgroundColor(getResources().getColor(R.color.gallery_image_default_background));
mImageView.setImageResourceId(mData.getImageRequestDescriptor());