1d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/* 2d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Copyright (C) 2015 The Android Open Source Project 3d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 4d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Licensed under the Apache License, Version 2.0 (the "License"); 5d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * you may not use this file except in compliance with the License. 6d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * You may obtain a copy of the License at 7d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 8d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * http://www.apache.org/licenses/LICENSE-2.0 9d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 10d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Unless required by applicable law or agreed to in writing, software 11d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * distributed under the License is distributed on an "AS IS" BASIS, 12d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * See the License for the specific language governing permissions and 14d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * limitations under the License. 15d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 16d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpackage com.android.messaging.datamodel.media; 17d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 18d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.Context; 19d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.net.Uri; 20d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 21d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.UriUtil; 22d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 23d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpublic class UriImageRequestDescriptor extends ImageRequestDescriptor { 24d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public final Uri uri; 25d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public final boolean allowCompression; 26d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 27d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public UriImageRequestDescriptor(final Uri uri) { 28d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd this(uri, UriImageRequest.UNSPECIFIED_SIZE, UriImageRequest.UNSPECIFIED_SIZE, false, false, 29d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd false, 0, 0); 30d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 31d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 32d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public UriImageRequestDescriptor(final Uri uri, final int desiredWidth, final int desiredHeight) 33d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd { 34d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd this(uri, desiredWidth, desiredHeight, false, false, false, 0, 0); 35d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 36d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 37d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public UriImageRequestDescriptor(final Uri uri, final int desiredWidth, final int desiredHeight, 38d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final boolean cropToCircle, final int circleBackgroundColor, int circleStrokeColor) 39d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd { 40d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd this(uri, desiredWidth, desiredHeight, false, 41d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd false, cropToCircle, circleBackgroundColor, circleStrokeColor); 42d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 43d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 44d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public UriImageRequestDescriptor(final Uri uri, final int desiredWidth, 45d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final int desiredHeight, final boolean allowCompression, boolean isStatic, 46d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd boolean cropToCircle, int circleBackgroundColor, int circleStrokeColor) { 47d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd this(uri, desiredWidth, desiredHeight, UriImageRequest.UNSPECIFIED_SIZE, 48d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd UriImageRequest.UNSPECIFIED_SIZE, allowCompression, isStatic, cropToCircle, 49d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd circleBackgroundColor, circleStrokeColor); 50d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 51d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 52d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 53d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Creates a new Uri-based image request. 54d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * @param uri the content Uri. Currently Bugle only supports local resources Uri (i.e. it has 55d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * to begin with content: or android.resource: 56d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * @param circleStrokeColor 57d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 58d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public UriImageRequestDescriptor(final Uri uri, final int desiredWidth, 59d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final int desiredHeight, final int sourceWidth, final int sourceHeight, 60d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final boolean allowCompression, final boolean isStatic, final boolean cropToCircle, 61d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final int circleBackgroundColor, int circleStrokeColor) { 62d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd super(desiredWidth, desiredHeight, sourceWidth, sourceHeight, isStatic, 63d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd cropToCircle, circleBackgroundColor, circleStrokeColor); 64d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd this.uri = uri; 65d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd this.allowCompression = allowCompression; 66d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 67d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 68d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 69d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getKey() { 70d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (uri != null) { 71d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final String key = super.getKey(); 72d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (key != null) { 73d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return new StringBuilder() 74d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .append(uri).append(KEY_PART_DELIMITER) 75d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .append(String.valueOf(allowCompression)).append(KEY_PART_DELIMITER) 76d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .append(key).toString(); 77d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 78d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 79d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return null; 80d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 81d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 82d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 83d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public MediaRequest<ImageResource> buildSyncMediaRequest(final Context context) { 84d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (uri == null || UriUtil.isLocalUri(uri)) { 85d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return new UriImageRequest<UriImageRequestDescriptor>(context, this); 86d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } else { 87d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return new NetworkUriImageRequest<UriImageRequestDescriptor>(context, this); 88d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 89d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 90d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 91d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** ID of the resource in MediaStore or null if this resource didn't come from MediaStore */ 92d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public Long getMediaStoreId() { 93d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return null; 94d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 95d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd}