OLD | NEW |
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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.libadblockplus.android; |
19 | 19 |
20 import java.io.BufferedReader; | 20 import java.io.BufferedReader; |
| 21 import java.io.IOException; |
| 22 import java.io.InputStream; |
21 import java.io.InputStreamReader; | 23 import java.io.InputStreamReader; |
| 24 import java.util.List; |
22 | 25 |
23 import org.adblockplus.libadblockplus.JsValue; | 26 import org.json.JSONArray; |
24 import org.adblockplus.libadblockplus.Subscription; | |
25 import org.apache.commons.lang.StringUtils; | |
26 | 27 |
27 import android.app.Notification; | |
28 import android.app.NotificationManager; | |
29 import android.app.PendingIntent; | |
30 import android.content.Context; | 28 import android.content.Context; |
31 import android.content.Intent; | |
32 | 29 |
33 public final class Utils | 30 public final class Utils |
34 { | 31 { |
35 private Utils() | 32 private Utils() |
36 { | 33 { |
37 // | 34 // |
38 } | 35 } |
39 | 36 |
40 public static String getTag(final Class<?> clazz) | 37 public static String getTag(final Class<?> clazz) |
41 { | 38 { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 { | 70 { |
74 buf.close(); | 71 buf.close(); |
75 } | 72 } |
76 | 73 |
77 } | 74 } |
78 catch (final Exception e) | 75 catch (final Exception e) |
79 { | 76 { |
80 // Ignored for now | 77 // Ignored for now |
81 } | 78 } |
82 } | 79 } |
| 80 |
| 81 public static String stringListToJsonArray(List<String> list) |
| 82 { |
| 83 JSONArray array = new JSONArray(); |
| 84 |
| 85 if (list != null) |
| 86 { |
| 87 for (String eachString : list) |
| 88 { |
| 89 if (eachString != null) |
| 90 { |
| 91 array.put(eachString); |
| 92 } |
| 93 } |
| 94 } |
| 95 |
| 96 return array.toString(); |
| 97 } |
| 98 |
| 99 public static String readAssetAsString(Context context, String filename) throw
s IOException |
| 100 { |
| 101 BufferedReader in = null; |
| 102 try { |
| 103 StringBuilder buf = new StringBuilder(); |
| 104 InputStream is = context.getAssets().open(filename); |
| 105 in = new BufferedReader(new InputStreamReader(is)); |
| 106 |
| 107 String str; |
| 108 boolean isFirst = true; |
| 109 while ( (str = in.readLine()) != null ) { |
| 110 if (isFirst) |
| 111 isFirst = false; |
| 112 else |
| 113 buf.append('\n'); |
| 114 buf.append(str); |
| 115 } |
| 116 return buf.toString(); |
| 117 } finally { |
| 118 if (in != null) { |
| 119 try { |
| 120 in.close(); |
| 121 } catch (IOException e) { |
| 122 // ignored |
| 123 } |
| 124 } |
| 125 } |
| 126 } |
83 } | 127 } |
OLD | NEW |