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 Dodd 17d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpackage com.android.messaging.datamodel.media; 18d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 19d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.Context; 20d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.net.Uri; 21d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 22d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.Assert; 23d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.AvatarUriUtil; 24d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.ImageUtils; 25d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.UriUtil; 26d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 27d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpublic class AvatarRequestDescriptor extends UriImageRequestDescriptor { 28d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final boolean isWearBackground; 29d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 30d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public AvatarRequestDescriptor(final Uri uri, final int desiredWidth, 31d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final int desiredHeight) { 32d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd this(uri, desiredWidth, desiredHeight, true /* cropToCircle */); 33d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 34d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 35d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public AvatarRequestDescriptor(final Uri uri, final int desiredWidth, 36d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final int desiredHeight, final boolean cropToCircle) { 37d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd this(uri, desiredWidth, desiredHeight, cropToCircle, false /* isWearBackground */); 38d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 39d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 40d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public AvatarRequestDescriptor(final Uri uri, final int desiredWidth, 41d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final int desiredHeight, boolean cropToCircle, boolean isWearBackground) { 42d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd super(uri, desiredWidth, desiredHeight, false /* allowCompression */, true /* isStatic */, 43d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd cropToCircle, 44d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ImageUtils.DEFAULT_CIRCLE_BACKGROUND_COLOR /* circleBackgroundColor */, 45d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ImageUtils.DEFAULT_CIRCLE_STROKE_COLOR /* circleStrokeColor */); 46d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd Assert.isTrue(uri == null || UriUtil.isLocalResourceUri(uri) || 47d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd AvatarUriUtil.isAvatarUri(uri)); 48d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd this.isWearBackground = isWearBackground; 49d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 50d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 51d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 52d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public MediaRequest<ImageResource> buildSyncMediaRequest(final Context context) { 53d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final String avatarType = uri == null ? null : AvatarUriUtil.getAvatarType(uri); 54d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (AvatarUriUtil.TYPE_SIM_SELECTOR_URI.equals(avatarType)) { 55d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return new SimSelectorAvatarRequest(context, this); 56d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } else { 57d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return new AvatarRequest(context, this); 58d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 59d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 60d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd} 61