blob: d4708c30e7f7ba30062e38828fb35995bebc046e [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 BrowserHomepagePreference extends EditTextPreference implements
29 TextWatcher {
30
31 public BrowserHomepagePreference(Context context, AttributeSet attrs,
32 int defStyle) {
33 super(context, attrs, defStyle);
34 getEditText().addTextChangedListener(this);
35 }
36
37 public BrowserHomepagePreference(Context context, AttributeSet attrs) {
38 super(context, attrs);
39 getEditText().addTextChangedListener(this);
40 }
41
42 public BrowserHomepagePreference(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 url = s.toString();
52 dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(
53 url.length() == 0 || url.equals("about:blank") ||
54 Regex.WEB_URL_PATTERN.matcher(url).matches());
55 }
56 }
57
58 public void beforeTextChanged(CharSequence s, int start, int count,
59 int after) {
60 }
61
62 public void onTextChanged(CharSequence s, int start, int before, int count) {
63 }
64}