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