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

Side by Side Diff: src/org/adblockplus/android/Utils.java

Issue 5153282527854592: Issue 98 - Use the libadblockplus update mechanism (Closed)
Patch Set: Only append the revision to the version for devbuilds Created Sept. 26, 2014, 2:54 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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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; 18 package org.adblockplus.android;
19 19
20 import org.adblockplus.android.updater.UpdaterActivity; 20 import org.adblockplus.android.updater.UpdaterActivity;
21 import org.adblockplus.libadblockplus.JsValue; 21 import org.adblockplus.libadblockplus.JsValue;
22 import org.adblockplus.libadblockplus.Subscription; 22 import org.adblockplus.libadblockplus.Subscription;
23 import org.apache.commons.lang.StringUtils; 23 import org.apache.commons.lang.StringUtils;
24 24
25 import android.app.Notification; 25 import android.app.Notification;
26 import android.app.NotificationManager;
26 import android.app.PendingIntent; 27 import android.app.PendingIntent;
27 import android.content.Context; 28 import android.content.Context;
28 import android.content.Intent; 29 import android.content.Intent;
29 import android.support.v4.app.NotificationCompat; 30 import android.support.v4.app.NotificationCompat;
30 31
31 public final class Utils 32 public final class Utils
32 { 33 {
33 private Utils() 34 private Utils()
34 { 35 {
35 // 36 //
36 } 37 }
37 38
38 public static String getTag(final Class<?> clazz) 39 public static String getTag(final Class<?> clazz)
39 { 40 {
40 return clazz.getSimpleName(); 41 return clazz.getSimpleName();
41 } 42 }
42 43
43 public static String capitalizeString(final String s) 44 public static String capitalizeString(final String s)
44 { 45 {
45 if (s == null || s.length() == 0) 46 if (s == null || s.length() == 0)
46 { 47 {
47 return ""; 48 return "";
48 } 49 }
49 50
50 final char first = s.charAt(0); 51 final char first = s.charAt(0);
51 52
52 return Character.isUpperCase(first) ? s : Character.toUpperCase(first) + s.s ubstring(1); 53 return Character.isUpperCase(first) ? s : Character.toUpperCase(first) + s.s ubstring(1);
53 } 54 }
54 55
55 protected static Notification createUpdateNotification(final Context context, final String url, final String error) 56 protected static void showUpdateNotification(final Context context, final Stri ng url,
57 final String error)
56 { 58 {
57 final PendingIntent emptyIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
58
59 final NotificationCompat.Builder builder = new NotificationCompat.Builder(co ntext); 59 final NotificationCompat.Builder builder = new NotificationCompat.Builder(co ntext);
60 builder.setContentTitle(context.getText(R.string.app_name)); 60 builder.setContentTitle(context.getText(R.string.app_name));
61 builder.setSmallIcon(R.drawable.ic_stat_warning); 61 builder.setSmallIcon(R.drawable.ic_stat_warning);
62 builder.setWhen(System.currentTimeMillis());
63 builder.setAutoCancel(true); 62 builder.setAutoCancel(true);
64 builder.setOnlyAlertOnce(true); 63 builder.setOnlyAlertOnce(true);
64 final PendingIntent emptyIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
65 builder.setContentIntent(emptyIntent); 65 builder.setContentIntent(emptyIntent);
66 66
67 if (url != null) 67 if (StringUtils.isNotEmpty(error))
68 {
69 builder.setContentText(context.getString(R.string.msg_update_fail));
70 }
71 else if (StringUtils.isNotEmpty(url))
68 { 72 {
69 builder.setSmallIcon(R.drawable.ic_stat_download); 73 builder.setSmallIcon(R.drawable.ic_stat_download);
70 74 final Intent intent = new Intent(context, UpdaterActivity.class)
71 final Intent intent = new Intent(context, UpdaterActivity.class).addFlags( Intent.FLAG_ACTIVITY_NEW_TASK); 75 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
72 intent.setAction("download"); 76 intent.setAction("download");
73 intent.putExtra("url", url); 77 intent.putExtra("url", url);
74 final PendingIntent updateIntent = PendingIntent.getActivity(context, 0, i ntent, PendingIntent.FLAG_UPDATE_CURRENT); 78 final PendingIntent updateIntent =
79 PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDAT E_CURRENT);
75 builder.setContentIntent(updateIntent); 80 builder.setContentIntent(updateIntent);
76 builder.setContentText(context.getString(R.string.msg_update_available)); 81 builder.setContentText(context.getString(R.string.msg_update_available));
77 } 82 }
78 else if (error != null)
79 {
80 // TODO Should we show error message to the user?
81 builder.setContentText(context.getString(R.string.msg_update_fail));
82 }
83 else 83 else
84 { 84 {
85 builder.setContentText(context.getString(R.string.msg_update_missing)); 85 builder.setContentText(context.getString(R.string.msg_update_missing));
86 } 86 }
87 87
88 final Notification notification = builder.getNotification(); 88 final Notification notification = builder.getNotification();
89 return notification; 89 final NotificationManager notificationManager =
90 (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERV ICE);
91 final int updateNotificationId = R.string.app_name + 1;
92 notificationManager.notify(updateNotificationId, notification);
90 } 93 }
91 94
92 protected static void updateSubscriptionStatus(final Context context, final Su bscription sub) 95 protected static void updateSubscriptionStatus(final Context context, final Su bscription sub)
93 { 96 {
94 final JsValue jsDownloadStatus = sub.getProperty("downloadStatus"); 97 final JsValue jsDownloadStatus = sub.getProperty("downloadStatus");
95 final String downloadStatus = jsDownloadStatus.isNull() ? "" : jsDownloadSta tus.toString(); 98 final String downloadStatus = jsDownloadStatus.isNull() ? "" : jsDownloadSta tus.toString();
96 final long lastDownload = sub.getProperty("lastDownload").asLong(); 99 final long lastDownload = sub.getProperty("lastDownload").asLong();
97 100
98 String status = "synchronize_never"; 101 String status = "synchronize_never";
99 long time = 0; 102 long time = 0;
(...skipping 11 matching lines...) Expand all
111 time = lastDownload; 114 time = lastDownload;
112 status = "synchronize_last_at"; 115 status = "synchronize_last_at";
113 } 116 }
114 117
115 context.sendBroadcast(new Intent(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS) 118 context.sendBroadcast(new Intent(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS)
116 .putExtra("url", sub.getProperty("url").toString()) 119 .putExtra("url", sub.getProperty("url").toString())
117 .putExtra("status", status) 120 .putExtra("status", status)
118 .putExtra("time", time * 1000L)); 121 .putExtra("time", time * 1000L));
119 } 122 }
120 } 123 }
OLDNEW
« no previous file with comments | « src/org/adblockplus/android/Preferences.java ('k') | src/org/adblockplus/android/updater/AlarmReceiver.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld