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

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

Issue 9423010: ABP/Android Better icon hide (Closed)
Patch Set: Created Feb. 20, 2013, 12:08 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 the Adblock Plus, 2 * This file is part of the Adblock Plus,
3 * Copyright (C) 2006-2012 Eyeo GmbH 3 * Copyright (C) 2006-2012 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
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 import android.app.PendingIntent; 55 import android.app.PendingIntent;
56 import android.content.Context; 56 import android.content.Context;
57 import android.content.Intent; 57 import android.content.Intent;
58 import android.content.SharedPreferences; 58 import android.content.SharedPreferences;
59 import android.content.pm.PackageInfo; 59 import android.content.pm.PackageInfo;
60 import android.content.pm.PackageManager; 60 import android.content.pm.PackageManager;
61 import android.content.pm.PackageManager.NameNotFoundException; 61 import android.content.pm.PackageManager.NameNotFoundException;
62 import android.content.res.AssetManager; 62 import android.content.res.AssetManager;
63 import android.net.ConnectivityManager; 63 import android.net.ConnectivityManager;
64 import android.net.NetworkInfo; 64 import android.net.NetworkInfo;
65 import android.net.Uri;
65 import android.os.AsyncTask; 66 import android.os.AsyncTask;
66 import android.os.Build; 67 import android.os.Build;
67 import android.os.Bundle; 68 import android.os.Bundle;
68 import android.os.Handler; 69 import android.os.Handler;
69 import android.os.Message; 70 import android.os.Message;
70 import android.os.SystemClock; 71 import android.os.SystemClock;
71 import android.preference.PreferenceManager; 72 import android.preference.PreferenceManager;
73 import android.provider.Settings;
72 import android.util.Log; 74 import android.util.Log;
73 import android.widget.Toast; 75 import android.widget.Toast;
74 76
75 public class AdblockPlus extends Application 77 public class AdblockPlus extends Application
76 { 78 {
77 private final static String TAG = "Application"; 79 private final static String TAG = "Application";
78 80
79 private final static int MSG_TOAST = 1; 81 private final static int MSG_TOAST = 1;
80 82
81 /** 83 /**
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 119 }
118 catch (NameNotFoundException e) 120 catch (NameNotFoundException e)
119 { 121 {
120 // ignore - this shouldn't happen 122 // ignore - this shouldn't happen
121 Log.e(TAG, e.getMessage(), e); 123 Log.e(TAG, e.getMessage(), e);
122 } 124 }
123 return buildNumber; 125 return buildNumber;
124 } 126 }
125 127
126 /** 128 /**
129 * Opens Android application settings
130 */
131 public static void showAppDetails(Context context)
132 {
133 String packageName = context.getPackageName();
134 Intent intent = new Intent();
135 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)
136 {
137 // above 2.3
138 intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
139 Uri uri = Uri.fromParts("package", packageName, null);
140 intent.setData(uri);
141 }
142 else
143 {
144 // below 2.3
145 final String appPkgName = (Build.VERSION.SDK_INT == Build.VERSION_CODES.FR OYO ? "pkg" : "com.android.settings.ApplicationPkgName");
146 intent.setAction(Intent.ACTION_VIEW);
147 intent.setClassName("com.android.settings", "com.android.settings.Installe dAppDetails");
148 intent.putExtra(appPkgName, packageName);
149 }
150 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
151 context.startActivity(intent);
152 }
153
154 /**
127 * Returns device name in user-friendly format 155 * Returns device name in user-friendly format
128 */ 156 */
129 public static String getDeviceName() 157 public static String getDeviceName()
130 { 158 {
131 String manufacturer = Build.MANUFACTURER; 159 String manufacturer = Build.MANUFACTURER;
132 String model = Build.MODEL; 160 String model = Build.MODEL;
133 if (model.startsWith(manufacturer)) 161 if (model.startsWith(manufacturer))
134 return capitalize(model); 162 return capitalize(model);
135 else 163 else
136 return capitalize(manufacturer) + " " + model; 164 return capitalize(manufacturer) + " " + model;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 { 246 {
219 // TODO Auto-generated catch block 247 // TODO Auto-generated catch block
220 Log.e(TAG, e.getMessage(), e); 248 Log.e(TAG, e.getMessage(), e);
221 } 249 }
222 } 250 }
223 return subscriptions; 251 return subscriptions;
224 } 252 }
225 253
226 /** 254 /**
227 * Returns subscription information. 255 * Returns subscription information.
228 * 256 *
Thomas Greiner 2013/02/27 16:34:29 How did that happen? I noticed that there are 8 oc
229 * @param url 257 * @param url
230 * subscription url 258 * subscription url
231 */ 259 */
232 public Subscription getSubscription(String url) 260 public Subscription getSubscription(String url)
233 { 261 {
234 List<Subscription> subscriptions = getSubscriptions(); 262 List<Subscription> subscriptions = getSubscriptions();
235 263
236 for (Subscription subscription : subscriptions) 264 for (Subscription subscription : subscriptions)
237 { 265 {
238 if (subscription.url.equals(url)) 266 if (subscription.url.equals(url))
239 return subscription; 267 return subscription;
240 } 268 }
241 return null; 269 return null;
242 } 270 }
243 271
244 /** 272 /**
245 * Adds provided subscription and removes previous subscriptions if any. 273 * Adds provided subscription and removes previous subscriptions if any.
246 * 274 *
247 * @param subscription 275 * @param subscription
248 * Subscription to add 276 * Subscription to add
249 */ 277 */
250 public void setSubscription(Subscription subscription) 278 public void setSubscription(Subscription subscription)
251 { 279 {
252 if (subscription != null) 280 if (subscription != null)
253 { 281 {
254 final JSONObject jsonSub = new JSONObject(); 282 final JSONObject jsonSub = new JSONObject();
255 try 283 try
256 { 284 {
(...skipping 28 matching lines...) Expand all
285 @Override 313 @Override
286 public void run() 314 public void run()
287 { 315 {
288 js.evaluate("refreshSubscriptions()"); 316 js.evaluate("refreshSubscriptions()");
289 } 317 }
290 }); 318 });
291 } 319 }
292 320
293 /** 321 /**
294 * Selects which subscription to offer for the first time. 322 * Selects which subscription to offer for the first time.
295 * 323 *
296 * @return offered subscription 324 * @return offered subscription
297 */ 325 */
298 public Subscription offerSubscription() 326 public Subscription offerSubscription()
299 { 327 {
300 Subscription selectedItem = null; 328 Subscription selectedItem = null;
301 String selectedPrefix = null; 329 String selectedPrefix = null;
302 int matchCount = 0; 330 int matchCount = 0;
303 for (Subscription subscription : getSubscriptions()) 331 for (Subscription subscription : getSubscriptions())
304 { 332 {
305 if (selectedItem == null) 333 if (selectedItem == null)
(...skipping 24 matching lines...) Expand all
330 } 358 }
331 } 359 }
332 } 360 }
333 } 361 }
334 return selectedItem; 362 return selectedItem;
335 } 363 }
336 364
337 /** 365 /**
338 * Verifies that subscriptions are loaded and returns flag of subscription 366 * Verifies that subscriptions are loaded and returns flag of subscription
339 * presence. 367 * presence.
340 * 368 *
341 * @return true if at least one subscription is present and downloaded 369 * @return true if at least one subscription is present and downloaded
342 */ 370 */
343 public boolean verifySubscriptions() 371 public boolean verifySubscriptions()
344 { 372 {
345 Future<Boolean> future = js.submit(new Callable<Boolean>() 373 Future<Boolean> future = js.submit(new Callable<Boolean>()
346 { 374 {
347 @Override 375 @Override
348 public Boolean call() throws Exception 376 public Boolean call() throws Exception
349 { 377 {
350 Boolean result = (Boolean) js.evaluate("verifySubscriptions()"); 378 Boolean result = (Boolean) js.evaluate("verifySubscriptions()");
(...skipping 12 matching lines...) Expand all
363 catch (ExecutionException e) 391 catch (ExecutionException e)
364 { 392 {
365 // TODO Auto-generated catch block 393 // TODO Auto-generated catch block
366 Log.e(TAG, e.getMessage(), e); 394 Log.e(TAG, e.getMessage(), e);
367 } 395 }
368 return false; 396 return false;
369 } 397 }
370 398
371 /** 399 /**
372 * Returns ElemHide selectors for domain. 400 * Returns ElemHide selectors for domain.
373 * 401 *
374 * @return ready to use HTML element with CSS selectors 402 * @return ready to use HTML element with CSS selectors
375 */ 403 */
376 public String getSelectorsForDomain(final String domain) 404 public String getSelectorsForDomain(final String domain)
377 { 405 {
378 Future<String> future = js.submit(new Callable<String>() 406 Future<String> future = js.submit(new Callable<String>()
379 { 407 {
380 @Override 408 @Override
381 public String call() throws Exception 409 public String call() throws Exception
382 { 410 {
383 String result = (String) js.evaluate("ElemHide.getSelectorsForDomain('" + domain + "')"); 411 String result = (String) js.evaluate("ElemHide.getSelectorsForDomain('" + domain + "')");
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 @Override 449 @Override
422 public Boolean call() throws Exception 450 public Boolean call() throws Exception
423 { 451 {
424 Boolean result = (Boolean) js.evaluate("matchesAny('" + url + "', '" + que ry + "', '" + reqHost + "', '" + refHost + "', '" + accept + "');"); 452 Boolean result = (Boolean) js.evaluate("matchesAny('" + url + "', '" + que ry + "', '" + reqHost + "', '" + refHost + "', '" + accept + "');");
425 return result; 453 return result;
426 } 454 }
427 } 455 }
428 456
429 /** 457 /**
430 * Checks if filters match request parameters. 458 * Checks if filters match request parameters.
431 * 459 *
432 * @param url 460 * @param url
433 * Request URL 461 * Request URL
434 * @param query 462 * @param query
435 * Request query string 463 * Request query string
436 * @param reqHost 464 * @param reqHost
437 * Request host 465 * Request host
438 * @param refHost 466 * @param refHost
439 * Request referrer header 467 * Request referrer header
440 * @param accept 468 * @param accept
441 * Request accept header 469 * Request accept header
(...skipping 27 matching lines...) Expand all
469 497
470 /** 498 /**
471 * Notifies JS code that application quit interactive mode. 499 * Notifies JS code that application quit interactive mode.
472 */ 500 */
473 public void stopInteractive() 501 public void stopInteractive()
474 { 502 {
475 // onStop is sometimes called without prior calling onStart 503 // onStop is sometimes called without prior calling onStart
476 // by Android system 504 // by Android system
477 if (js == null) 505 if (js == null)
478 return; 506 return;
479 507
480 js.execute(new Runnable() 508 js.execute(new Runnable()
481 { 509 {
482 @Override 510 @Override
483 public void run() 511 public void run()
484 { 512 {
485 js.evaluate("stopInteractive()"); 513 js.evaluate("stopInteractive()");
486 } 514 }
487 }); 515 });
488 interactive = false; 516 interactive = false;
489 } 517 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 // Refresh if user selected refresh on each start 551 // Refresh if user selected refresh on each start
524 if (refresh == 1 && (!wifionly || isWiFiConnected(this))) 552 if (refresh == 1 && (!wifionly || isWiFiConnected(this)))
525 { 553 {
526 refreshSubscription(); 554 refreshSubscription();
527 } 555 }
528 } 556 }
529 } 557 }
530 558
531 /** 559 /**
532 * Stops JS engine. 560 * Stops JS engine.
533 * 561 *
534 * @param implicitly 562 * @param implicitly
535 * stop even in interactive mode 563 * stop even in interactive mode
536 */ 564 */
537 public void stopEngine(boolean implicitly) 565 public void stopEngine(boolean implicitly)
538 { 566 {
539 if ((implicitly || !interactive) && js != null) 567 if ((implicitly || !interactive) && js != null)
540 { 568 {
541 js.stopEngine(); 569 js.stopEngine();
542 try 570 try
543 { 571 {
544 js.join(); 572 js.join();
545 } 573 }
546 catch (InterruptedException e) 574 catch (InterruptedException e)
547 { 575 {
548 Log.e(TAG, e.getMessage(), e); 576 Log.e(TAG, e.getMessage(), e);
549 } 577 }
550 js = null; 578 js = null;
551 } 579 }
552 } 580 }
553 581
554 /** 582 /**
555 * Sets Alarm to call updater after specified number of minutes or after one 583 * Sets Alarm to call updater after specified number of minutes or after one
556 * day if 584 * day if
557 * minutes are set to 0. 585 * minutes are set to 0.
558 * 586 *
559 * @param minutes 587 * @param minutes
560 * number of minutes to wait 588 * number of minutes to wait
561 */ 589 */
562 public void scheduleUpdater(int minutes) 590 public void scheduleUpdater(int minutes)
563 { 591 {
564 Calendar updateTime = Calendar.getInstance(); 592 Calendar updateTime = Calendar.getInstance();
565 593
566 if (minutes == 0) 594 if (minutes == 0)
567 { 595 {
568 // Start update checks at 10:00 GMT... 596 // Start update checks at 10:00 GMT...
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 } 1089 }
1062 return result; 1090 return result;
1063 } 1091 }
1064 1092
1065 protected void onProgressUpdate(Integer... progress) 1093 protected void onProgressUpdate(Integer... progress)
1066 { 1094 {
1067 Log.d("HTTP", "Progress: " + progress[0].intValue()); 1095 Log.d("HTTP", "Progress: " + progress[0].intValue());
1068 } 1096 }
1069 } 1097 }
1070 } 1098 }
OLDNEW

Powered by Google App Engine
This is Rietveld