• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
builder()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
getText()44   public abstract String getText();
45 
46   /** Returns the location part of this data. */
47   @Nullable
getLocation()48   public abstract Location getLocation();
49 
50   /** Returns {@code true} if this object contains image data. */
hasImageData()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
getImageUri()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
getImageContentType()62   public abstract String getImageContentType();
63 
64   /** Returns {@code true} if this data is marked as important. */
isImportant()65   public abstract boolean isImportant();
66 
67   /** Returns true if this has image, text or location data. */
hasData()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
toString()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 
setText(@onNull String subject)89     public abstract Builder setText(@NonNull String subject);
90 
setLocation(@onNull Location location)91     public abstract Builder setLocation(@NonNull Location location);
92 
setImage(@onNull Uri image, @NonNull String imageContentType)93     public Builder setImage(@NonNull Uri image, @NonNull String imageContentType) {
94       setImageUri(image);
95       setImageContentType(imageContentType);
96       return this;
97     }
98 
setImageUri(@onNull Uri image)99     abstract Builder setImageUri(@NonNull Uri image);
100 
setImageContentType(@onNull String imageContentType)101     abstract Builder setImageContentType(@NonNull String imageContentType);
102 
setImportant(boolean isImportant)103     public abstract Builder setImportant(boolean isImportant);
104 
build()105     public abstract MultimediaData build();
106   }
107 }
108