blob: 09e89933bc2b68f4f94c0bdb813b9896244bcdf7 [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser;
18
19import android.app.AlertDialog;
20import android.content.Context;
21import android.content.DialogInterface;
22import android.preference.EditTextPreference;
23import android.text.Editable;
24import android.text.TextWatcher;
25import android.text.util.Regex;
26import android.util.AttributeSet;
27
28public class BrowserSearchpagePreference extends EditTextPreference implements
29 TextWatcher {
30
31 public BrowserSearchpagePreference(Context context, AttributeSet attrs,
32 int defStyle) {
33 super(context, attrs, defStyle);
34 getEditText().addTextChangedListener(this);
35 }
36
37 public BrowserSearchpagePreference(Context context, AttributeSet attrs) {
38 super(context, attrs);
39 getEditText().addTextChangedListener(this);
40 }
41
42 public BrowserSearchpagePreference(Context context) {
43 super(context);
44 getEditText().addTextChangedListener(this);
45 }
46
47 public void afterTextChanged(Editable s) {
48 AlertDialog dialog = (AlertDialog) getDialog();
49 // This callback is called before the dialog has been fully constructed
50 if (dialog != null) {
51 String string = s.toString();
52 int length = string.length();
53 int first = length > 0 ? string
54 .indexOf(BrowserActivity.QUERY_PLACE_HOLDER) : -1;
55 int last = length > 0 ? string
56 .lastIndexOf(BrowserActivity.QUERY_PLACE_HOLDER) : -1;
57 dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(
58 length == 0 || (first > 0 && first == last));
59 }
60 }
61
62 public void beforeTextChanged(CharSequence s, int start, int count,
63 int after) {
64 }
65
66 public void onTextChanged(CharSequence s, int start, int before, int count) {
67 }
68}