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