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

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

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Patch Set: Even more review issues fixed. Created April 28, 2014, 10:18 a.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
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 package org.adblockplus.android;
19
20 import org.adblockplus.android.updater.UpdaterActivity;
21 import org.adblockplus.libadblockplus.JsValue;
22 import org.adblockplus.libadblockplus.Subscription;
23 import org.apache.commons.lang.StringUtils;
24
25 import android.app.Notification;
26 import android.app.PendingIntent;
27 import android.content.Context;
28 import android.content.Intent;
29 import android.support.v4.app.NotificationCompat;
30
31 public final class Utils
32 {
33 private Utils()
34 {
35 //
36 }
37
38 public static String getTag(final Class<?> clazz)
39 {
40 return clazz.getSimpleName();
41 }
42
43 public static String capitalizeString(final String s)
44 {
45 if (s == null || s.length() == 0)
46 {
47 return "";
48 }
49
50 final char first = s.charAt(0);
51
52 return Character.isUpperCase(first) ? s : Character.toUpperCase(first) + s.s ubstring(1);
53 }
54
55 protected static Notification createUpdateNotification(final Context context, final String url, final String error)
56 {
57 final PendingIntent emptyIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
58
59 final NotificationCompat.Builder builder = new NotificationCompat.Builder(co ntext);
60 builder.setContentTitle(context.getText(R.string.app_name));
61 builder.setSmallIcon(R.drawable.ic_stat_warning);
62 builder.setWhen(System.currentTimeMillis());
63 builder.setAutoCancel(true);
64 builder.setOnlyAlertOnce(true);
65 builder.setContentIntent(emptyIntent);
66
67 if (url != null)
68 {
69 builder.setSmallIcon(R.drawable.ic_stat_download);
70
71 final Intent intent = new Intent(context, UpdaterActivity.class).addFlags( Intent.FLAG_ACTIVITY_NEW_TASK);
72 intent.setAction("download");
73 intent.putExtra("url", url);
74 final PendingIntent updateIntent = PendingIntent.getActivity(context, 0, i ntent, PendingIntent.FLAG_UPDATE_CURRENT);
75 builder.setContentIntent(updateIntent);
76 builder.setContentText(context.getString(R.string.msg_update_available));
77 }
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
84 {
85 builder.setContentText(context.getString(R.string.msg_update_missing));
86 }
87
88 final Notification notification = builder.getNotification();
89 return notification;
90 }
91
92 protected static void updateSubscriptionStatus(final Context context, final Su bscription sub)
93 {
94 final JsValue jsDownloadStatus = sub.getProperty("downloadStatus");
95 final String downloadStatus = jsDownloadStatus.isNull() ? "" : jsDownloadSta tus.toString();
96 final long lastDownload = sub.getProperty("lastDownload").asLong();
97
98 String status = "synchronize_never";
99 long time = 0;
100
101 if (sub.isUpdating())
102 {
103 status = "synchronize_in_progress";
104 }
105 else if (StringUtils.isNotEmpty(downloadStatus) && !downloadStatus.equals("s ynchronize_ok"))
106 {
107 status = downloadStatus;
108 }
109 else if (lastDownload > 0)
110 {
111 time = lastDownload;
112 status = "synchronize_last_at";
113 }
114
115 context.sendBroadcast(new Intent(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS)
116 .putExtra("url", sub.getProperty("url").toString())
117 .putExtra("status", status)
118 .putExtra("time", time * 1000L));
119 }
120 }
OLDNEW
« no previous file with comments | « src/org/adblockplus/android/SummarizedPreferences.java ('k') | src/org/adblockplus/android/updater/AlarmReceiver.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld