2023-09-12 23:18:47 +02:00
|
|
|
package android.app;
|
|
|
|
|
|
2024-03-17 11:05:42 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2023-09-21 22:49:36 +02:00
|
|
|
import android.content.Context;
|
|
|
|
|
import android.graphics.Bitmap;
|
2024-12-10 23:23:14 +01:00
|
|
|
import android.graphics.drawable.Icon;
|
2023-09-12 23:18:47 +02:00
|
|
|
import android.media.AudioAttributes;
|
2023-09-21 22:49:36 +02:00
|
|
|
import android.media.session.MediaSession;
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
import android.os.Bundle;
|
2024-06-13 21:00:06 +02:00
|
|
|
import android.os.Parcelable;
|
2023-09-21 22:49:36 +02:00
|
|
|
import android.widget.RemoteViews;
|
2023-09-12 23:18:47 +02:00
|
|
|
|
2024-06-13 21:00:06 +02:00
|
|
|
public class Notification implements Parcelable {
|
2023-09-12 23:18:47 +02:00
|
|
|
|
|
|
|
|
public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes();
|
2023-09-21 22:49:36 +02:00
|
|
|
|
|
|
|
|
public long when;
|
|
|
|
|
|
|
|
|
|
public int audioStreamType;
|
|
|
|
|
|
|
|
|
|
public int icon;
|
|
|
|
|
|
|
|
|
|
public PendingIntent deleteIntent;
|
|
|
|
|
|
|
|
|
|
public CharSequence tickerText;
|
|
|
|
|
|
|
|
|
|
public int iconLevel;
|
|
|
|
|
|
|
|
|
|
public RemoteViews contentView;
|
|
|
|
|
|
|
|
|
|
public long[] vibrate;
|
|
|
|
|
|
|
|
|
|
public int ledARGB;
|
|
|
|
|
|
|
|
|
|
public int ledOnMS;
|
|
|
|
|
|
|
|
|
|
public int ledOffMS;
|
|
|
|
|
|
|
|
|
|
public int flags;
|
|
|
|
|
|
|
|
|
|
public int defaults;
|
|
|
|
|
|
|
|
|
|
public Uri sound;
|
|
|
|
|
|
|
|
|
|
public AudioAttributes audioAttributes;
|
|
|
|
|
|
|
|
|
|
public Bundle extras;
|
|
|
|
|
|
2024-03-17 11:05:42 +01:00
|
|
|
String text;
|
|
|
|
|
String title;
|
|
|
|
|
List<Action> actions = new ArrayList<Action>();
|
|
|
|
|
PendingIntent intent;
|
2024-03-18 14:37:56 +01:00
|
|
|
String iconPath;
|
2024-03-18 15:41:44 +01:00
|
|
|
boolean ongoing;
|
2024-07-15 16:39:45 +02:00
|
|
|
Style style;
|
2024-03-17 11:05:42 +01:00
|
|
|
|
|
|
|
|
public String toString() {
|
|
|
|
|
return "Notification [" + title + ", " + text + ", " + actions + "]";
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-12 10:42:51 +01:00
|
|
|
public String getGroup() {return null;}
|
|
|
|
|
|
2023-09-21 22:49:36 +02:00
|
|
|
public static class Builder {
|
2024-03-17 11:05:42 +01:00
|
|
|
private Notification notification;
|
|
|
|
|
|
|
|
|
|
public Builder(Context context) {
|
|
|
|
|
notification = new Notification();
|
|
|
|
|
}
|
2023-09-21 22:49:36 +02:00
|
|
|
|
2024-12-10 23:23:14 +01:00
|
|
|
public Builder(Context context, String tag) {
|
|
|
|
|
this(context);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 22:49:36 +02:00
|
|
|
public Builder setWhen(long when) {return this;}
|
|
|
|
|
|
2024-03-18 14:37:56 +01:00
|
|
|
public Builder setSmallIcon(int icon, int level) {
|
|
|
|
|
notification.iconPath = Context.this_application.getString(icon);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2023-09-21 22:49:36 +02:00
|
|
|
|
|
|
|
|
public Builder setContent(RemoteViews contentView) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setTicker(CharSequence tickerText, RemoteViews contentView) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setVibrate(long[] pattern) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setLights(int argb, int onMs, int offMs) {return this;}
|
|
|
|
|
|
2024-03-18 15:41:44 +01:00
|
|
|
public Builder setOngoing(boolean ongoing) {
|
|
|
|
|
notification.ongoing = ongoing;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2023-09-21 22:49:36 +02:00
|
|
|
|
|
|
|
|
public Builder setOnlyAlertOnce(boolean onlyAlertOnce) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setAutoCancel(boolean autoCancel) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setDefaults(int defaults) {return this;}
|
|
|
|
|
|
2024-03-17 11:05:42 +01:00
|
|
|
public Builder setContentTitle(CharSequence title) {
|
|
|
|
|
notification.title = title != null ? title.toString() : null;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2023-09-21 22:49:36 +02:00
|
|
|
|
2024-03-17 11:05:42 +01:00
|
|
|
public Builder setContentText(CharSequence text) {
|
|
|
|
|
notification.text = text != null ? text.toString() : null;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2023-09-21 22:49:36 +02:00
|
|
|
|
|
|
|
|
public Builder setContentInfo(CharSequence info) {return this;}
|
|
|
|
|
|
2024-03-17 11:05:42 +01:00
|
|
|
public Builder setContentIntent(PendingIntent intent) {
|
|
|
|
|
notification.intent = intent;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2023-09-21 22:49:36 +02:00
|
|
|
|
|
|
|
|
public Builder setDeleteIntent(PendingIntent intent) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setLargeIcon(Bitmap icon) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setNumber(int number) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setProgress(int max, int progress, boolean indeterminate) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setSubText(CharSequence subText) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setUsesChronometer(boolean useChronometer) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setPriority(int priority) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setShowWhen(boolean showWhen) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setLocalOnly(boolean localOnly) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setGroup(String group) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setSortKey(String sortKey) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setGroupSummary(boolean isGroupSummary) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setCategory(String category) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setColor(int argb) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setVisibility(int visibility) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setPublicVersion(Notification notification) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setSound(Uri sound, AudioAttributes audioAttributes) {return this;}
|
|
|
|
|
|
2024-03-17 11:05:42 +01:00
|
|
|
public Builder addAction(Action action) {
|
|
|
|
|
notification.actions.add(action);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2023-09-21 22:49:36 +02:00
|
|
|
|
2024-03-18 15:41:44 +01:00
|
|
|
public Builder setStyle(Style style) {
|
2024-07-15 16:39:45 +02:00
|
|
|
notification.style = style;
|
2024-03-18 15:41:44 +01:00
|
|
|
if (style instanceof MediaStyle) {
|
|
|
|
|
notification.ongoing = true;
|
|
|
|
|
}
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2023-09-21 22:49:36 +02:00
|
|
|
|
|
|
|
|
public Builder setExtras(Bundle extras) {return this;}
|
|
|
|
|
|
2024-12-10 23:23:14 +01:00
|
|
|
public Builder setLargeIcon(Icon icon) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setRemoteInputHistory(CharSequence[] history) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setBadgeIconType(int iconType) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setSettingsText(CharSequence settingsText) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setShortcutId(String shortcutId) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setTimeoutAfter(long timeout) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setGroupAlertBehavior(int groupAlertBehavior) {return this;}
|
|
|
|
|
|
|
|
|
|
public Builder setSound(Uri sound) {return this;}
|
|
|
|
|
|
2023-09-21 22:49:36 +02:00
|
|
|
public Notification build() {
|
2024-03-17 11:05:42 +01:00
|
|
|
return notification;
|
2023-09-21 22:49:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class Action {
|
2024-03-17 11:05:42 +01:00
|
|
|
|
|
|
|
|
int icon;
|
|
|
|
|
String title;
|
|
|
|
|
PendingIntent intent;
|
|
|
|
|
|
|
|
|
|
public String toString() {
|
|
|
|
|
return "Action [" + icon + ", " + title + ", " + intent + "]";
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 22:49:36 +02:00
|
|
|
public static final class Builder {
|
|
|
|
|
|
2024-03-17 11:05:42 +01:00
|
|
|
private Action action;
|
|
|
|
|
public Builder(int icon, CharSequence title, PendingIntent intent) {
|
|
|
|
|
action = new Action();
|
|
|
|
|
action.icon = icon;
|
|
|
|
|
action.title = String.valueOf(title);
|
|
|
|
|
action.intent = intent;
|
|
|
|
|
}
|
2023-09-21 22:49:36 +02:00
|
|
|
|
2024-12-10 23:23:14 +01:00
|
|
|
public Builder(Icon icon, CharSequence title, PendingIntent intent) {
|
|
|
|
|
this(0, title, intent);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 22:49:36 +02:00
|
|
|
public Builder addExtras(Bundle extras) {return this;}
|
|
|
|
|
|
2024-08-25 11:20:01 +02:00
|
|
|
public Builder addRemoteInput(RemoteInput remoteInput) {return this;}
|
|
|
|
|
|
2024-12-10 23:23:14 +01:00
|
|
|
public Builder setAllowGeneratedReplies(boolean allowGeneratedReplies) {return this;}
|
|
|
|
|
|
2023-09-21 22:49:36 +02:00
|
|
|
public Action build() {
|
2024-03-17 11:05:42 +01:00
|
|
|
return action;
|
2023-09-21 22:49:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static abstract class Style {}
|
|
|
|
|
|
|
|
|
|
public static class MediaStyle extends Style {
|
|
|
|
|
|
|
|
|
|
public MediaStyle setShowActionsInCompactView(int... viewActions) {return this;}
|
|
|
|
|
|
|
|
|
|
public MediaStyle setMediaSession(MediaSession.Token token) {return this;}
|
|
|
|
|
}
|
2024-03-16 12:49:28 +01:00
|
|
|
|
|
|
|
|
public static class BigTextStyle extends Style {
|
|
|
|
|
|
|
|
|
|
public BigTextStyle(Notification.Builder builder) {}
|
|
|
|
|
|
|
|
|
|
public BigTextStyle setBigContentTitle(CharSequence title) {return this;}
|
|
|
|
|
|
|
|
|
|
public BigTextStyle bigText(CharSequence text) {return this;}
|
2024-08-25 11:20:01 +02:00
|
|
|
|
|
|
|
|
public BigTextStyle setSummaryText(CharSequence summaryText) {return this;}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class InboxStyle extends Style {
|
|
|
|
|
|
|
|
|
|
public InboxStyle(Notification.Builder builder) {}
|
|
|
|
|
|
|
|
|
|
public InboxStyle setBigContentTitle(CharSequence title) {return this;}
|
|
|
|
|
|
|
|
|
|
public InboxStyle setSummaryText(CharSequence summaryText) {return this;}
|
|
|
|
|
|
|
|
|
|
public InboxStyle addLine(CharSequence line) {return this;}
|
|
|
|
|
|
2024-03-16 12:49:28 +01:00
|
|
|
}
|
2023-09-12 23:18:47 +02:00
|
|
|
}
|