1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.messaging.datamodel.media; 18 19 import android.net.Uri; 20 21 import com.android.messaging.datamodel.action.UpdateMessagePartSizeAction; 22 import com.android.messaging.datamodel.data.MessagePartData; 23 import com.android.messaging.util.ImageUtils; 24 25 /** 26 * Image descriptor attached to a message part. 27 * Once image size is determined during loading this descriptor will update the db if necessary. 28 */ 29 public class MessagePartImageRequestDescriptor extends UriImageRequestDescriptor { 30 private final String mMessagePartId; 31 32 /** 33 * Creates a new image request for a message part. 34 */ 35 public MessagePartImageRequestDescriptor(final MessagePartData messagePart, 36 final int desiredWidth, final int desiredHeight, boolean isStatic) { 37 // Pull image parameters out of the MessagePart record 38 this(messagePart.getPartId(), messagePart.getContentUri(), desiredWidth, desiredHeight, 39 messagePart.getWidth(), messagePart.getHeight(), isStatic); 40 } 41 42 protected MessagePartImageRequestDescriptor(final String messagePartId, final Uri contentUri, 43 final int desiredWidth, final int desiredHeight, final int sourceWidth, 44 final int sourceHeight, boolean isStatic) { 45 super(contentUri, desiredWidth, desiredHeight, sourceWidth, sourceHeight, 46 true /* allowCompression */, isStatic, false /* cropToCircle */, 47 ImageUtils.DEFAULT_CIRCLE_BACKGROUND_COLOR /* circleBackgroundColor */, 48 ImageUtils.DEFAULT_CIRCLE_STROKE_COLOR /* circleStrokeColor */); 49 mMessagePartId = messagePartId; 50 } 51 52 @Override 53 public void updateSourceDimensions(final int updatedWidth, final int updatedHeight) { 54 // If the dimensions of the image do not match then queue a DB update with new size. 55 // Don't update if we don't have a part id, which happens if this part is loaded as 56 // draft through actions such as share intent/message forwarding. 57 if (mMessagePartId != null && 58 updatedWidth != MessagePartData.UNSPECIFIED_SIZE && 59 updatedHeight != MessagePartData.UNSPECIFIED_SIZE && 60 updatedWidth != sourceWidth && updatedHeight != sourceHeight) { 61 UpdateMessagePartSizeAction.updateSize(mMessagePartId, updatedWidth, updatedHeight); 62 } 63 } 64 } 65