blob: dd3a639e6bf37882b93250d7ed40aa9ee579e4e3 [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
Tyler Gunn711d876fd2014-09-19 11:17:02 -070019import android.annotation.SystemApi;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070020import android.content.ComponentName;
21import android.content.Context;
22import android.content.pm.PackageManager;
23import android.graphics.drawable.Drawable;
Sailesh Nepal61203862014-07-11 14:50:13 -070024import android.os.Bundle;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070025import android.os.Parcel;
26import android.os.Parcelable;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070027
28import java.util.MissingResourceException;
Sailesh Nepalf20b9162014-08-12 11:53:32 -070029import java.util.Objects;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070030
31/**
32 * Contains status label and icon displayed in the in-call UI.
Tyler Gunn711d876fd2014-09-19 11:17:02 -070033 * @hide
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070034 */
Tyler Gunn711d876fd2014-09-19 11:17:02 -070035@SystemApi
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070036public final class StatusHints implements Parcelable {
37
Nancy Chenea38cca2014-09-05 16:38:49 -070038 private final ComponentName mPackageName;
Santos Cordon146a3e32014-07-21 00:00:44 -070039 private final CharSequence mLabel;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070040 private final int mIconResId;
Sailesh Nepal61203862014-07-11 14:50:13 -070041 private final Bundle mExtras;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070042
Nancy Chenea38cca2014-09-05 16:38:49 -070043 public StatusHints(ComponentName packageName, CharSequence label, int iconResId,
44 Bundle extras) {
45 mPackageName = packageName;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070046 mLabel = label;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070047 mIconResId = iconResId;
Sailesh Nepal61203862014-07-11 14:50:13 -070048 mExtras = extras;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070049 }
50
51 /**
Nancy Chenea38cca2014-09-05 16:38:49 -070052 * @return A package used to load the icon.
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070053 */
Nancy Chenea38cca2014-09-05 16:38:49 -070054 public ComponentName getPackageName() {
55 return mPackageName;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070056 }
57
58 /**
59 * @return The label displayed in the in-call UI.
60 */
Santos Cordon146a3e32014-07-21 00:00:44 -070061 public CharSequence getLabel() {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070062 return mLabel;
63 }
64
65 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070066 * The icon resource ID for the icon to show.
67 *
68 * @return A resource ID.
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070069 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070070 public int getIconResId() {
71 return mIconResId;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070072 }
73
74 /**
75 * @return An icon displayed in the in-call UI.
76 */
77 public Drawable getIcon(Context context) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -070078 return getIcon(context, mIconResId);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070079 }
80
Sailesh Nepal61203862014-07-11 14:50:13 -070081 /**
82 * @return Extra data used to display status.
83 */
84 public Bundle getExtras() {
85 return mExtras;
86 }
87
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070088 @Override
89 public int describeContents() {
90 return 0;
91 }
92
93 @Override
94 public void writeToParcel(Parcel out, int flags) {
Nancy Chenea38cca2014-09-05 16:38:49 -070095 out.writeParcelable(mPackageName, flags);
Santos Cordon146a3e32014-07-21 00:00:44 -070096 out.writeCharSequence(mLabel);
Ihab Awadb19a0bc2014-08-07 19:46:01 -070097 out.writeInt(mIconResId);
Sailesh Nepal61203862014-07-11 14:50:13 -070098 out.writeParcelable(mExtras, 0);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070099 }
100
101 public static final Creator<StatusHints> CREATOR
102 = new Creator<StatusHints>() {
103 public StatusHints createFromParcel(Parcel in) {
104 return new StatusHints(in);
105 }
106
107 public StatusHints[] newArray(int size) {
108 return new StatusHints[size];
109 }
110 };
111
112 private StatusHints(Parcel in) {
Nancy Chenea38cca2014-09-05 16:38:49 -0700113 mPackageName = in.readParcelable(getClass().getClassLoader());
Santos Cordon146a3e32014-07-21 00:00:44 -0700114 mLabel = in.readCharSequence();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700115 mIconResId = in.readInt();
116 mExtras = in.readParcelable(getClass().getClassLoader());
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700117 }
118
119 private Drawable getIcon(Context context, int resId) {
120 Context packageContext;
121 try {
Nancy Chenea38cca2014-09-05 16:38:49 -0700122 packageContext = context.createPackageContext(mPackageName.getPackageName(), 0);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700123 } catch (PackageManager.NameNotFoundException e) {
Nancy Chenea38cca2014-09-05 16:38:49 -0700124 Log.e(this, e, "Cannot find package %s", mPackageName.getPackageName());
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700125 return null;
126 }
127 try {
Alan Viverette03d30a52014-08-14 12:59:10 -0700128 return packageContext.getDrawable(resId);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700129 } catch (MissingResourceException e) {
130 Log.e(this, e, "Cannot find icon %d in package %s",
Nancy Chenea38cca2014-09-05 16:38:49 -0700131 resId, mPackageName.getPackageName());
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700132 return null;
133 }
134 }
Sailesh Nepalf20b9162014-08-12 11:53:32 -0700135
136 @Override
137 public boolean equals(Object other) {
138 if (other != null && other instanceof StatusHints) {
139 StatusHints otherHints = (StatusHints) other;
Nancy Chenea38cca2014-09-05 16:38:49 -0700140 return Objects.equals(otherHints.getPackageName(), getPackageName()) &&
Sailesh Nepalf20b9162014-08-12 11:53:32 -0700141 Objects.equals(otherHints.getLabel(), getLabel()) &&
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700142 otherHints.getIconResId() == getIconResId() &&
Sailesh Nepalf20b9162014-08-12 11:53:32 -0700143 Objects.equals(otherHints.getExtras(), getExtras());
144 }
145 return false;
146 }
147
148 @Override
149 public int hashCode() {
Nancy Chenea38cca2014-09-05 16:38:49 -0700150 return Objects.hashCode(mPackageName) + Objects.hashCode(mLabel) + mIconResId +
Sailesh Nepalf20b9162014-08-12 11:53:32 -0700151 Objects.hashCode(mExtras);
152 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700153}