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 package com.android.messaging.datamodel.media;
     17 
     18 import android.content.Context;
     19 
     20 import com.android.messaging.util.ImageUtils;
     21 import com.android.messaging.util.UriUtil;
     22 
     23 /**
     24  * Holds image request info about file system based image resource.
     25  */
     26 public class FileImageRequestDescriptor extends UriImageRequestDescriptor {
     27     public final String path;
     28 
     29     // Can we use the thumbnail image from Exif data?
     30     public final boolean canUseThumbnail;
     31 
     32     /**
     33      * Convenience constructor for when the image file's dimensions are not known.
     34      */
     35     public FileImageRequestDescriptor(final String path, final int desiredWidth,
     36             final int desiredHeight, final boolean canUseThumbnail, final boolean canCompress,
     37             final boolean isStatic) {
     38         this(path, desiredWidth, desiredHeight, FileImageRequest.UNSPECIFIED_SIZE,
     39                 FileImageRequest.UNSPECIFIED_SIZE, canUseThumbnail, canCompress, isStatic);
     40     }
     41 
     42     /**
     43      * Creates a new file image request with this descriptor. Oftentimes image file metadata
     44      * has information such as the size of the image. Provide these metrics if they are known.
     45      */
     46     public FileImageRequestDescriptor(final String path, final int desiredWidth,
     47             final int desiredHeight, final int sourceWidth, final int sourceHeight,
     48             final boolean canUseThumbnail, final boolean canCompress, final boolean isStatic) {
     49         super(UriUtil.getUriForResourceFile(path), desiredWidth, desiredHeight, sourceWidth,
     50                 sourceHeight, canCompress,  isStatic, false /* cropToCircle */,
     51                 ImageUtils.DEFAULT_CIRCLE_BACKGROUND_COLOR /* circleBackgroundColor */,
     52                 ImageUtils.DEFAULT_CIRCLE_STROKE_COLOR /* circleStrokeColor */);
     53         this.path = path;
     54         this.canUseThumbnail = canUseThumbnail;
     55     }
     56 
     57     @Override
     58     public String getKey() {
     59         final String prefixKey = super.getKey();
     60         return prefixKey == null ? null : new StringBuilder(prefixKey).append(KEY_PART_DELIMITER)
     61                 .append(canUseThumbnail).toString();
     62     }
     63 
     64     @Override
     65     public MediaRequest<ImageResource> buildSyncMediaRequest(final Context context) {
     66         return new FileImageRequest(context, this);
     67     }
     68 }