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