Home | History | Annotate | Download | only in status
      1 /*
      2  * Copyright (C) 2008 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.server.status;
     18 
     19 import android.util.Slog;
     20 
     21 public class IconData {
     22     /**
     23      * Indicates ths item represents a piece of text.
     24      */
     25     public static final int TEXT = 1;
     26 
     27     /**
     28      * Indicates ths item represents an icon.
     29      */
     30     public static final int ICON = 2;
     31 
     32     /**
     33      * The type of this item. One of TEXT, ICON, or LEVEL_ICON.
     34      */
     35     public int type;
     36 
     37     /**
     38      * The slot that this icon will be in if it is not a notification
     39      */
     40     public String slot;
     41 
     42     /**
     43      * The package containting the icon to draw for this item. Valid if this is
     44      * an ICON type.
     45      */
     46     public String iconPackage;
     47 
     48     /**
     49      * The icon to draw for this item. Valid if this is an ICON type.
     50      */
     51     public int iconId;
     52 
     53     /**
     54      * The level associated with the icon. Valid if this is a LEVEL_ICON type.
     55      */
     56     public int iconLevel;
     57 
     58     /**
     59      * The "count" number.
     60      */
     61     public int number;
     62 
     63     /**
     64      * The text associated with the icon. Valid if this is a TEXT type.
     65      */
     66     public CharSequence text;
     67 
     68     private IconData() {
     69     }
     70 
     71     public static IconData makeIcon(String slot,
     72             String iconPackage, int iconId, int iconLevel, int number) {
     73         IconData data = new IconData();
     74         data.type = ICON;
     75         data.slot = slot;
     76         data.iconPackage = iconPackage;
     77         data.iconId = iconId;
     78         data.iconLevel = iconLevel;
     79         data.number = number;
     80         return data;
     81     }
     82 
     83     public static IconData makeText(String slot, CharSequence text) {
     84         IconData data = new IconData();
     85         data.type = TEXT;
     86         data.slot = slot;
     87         data.text = text;
     88         return data;
     89     }
     90 
     91     public void copyFrom(IconData that) {
     92         this.type = that.type;
     93         this.slot = that.slot;
     94         this.iconPackage = that.iconPackage;
     95         this.iconId = that.iconId;
     96         this.iconLevel = that.iconLevel;
     97         this.number = that.number;
     98         this.text = that.text; // should we clone this?
     99     }
    100 
    101     public IconData clone() {
    102         IconData that = new IconData();
    103         that.copyFrom(this);
    104         return that;
    105     }
    106 
    107     public String toString() {
    108         if (this.type == TEXT) {
    109             return "IconData(slot=" + (this.slot != null ? "'" + this.slot + "'" : "null")
    110                     + " text='" + this.text + "')";
    111         }
    112         else if (this.type == ICON) {
    113             return "IconData(slot=" + (this.slot != null ? "'" + this.slot + "'" : "null")
    114                     + " package=" + this.iconPackage
    115                     + " iconId=" + Integer.toHexString(this.iconId)
    116                     + " iconLevel=" + this.iconLevel + ")";
    117         }
    118         else {
    119             return "IconData(type=" + type + ")";
    120         }
    121     }
    122 }
    123