blob: a32eae76dcea757c89a6c56eb11a38060199429d [file] [log] [blame]
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001/*
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
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070018
19import android.content.ComponentName;
20import android.content.Context;
21import android.content.pm.PackageManager;
22import android.graphics.drawable.Drawable;
Sailesh Nepal61203862014-07-11 14:50:13 -070023import android.os.Bundle;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070024import android.os.Parcel;
25import android.os.Parcelable;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070026
27import java.util.MissingResourceException;
Sailesh Nepalf20b9162014-08-12 11:53:32 -070028import java.util.Objects;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070029
30/**
31 * Contains status label and icon displayed in the in-call UI.
32 */
33public final class StatusHints implements Parcelable {
34
Nancy Chenea38cca2014-09-05 16:38:49 -070035 private final ComponentName mPackageName;
Santos Cordon146a3e32014-07-21 00:00:44 -070036 private final CharSequence mLabel;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070037 private final int mIconResId;
Sailesh Nepal61203862014-07-11 14:50:13 -070038 private final Bundle mExtras;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070039
Nancy Chenea38cca2014-09-05 16:38:49 -070040 public StatusHints(ComponentName packageName, CharSequence label, int iconResId,
41 Bundle extras) {
42 mPackageName = packageName;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070043 mLabel = label;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070044 mIconResId = iconResId;
Sailesh Nepal61203862014-07-11 14:50:13 -070045 mExtras = extras;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070046 }
47
48 /**
Nancy Chenea38cca2014-09-05 16:38:49 -070049 * @return A package used to load the icon.
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070050 */
Nancy Chenea38cca2014-09-05 16:38:49 -070051 public ComponentName getPackageName() {
52 return mPackageName;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070053 }
54
55 /**
56 * @return The label displayed in the in-call UI.
57 */
Santos Cordon146a3e32014-07-21 00:00:44 -070058 public CharSequence getLabel() {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070059 return mLabel;
60 }
61
62 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070063 * The icon resource ID for the icon to show.
64 *
65 * @return A resource ID.
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070066 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070067 public int getIconResId() {
68 return mIconResId;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070069 }
70
71 /**
72 * @return An icon displayed in the in-call UI.
73 */
74 public Drawable getIcon(Context context) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -070075 return getIcon(context, mIconResId);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070076 }
77
Sailesh Nepal61203862014-07-11 14:50:13 -070078 /**
79 * @return Extra data used to display status.
80 */
81 public Bundle getExtras() {
82 return mExtras;
83 }
84
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070085 @Override
86 public int describeContents() {
87 return 0;
88 }
89
90 @Override
91 public void writeToParcel(Parcel out, int flags) {
Nancy Chenea38cca2014-09-05 16:38:49 -070092 out.writeParcelable(mPackageName, flags);
Santos Cordon146a3e32014-07-21 00:00:44 -070093 out.writeCharSequence(mLabel);
Ihab Awadb19a0bc2014-08-07 19:46:01 -070094 out.writeInt(mIconResId);
Sailesh Nepal61203862014-07-11 14:50:13 -070095 out.writeParcelable(mExtras, 0);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070096 }
97
98 public static final Creator<StatusHints> CREATOR
99 = new Creator<StatusHints>() {
100 public StatusHints createFromParcel(Parcel in) {
101 return new StatusHints(in);
102 }
103
104 public StatusHints[] newArray(int size) {
105 return new StatusHints[size];
106 }
107 };
108
109 private StatusHints(Parcel in) {
Nancy Chenea38cca2014-09-05 16:38:49 -0700110 mPackageName = in.readParcelable(getClass().getClassLoader());
Santos Cordon146a3e32014-07-21 00:00:44 -0700111 mLabel = in.readCharSequence();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700112 mIconResId = in.readInt();
113 mExtras = in.readParcelable(getClass().getClassLoader());
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700114 }
115
116 private Drawable getIcon(Context context, int resId) {
117 Context packageContext;
118 try {
Nancy Chenea38cca2014-09-05 16:38:49 -0700119 packageContext = context.createPackageContext(mPackageName.getPackageName(), 0);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700120 } catch (PackageManager.NameNotFoundException e) {
Nancy Chenea38cca2014-09-05 16:38:49 -0700121 Log.e(this, e, "Cannot find package %s", mPackageName.getPackageName());
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700122 return null;
123 }
124 try {
Alan Viverette03d30a52014-08-14 12:59:10 -0700125 return packageContext.getDrawable(resId);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700126 } catch (MissingResourceException e) {
127 Log.e(this, e, "Cannot find icon %d in package %s",
Nancy Chenea38cca2014-09-05 16:38:49 -0700128 resId, mPackageName.getPackageName());
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700129 return null;
130 }
131 }
Sailesh Nepalf20b9162014-08-12 11:53:32 -0700132
133 @Override
134 public boolean equals(Object other) {
135 if (other != null && other instanceof StatusHints) {
136 StatusHints otherHints = (StatusHints) other;
Nancy Chenea38cca2014-09-05 16:38:49 -0700137 return Objects.equals(otherHints.getPackageName(), getPackageName()) &&
Sailesh Nepalf20b9162014-08-12 11:53:32 -0700138 Objects.equals(otherHints.getLabel(), getLabel()) &&
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700139 otherHints.getIconResId() == getIconResId() &&
Sailesh Nepalf20b9162014-08-12 11:53:32 -0700140 Objects.equals(otherHints.getExtras(), getExtras());
141 }
142 return false;
143 }
144
145 @Override
146 public int hashCode() {
Nancy Chenea38cca2014-09-05 16:38:49 -0700147 return Objects.hashCode(mPackageName) + Objects.hashCode(mLabel) + mIconResId +
Sailesh Nepalf20b9162014-08-12 11:53:32 -0700148 Objects.hashCode(mExtras);
149 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700150}