Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/org/adblockplus/android/updater/UpdaterService.java

Issue 5327480814567424: Issue 1108 - Support notifications (Closed)
Patch Set: Even more renaming, ignore INVALID/QUESTION Created Feb. 18, 2015, 3 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 package org.adblockplus.android.updater; 18 package org.adblockplus.android.updater;
19 19
20 import java.io.BufferedInputStream; 20 import java.io.BufferedInputStream;
21 import java.io.File; 21 import java.io.File;
22 import java.io.FileOutputStream; 22 import java.io.FileOutputStream;
23 import java.io.InputStream; 23 import java.io.InputStream;
24 import java.io.OutputStream; 24 import java.io.OutputStream;
25 import java.net.URL; 25 import java.net.URL;
26 import java.net.URLConnection; 26 import java.net.URLConnection;
27 27
28 import org.adblockplus.android.AdblockPlus;
28 import org.adblockplus.android.R; 29 import org.adblockplus.android.R;
29 import org.adblockplus.android.Utils; 30 import org.adblockplus.android.Utils;
30 31
31 import android.app.Notification; 32 import android.app.Notification;
32 import android.app.NotificationManager; 33 import android.app.NotificationManager;
33 import android.app.PendingIntent; 34 import android.app.PendingIntent;
34 import android.app.Service; 35 import android.app.Service;
35 import android.content.Context; 36 import android.content.Context;
36 import android.content.Intent; 37 import android.content.Intent;
37 import android.os.AsyncTask; 38 import android.os.AsyncTask;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 { 80 {
80 return null; 81 return null;
81 } 82 }
82 83
83 private class DownloadTask extends AsyncTask<String, Integer, String> 84 private class DownloadTask extends AsyncTask<String, Integer, String>
84 { 85 {
85 private final Context context; 86 private final Context context;
86 private final Notification notification; 87 private final Notification notification;
87 private final PendingIntent contentIntent; 88 private final PendingIntent contentIntent;
88 private final NotificationManager notificationManager; 89 private final NotificationManager notificationManager;
89 private final int notificationId = R.string.app_name + 2;
90 90
91 public DownloadTask(final Context context) 91 public DownloadTask(final Context context)
92 { 92 {
93 this.context = context; 93 this.context = context;
94 notificationManager = (NotificationManager) context.getSystemService(Conte xt.NOTIFICATION_SERVICE); 94 notificationManager = (NotificationManager) context.getSystemService(Conte xt.NOTIFICATION_SERVICE);
95 notification = new Notification(); 95 notification = new Notification();
96 contentIntent = PendingIntent.getActivity(context, 0, new Intent(), Pendin gIntent.FLAG_UPDATE_CURRENT); 96 contentIntent = PendingIntent.getActivity(context, 0, new Intent(), Pendin gIntent.FLAG_UPDATE_CURRENT);
97 } 97 }
98 98
99 @Override 99 @Override
100 protected void onPreExecute() 100 protected void onPreExecute()
101 { 101 {
102 notification.flags |= Notification.FLAG_ONGOING_EVENT; 102 notification.flags |= Notification.FLAG_ONGOING_EVENT;
103 notification.when = 0; 103 notification.when = 0;
104 notification.icon = R.drawable.ic_stat_download; 104 notification.icon = R.drawable.ic_stat_download;
105 notification.setLatestEventInfo(context, getString(R.string.app_name), Str ing.format(getString(R.string.msg_update_downloading), 0), contentIntent); 105 notification.setLatestEventInfo(context, getString(R.string.app_name), Str ing.format(getString(R.string.msg_update_downloading), 0), contentIntent);
106 notificationManager.notify(notificationId, notification); 106 notificationManager.notify(AdblockPlus.UPDATE_NOTIFICATION_ID, notificatio n);
107 } 107 }
108 108
109 @Override 109 @Override
110 protected String doInBackground(final String... sUrl) 110 protected String doInBackground(final String... sUrl)
111 { 111 {
112 try 112 try
113 { 113 {
114 // Create connection 114 // Create connection
115 final URL url = new URL(sUrl[0]); 115 final URL url = new URL(sUrl[0]);
116 Log.e(TAG, "D: " + sUrl[0]); 116 Log.e(TAG, "D: " + sUrl[0]);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 { 159 {
160 Log.e(TAG, "Download error", e); 160 Log.e(TAG, "Download error", e);
161 return null; 161 return null;
162 } 162 }
163 } 163 }
164 164
165 @Override 165 @Override
166 protected void onProgressUpdate(final Integer... progress) 166 protected void onProgressUpdate(final Integer... progress)
167 { 167 {
168 notification.setLatestEventInfo(context, getString(R.string.app_name), Str ing.format(getString(R.string.msg_update_downloading), progress[0]), contentInte nt); 168 notification.setLatestEventInfo(context, getString(R.string.app_name), Str ing.format(getString(R.string.msg_update_downloading), progress[0]), contentInte nt);
169 notificationManager.notify(notificationId, notification); 169 notificationManager.notify(AdblockPlus.UPDATE_NOTIFICATION_ID, notificatio n);
170 } 170 }
171 171
172 @Override 172 @Override
173 protected void onPostExecute(final String result) 173 protected void onPostExecute(final String result)
174 { 174 {
175 notificationManager.cancel(notificationId); 175 notificationManager.cancel(AdblockPlus.UPDATE_NOTIFICATION_ID);
176 if (result != null) 176 if (result != null)
177 { 177 {
178 final Notification notification = new Notification(); 178 final Notification notification = new Notification();
179 notification.icon = R.drawable.ic_stat_download; 179 notification.icon = R.drawable.ic_stat_download;
180 notification.when = System.currentTimeMillis(); 180 notification.when = System.currentTimeMillis();
181 notification.flags |= Notification.FLAG_AUTO_CANCEL; 181 notification.flags |= Notification.FLAG_AUTO_CANCEL;
182 final Intent intent = new Intent(context, UpdaterActivity.class).addFlag s(Intent.FLAG_ACTIVITY_NEW_TASK); 182 final Intent intent = new Intent(context, UpdaterActivity.class).addFlag s(Intent.FLAG_ACTIVITY_NEW_TASK);
183 intent.setAction("update"); 183 intent.setAction("update");
184 intent.putExtra("path", result); 184 intent.putExtra("path", result);
185 final PendingIntent contentIntent = PendingIntent.getActivity(context, 0 , intent, PendingIntent.FLAG_UPDATE_CURRENT); 185 final PendingIntent contentIntent = PendingIntent.getActivity(context, 0 , intent, PendingIntent.FLAG_UPDATE_CURRENT);
186 notification.setLatestEventInfo(context, context.getText(R.string.app_na me), context.getString(R.string.msg_update_ready), contentIntent); 186 notification.setLatestEventInfo(context, context.getText(R.string.app_na me), context.getString(R.string.msg_update_ready), contentIntent);
187 notificationManager.notify(R.string.app_name + 1, notification); 187 notificationManager.notify(AdblockPlus.UPDATE_NOTIFICATION_ID, notificat ion);
188 } 188 }
189 } 189 }
190 } 190 }
191 } 191 }
OLDNEW

Powered by Google App Engine
This is Rietveld