StatusHints.java revision e7ef59a77d55c9802cc7d919f7dd794bd5fea30e
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.telecomm; 18 19import android.content.ComponentName; 20import android.content.Context; 21import android.content.pm.PackageManager; 22import android.graphics.drawable.Drawable; 23import android.net.Uri; 24import android.os.Parcel; 25import android.os.Parcelable; 26import android.util.DisplayMetrics; 27 28import java.util.MissingResourceException; 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 ComponentName mComponentName; 36 private final String mLabel; 37 private final int mIconId; 38 39 public StatusHints(ComponentName componentName, String label, int iconId) { 40 mComponentName = componentName; 41 mLabel = label; 42 mIconId = iconId; 43 } 44 45 /** 46 * @return A component used to load the icon. 47 */ 48 public ComponentName getComponentName() { 49 return mComponentName; 50 } 51 52 /** 53 * @return The label displayed in the in-call UI. 54 */ 55 public String getLabel() { 56 return mLabel; 57 } 58 59 /** 60 * @return The icon resource identifier. 61 */ 62 public int getIconId() { 63 return mIconId; 64 } 65 66 /** 67 * @return An icon displayed in the in-call UI. 68 */ 69 public Drawable getIcon(Context context) { 70 return getIcon(context, mIconId); 71 } 72 73 @Override 74 public int describeContents() { 75 return 0; 76 } 77 78 @Override 79 public void writeToParcel(Parcel out, int flags) { 80 out.writeParcelable(mComponentName, flags); 81 out.writeString(mLabel); 82 out.writeInt(mIconId); 83 } 84 85 public static final Creator<StatusHints> CREATOR 86 = new Creator<StatusHints>() { 87 public StatusHints createFromParcel(Parcel in) { 88 return new StatusHints(in); 89 } 90 91 public StatusHints[] newArray(int size) { 92 return new StatusHints[size]; 93 } 94 }; 95 96 private StatusHints(Parcel in) { 97 mComponentName = in.readParcelable(getClass().getClassLoader()); 98 mLabel = in.readString(); 99 mIconId = in.readInt(); 100 } 101 102 private Drawable getIcon(Context context, int resId) { 103 Context packageContext; 104 try { 105 packageContext = context.createPackageContext(mComponentName.getPackageName(), 0); 106 } catch (PackageManager.NameNotFoundException e) { 107 Log.e(this, e, "Cannot find package %s", mComponentName.getPackageName()); 108 return null; 109 } 110 try { 111 return packageContext.getResources().getDrawable(resId); 112 } catch (MissingResourceException e) { 113 Log.e(this, e, "Cannot find icon %d in package %s", 114 resId, mComponentName.getPackageName()); 115 return null; 116 } 117 } 118} 119