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