Home | History | Annotate | Download | only in statusbar
      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.internal.statusbar;
     18 
     19 import android.app.Notification;
     20 import android.os.Parcel;
     21 import android.os.Parcelable;
     22 import android.widget.RemoteViews;
     23 
     24 
     25 /*
     26 boolean clearable = !n.ongoingEvent && ((notification.flags & Notification.FLAG_NO_CLEAR) == 0);
     27 
     28 
     29 // TODO: make this restriction do something smarter like never fill
     30 // more than two screens.  "Why would anyone need more than 80 characters." :-/
     31 final int maxTickerLen = 80;
     32 if (truncatedTicker != null && truncatedTicker.length() > maxTickerLen) {
     33     truncatedTicker = truncatedTicker.subSequence(0, maxTickerLen);
     34 }
     35 */
     36 
     37 public class StatusBarNotification implements Parcelable {
     38     public static int PRIORITY_JIFFY_EXPRESS = -100;
     39     public static int PRIORITY_NORMAL        = 0;
     40     public static int PRIORITY_ONGOING       = 100;
     41     public static int PRIORITY_SYSTEM        = 200;
     42 
     43     public String pkg;
     44     public int id;
     45     public String tag;
     46     public int uid;
     47     public int initialPid;
     48     public Notification notification;
     49     public int priority = PRIORITY_NORMAL;
     50 
     51     public StatusBarNotification() {
     52     }
     53 
     54     public StatusBarNotification(String pkg, int id, String tag,
     55             int uid, int initialPid, Notification notification) {
     56         if (pkg == null) throw new NullPointerException();
     57         if (notification == null) throw new NullPointerException();
     58 
     59         this.pkg = pkg;
     60         this.id = id;
     61         this.tag = tag;
     62         this.uid = uid;
     63         this.initialPid = initialPid;
     64         this.notification = notification;
     65 
     66         this.priority = PRIORITY_NORMAL;
     67     }
     68 
     69     public StatusBarNotification(Parcel in) {
     70         readFromParcel(in);
     71     }
     72 
     73     public void readFromParcel(Parcel in) {
     74         this.pkg = in.readString();
     75         this.id = in.readInt();
     76         if (in.readInt() != 0) {
     77             this.tag = in.readString();
     78         } else {
     79             this.tag = null;
     80         }
     81         this.uid = in.readInt();
     82         this.initialPid = in.readInt();
     83         this.priority = in.readInt();
     84         this.notification = new Notification(in);
     85     }
     86 
     87     public void writeToParcel(Parcel out, int flags) {
     88         out.writeString(this.pkg);
     89         out.writeInt(this.id);
     90         if (this.tag != null) {
     91             out.writeInt(1);
     92             out.writeString(this.tag);
     93         } else {
     94             out.writeInt(0);
     95         }
     96         out.writeInt(this.uid);
     97         out.writeInt(this.initialPid);
     98         out.writeInt(this.priority);
     99         this.notification.writeToParcel(out, flags);
    100     }
    101 
    102     public int describeContents() {
    103         return 0;
    104     }
    105 
    106     public static final Parcelable.Creator<StatusBarNotification> CREATOR
    107             = new Parcelable.Creator<StatusBarNotification>()
    108     {
    109         public StatusBarNotification createFromParcel(Parcel parcel)
    110         {
    111             return new StatusBarNotification(parcel);
    112         }
    113 
    114         public StatusBarNotification[] newArray(int size)
    115         {
    116             return new StatusBarNotification[size];
    117         }
    118     };
    119 
    120     public StatusBarNotification clone() {
    121         return new StatusBarNotification(this.pkg, this.id, this.tag,
    122                 this.uid, this.initialPid, this.notification.clone());
    123     }
    124 
    125     public String toString() {
    126         return "StatusBarNotification(package=" + pkg + " id=" + id + " tag=" + tag
    127                 + " notification=" + notification + " priority=" + priority + ")";
    128     }
    129 
    130     public boolean isOngoing() {
    131         return (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0;
    132     }
    133 
    134     public boolean isClearable() {
    135         return ((notification.flags & Notification.FLAG_ONGOING_EVENT) == 0)
    136                 && ((notification.flags & Notification.FLAG_NO_CLEAR) == 0);
    137     }
    138 }
    139 
    140 
    141