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