| LEFT | RIGHT |
| 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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 19 matching lines...) Expand all Loading... |
| 30 import android.view.View.OnClickListener; | 30 import android.view.View.OnClickListener; |
| 31 import android.view.inputmethod.EditorInfo; | 31 import android.view.inputmethod.EditorInfo; |
| 32 import android.widget.Button; | 32 import android.widget.Button; |
| 33 import android.widget.EditText; | 33 import android.widget.EditText; |
| 34 import android.widget.TextView; | 34 import android.widget.TextView; |
| 35 import android.widget.TextView.OnEditorActionListener; | 35 import android.widget.TextView.OnEditorActionListener; |
| 36 | 36 |
| 37 public class UrlInputDialog extends Dialog implements TextWatcher, | 37 public class UrlInputDialog extends Dialog implements TextWatcher, |
| 38 OnEditorActionListener, OnClickListener | 38 OnEditorActionListener, OnClickListener |
| 39 { | 39 { |
| 40 private static final int BUTTON_ENABLED_COLOR = 0xff0099cc; | |
| 41 private static final int BUTTON_DISABLED_COLOR = 0xffc5dfe8; | |
| 42 private final Type type; | 40 private final Type type; |
| 43 private final UrlReadyCallback callback; | 41 private final UrlReadyCallback callback; |
| 44 | 42 |
| 45 private EditText editText = null; | 43 private EditText editText = null; |
| 46 private Button button = null; | 44 private Button button = null; |
| 47 | 45 |
| 48 private boolean submitEnabled = false; | 46 private boolean submitEnabled = false; |
| 49 private boolean triedSubmit = false; | 47 private boolean triedSubmit = false; |
| 50 private String currentEditTextValue = null; | 48 private String currentEditTextValue = null; |
| 51 | 49 |
| 52 public enum Type | 50 public enum Type |
| 53 { | 51 { |
| 54 ADD_BLOCKING_LIST, | 52 ADD_SUBSCRIPTION, |
| 55 ADD_WHITELIST | 53 ADD_WHITELISTED_SITE |
| 56 } | 54 } |
| 57 | 55 |
| 58 public UrlInputDialog(final Context context, final Type type, final UrlReadyCa
llback callback) | 56 public UrlInputDialog(final Context context, final Type type, final UrlReadyCa
llback callback) |
| 59 { | 57 { |
| 60 super(context); | 58 super(context); |
| 61 this.type = type; | 59 this.type = type; |
| 62 this.callback = callback; | 60 this.callback = callback; |
| 63 } | 61 } |
| 64 | 62 |
| 65 @Override | 63 @Override |
| (...skipping 15 matching lines...) Expand all Loading... |
| 81 this.button.setOnClickListener(this); | 79 this.button.setOnClickListener(this); |
| 82 | 80 |
| 83 if (this.currentEditTextValue != null) | 81 if (this.currentEditTextValue != null) |
| 84 { | 82 { |
| 85 this.editText.setText(this.currentEditTextValue); | 83 this.editText.setText(this.currentEditTextValue); |
| 86 } | 84 } |
| 87 this.updateButtonState(); | 85 this.updateButtonState(); |
| 88 | 86 |
| 89 switch (this.type) | 87 switch (this.type) |
| 90 { | 88 { |
| 91 case ADD_BLOCKING_LIST: | 89 case ADD_SUBSCRIPTION: |
| 92 this.button.setText(R.string.abb_block_list_button); | 90 this.button.setText(R.string.abb_add_subscription_button); |
| 93 this.editText.setHint(R.string.abb_block_list_url); | 91 this.editText.setHint(R.string.abb_add_subscription_url); |
| 94 this.setTitle(R.string.abb_pref_category_add_other_list); | 92 this.setTitle(R.string.abb_pref_category_add_other_list); |
| 95 break; | 93 break; |
| 96 default: | 94 default: |
| 97 break; | 95 break; |
| 98 } | 96 } |
| 99 } | 97 } |
| 100 | 98 |
| 101 private void updateButtonState() | 99 private void updateButtonState() |
| 102 { | 100 { |
| 103 this.button.setEnabled(this.submitEnabled); | 101 this.button.setEnabled(this.submitEnabled); |
| 104 this.button.setBackgroundColor(this.submitEnabled | 102 this.button.setBackgroundColor(this.submitEnabled |
| 105 ? BUTTON_ENABLED_COLOR | 103 ? this.getContext().getResources().getColor(R.color.abb_url_input_button
_enabled) |
| 106 : BUTTON_DISABLED_COLOR); | 104 : this.getContext().getResources().getColor(R.color.abb_url_input_button
_disabled)); |
| 107 this.button.invalidate(); | 105 this.button.invalidate(); |
| 108 } | 106 } |
| 109 | 107 |
| 110 @Override | 108 @Override |
| 111 public void afterTextChanged(final Editable s) | 109 public void afterTextChanged(final Editable s) |
| 112 { | 110 { |
| 113 this.currentEditTextValue = s.toString(); | 111 this.currentEditTextValue = s.toString(); |
| 114 this.submitEnabled = this.validateUrl(this.currentEditTextValue) != null; | 112 this.submitEnabled = this.validateUrl(this.currentEditTextValue) != null; |
| 115 if (this.submitEnabled) | 113 if (this.submitEnabled) |
| 116 { | 114 { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 186 |
| 189 @Override | 187 @Override |
| 190 public void onClick(final View v) | 188 public void onClick(final View v) |
| 191 { | 189 { |
| 192 if (this.currentEditTextValue != null) | 190 if (this.currentEditTextValue != null) |
| 193 { | 191 { |
| 194 this.validateAndSubmit(this.currentEditTextValue); | 192 this.validateAndSubmit(this.currentEditTextValue); |
| 195 } | 193 } |
| 196 } | 194 } |
| 197 } | 195 } |
| LEFT | RIGHT |