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: Adressed first batch of review issues. Created April 16, 2014, 5:36 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
(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
24 import com.github.rjeschke.neetutils.Strings;
25
26 import android.app.Notification;
27 import android.app.PendingIntent;
28 import android.content.Context;
29 import android.content.Intent;
30 import android.support.v4.app.NotificationCompat;
31
32 public final class Utils
33 {
34 private Utils()
35 {
36 //
37 }
38
39 public static String getTag(final Class<?> clazz)
40 {
41 return clazz.getSimpleName();
42 }
43
44 public static String capitalizeString(final String s)
45 {
46 if (s == null || s.length() == 0)
47 {
48 return "";
49 }
50
51 final char first = s.charAt(0);
52
53 return Character.isUpperCase(first) ? s : Character.toUpperCase(first) + s.s ubstring(1);
54 }
55
56 protected static Notification createUpdateNotification(final Context context, final String url, final String error)
57 {
58 final PendingIntent emptyIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
59
60 final NotificationCompat.Builder builder = new NotificationCompat.Builder(co ntext);
61 builder.setContentTitle(context.getText(R.string.app_name));
62 builder.setSmallIcon(R.drawable.ic_stat_warning);
63 builder.setWhen(System.currentTimeMillis());
64 builder.setAutoCancel(true);
65 builder.setOnlyAlertOnce(true);
66 builder.setContentIntent(emptyIntent);
67
68 if (url != null)
69 {
70 builder.setSmallIcon(R.drawable.ic_stat_download);
71
72 final Intent intent = new Intent(context, UpdaterActivity.class).addFlags( Intent.FLAG_ACTIVITY_NEW_TASK);
73 intent.setAction("download");
74 intent.putExtra("url", url);
75 final PendingIntent updateIntent = PendingIntent.getActivity(context, 0, i ntent, PendingIntent.FLAG_UPDATE_CURRENT);
76 builder.setContentIntent(updateIntent);
77 builder.setContentText(context.getString(R.string.msg_update_available));
78 }
79 else if (error != null)
80 {
81 // TODO Should we show error message to the user?
82 builder.setContentText(context.getString(R.string.msg_update_fail));
83 }
84 else
85 {
86 builder.setContentText(context.getString(R.string.msg_update_missing));
87 }
88
89 final Notification notification = builder.getNotification();
90 return notification;
91 }
92
93 protected static void updateSubscriptionStatus(final Context context, final Su bscription sub)
94 {
95 final JsValue jsDownloadStatus = sub.getProperty("downloadStatus");
96 final String downloadStatus = jsDownloadStatus.isNull() ? "" : jsDownloadSta tus.toString();
97 final long lastDownload = sub.getProperty("lastDownload").asLong();
98
99 String status = "synchronize_never";
100 long time = 0;
101
102 if (sub.isUpdating())
103 {
104 status = "synchronize_in_progress";
105 }
106 else if (!Strings.isEmpty(downloadStatus) && !downloadStatus.equals("synchro nize_ok"))
107 {
108 status = downloadStatus;
109 }
110 else if (lastDownload > 0)
111 {
112 time = lastDownload;
113 status = "synchronize_last_at";
114 }
115
116 context.sendBroadcast(new Intent(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS)
117 .putExtra("url", sub.getProperty("url").toString())
118 .putExtra("status", status)
119 .putExtra("time", time * 1000L));
120 }
121 }
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