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 package com.android.messaging.datamodel.media; 17 18 import android.content.Context; 19 import android.net.Uri; 20 21 import com.android.messaging.util.UriUtil; 22 23 public class UriImageRequestDescriptor extends ImageRequestDescriptor { 24 public final Uri uri; 25 public final boolean allowCompression; 26 UriImageRequestDescriptor(final Uri uri)27 public UriImageRequestDescriptor(final Uri uri) { 28 this(uri, UriImageRequest.UNSPECIFIED_SIZE, UriImageRequest.UNSPECIFIED_SIZE, false, false, 29 false, 0, 0); 30 } 31 UriImageRequestDescriptor(final Uri uri, final int desiredWidth, final int desiredHeight)32 public UriImageRequestDescriptor(final Uri uri, final int desiredWidth, final int desiredHeight) 33 { 34 this(uri, desiredWidth, desiredHeight, false, false, false, 0, 0); 35 } 36 UriImageRequestDescriptor(final Uri uri, final int desiredWidth, final int desiredHeight, final boolean cropToCircle, final int circleBackgroundColor, int circleStrokeColor)37 public UriImageRequestDescriptor(final Uri uri, final int desiredWidth, final int desiredHeight, 38 final boolean cropToCircle, final int circleBackgroundColor, int circleStrokeColor) 39 { 40 this(uri, desiredWidth, desiredHeight, false, 41 false, cropToCircle, circleBackgroundColor, circleStrokeColor); 42 } 43 UriImageRequestDescriptor(final Uri uri, final int desiredWidth, final int desiredHeight, final boolean allowCompression, boolean isStatic, boolean cropToCircle, int circleBackgroundColor, int circleStrokeColor)44 public UriImageRequestDescriptor(final Uri uri, final int desiredWidth, 45 final int desiredHeight, final boolean allowCompression, boolean isStatic, 46 boolean cropToCircle, int circleBackgroundColor, int circleStrokeColor) { 47 this(uri, desiredWidth, desiredHeight, UriImageRequest.UNSPECIFIED_SIZE, 48 UriImageRequest.UNSPECIFIED_SIZE, allowCompression, isStatic, cropToCircle, 49 circleBackgroundColor, circleStrokeColor); 50 } 51 52 /** 53 * Creates a new Uri-based image request. 54 * @param uri the content Uri. Currently Bugle only supports local resources Uri (i.e. it has 55 * to begin with content: or android.resource: 56 * @param circleStrokeColor 57 */ UriImageRequestDescriptor(final Uri uri, final int desiredWidth, final int desiredHeight, final int sourceWidth, final int sourceHeight, final boolean allowCompression, final boolean isStatic, final boolean cropToCircle, final int circleBackgroundColor, int circleStrokeColor)58 public UriImageRequestDescriptor(final Uri uri, final int desiredWidth, 59 final int desiredHeight, final int sourceWidth, final int sourceHeight, 60 final boolean allowCompression, final boolean isStatic, final boolean cropToCircle, 61 final int circleBackgroundColor, int circleStrokeColor) { 62 super(desiredWidth, desiredHeight, sourceWidth, sourceHeight, isStatic, 63 cropToCircle, circleBackgroundColor, circleStrokeColor); 64 this.uri = uri; 65 this.allowCompression = allowCompression; 66 } 67 68 @Override getKey()69 public String getKey() { 70 if (uri != null) { 71 final String key = super.getKey(); 72 if (key != null) { 73 return new StringBuilder() 74 .append(uri).append(KEY_PART_DELIMITER) 75 .append(String.valueOf(allowCompression)).append(KEY_PART_DELIMITER) 76 .append(key).toString(); 77 } 78 } 79 return null; 80 } 81 82 @Override buildSyncMediaRequest(final Context context)83 public MediaRequest<ImageResource> buildSyncMediaRequest(final Context context) { 84 if (uri == null || UriUtil.isLocalUri(uri)) { 85 return new UriImageRequest<UriImageRequestDescriptor>(context, this); 86 } else { 87 return new NetworkUriImageRequest<UriImageRequestDescriptor>(context, this); 88 } 89 } 90 91 /** ID of the resource in MediaStore or null if this resource didn't come from MediaStore */ getMediaStoreId()92 public Long getMediaStoreId() { 93 return null; 94 } 95 }