Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 46439cec authored by Joe Onorato's avatar Joe Onorato
Browse files

Update the look of the notifications. Includes adding a new Notification.Builder class.

Change-Id: I7c57b81c45defe77d6f3d22472e9cf8432bbed03
parent 80404319
Loading
Loading
Loading
Loading
+326 −22
Original line number Diff line number Diff line
@@ -32205,7 +32205,7 @@
 type="android.app.Notification"
 static="false"
 final="false"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<parameter name="icon" type="int">
@@ -32254,7 +32254,7 @@
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<parameter name="context" type="android.content.Context">
@@ -32524,6 +32524,16 @@
 visibility="public"
>
</field>
<field name="largeIcon"
 type="android.graphics.Bitmap"
 transient="false"
 volatile="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="ledARGB"
 type="int"
 transient="false"
@@ -32574,19 +32584,18 @@
 visibility="public"
>
</field>
<field name="tickerIcons"
 type="android.graphics.Bitmap[]"
<field name="tickerText"
 type="java.lang.CharSequence"
 transient="false"
 volatile="false"
 value="null"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="tickerSubtitle"
 type="java.lang.CharSequence"
<field name="tickerView"
 type="android.widget.RemoteViews"
 transient="false"
 volatile="false"
 static="false"
@@ -32595,18 +32604,19 @@
 visibility="public"
>
</field>
<field name="tickerText"
 type="java.lang.CharSequence"
<field name="vibrate"
 type="long[]"
 transient="false"
 volatile="false"
 value="null"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="tickerTitle"
 type="java.lang.CharSequence"
<field name="when"
 type="long"
 transient="false"
 volatile="false"
 static="false"
@@ -32615,27 +32625,321 @@
 visibility="public"
>
</field>
<field name="vibrate"
 type="long[]"
 transient="false"
 volatile="false"
 value="null"
</class>
<class name="Notification.Builder"
 extends="java.lang.Object"
 abstract="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<constructor name="Notification.Builder"
 type="android.app.Notification.Builder"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="when"
 type="long"
 transient="false"
 volatile="false"
<parameter name="context" type="android.content.Context">
</parameter>
</constructor>
<method name="getNotification"
 return="android.app.Notification"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</method>
<method name="setAutoCancel"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="autoCancel" type="boolean">
</parameter>
</method>
<method name="setContent"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="views" type="android.widget.RemoteViews">
</parameter>
</method>
<method name="setContentInfo"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="info" type="java.lang.CharSequence">
</parameter>
</method>
<method name="setContentIntent"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="intent" type="android.app.PendingIntent">
</parameter>
</method>
<method name="setContentText"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="text" type="java.lang.CharSequence">
</parameter>
</method>
<method name="setContentTitle"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="title" type="java.lang.CharSequence">
</parameter>
</method>
<method name="setDefaults"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="defaults" type="int">
</parameter>
</method>
<method name="setDeleteIntent"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="intent" type="android.app.PendingIntent">
</parameter>
</method>
<method name="setFullScreenIntent"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="intent" type="android.app.PendingIntent">
</parameter>
<parameter name="highPriority" type="boolean">
</parameter>
</method>
<method name="setLargeIcon"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="icon" type="android.graphics.Bitmap">
</parameter>
</method>
<method name="setLights"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="argb" type="int">
</parameter>
<parameter name="onMs" type="int">
</parameter>
<parameter name="offMs" type="int">
</parameter>
</method>
<method name="setOngoing"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="ongoing" type="boolean">
</parameter>
</method>
<method name="setOnlyAlertOnce"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="onlyAlertOnce" type="boolean">
</parameter>
</method>
<method name="setSmallIcon"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="icon" type="int">
</parameter>
</method>
<method name="setSmallIcon"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="icon" type="int">
</parameter>
<parameter name="level" type="int">
</parameter>
</method>
<method name="setSmallIconNumber"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="number" type="int">
</parameter>
</method>
<method name="setSound"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="sound" type="android.net.Uri">
</parameter>
<parameter name="streamType" type="int">
</parameter>
</method>
<method name="setTicker"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="tickerText" type="java.lang.CharSequence">
</parameter>
</method>
<method name="setTicker"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="tickerText" type="java.lang.CharSequence">
</parameter>
<parameter name="views" type="android.widget.RemoteViews">
</parameter>
</method>
<method name="setVibrate"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="pattern" type="long[]">
</parameter>
</method>
<method name="setWhen"
 return="android.app.Notification.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="when" type="long">
</parameter>
</method>
</class>
<class name="NotificationManager"
 extends="java.lang.Object"
+240 −81
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.Parcelable;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
import android.util.Slog;
import android.widget.RemoteViews;

/**
@@ -41,6 +42,8 @@ import android.widget.RemoteViews;
 */
public class Notification implements Parcelable
{
    private static final String TAG = "Notification";

    /**
     * Use all default values (where applicable).
     */
@@ -83,6 +86,15 @@ public class Notification implements Parcelable
     */
    public int icon;

    /**
     * If the icon in the status bar is to have more than one level, you can set this.  Otherwise,
     * leave it at its default value of 0.
     *
     * @see android.widget.ImageView#setImageLevel
     * @see android.graphics.drawable#setLevel
     */
    public int iconLevel;

    /**
     * The number of events that this notification represents.  For example, in a new mail
     * notification, this could be the number of unread messages.  This number is superimposed over
@@ -132,38 +144,15 @@ public class Notification implements Parcelable
     * text for when the text scrolls in and when it is displayed all at once
     * in conjunction with one or more icons.
     *
     * @see #tickerTitle
     * @see #tickerSubtitle
     * @see #tickerIcons
     * @see #tickerView
     */
    public CharSequence tickerText;

    /**
     * The title line for the ticker over a the fat status bar on xlarge devices.
     *
     * @see #tickerText
     * @see #tickerSubtitle
     * @see #tickerIcons
     */
    public CharSequence tickerTitle;

    /**
     * The subtitle line for the ticker over a the fat status bar on xlarge devices.
     *
     * @see #tickerText
     * @see #tickerTitle
     * @see #tickerIcons
     * The view to show as the ticker in the status bar when the notification
     * is posted.
     */
    public CharSequence tickerSubtitle;

    /**
     * The icons to show to the left of the other ticker fields.
     *
     * @see #tickerText
     * @see #tickerTitle
     * @see #tickerSubtitle
     */
    public Bitmap[] tickerIcons;
    public RemoteViews tickerView;

    /**
     * The view that will represent this notification in the expanded status bar.
@@ -171,13 +160,9 @@ public class Notification implements Parcelable
    public RemoteViews contentView;

    /**
     * If the icon in the status bar is to have more than one level, you can set this.  Otherwise,
     * leave it at its default value of 0.
     *
     * @see android.widget.ImageView#setImageLevel
     * @see android.graphics.drawable#setLevel
     * The bitmap that may escape the bounds of the panel and bar.
     */
    public int iconLevel;
    public Bitmap largeIcon;

    /**
     * The sound to play.
@@ -327,6 +312,7 @@ public class Notification implements Parcelable

    /**
     * Constructs a Notification object with everything set to 0.
     * You might want to consider using {@link Builder} instead.
     */
    public Notification()
    {
@@ -334,7 +320,6 @@ public class Notification implements Parcelable
    }

    /**
     * @deprecated use {@link #Notification(int,CharSequence,long)} and {@link #setLatestEventInfo}.
     * @hide
     */
    public Notification(Context context, int icon, CharSequence tickerText, long when,
@@ -356,7 +341,10 @@ public class Notification implements Parcelable
     *                      activates.
     * @param when          The time to show in the time field.  In the System.currentTimeMillis
     *                      timebase.
     *
     * @deprecated Use {@link Builder} instead.
     */
    @Deprecated
    public Notification(int icon, CharSequence tickerText, long when)
    {
        this.icon = icon;
@@ -384,19 +372,7 @@ public class Notification implements Parcelable
            tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
        }
        if (parcel.readInt() != 0) {
            tickerTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
        }
        if (parcel.readInt() != 0) {
            tickerSubtitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
        }
        final int tickerIconCount = parcel.readInt();
        if (tickerIconCount >= 0) {
            tickerIcons = new Bitmap[tickerIconCount];
            for (int i=0; i<tickerIconCount; i++) {
                if (parcel.readInt() != 0) {
                    tickerIcons[i] = Bitmap.CREATOR.createFromParcel(parcel);
                }
            }
            tickerView = RemoteViews.CREATOR.createFromParcel(parcel);
        }
        if (parcel.readInt() != 0) {
            contentView = RemoteViews.CREATOR.createFromParcel(parcel);
@@ -434,18 +410,8 @@ public class Notification implements Parcelable
        if (this.tickerText != null) {
            that.tickerText = this.tickerText.toString();
        }
        if (this.tickerTitle != null) {
            that.tickerTitle = this.tickerTitle.toString();
        }
        if (this.tickerSubtitle != null) {
            that.tickerSubtitle = this.tickerSubtitle.toString();
        }
        if (this.tickerIcons != null) {
            final int N = this.tickerIcons.length;
            that.tickerIcons = new Bitmap[N];
            for (int i=0; i<N; i++) {
                that.tickerIcons[i] = Bitmap.createBitmap(this.tickerIcons[i]);
            }
        if (this.tickerView != null) {
            that.tickerView = this.tickerView.clone();
        }
        if (this.contentView != null) {
            that.contentView = this.contentView.clone();
@@ -503,32 +469,12 @@ public class Notification implements Parcelable
        } else {
            parcel.writeInt(0);
        }
        if (tickerTitle != null) {
            parcel.writeInt(1);
            TextUtils.writeToParcel(tickerTitle, parcel, flags);
        } else {
            parcel.writeInt(0);
        }
        if (tickerSubtitle != null) {
            parcel.writeInt(1);
            TextUtils.writeToParcel(tickerSubtitle, parcel, flags);
        } else {
            parcel.writeInt(0);
        }
        if (tickerIcons != null) {
            final int N = tickerIcons.length;
            parcel.writeInt(N);
            for (int i=0; i<N; i++) {
                if (tickerIcons[i] != null) {
        if (tickerView != null) {
            parcel.writeInt(1);
                    tickerIcons[i].writeToParcel(parcel, flags);
            tickerView.writeToParcel(parcel, 0);
        } else {
            parcel.writeInt(0);
        }
            }
        } else {
            parcel.writeInt(-1);
        }
        if (contentView != null) {
            parcel.writeInt(1);
            contentView.writeToParcel(parcel, 0);
@@ -591,7 +537,10 @@ public class Notification implements Parcelable
     * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
     * that you take care of task management as described in 
     * <a href="{@docRoot}guide/topics/fundamentals.html#lcycles">Application Fundamentals: Activities and Tasks</a>.
     * 
     * @deprecated Use {@link Builder} instead.
     */
    @Deprecated
    public void setLatestEventInfo(Context context,
            CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) {
        RemoteViews contentView = new RemoteViews(context.getPackageName(),
@@ -651,4 +600,214 @@ public class Notification implements Parcelable
        sb.append(")");
        return sb.toString();
    }

    public static class Builder {
        private Context mContext;

        private long mWhen;
        private int mSmallIcon;
        private int mSmallIconLevel;
        private int mSmallIconNumber;
        private CharSequence mContentTitle;
        private CharSequence mContentText;
        private CharSequence mContentInfo;
        private PendingIntent mContentIntent;
        private RemoteViews mContentView;
        private PendingIntent mDeleteIntent;
        private PendingIntent mFullScreenIntent;
        private CharSequence mTickerText;
        private RemoteViews mTickerView;
        private Bitmap mLargeIcon;
        private Uri mSound;
        private int mAudioStreamType;
        private long[] mVibrate;
        private int mLedArgb;
        private int mLedOnMs;
        private int mLedOffMs;
        private int mDefaults;
        private int mFlags;

        public Builder(Context context) {
            mContext = context;
            mWhen = System.currentTimeMillis();
        }

        public Builder setWhen(long when) {
            mWhen = when;
            return this;
        }

        public Builder setSmallIcon(int icon) {
            mSmallIcon = icon;
            return this;
        }

        public Builder setSmallIcon(int icon, int level) {
            mSmallIcon = icon;
            mSmallIconLevel = level;
            return this;
        }

        public Builder setSmallIconNumber(int number) {
            mSmallIconNumber = number;
            return this;
        }

        public Builder setContentTitle(CharSequence title) {
            mContentTitle = title;
            return this;
        }

        public Builder setContentText(CharSequence text) {
            mContentText = text;
            return this;
        }

        public Builder setContentInfo(CharSequence info) {
            mContentInfo = info;
            return this;
        }

        public Builder setContent(RemoteViews views) {
            mContentView = views;
            return this;
        }

        public Builder setContentIntent(PendingIntent intent) {
            mContentIntent = intent;
            return this;
        }

        public Builder setDeleteIntent(PendingIntent intent) {
            mDeleteIntent = intent;
            return this;
        }

        public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) {
            mFullScreenIntent = intent;
            setFlag(FLAG_HIGH_PRIORITY, highPriority);
            return this;
        }

        public Builder setTicker(CharSequence tickerText) {
            mTickerText = tickerText;
            return this;
        }

        public Builder setTicker(CharSequence tickerText, RemoteViews views) {
            mTickerText = tickerText;
            mTickerView = views;
            return this;
        }

        public Builder setLargeIcon(Bitmap icon) {
            mLargeIcon = icon;
            return this;
        }

        public Builder setSound(Uri sound, int streamType) {
            mSound = sound;
            mAudioStreamType = streamType;
            return this;
        }

        public Builder setVibrate(long[] pattern) {
            mVibrate = pattern;
            return this;
        }

        public Builder setLights(int argb, int onMs, int offMs) {
            mLedArgb = argb;
            mLedOnMs = onMs;
            mLedOffMs = offMs;
            mFlags |= FLAG_SHOW_LIGHTS;
            return this;
        }

        public Builder setOngoing(boolean ongoing) {
            setFlag(FLAG_ONGOING_EVENT, ongoing);
            return this;
        }

        public Builder setOnlyAlertOnce(boolean onlyAlertOnce) {
            setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce);
            return this;
        }

        public Builder setAutoCancel(boolean autoCancel) {
            setFlag(FLAG_ONLY_ALERT_ONCE, autoCancel);
            return this;
        }

        public Builder setDefaults(int defaults) {
            mDefaults = defaults;
            return this;
        }

        private void setFlag(int mask, boolean value) {
            if (value) {
                mFlags |= mask;
            } else {
                mFlags &= ~mask;
            }
        }

        private RemoteViews makeContentView() {
            if (mContentView != null) {
                return mContentView;
            } else {
                RemoteViews contentView = new RemoteViews(mContext.getPackageName(),
                        com.android.internal.R.layout.status_bar_latest_event_content);
                if (mSmallIcon != 0) {
                    contentView.setImageViewResource(com.android.internal.R.id.icon, mSmallIcon);
                }
                if (mContentTitle != null) {
                    contentView.setTextViewText(com.android.internal.R.id.title, mContentTitle);
                }
                if (mContentText != null) {
                    contentView.setTextViewText(com.android.internal.R.id.text, mContentText);
                }
                //TODO
                //if (mContentInfo) {
                //    contentVeiw.setTextViewText(com.android.internal.R.id.info, mContentInfo);
                //}
                if (mWhen != 0) {
                    contentView.setLong(com.android.internal.R.id.time, "setTime", mWhen);
                }
                return contentView;
            }
        }

        private RemoteViews makeTickerView() {
            if (mTickerView != null) {
                return mTickerView;
            } else {
                return makeContentView();
            }
        }

        public Notification getNotification() {
            Notification n = new Notification();
            n.when = mWhen;
            n.icon = mSmallIcon;
            n.iconLevel = mSmallIconLevel;
            n.number = mSmallIconNumber;
            n.contentView = makeContentView();
            n.contentIntent = mContentIntent;
            n.deleteIntent = mDeleteIntent;
            n.fullScreenIntent = mFullScreenIntent;
            n.tickerText = mTickerText;
            n.tickerView = makeTickerView();
            n.largeIcon = mLargeIcon;
            n.sound = mSound;
            n.audioStreamType = mAudioStreamType;
            n.vibrate = mVibrate;
            n.ledARGB = mLedArgb;
            n.ledOnMS = mLedOnMs;
            n.ledOffMS = mLedOffMs;
            n.defaults = mDefaults;
            n.flags = mFlags;
            return n;
        }
    }
}
+27 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 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.
-->

<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:opacity="translucent"
    >
    <!-- the large icon extends 12dp beyond the edge of the status bar -->
    <item
        android:drawable="@drawable/notification_item_background_color"
        android:top="12dp"
        />
</layer-list>
+1 −1
Original line number Diff line number Diff line
@@ -242,7 +242,7 @@
        <!-- ticker: transient incoming notification information -->
        <FrameLayout
            android:id="@+id/ticker"
            android:layout_width="wrap_content"
            android:layout_width="392dp"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:layout_toRightOf="@+id/systemInfo"
+4 −27
Original line number Diff line number Diff line
@@ -18,36 +18,13 @@
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="#ff000000"
    >
    <!--
    android:background="@drawable/ticker_background"
    -->

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="center_vertical"
        android:orientation="vertical"
        android:paddingLeft="12dp"
        >

        <TextView android:id="@+id/title"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:textAppearance="@*android:style/TextAppearance.StatusBar.Ticker"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:maxLines="1"
            />
        <TextView android:id="@+id/subtitle"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:textAppearance="@*android:style/TextAppearance.StatusBar.Ticker"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="1"
            />
    </LinearLayout>

</LinearLayout>
Loading