1 /* 2 * Copyright (C) 2014 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 android.telecom; 18 19 import android.annotation.SystemApi; 20 import android.content.ComponentName; 21 import android.content.Context; 22 import android.graphics.drawable.Drawable; 23 import android.graphics.drawable.Icon; 24 import android.os.Bundle; 25 import android.os.Parcel; 26 import android.os.Parcelable; 27 28 import java.util.Objects; 29 30 /** 31 * Contains status label and icon displayed in the in-call UI. 32 */ 33 public final class StatusHints implements Parcelable { 34 35 private final CharSequence mLabel; 36 private final Icon mIcon; 37 private final Bundle mExtras; 38 39 /** 40 * @hide 41 */ 42 @SystemApi @Deprecated StatusHints(ComponentName packageName, CharSequence label, int iconResId, Bundle extras)43 public StatusHints(ComponentName packageName, CharSequence label, int iconResId, 44 Bundle extras) { 45 this(label, iconResId == 0 ? null : Icon.createWithResource(packageName.getPackageName(), 46 iconResId), extras); 47 } 48 StatusHints(CharSequence label, Icon icon, Bundle extras)49 public StatusHints(CharSequence label, Icon icon, Bundle extras) { 50 mLabel = label; 51 mIcon = icon; 52 mExtras = extras; 53 } 54 55 /** 56 * @return A package used to load the icon. 57 * 58 * @hide 59 */ 60 @SystemApi @Deprecated getPackageName()61 public ComponentName getPackageName() { 62 // Minimal compatibility shim for legacy apps' tests 63 return new ComponentName("", ""); 64 } 65 66 /** 67 * @return The label displayed in the in-call UI. 68 */ getLabel()69 public CharSequence getLabel() { 70 return mLabel; 71 } 72 73 /** 74 * The icon resource ID for the icon to show. 75 * 76 * @return A resource ID. 77 * 78 * @hide 79 */ 80 @SystemApi @Deprecated getIconResId()81 public int getIconResId() { 82 // Minimal compatibility shim for legacy apps' tests 83 return 0; 84 } 85 86 /** 87 * @return An icon displayed in the in-call UI. 88 * 89 * @hide 90 */ 91 @SystemApi @Deprecated getIcon(Context context)92 public Drawable getIcon(Context context) { 93 return mIcon.loadDrawable(context); 94 } 95 96 /** 97 * @return An icon depicting the status. 98 */ getIcon()99 public Icon getIcon() { 100 return mIcon; 101 } 102 103 /** 104 * @return Extra data used to display status. 105 */ getExtras()106 public Bundle getExtras() { 107 return mExtras; 108 } 109 110 @Override describeContents()111 public int describeContents() { 112 return 0; 113 } 114 115 @Override writeToParcel(Parcel out, int flags)116 public void writeToParcel(Parcel out, int flags) { 117 out.writeCharSequence(mLabel); 118 out.writeParcelable(mIcon, 0); 119 out.writeParcelable(mExtras, 0); 120 } 121 122 public static final Creator<StatusHints> CREATOR 123 = new Creator<StatusHints>() { 124 public StatusHints createFromParcel(Parcel in) { 125 return new StatusHints(in); 126 } 127 128 public StatusHints[] newArray(int size) { 129 return new StatusHints[size]; 130 } 131 }; 132 StatusHints(Parcel in)133 private StatusHints(Parcel in) { 134 mLabel = in.readCharSequence(); 135 mIcon = in.readParcelable(getClass().getClassLoader()); 136 mExtras = in.readParcelable(getClass().getClassLoader()); 137 } 138 139 @Override equals(Object other)140 public boolean equals(Object other) { 141 if (other != null && other instanceof StatusHints) { 142 StatusHints otherHints = (StatusHints) other; 143 return Objects.equals(otherHints.getLabel(), getLabel()) && 144 Objects.equals(otherHints.getIcon(), getIcon()) && 145 Objects.equals(otherHints.getExtras(), getExtras()); 146 } 147 return false; 148 } 149 150 @Override hashCode()151 public int hashCode() { 152 return Objects.hashCode(mLabel) + Objects.hashCode(mIcon) + Objects.hashCode(mExtras); 153 } 154 } 155