| LEFT | RIGHT |
| 1 /* | |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-2016 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 java.io.BufferedReader; | |
| 21 import java.io.IOException; | |
| 22 import java.io.InputStream; | |
| 23 import java.io.InputStreamReader; | |
| 24 import java.net.URI; | |
| 25 import java.net.URISyntaxException; | |
| 26 import java.util.List; | |
| 27 | |
| 28 import org.adblockplus.libadblockplus.JsValue; | |
| 29 import org.adblockplus.libadblockplus.Subscription; | |
| 30 import org.apache.commons.lang.StringUtils; | |
| 31 import org.json.JSONArray; | |
| 32 | |
| 33 import android.app.Notification; | |
| 34 import android.app.NotificationManager; | |
| 35 import android.app.PendingIntent; | |
| 36 import android.content.Context; | |
| 37 import android.content.Intent; | |
| 38 | |
| 39 public final class Utils | |
| 40 { | |
| 41 private Utils() | |
| 42 { | |
| 43 // | |
| 44 } | |
| 45 | |
| 46 public static String getTag(final Class<?> clazz) | |
| 47 { | |
| 48 return clazz.getSimpleName(); | |
| 49 } | |
| 50 | |
| 51 public static String capitalizeString(final String s) | |
| 52 { | |
| 53 if (s == null || s.length() == 0) | |
| 54 { | |
| 55 return ""; | |
| 56 } | |
| 57 | |
| 58 final char first = s.charAt(0); | |
| 59 | |
| 60 return Character.isUpperCase(first) ? s : Character.toUpperCase(first) + s.s
ubstring(1); | |
| 61 } | |
| 62 | |
| 63 public static void appendRawTextFile(final Context context, final StringBuilde
r text, final int id) | |
| 64 { | |
| 65 try | |
| 66 { | |
| 67 final BufferedReader buf = new BufferedReader(new InputStreamReader(contex
t.getResources().openRawResource(id))); | |
| 68 | |
| 69 try | |
| 70 { | |
| 71 String line; | |
| 72 while ((line = buf.readLine()) != null) | |
| 73 { | |
| 74 text.append(line); | |
| 75 text.append('\n'); | |
| 76 } | |
| 77 } | |
| 78 finally | |
| 79 { | |
| 80 buf.close(); | |
| 81 } | |
| 82 | |
| 83 } | |
| 84 catch (final Exception e) | |
| 85 { | |
| 86 // Ignored for now | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 public static String stringListToJsonArray(List<String> list) | |
| 91 { | |
| 92 JSONArray array = new JSONArray(); | |
| 93 | |
| 94 if (list != null) | |
| 95 { | |
| 96 for (String eachString : list) | |
| 97 { | |
| 98 if (eachString != null) | |
| 99 { | |
| 100 array.put(eachString); | |
| 101 } | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 return array.toString(); | |
| 106 } | |
| 107 | |
| 108 /** | |
| 109 * Extract domain from URL | |
| 110 * @param url valid URL (with scheme) | |
| 111 * @return domain | |
| 112 * @throws URISyntaxException | |
| 113 */ | |
| 114 public static String getDomain(String url) throws URISyntaxException | |
| 115 { | |
| 116 URI uri = new URI(url); | |
| 117 String domain = uri.getHost(); | |
| 118 if (domain == null) | |
| 119 throw new URISyntaxException(url, "Invalid url"); | |
| 120 return domain.startsWith("www.") ? domain.substring(4) : domain; | |
| 121 } | |
| 122 | |
| 123 public static String readAssetAsString(Context context, String filename) throw
s IOException | |
| 124 { | |
| 125 BufferedReader in = null; | |
| 126 try { | |
| 127 StringBuilder buf = new StringBuilder(); | |
| 128 InputStream is = context.getAssets().open(filename); | |
| 129 in = new BufferedReader(new InputStreamReader(is)); | |
| 130 | |
| 131 String str; | |
| 132 boolean isFirst = true; | |
| 133 while ( (str = in.readLine()) != null ) { | |
| 134 if (isFirst) | |
| 135 isFirst = false; | |
| 136 else | |
| 137 buf.append('\n'); | |
| 138 buf.append(str); | |
| 139 } | |
| 140 return buf.toString(); | |
| 141 } finally { | |
| 142 if (in != null) { | |
| 143 try { | |
| 144 in.close(); | |
| 145 } catch (IOException e) { | |
| 146 // ignored | |
| 147 } | |
| 148 } | |
| 149 } | |
| 150 } | |
| 151 } | |
| LEFT | RIGHT |