Index: mobile/android/thirdparty/org/adblockplus/browser/UrlInputOpenerPreference.java |
diff --git a/mobile/android/thirdparty/org/adblockplus/browser/UrlInputOpenerPreference.java b/mobile/android/thirdparty/org/adblockplus/browser/UrlInputOpenerPreference.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..545f69c50590e1f1b8c96628f420bbebfb8d3667 |
--- /dev/null |
+++ b/mobile/android/thirdparty/org/adblockplus/browser/UrlInputOpenerPreference.java |
@@ -0,0 +1,82 @@ |
+/* |
+ * This file is part of Adblock Plus <https://adblockplus.org/>, |
+ * Copyright (C) 2006-2015 Eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+package org.adblockplus.browser; |
+ |
+import java.lang.ref.WeakReference; |
+ |
+import android.content.Context; |
+import android.preference.Preference; |
+import android.util.AttributeSet; |
+ |
+public class UrlInputOpenerPreference extends Preference implements UrlInputDialog.UrlReadyCallback |
+{ |
+ private static WeakReference<UrlInputDialog.UrlReadyCallback> redirectUrlReadyCallback = null; |
+ |
+ public UrlInputOpenerPreference(Context context) |
+ { |
+ super(context); |
+ } |
+ |
+ public UrlInputOpenerPreference(Context context, AttributeSet attrs) |
+ { |
+ super(context, attrs); |
+ } |
+ |
+ public UrlInputOpenerPreference(Context context, AttributeSet attrs, int defStyleAttr) |
+ { |
+ super(context, attrs, defStyleAttr); |
+ } |
+ |
+ protected static synchronized void setRedirectUrlReadyCallback( |
+ final UrlInputDialog.UrlReadyCallback callback) |
+ { |
+ redirectUrlReadyCallback = new WeakReference<UrlInputDialog.UrlReadyCallback>(callback); |
+ } |
+ |
+ @Override |
+ protected void onAttachedToActivity() |
+ { |
+ this.setPersistent(false); |
+ } |
+ |
+ @Override |
+ protected void onClick() |
+ { |
+ new UrlInputDialog(this.getContext(), UrlInputDialog.Type.ADD_SUBSCRIPTION, this).show(); |
+ } |
+ |
+ @Override |
+ public void callback(String url) |
+ { |
+ try |
+ { |
+ if (redirectUrlReadyCallback != null) |
+ { |
+ final UrlInputDialog.UrlReadyCallback callback = redirectUrlReadyCallback.get(); |
+ if (callback != null) |
+ { |
+ callback.callback(url); |
+ } |
+ } |
+ } |
+ catch (Throwable t) |
+ { |
+ // we do not care |
+ } |
+ } |
+} |