1 /* 2 * Copyright (C) 2010 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 17 package com.android.internal.statusbar; 18 19 import android.graphics.drawable.Icon; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 import android.os.UserHandle; 23 import android.text.TextUtils; 24 25 public class StatusBarIcon implements Parcelable { 26 public UserHandle user; 27 public String pkg; 28 public Icon icon; 29 public int iconLevel; 30 public boolean visible = true; 31 public int number; 32 public CharSequence contentDescription; 33 34 public StatusBarIcon(UserHandle user, String resPackage, Icon icon, int iconLevel, int number, 35 CharSequence contentDescription) { 36 if (icon.getType() == Icon.TYPE_RESOURCE 37 && TextUtils.isEmpty(icon.getResPackage())) { 38 // This is an odd situation where someone's managed to hand us an icon without a 39 // package inside, probably by mashing an int res into a Notification object. 40 // Now that we have the correct package name handy, let's fix it. 41 icon = Icon.createWithResource(resPackage, icon.getResId()); 42 } 43 this.pkg = resPackage; 44 this.user = user; 45 this.icon = icon; 46 this.iconLevel = iconLevel; 47 this.number = number; 48 this.contentDescription = contentDescription; 49 } 50 51 public StatusBarIcon(String iconPackage, UserHandle user, 52 int iconId, int iconLevel, int number, 53 CharSequence contentDescription) { 54 this(user, iconPackage, Icon.createWithResource(iconPackage, iconId), 55 iconLevel, number, contentDescription); 56 } 57 58 @Override 59 public String toString() { 60 return "StatusBarIcon(icon=" + icon 61 + ((iconLevel != 0)?(" level=" + iconLevel):"") 62 + (visible?" visible":"") 63 + " user=" + user.getIdentifier() 64 + ((number != 0)?(" num=" + number):"") 65 + " )"; 66 } 67 68 @Override 69 public StatusBarIcon clone() { 70 StatusBarIcon that = new StatusBarIcon(this.user, this.pkg, this.icon, 71 this.iconLevel, this.number, this.contentDescription); 72 that.visible = this.visible; 73 return that; 74 } 75 76 /** 77 * Unflatten the StatusBarIcon from a parcel. 78 */ 79 public StatusBarIcon(Parcel in) { 80 readFromParcel(in); 81 } 82 83 public void readFromParcel(Parcel in) { 84 this.icon = (Icon) in.readParcelable(null); 85 this.pkg = in.readString(); 86 this.user = (UserHandle) in.readParcelable(null); 87 this.iconLevel = in.readInt(); 88 this.visible = in.readInt() != 0; 89 this.number = in.readInt(); 90 this.contentDescription = in.readCharSequence(); 91 } 92 93 public void writeToParcel(Parcel out, int flags) { 94 out.writeParcelable(this.icon, 0); 95 out.writeString(this.pkg); 96 out.writeParcelable(this.user, 0); 97 out.writeInt(this.iconLevel); 98 out.writeInt(this.visible ? 1 : 0); 99 out.writeInt(this.number); 100 out.writeCharSequence(this.contentDescription); 101 } 102 103 public int describeContents() { 104 return 0; 105 } 106 107 /** 108 * Parcelable.Creator that instantiates StatusBarIcon objects 109 */ 110 public static final Parcelable.Creator<StatusBarIcon> CREATOR 111 = new Parcelable.Creator<StatusBarIcon>() 112 { 113 public StatusBarIcon createFromParcel(Parcel parcel) 114 { 115 return new StatusBarIcon(parcel); 116 } 117 118 public StatusBarIcon[] newArray(int size) 119 { 120 return new StatusBarIcon[size]; 121 } 122 }; 123 } 124 125