use notification builder for offline notifications; make a placeholder monochrome notification icon

This commit is contained in:
Andrew Dolgov 2015-02-17 22:20:38 +03:00
parent 70deffc067
commit ea717ae7da
3 changed files with 71 additions and 43 deletions

View File

@ -1,8 +1,28 @@
package org.fox.ttrss.offline; package org.fox.ttrss.offline;
import java.lang.reflect.Type; import android.app.ActivityManager;
import java.util.HashMap; import android.app.ActivityManager.RunningServiceInfo;
import java.util.List; import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
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.ApiRequest;
import org.fox.ttrss.OnlineActivity; import org.fox.ttrss.OnlineActivity;
@ -17,26 +37,9 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import android.app.ActivityManager; import java.lang.reflect.Type;
import android.app.ActivityManager.RunningServiceInfo; import java.util.HashMap;
import android.app.Notification; import java.util.List;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import android.os.Binder;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.provider.BaseColumns;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
public class OfflineDownloadService extends Service { public class OfflineDownloadService extends Service {
@ -90,21 +93,32 @@ public class OfflineDownloadService extends Service {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void updateNotification(String msg) { 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 intent = new Intent(this, OnlineActivity.class);
intent.setAction(INTENT_ACTION_CANCEL); intent.setAction(INTENT_ACTION_CANCEL);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
intent, 0); intent, 0);
notification.flags |= Notification.FLAG_ONGOING_EVENT; NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; .setContentText(msg)
.setContentTitle(getString(R.string.notify_downloading_title))
notification.setLatestEventInfo(this, getString(R.string.notify_downloading_title), msg, contentIntent); .setContentIntent(contentIntent)
.setWhen(System.currentTimeMillis())
m_nmgr.notify(NOTIFY_DOWNLOADING, notification); .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) { private void updateNotification(int msgResId) {

View File

@ -9,6 +9,9 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.util.Log; import android.util.Log;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
@ -53,18 +56,29 @@ public class OfflineUploadService extends IntentService {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void updateNotification(String msg) { 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, PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, OnlineActivity.class), 0); new Intent(this, OnlineActivity.class), 0);
notification.flags |= Notification.FLAG_ONGOING_EVENT; NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; .setContentText(msg)
.setContentTitle(getString(R.string.notify_uploading_title))
notification.setLatestEventInfo(this, getString(R.string.notify_uploading_title), msg, contentIntent); .setContentIntent(contentIntent)
.setWhen(System.currentTimeMillis())
m_nmgr.notify(NOTIFY_UPLOADING, notification); .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) { private void updateNotification(int msgResId) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB