Home | History | Annotate | Download | only in multimedia
      1 /*
      2  * Copyright (C) 2016 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.dialer.multimedia;
     18 
     19 import android.location.Location;
     20 import android.net.Uri;
     21 import android.support.annotation.NonNull;
     22 import android.support.annotation.Nullable;
     23 import android.text.TextUtils;
     24 import com.android.dialer.common.LogUtil;
     25 import com.google.auto.value.AutoValue;
     26 
     27 /** Holds data associated with a call. */
     28 @AutoValue
     29 public abstract class MultimediaData {
     30 
     31   public static final MultimediaData EMPTY = builder().build();
     32 
     33   @NonNull
     34   public static Builder builder() {
     35     return new AutoValue_MultimediaData.Builder().setImportant(false);
     36   }
     37 
     38   /**
     39    * Returns the text part of this data.
     40    *
     41    * <p>This field is used for both the call composer session and the post call note.
     42    */
     43   @Nullable
     44   public abstract String getText();
     45 
     46   /** Returns the location part of this data. */
     47   @Nullable
     48   public abstract Location getLocation();
     49 
     50   /** Returns {@code true} if this object contains image data. */
     51   public boolean hasImageData() {
     52     // imageUri and content are always either both null or nonnull
     53     return getImageUri() != null && getImageContentType() != null;
     54   }
     55 
     56   /** Returns the image uri part of this object's image. */
     57   @Nullable
     58   public abstract Uri getImageUri();
     59 
     60   /** Returns the content type part of this object's image, either image/png or image/jpeg. */
     61   @Nullable
     62   public abstract String getImageContentType();
     63 
     64   /** Returns {@code true} if this data is marked as important. */
     65   public abstract boolean isImportant();
     66 
     67   /** Returns true if this has image, text or location data. */
     68   public boolean hasData() {
     69     return hasImageData() || !TextUtils.isEmpty(getText()) || getLocation() != null;
     70   }
     71 
     72   /** Returns the string form of this MultimediaData with no PII. */
     73   @Override
     74   public String toString() {
     75     return String.format(
     76         "MultimediaData{subject: %s, location: %s, imageUrl: %s, imageContentType: %s, "
     77             + "important: %b}",
     78         LogUtil.sanitizePii(getText()),
     79         LogUtil.sanitizePii(getLocation()),
     80         LogUtil.sanitizePii(getImageUri()),
     81         getImageContentType(),
     82         isImportant());
     83   }
     84 
     85   /** Creates instances of {@link MultimediaData}. */
     86   @AutoValue.Builder
     87   public abstract static class Builder {
     88 
     89     public abstract Builder setText(@NonNull String subject);
     90 
     91     public abstract Builder setLocation(@NonNull Location location);
     92 
     93     public Builder setImage(@NonNull Uri image, @NonNull String imageContentType) {
     94       setImageUri(image);
     95       setImageContentType(imageContentType);
     96       return this;
     97     }
     98 
     99     abstract Builder setImageUri(@NonNull Uri image);
    100 
    101     abstract Builder setImageContentType(@NonNull String imageContentType);
    102 
    103     public abstract Builder setImportant(boolean isImportant);
    104 
    105     public abstract MultimediaData build();
    106   }
    107 }
    108