Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 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 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 18 | |
Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
| 21 | import android.content.Context; |
| 22 | import android.content.pm.PackageManager; |
| 23 | import android.graphics.drawable.Drawable; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 24 | import android.os.Bundle; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 25 | import android.os.Parcel; |
| 26 | import android.os.Parcelable; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 27 | |
| 28 | import java.util.MissingResourceException; |
Sailesh Nepal | f20b916 | 2014-08-12 11:53:32 -0700 | [diff] [blame] | 29 | import java.util.Objects; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Contains status label and icon displayed in the in-call UI. |
Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 33 | * @hide |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 34 | */ |
Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 35 | @SystemApi |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 36 | public final class StatusHints implements Parcelable { |
| 37 | |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 38 | private final ComponentName mPackageName; |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 39 | private final CharSequence mLabel; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 40 | private final int mIconResId; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 41 | private final Bundle mExtras; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 42 | |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 43 | public StatusHints(ComponentName packageName, CharSequence label, int iconResId, |
| 44 | Bundle extras) { |
| 45 | mPackageName = packageName; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 46 | mLabel = label; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 47 | mIconResId = iconResId; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 48 | mExtras = extras; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /** |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 52 | * @return A package used to load the icon. |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 53 | */ |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 54 | public ComponentName getPackageName() { |
| 55 | return mPackageName; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @return The label displayed in the in-call UI. |
| 60 | */ |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 61 | public CharSequence getLabel() { |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 62 | return mLabel; |
| 63 | } |
| 64 | |
| 65 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 66 | * The icon resource ID for the icon to show. |
| 67 | * |
| 68 | * @return A resource ID. |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 69 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 70 | public int getIconResId() { |
| 71 | return mIconResId; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @return An icon displayed in the in-call UI. |
| 76 | */ |
| 77 | public Drawable getIcon(Context context) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 78 | return getIcon(context, mIconResId); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 81 | /** |
| 82 | * @return Extra data used to display status. |
| 83 | */ |
| 84 | public Bundle getExtras() { |
| 85 | return mExtras; |
| 86 | } |
| 87 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 88 | @Override |
| 89 | public int describeContents() { |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public void writeToParcel(Parcel out, int flags) { |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 95 | out.writeParcelable(mPackageName, flags); |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 96 | out.writeCharSequence(mLabel); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 97 | out.writeInt(mIconResId); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 98 | out.writeParcelable(mExtras, 0); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 99 | } |
| 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 Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 113 | mPackageName = in.readParcelable(getClass().getClassLoader()); |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 114 | mLabel = in.readCharSequence(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 115 | mIconResId = in.readInt(); |
| 116 | mExtras = in.readParcelable(getClass().getClassLoader()); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | private Drawable getIcon(Context context, int resId) { |
| 120 | Context packageContext; |
| 121 | try { |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 122 | packageContext = context.createPackageContext(mPackageName.getPackageName(), 0); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 123 | } catch (PackageManager.NameNotFoundException e) { |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 124 | Log.e(this, e, "Cannot find package %s", mPackageName.getPackageName()); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 125 | return null; |
| 126 | } |
| 127 | try { |
Alan Viverette | 03d30a5 | 2014-08-14 12:59:10 -0700 | [diff] [blame] | 128 | return packageContext.getDrawable(resId); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 129 | } catch (MissingResourceException e) { |
| 130 | Log.e(this, e, "Cannot find icon %d in package %s", |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 131 | resId, mPackageName.getPackageName()); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 132 | return null; |
| 133 | } |
| 134 | } |
Sailesh Nepal | f20b916 | 2014-08-12 11:53:32 -0700 | [diff] [blame] | 135 | |
| 136 | @Override |
| 137 | public boolean equals(Object other) { |
| 138 | if (other != null && other instanceof StatusHints) { |
| 139 | StatusHints otherHints = (StatusHints) other; |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 140 | return Objects.equals(otherHints.getPackageName(), getPackageName()) && |
Sailesh Nepal | f20b916 | 2014-08-12 11:53:32 -0700 | [diff] [blame] | 141 | Objects.equals(otherHints.getLabel(), getLabel()) && |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 142 | otherHints.getIconResId() == getIconResId() && |
Sailesh Nepal | f20b916 | 2014-08-12 11:53:32 -0700 | [diff] [blame] | 143 | Objects.equals(otherHints.getExtras(), getExtras()); |
| 144 | } |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public int hashCode() { |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 150 | return Objects.hashCode(mPackageName) + Objects.hashCode(mLabel) + mIconResId + |
Sailesh Nepal | f20b916 | 2014-08-12 11:53:32 -0700 | [diff] [blame] | 151 | Objects.hashCode(mExtras); |
| 152 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 153 | } |