PageRenderTime 14ms CodeModel.GetById 7ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/WebVox/src/com/marvin/webvox/BrowserHomepagePreference.java

http://eyes-free.googlecode.com/
Java | 65 lines | 39 code | 8 blank | 18 comment | 8 complexity | 28964ebcba990817d9711df158d29ae0 MD5 | raw file
 1/*
 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.marvin.webvox;
18
19import com.marvin.webvox.R;
20
21import android.app.AlertDialog;
22import android.content.Context;
23import android.preference.EditTextPreference;
24import android.util.AttributeSet;
25
26public class BrowserHomepagePreference extends EditTextPreference {
27
28    public BrowserHomepagePreference(Context context, AttributeSet attrs,
29            int defStyle) {
30        super(context, attrs, defStyle);
31    }
32
33    public BrowserHomepagePreference(Context context, AttributeSet attrs) {
34        super(context, attrs);
35    }
36
37    public BrowserHomepagePreference(Context context) {
38        super(context);
39    }
40
41    @Override
42    protected void onDialogClosed(boolean positiveResult) {
43        if (positiveResult) {
44            String url = getEditText().getText().toString();
45            if (url.length() > 0
46                    && !BrowserActivity.ACCEPTED_URI_SCHEMA.matcher(url)
47                            .matches()) {
48                int colon = url.indexOf(':');
49                int space = url.indexOf(' ');
50                if (colon == -1 && space == -1) {
51                    // if no colon, no space, add "http://" to make it a url
52                    getEditText().setText("http://" + url);
53                } else {
54                    // show an error dialog and change the positiveResult to
55                    // false so that the bad url will not override the old url
56                    new AlertDialog.Builder(this.getContext()).setMessage(
57                            R.string.bookmark_url_not_valid).setPositiveButton(
58                            R.string.ok, null).show();
59                    positiveResult = false;
60                }
61            }
62        }
63        super.onDialogClosed(positiveResult);
64    }
65}