blob: be96db321ee5fa7441ca86936b3338783e0012fd [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;
The Android Open Source Project0c908882009-03-03 19:32:16 -080021import android.preference.EditTextPreference;
The Android Open Source Project0c908882009-03-03 19:32:16 -080022import android.util.AttributeSet;
23
Grace Kloba7ec2ba32009-09-10 21:28:18 -070024public class BrowserHomepagePreference extends EditTextPreference {
The Android Open Source Project0c908882009-03-03 19:32:16 -080025
26 public BrowserHomepagePreference(Context context, AttributeSet attrs,
27 int defStyle) {
28 super(context, attrs, defStyle);
The Android Open Source Project0c908882009-03-03 19:32:16 -080029 }
30
31 public BrowserHomepagePreference(Context context, AttributeSet attrs) {
32 super(context, attrs);
The Android Open Source Project0c908882009-03-03 19:32:16 -080033 }
34
35 public BrowserHomepagePreference(Context context) {
36 super(context);
The Android Open Source Project0c908882009-03-03 19:32:16 -080037 }
38
Grace Kloba7ec2ba32009-09-10 21:28:18 -070039 @Override
40 protected void onDialogClosed(boolean positiveResult) {
41 if (positiveResult) {
42 String url = getEditText().getText().toString();
43 if (url.length() > 0
44 && !BrowserActivity.ACCEPTED_URI_SCHEMA.matcher(url)
45 .matches()) {
46 int colon = url.indexOf(':');
47 int space = url.indexOf(' ');
48 if (colon == -1 && space == -1) {
49 // if no colon, no space, add "http://" to make it a url
50 getEditText().setText("http://" + url);
51 } else {
52 // show an error dialog and change the positiveResult to
53 // false so that the bad url will not override the old url
54 new AlertDialog.Builder(this.getContext()).setMessage(
55 R.string.bookmark_url_not_valid).setPositiveButton(
56 R.string.ok, null).show();
57 positiveResult = false;
58 }
59 }
The Android Open Source Project0c908882009-03-03 19:32:16 -080060 }
Grace Kloba7ec2ba32009-09-10 21:28:18 -070061 super.onDialogClosed(positiveResult);
The Android Open Source Project0c908882009-03-03 19:32:16 -080062 }
63}