mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
Remove own Notification.Builder abstraction.
Replace it by NotificationCompat.Builder, which is in the support library we're using anyway.
This commit is contained in:
parent
68dfde00f1
commit
565fef0cea
@ -32,6 +32,7 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.os.Process;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
@ -45,7 +46,6 @@ import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.R;
|
||||
import com.fsck.k9.activity.FolderList;
|
||||
import com.fsck.k9.activity.MessageList;
|
||||
import com.fsck.k9.helper.NotificationBuilder;
|
||||
import com.fsck.k9.helper.power.TracingPowerManager;
|
||||
import com.fsck.k9.helper.power.TracingPowerManager.TracingWakeLock;
|
||||
import com.fsck.k9.mail.Address;
|
||||
@ -3071,7 +3071,7 @@ public class MessagingController implements Runnable {
|
||||
NotificationManager notifMgr =
|
||||
(NotificationManager) mApplication.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
NotificationBuilder builder = NotificationBuilder.createInstance(mApplication);
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(mApplication);
|
||||
builder.setSmallIcon(R.drawable.ic_menu_refresh);
|
||||
builder.setWhen(System.currentTimeMillis());
|
||||
builder.setOngoing(true);
|
||||
@ -3121,7 +3121,7 @@ public class MessagingController implements Runnable {
|
||||
NotificationManager notifMgr =
|
||||
(NotificationManager) mApplication.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
NotificationBuilder builder = NotificationBuilder.createInstance(mApplication);
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(mApplication);
|
||||
builder.setSmallIcon(R.drawable.stat_notify_email_generic);
|
||||
builder.setWhen(System.currentTimeMillis());
|
||||
builder.setAutoCancel(true);
|
||||
@ -3156,7 +3156,7 @@ public class MessagingController implements Runnable {
|
||||
final NotificationManager notifMgr =
|
||||
(NotificationManager) mApplication.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
NotificationBuilder builder = NotificationBuilder.createInstance(mApplication);
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(mApplication);
|
||||
builder.setSmallIcon(R.drawable.ic_menu_refresh);
|
||||
builder.setWhen(System.currentTimeMillis());
|
||||
builder.setOngoing(true);
|
||||
@ -4422,7 +4422,7 @@ public class MessagingController implements Runnable {
|
||||
NotificationManager notifMgr =
|
||||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
NotificationBuilder builder = NotificationBuilder.createInstance(context);
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||
builder.setSmallIcon(R.drawable.stat_notify_email_generic);
|
||||
builder.setWhen(System.currentTimeMillis());
|
||||
builder.setTicker(messageNotice);
|
||||
@ -4464,7 +4464,7 @@ public class MessagingController implements Runnable {
|
||||
K9.NOTIFICATION_LED_BLINK_SLOW,
|
||||
ringAndVibrate);
|
||||
|
||||
notifMgr.notify(account.getAccountNumber(), builder.getNotification());
|
||||
notifMgr.notify(account.getAccountNumber(), builder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4485,7 +4485,7 @@ public class MessagingController implements Runnable {
|
||||
* @param ringAndVibrate
|
||||
* {@code true}, if ringtone/vibration are allowed. {@code false}, otherwise.
|
||||
*/
|
||||
private void configureNotification(NotificationBuilder builder, String ringtone,
|
||||
private void configureNotification(NotificationCompat.Builder builder, String ringtone,
|
||||
long[] vibrationPattern, Integer ledColor, int ledSpeed, boolean ringAndVibrate) {
|
||||
|
||||
// if it's quiet time, then we shouldn't be ringing, buzzing or flashing
|
||||
|
@ -1,164 +0,0 @@
|
||||
package com.fsck.k9.helper;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Vibrator;
|
||||
|
||||
/**
|
||||
* Helper class to create system notifications
|
||||
*
|
||||
* @see NotificationBuilderApi1
|
||||
* @see NotificationBuilderApi11
|
||||
*/
|
||||
public abstract class NotificationBuilder {
|
||||
|
||||
/**
|
||||
* Create instance of an API-specific {@code NotificationBuilder} subclass.
|
||||
*
|
||||
* @param context
|
||||
* A {@link Context} instance.
|
||||
*
|
||||
* @return Appropriate {@link NotificationBuilder} instance for this device.
|
||||
*/
|
||||
public static NotificationBuilder createInstance(Context context) {
|
||||
Context appContext = context.getApplicationContext();
|
||||
|
||||
NotificationBuilder instance;
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
||||
instance = new NotificationBuilderApi1(appContext);
|
||||
} else {
|
||||
instance = new NotificationBuilderApi11(appContext);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
protected Context mContext;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param context
|
||||
* A {@link Context} instance.
|
||||
*/
|
||||
protected NotificationBuilder(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the small icon to use in the notification layouts.
|
||||
*
|
||||
* @param icon
|
||||
* A resource ID in the application's package of the drawble to use.
|
||||
*/
|
||||
public abstract void setSmallIcon(int icon);
|
||||
|
||||
/**
|
||||
* Set the time that the event occurred.
|
||||
*
|
||||
* @param when
|
||||
* Timestamp of when the event occurred.
|
||||
*/
|
||||
public abstract void setWhen(long when);
|
||||
|
||||
/**
|
||||
* Set the text that is displayed in the status bar when the notification first arrives.
|
||||
*
|
||||
* @param tickerText
|
||||
* The text to display.
|
||||
*/
|
||||
public abstract void setTicker(CharSequence tickerText);
|
||||
|
||||
/**
|
||||
* Set the title (first row) of the notification, in a standard notification.
|
||||
*
|
||||
* @param title
|
||||
* The text to display as notification title.
|
||||
*/
|
||||
public abstract void setContentTitle(CharSequence title);
|
||||
|
||||
/**
|
||||
* Set the text (second row) of the notification, in a standard notification.
|
||||
*
|
||||
* @param text
|
||||
* The text to display.
|
||||
*/
|
||||
public abstract void setContentText(CharSequence text);
|
||||
|
||||
/**
|
||||
* Supply a PendingIntent to send when the notification is clicked.
|
||||
*
|
||||
* @param intent
|
||||
* The intent that will be sent when the notification was clicked.
|
||||
*/
|
||||
public abstract void setContentIntent(PendingIntent intent);
|
||||
|
||||
/**
|
||||
* Set the large number at the right-hand side of the notification.
|
||||
*
|
||||
* @param number
|
||||
* The number to display in the notification.
|
||||
*/
|
||||
public abstract void setNumber(int number);
|
||||
|
||||
/**
|
||||
* Set whether this is an ongoing notification.
|
||||
*
|
||||
* @param ongoing
|
||||
* {@code true}, if it this is an ongoing notification. {@code false}, otherwise.
|
||||
*/
|
||||
public abstract void setOngoing(boolean ongoing);
|
||||
|
||||
/**
|
||||
* Setting this flag will make it so the notification is automatically canceled when the user
|
||||
* clicks it in the panel.
|
||||
*
|
||||
* @param autoCancel
|
||||
* {@code true}, if the notification should be automatically cancelled when the user
|
||||
* clicks on it. {@code false}, otherwise.
|
||||
*/
|
||||
public abstract void setAutoCancel(boolean autoCancel);
|
||||
|
||||
/**
|
||||
* Set the sound to play.
|
||||
*
|
||||
* It will play on the notification stream.
|
||||
*
|
||||
* @param sound
|
||||
* The URI of the sound to play.
|
||||
*/
|
||||
public abstract void setSound(Uri sound);
|
||||
|
||||
/**
|
||||
* Set the vibration pattern to use.
|
||||
*
|
||||
* @param pattern
|
||||
* An array of longs of times for which to turn the vibrator on or off.
|
||||
*
|
||||
* @see Vibrator#vibrate(long[], int)
|
||||
*/
|
||||
public abstract void setVibrate(long[] pattern);
|
||||
|
||||
/**
|
||||
* Set the color that you would like the LED on the device to blink, as well as the rate.
|
||||
*
|
||||
* @param argb
|
||||
* The color the LED should blink.
|
||||
* @param onMs
|
||||
* The number of milliseconds the LED should be on.
|
||||
* @param offMs
|
||||
* The number of milliseconds the LED should be off.
|
||||
*/
|
||||
public abstract void setLights(int argb, int onMs, int offMs);
|
||||
|
||||
/**
|
||||
* Combine all of the options that have been set and return a new {@link Notification} object.
|
||||
*
|
||||
* @return A new {@code Notification} object configured by this {@link NotificationBuilder}.
|
||||
*/
|
||||
public abstract Notification getNotification();
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
package com.fsck.k9.helper;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
|
||||
/**
|
||||
* Create notifications using the now deprecated {@link Notification} constructor.
|
||||
*/
|
||||
public class NotificationBuilderApi1 extends NotificationBuilder {
|
||||
private int mSmallIcon;
|
||||
private long mWhen;
|
||||
private CharSequence mTickerText;
|
||||
private CharSequence mContentText;
|
||||
private CharSequence mContentTitle;
|
||||
private PendingIntent mContentIntent;
|
||||
private int mNumber;
|
||||
private boolean mOngoing;
|
||||
private boolean mAutoCancel;
|
||||
private Uri mSoundUri;
|
||||
private long[] mVibrationPattern;
|
||||
private int mLedColor;
|
||||
private int mLedOnMS;
|
||||
private int mLedOffMS;
|
||||
private boolean mBlinkLed;
|
||||
|
||||
|
||||
protected NotificationBuilderApi1(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSmallIcon(int icon) {
|
||||
mSmallIcon = icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWhen(long when) {
|
||||
mWhen = when;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTicker(CharSequence tickerText) {
|
||||
mTickerText = tickerText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentTitle(CharSequence title) {
|
||||
mContentTitle = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentText(CharSequence text) {
|
||||
mContentText = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentIntent(PendingIntent intent) {
|
||||
mContentIntent = intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumber(int number) {
|
||||
mNumber = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOngoing(boolean ongoing) {
|
||||
mOngoing = ongoing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoCancel(boolean autoCancel) {
|
||||
mAutoCancel = autoCancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSound(Uri sound) {
|
||||
mSoundUri = sound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVibrate(long[] pattern) {
|
||||
mVibrationPattern = pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLights(int argb, int onMs, int offMs) {
|
||||
mBlinkLed = true;
|
||||
mLedColor = argb;
|
||||
mLedOnMS = onMs;
|
||||
mLedOffMS = offMs;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Notification getNotification() {
|
||||
Notification notification = new Notification(mSmallIcon, mTickerText, mWhen);
|
||||
notification.number = mNumber;
|
||||
notification.setLatestEventInfo(mContext, mContentTitle, mContentText, mContentIntent);
|
||||
|
||||
if (mSoundUri != null) {
|
||||
notification.sound = mSoundUri;
|
||||
notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;
|
||||
}
|
||||
|
||||
if (mVibrationPattern != null) {
|
||||
notification.vibrate = mVibrationPattern;
|
||||
}
|
||||
|
||||
if (mBlinkLed) {
|
||||
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
|
||||
notification.ledARGB = mLedColor;
|
||||
notification.ledOnMS = mLedOnMS;
|
||||
notification.ledOffMS = mLedOffMS;
|
||||
}
|
||||
|
||||
if (mAutoCancel) {
|
||||
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
||||
}
|
||||
|
||||
if (mOngoing) {
|
||||
notification.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
}
|
||||
|
||||
return notification;
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
package com.fsck.k9.helper;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
|
||||
/**
|
||||
* Create notifications using the new {@link android.app.Notification.Builder} class.
|
||||
*/
|
||||
@TargetApi(11)
|
||||
public class NotificationBuilderApi11 extends NotificationBuilder {
|
||||
private Notification.Builder mBuilder;
|
||||
|
||||
|
||||
protected NotificationBuilderApi11(Context context) {
|
||||
super(context);
|
||||
mBuilder = new Notification.Builder(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSmallIcon(int icon) {
|
||||
mBuilder.setSmallIcon(icon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWhen(long when) {
|
||||
mBuilder.setWhen(when);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTicker(CharSequence tickerText) {
|
||||
mBuilder.setTicker(tickerText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentTitle(CharSequence title) {
|
||||
mBuilder.setContentTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentText(CharSequence text) {
|
||||
mBuilder.setContentText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentIntent(PendingIntent intent) {
|
||||
mBuilder.setContentIntent(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumber(int number) {
|
||||
mBuilder.setNumber(number);
|
||||
mBuilder.setContentInfo("" + number);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOngoing(boolean ongoing) {
|
||||
mBuilder.setOngoing(ongoing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoCancel(boolean autoCancel) {
|
||||
mBuilder.setAutoCancel(autoCancel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSound(Uri sound) {
|
||||
mBuilder.setSound(sound, AudioManager.STREAM_NOTIFICATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVibrate(long[] pattern) {
|
||||
mBuilder.setVibrate(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLights(int argb, int onMs, int offMs) {
|
||||
mBuilder.setLights(argb, onMs, offMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Notification getNotification() {
|
||||
return mBuilder.getNotification();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user