diff options
author | Joe Onorato <joeo@android.com> | 2010-05-17 22:26:12 -0700 |
---|---|---|
committer | Joe Onorato <joeo@android.com> | 2010-06-02 14:48:43 -0700 |
commit | 18e69dfc7235f8a4bfe257f9d1c43539049a22ce (patch) | |
tree | da47804d8acd8680cfdd0fb8fa33dad6e01889c1 /core | |
parent | 6528b35585020fafe7e39dfa416f728df5158c63 (diff) | |
download | frameworks_base-18e69dfc7235f8a4bfe257f9d1c43539049a22ce.zip frameworks_base-18e69dfc7235f8a4bfe257f9d1c43539049a22ce.tar.gz frameworks_base-18e69dfc7235f8a4bfe257f9d1c43539049a22ce.tar.bz2 |
Checkpoint. Data structures for Notifications in place.
Change-Id: I146fb9bc1d349112541368e2c99a667821dfdf6e
Diffstat (limited to 'core')
6 files changed, 349 insertions, 2 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 4d72f73..739aca3 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -341,6 +341,44 @@ public class Notification implements Parcelable iconLevel = parcel.readInt(); } + public Notification clone() { + Notification that = new Notification(); + + that.when = this.when; + that.icon = this.icon; + that.number = this.number; + + // PendingIntents are global, so there's no reason (or way) to clone them. + that.contentIntent = this.contentIntent; + that.deleteIntent = this.deleteIntent; + + if (this.tickerText != null) { + that.tickerText = this.tickerText.toString(); + } + if (this.contentView != null) { + that.contentView = this.contentView.clone(); + } + that.iconLevel = that.iconLevel; + that.sound = this.sound; // android.net.Uri is immutable + that.audioStreamType = this.audioStreamType; + + final long[] vibrate = this.vibrate; + if (vibrate != null) { + final int N = vibrate.length; + final long[] vib = that.vibrate = new long[N]; + System.arraycopy(vibrate, 0, vib, 0, N); + } + + that.ledARGB = this.ledARGB; + that.ledOnMS = this.ledOnMS; + that.ledOffMS = this.ledOffMS; + that.defaults = this.defaults; + + that.flags = this.flags; + + return that; + } + public int describeContents() { return 0; } diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java index 3003580..7a70c80 100644 --- a/core/java/android/widget/RemoteViews.java +++ b/core/java/android/widget/RemoteViews.java @@ -100,6 +100,7 @@ public class RemoteViews implements Parcelable, Filter { * Base class for all actions that can be performed on an * inflated view. * + * SUBCLASSES MUST BE IMMUTABLE SO CLONE WORKS!!!!! */ private abstract static class Action implements Parcelable { public abstract void apply(View root) throws ActionException; @@ -568,6 +569,14 @@ public class RemoteViews implements Parcelable, Filter { } } + public RemoteViews clone() { + final RemoteViews that = new RemoteViews(mPackage, mLayoutId); + if (mActions != null) { + that.mActions = (ArrayList<Action>)mActions.clone(); + } + return that; + } + public String getPackage() { return mPackage; } diff --git a/core/java/com/android/internal/statusbar/StatusBarIcon.java b/core/java/com/android/internal/statusbar/StatusBarIcon.java index 455e17b..e28325c 100644 --- a/core/java/com/android/internal/statusbar/StatusBarIcon.java +++ b/core/java/com/android/internal/statusbar/StatusBarIcon.java @@ -27,6 +27,7 @@ public class StatusBarIcon implements Parcelable { public int iconId; public int iconLevel; public boolean visible = true; + public int number; private StatusBarIcon() { } @@ -39,12 +40,14 @@ public class StatusBarIcon implements Parcelable { public String toString() { return "StatusBarIcon(pkg=" + this.iconPackage + " id=0x" + Integer.toHexString(this.iconId) - + " level=" + this.iconLevel + " visible=" + visible + ")"; + + " level=" + this.iconLevel + " visible=" + visible + + " num=" + this.number + " )"; } public StatusBarIcon clone() { StatusBarIcon that = new StatusBarIcon(this.iconPackage, this.iconId, this.iconLevel); that.visible = this.visible; + that.number = this.number; return that; } @@ -60,13 +63,14 @@ public class StatusBarIcon implements Parcelable { this.iconId = in.readInt(); this.iconLevel = in.readInt(); this.visible = in.readInt() != 0; + this.number = in.readInt(); } public void writeToParcel(Parcel out, int flags) { out.writeString(this.iconPackage); out.writeInt(this.iconId); out.writeInt(this.iconLevel); - out.writeInt(this.visible ? 1 : 0); + out.writeInt(this.number); } public int describeContents() { diff --git a/core/java/com/android/internal/statusbar/StatusBarNotification.java b/core/java/com/android/internal/statusbar/StatusBarNotification.java new file mode 100644 index 0000000..ba1525e --- /dev/null +++ b/core/java/com/android/internal/statusbar/StatusBarNotification.java @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.statusbar; + +import android.app.Notification; +import android.os.Parcel; +import android.os.Parcelable; +import android.widget.RemoteViews; + + +/* +boolean clearable = !n.ongoingEvent && ((notification.flags & Notification.FLAG_NO_CLEAR) == 0); + + +// TODO: make this restriction do something smarter like never fill +// more than two screens. "Why would anyone need more than 80 characters." :-/ +final int maxTickerLen = 80; +if (truncatedTicker != null && truncatedTicker.length() > maxTickerLen) { + truncatedTicker = truncatedTicker.subSequence(0, maxTickerLen); +} +*/ + +public class StatusBarNotification implements Parcelable { + public String pkg; + public int id; + public String tag; + Notification notification; + + public StatusBarNotification() { + } + + public StatusBarNotification(String pkg, int id, String tag, Notification notification) { + if (pkg == null) throw new NullPointerException(); + if (notification == null) throw new NullPointerException(); + + this.pkg = pkg; + this.id = id; + this.tag = tag; + this.notification = notification; + } + + public StatusBarNotification(Parcel in) { + readFromParcel(in); + } + + public void readFromParcel(Parcel in) { + this.pkg = in.readString(); + this.id = in.readInt(); + if (in.readInt() != 0) { + this.tag = in.readString(); + } else { + this.tag = null; + } + this.notification = new Notification(in); + } + + public void writeToParcel(Parcel out, int flags) { + out.writeString(this.pkg); + out.writeInt(this.id); + if (this.tag != null) { + out.writeInt(1); + out.writeString(this.tag); + } else { + out.writeInt(0); + } + this.notification.writeToParcel(out, flags); + } + + public int describeContents() { + return 0; + } + + public static final Parcelable.Creator<StatusBarNotification> CREATOR + = new Parcelable.Creator<StatusBarNotification>() + { + public StatusBarNotification createFromParcel(Parcel parcel) + { + return new StatusBarNotification(parcel); + } + + public StatusBarNotification[] newArray(int size) + { + return new StatusBarNotification[size]; + } + }; + + public StatusBarNotification clone() { + return new StatusBarNotification(this.pkg, this.id, this.tag, this.notification.clone()); + } + + public String toString() { + return "StatusBarNotification(package=" + pkg + " tag=" + tag + + " notification=" + notification + ")"; + } + +} + + diff --git a/core/java/com/android/internal/statusbar/StatusBarNotificationList.aidl b/core/java/com/android/internal/statusbar/StatusBarNotificationList.aidl new file mode 100644 index 0000000..10abeee --- /dev/null +++ b/core/java/com/android/internal/statusbar/StatusBarNotificationList.aidl @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.statusbar; + +parcelable StatusBarNotificationList; + diff --git a/core/java/com/android/internal/statusbar/StatusBarNotificationList.java b/core/java/com/android/internal/statusbar/StatusBarNotificationList.java new file mode 100644 index 0000000..2b70f5f --- /dev/null +++ b/core/java/com/android/internal/statusbar/StatusBarNotificationList.java @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.statusbar; + +import android.os.Binder; +import android.os.IBinder; +import android.os.Parcel; +import android.os.Parcelable; + +import java.io.PrintWriter; +import java.util.ArrayList; + +public class StatusBarNotificationList implements Parcelable { + private class Entry { + IBinder key; + public StatusBarNotification notification; + + void writeToParcel(Parcel out, int flags) { + out.writeStrongBinder(key); + notification.writeToParcel(out, flags); + } + + void readFromParcel(Parcel in) { + key = in.readStrongBinder(); + notification = new StatusBarNotification(in); + } + + public Entry clone() { + Entry that = new Entry(); + that.key = this.key; + that.notification = this.notification.clone(); + return that; + } + } + + private ArrayList<Entry> mEntries = new ArrayList<Entry>(); + + public StatusBarNotificationList() { + } + + public StatusBarNotificationList(Parcel in) { + readFromParcel(in); + } + + public void readFromParcel(Parcel in) { + final int N = in.readInt(); + for (int i=0; i<N; i++) { + Entry e = new Entry(); + e.readFromParcel(in); + mEntries.add(e); + } + } + + public void writeToParcel(Parcel out, int flags) { + final int N = mEntries.size(); + out.writeInt(N); + for (int i=0; i<N; i++) { + mEntries.get(i).writeToParcel(out, flags); + } + } + + public int describeContents() { + return 0; + } + + /** + * Parcelable.Creator that instantiates StatusBarNotificationList objects + */ + public static final Parcelable.Creator<StatusBarNotificationList> CREATOR + = new Parcelable.Creator<StatusBarNotificationList>() + { + public StatusBarNotificationList createFromParcel(Parcel parcel) + { + return new StatusBarNotificationList(parcel); + } + + public StatusBarNotificationList[] newArray(int size) + { + return new StatusBarNotificationList[size]; + } + }; + + public void copyFrom(StatusBarNotificationList that) { + mEntries.clear(); + final int N = that.mEntries.size(); + for (int i=0; i<N; i++) { + mEntries.add(that.mEntries.get(i).clone()); + } + } + + public void dump(PrintWriter pw) { + final int N = mEntries.size(); + pw.println("Notification list:"); + for (int i=0; i<N; i++) { + Entry e = mEntries.get(i); + pw.printf(" %2d: %s\n", i, e.notification.toString()); + } + } + + + public int size() { + return mEntries.size(); + } + + public IBinder add(StatusBarNotification notification) { + if (notification == null) throw new NullPointerException(); + + Entry entry = new Entry(); + entry.key = new Binder(); + entry.notification = notification.clone(); + + // TODO: Sort correctly by "when" + mEntries.add(entry); + + return entry.key; + } + + public void update(IBinder key, StatusBarNotification notification) { + final int index = getIndex(key); + if (index < 0) { + throw new IllegalArgumentException("got invalid key: " + key); + } + final Entry entry = mEntries.get(index); + entry.notification = notification.clone(); + } + + public void remove(IBinder key) { + final int index = getIndex(key); + if (index < 0) { + throw new IllegalArgumentException("got invalid key: " + key); + } + mEntries.remove(index); + } + + public int getIndex(IBinder key) { + final ArrayList<Entry> entries = mEntries; + final int N = entries.size(); + for (int i=0; i<N; i++) { + if (entries.get(i).key == key) { + return i; + } + } + return -1; + } + + public StatusBarNotification getNotification(int index) { + return mEntries.get(index).notification; + } +} + |