| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 final String sdkVersion = String.valueOf(VERSION.SDK_INT); | 53 final String sdkVersion = String.valueOf(VERSION.SDK_INT); |
| 54 final String locale = context.getResources().getConfiguration().locale.toStr
ing(); | 54 final String locale = context.getResources().getConfiguration().locale.toStr
ing(); |
| 55 final boolean developmentBuild = !context.getResources().getBoolean(R.bool.d
ef_release); | 55 final boolean developmentBuild = !context.getResources().getBoolean(R.bool.d
ef_release); |
| 56 initialize(basePath, version, sdkVersion, locale, developmentBuild); | 56 initialize(basePath, version, sdkVersion, locale, developmentBuild); |
| 57 } | 57 } |
| 58 | 58 |
| 59 public void onFilterChanged(String url, String status, long time) | 59 public void onFilterChanged(String url, String status, long time) |
| 60 { | 60 { |
| 61 context.sendBroadcast(new Intent(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS).
putExtra("url", url).putExtra("status", status).putExtra("time", time)); | 61 context.sendBroadcast(new Intent(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS).
putExtra("url", url).putExtra("status", status).putExtra("time", time)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 /** | 64 /** |
| 65 * Called when update event occurred. | 65 * Called when update event occurred. |
| 66 * @param url Update download address | 66 * @param url Update download address |
| 67 */ | 67 */ |
| 68 public void onUpdateEvent(String url, String error) | 68 public void onUpdateEvent(String url, String error) |
| 69 { | 69 { |
| 70 Notification notification = getNotification(url, error); | 70 Notification notification = getNotification(url, error); |
| 71 NotificationManager notificationManager = (NotificationManager) context.getS
ystemService(Context.NOTIFICATION_SERVICE); | 71 NotificationManager notificationManager = (NotificationManager) context.getS
ystemService(Context.NOTIFICATION_SERVICE); |
| 72 notificationManager.notify(NOTIFICATION_ID, notification); | 72 notificationManager.notify(NOTIFICATION_ID, notification); |
| 73 } | 73 } |
| 74 | 74 |
| 75 private native void initialize(String basePath, String version, String sdkVers
ion, String locale, boolean developmentBuild); | 75 private native void initialize(String basePath, String version, String sdkVers
ion, String locale, boolean developmentBuild); |
| 76 | 76 |
| 77 public native void release(); | 77 public native void release(); |
| 78 | 78 |
| 79 public native boolean isFirstRun(); | 79 public native boolean isFirstRun(); |
| 80 | 80 |
| 81 public native Subscription[] getListedSubscriptions(); | 81 public native Subscription[] getListedSubscriptions(); |
| 82 | 82 |
| 83 public native Subscription[] getRecommendedSubscriptions(); | 83 public native Subscription[] getRecommendedSubscriptions(); |
| 84 | 84 |
| 85 public native void addSubscription(String url); | 85 public native void addSubscription(String url); |
| 86 | 86 |
| 87 public native void removeSubscription(String url); | 87 public native void removeSubscription(String url); |
| 88 | 88 |
| 89 public native void refreshSubscription(String url); | 89 public native void refreshSubscription(String url); |
| 90 | 90 |
| 91 public native void actualizeSubscriptionStatus(String url); | 91 public native void actualizeSubscriptionStatus(String url); |
| 92 | 92 |
| 93 public native void setAcceptableAdsEnabled(boolean enabled); | 93 public native void setAcceptableAdsEnabled(boolean enabled); |
| 94 | 94 |
| 95 public native String getDocumentationLink(); | 95 public native String getDocumentationLink(); |
| 96 | 96 |
| 97 public native boolean matches(String url, String contentType, String[] documen
tUrls); | 97 public native boolean matches(String url, String contentType, String[] documen
tUrls); |
| 98 | 98 |
| 99 public native String[] getSelectorsForDomain(String domain); | 99 public native String[] getSelectorsForDomain(String domain); |
| 100 | 100 |
| 101 public native void checkUpdates(); | 101 public native void checkUpdates(); |
| 102 | 102 |
| 103 private Notification getNotification(String url, String error) | 103 private Notification getNotification(String url, String error) |
| 104 { | 104 { |
| 105 final PendingIntent emptyIntent = PendingIntent.getActivity(context, 0, new
Intent(), 0); | 105 final PendingIntent emptyIntent = PendingIntent.getActivity(context, 0, new
Intent(), 0); |
| 106 | 106 |
| 107 NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
; | 107 NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
; |
| 108 builder.setContentTitle(context.getText(R.string.app_name)); | 108 builder.setContentTitle(context.getText(R.string.app_name)); |
| 109 builder.setSmallIcon(R.drawable.ic_stat_warning); | 109 builder.setSmallIcon(R.drawable.ic_stat_warning); |
| 110 builder.setWhen(System.currentTimeMillis()); | 110 builder.setWhen(System.currentTimeMillis()); |
| 111 builder.setAutoCancel(true); | 111 builder.setAutoCancel(true); |
| 112 builder.setOnlyAlertOnce(true); | 112 builder.setOnlyAlertOnce(true); |
| 113 builder.setContentIntent(emptyIntent); | 113 builder.setContentIntent(emptyIntent); |
| 114 | 114 |
| 115 if (url != null) | 115 if (url != null) |
| 116 { | 116 { |
| 117 builder.setSmallIcon(R.drawable.ic_stat_download); | 117 builder.setSmallIcon(R.drawable.ic_stat_download); |
| 118 | 118 |
| 119 | 119 |
| 120 Intent intent = new Intent(context, UpdaterActivity.class).addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK); | 120 Intent intent = new Intent(context, UpdaterActivity.class).addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK); |
| 121 intent.setAction("download"); | 121 intent.setAction("download"); |
| 122 intent.putExtra("url", url); | 122 intent.putExtra("url", url); |
| 123 PendingIntent updateIntent = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT); | 123 PendingIntent updateIntent = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT); |
| 124 builder.setContentIntent(updateIntent); | 124 builder.setContentIntent(updateIntent); |
| 125 builder.setContentText(context.getString(R.string.msg_update_available)); | 125 builder.setContentText(context.getString(R.string.msg_update_available)); |
| 126 } | 126 } |
| 127 else if (error != null) | 127 else if (error != null) |
| 128 { | 128 { |
| 129 //TODO Should we show error message to the user? | 129 //TODO Should we show error message to the user? |
| 130 builder.setContentText(context.getString(R.string.msg_update_fail)); | 130 builder.setContentText(context.getString(R.string.msg_update_fail)); |
| 131 } | 131 } |
| 132 else | 132 else |
| 133 { | 133 { |
| 134 builder.setContentText(context.getString(R.string.msg_update_missing)); | 134 builder.setContentText(context.getString(R.string.msg_update_missing)); |
| 135 } | 135 } |
| 136 | 136 |
| 137 Notification notification = builder.getNotification(); | 137 Notification notification = builder.getNotification(); |
| 138 return notification; | 138 return notification; |
| 139 } | 139 } |
| 140 | 140 |
| 141 static | 141 static |
| 142 { | 142 { |
| 143 System.loadLibrary("abpEngine"); | 143 System.loadLibrary("abpEngine"); |
| 144 } | 144 } |
| 145 } | 145 } |
| OLD | NEW |