diff options
author | Andrew Dolgov <[email protected]> | 2015-02-17 22:20:38 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2015-02-17 23:20:51 +0400 |
commit | ea717ae7dac6b3b92f6e4249df3bd675a38edad1 (patch) | |
tree | eebbdd6a17ebc844670af402f753dc02da254fcf /org.fox.ttrss/src/main/java | |
parent | 70deffc067c1593d5aabfc9023a6c5770492d985 (diff) |
use notification builder for offline notifications; make a placeholder monochrome notification icon
Diffstat (limited to 'org.fox.ttrss/src/main/java')
-rw-r--r-- | org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java | 68 | ||||
-rw-r--r-- | org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java | 34 |
2 files changed, 65 insertions, 37 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java index 7a85d210..e90899e8 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java @@ -1,22 +1,5 @@ package org.fox.ttrss.offline; -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.List; - -import org.fox.ttrss.ApiRequest; -import org.fox.ttrss.OnlineActivity; -import org.fox.ttrss.R; -import org.fox.ttrss.types.Article; -import org.fox.ttrss.types.Feed; -import org.fox.ttrss.types.FeedCategory; -import org.fox.ttrss.util.DatabaseHelper; -import org.fox.ttrss.util.ImageCacheService; -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; -import org.jsoup.nodes.Element; -import org.jsoup.select.Elements; - import android.app.ActivityManager; import android.app.ActivityManager.RunningServiceInfo; import android.app.Notification; @@ -28,16 +11,36 @@ import android.content.Intent; import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteStatement; +import android.graphics.BitmapFactory; import android.os.Binder; +import android.os.Build; import android.os.IBinder; import android.preference.PreferenceManager; import android.provider.BaseColumns; +import android.support.v4.app.NotificationCompat; import android.util.Log; import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.reflect.TypeToken; +import org.fox.ttrss.ApiRequest; +import org.fox.ttrss.OnlineActivity; +import org.fox.ttrss.R; +import org.fox.ttrss.types.Article; +import org.fox.ttrss.types.Feed; +import org.fox.ttrss.types.FeedCategory; +import org.fox.ttrss.util.DatabaseHelper; +import org.fox.ttrss.util.ImageCacheService; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.List; + public class OfflineDownloadService extends Service { private final String TAG = this.getClass().getSimpleName(); @@ -90,21 +93,32 @@ public class OfflineDownloadService extends Service { @SuppressWarnings("deprecation") private void updateNotification(String msg) { - Notification notification = new Notification(R.drawable.ic_launcher, - getString(R.string.notify_downloading_title), System.currentTimeMillis()); - Intent intent = new Intent(this, OnlineActivity.class); intent.setAction(INTENT_ACTION_CANCEL); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0); - - notification.flags |= Notification.FLAG_ONGOING_EVENT; - notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; - - notification.setLatestEventInfo(this, getString(R.string.notify_downloading_title), msg, contentIntent); - - m_nmgr.notify(NOTIFY_DOWNLOADING, notification); + + NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()) + .setContentText(msg) + .setContentTitle(getString(R.string.notify_downloading_title)) + .setContentIntent(contentIntent) + .setWhen(System.currentTimeMillis()) + .setSmallIcon(R.drawable.ic_notification) + .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), + R.drawable.ic_launcher)) + .setOngoing(true) + .setOnlyAlertOnce(true) + .setVibrate(new long[0]); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + builder.setCategory(Notification.CATEGORY_PROGRESS) + .setVisibility(Notification.VISIBILITY_PUBLIC) + .setColor(0x88b0f0) + .setGroup("org.fox.ttrss"); + } + + m_nmgr.notify(NOTIFY_DOWNLOADING, builder.build()); } private void updateNotification(int msgResId) { diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java index dbc56fbf..b9799d74 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java @@ -9,6 +9,9 @@ import android.content.Intent; import android.content.SharedPreferences; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; +import android.graphics.BitmapFactory; +import android.os.Build; +import android.support.v4.app.NotificationCompat; import android.util.Log; import com.google.gson.JsonElement; @@ -53,18 +56,29 @@ public class OfflineUploadService extends IntentService { @SuppressWarnings("deprecation") private void updateNotification(String msg) { - Notification notification = new Notification(R.drawable.ic_launcher, - getString(R.string.notify_uploading_title), System.currentTimeMillis()); - PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, OnlineActivity.class), 0); - - notification.flags |= Notification.FLAG_ONGOING_EVENT; - notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; - - notification.setLatestEventInfo(this, getString(R.string.notify_uploading_title), msg, contentIntent); - - m_nmgr.notify(NOTIFY_UPLOADING, notification); + + NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()) + .setContentText(msg) + .setContentTitle(getString(R.string.notify_uploading_title)) + .setContentIntent(contentIntent) + .setWhen(System.currentTimeMillis()) + .setSmallIcon(R.drawable.ic_notification) + .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), + R.drawable.ic_launcher)) + .setOngoing(true) + .setOnlyAlertOnce(true) + .setVibrate(new long[0]); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + builder.setCategory(Notification.CATEGORY_PROGRESS) + .setVisibility(Notification.VISIBILITY_PUBLIC) + .setColor(0x88b0f0) + .setGroup("org.fox.ttrss"); + } + + m_nmgr.notify(NOTIFY_UPLOADING, builder.build()); } private void updateNotification(int msgResId) { |