/ocr/ocrservice/src/com/googlecode/eyesfree/ocr/client/VersionAlert.java

http://eyes-free.googlecode.com/ · Java · 141 lines · 75 code · 16 blank · 50 comment · 0 complexity · 6829a257af4dbe77dbf7726865675c04 MD5 · raw file

  1. /*
  2. * Copyright (C) 2011 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * 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, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.googlecode.eyesfree.ocr.client;
  17. import android.app.AlertDialog;
  18. import android.content.Context;
  19. import android.content.DialogInterface;
  20. import android.content.DialogInterface.OnClickListener;
  21. import android.content.Intent;
  22. import android.net.Uri;
  23. /**
  24. * Creates an alert dialog that directs the user to the App Market.
  25. *
  26. * @author alanv@google.com (Alan Viverette)
  27. */
  28. public class VersionAlert {
  29. private final static String MARKET_URI = "market://search?q=pname:com.googlecode.eyesfree.ocr";
  30. public static String install = "This application requires the Mobile OCR library for text recognition.";
  31. public static String install_title = "Install OCR Library";
  32. public static String install_positive = "Install";
  33. public static String install_negative = "Do not install";
  34. public static String update = "This application requires a newer version of the Mobile OCR library.";
  35. public static String update_title = "Update OCR Library";
  36. public static String update_positive = "Update";
  37. public static String update_negative = "Do not update";
  38. public static String sdcard = "Please insert an SD card or turn off USB storage.";
  39. public static String sdcard_title = "Insert SD Card";
  40. public static String sdcard_neutral = "OK";
  41. public static String languages = "Please install at least one Mobile OCR language pack.";
  42. public static String languages_title = "Install OCR Languages";
  43. public static String languages_positive = "Select language";
  44. public static String languages_negative = "Do not install";
  45. private VersionAlert() {
  46. // This class is not instantiable.
  47. }
  48. /**
  49. * Returns an install dialog.
  50. *
  51. * @param context
  52. * @param onNegative
  53. * @return An install dialog.
  54. */
  55. public static AlertDialog createInstallAlert(final Context context, OnClickListener onNegative) {
  56. OnClickListener onPositive = new OnClickListener() {
  57. @Override
  58. public void onClick(DialogInterface dialog, int which) {
  59. Uri marketUri = Uri.parse(MARKET_URI);
  60. Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
  61. context.startActivity(marketIntent);
  62. }
  63. };
  64. AlertDialog alert = new AlertDialog.Builder(context).setMessage(install)
  65. .setTitle(install_title).setPositiveButton(install_positive, onPositive)
  66. .setNegativeButton(install_negative, onNegative).create();
  67. return alert;
  68. }
  69. /**
  70. * Returns an update dialog.
  71. *
  72. * @param context
  73. * @param onNegative
  74. * @return An update dialog.
  75. */
  76. public static AlertDialog createUpdateAlert(final Context context, OnClickListener onNegative) {
  77. OnClickListener onPositive = new OnClickListener() {
  78. @Override
  79. public void onClick(DialogInterface dialog, int which) {
  80. Uri marketUri = Uri.parse(MARKET_URI);
  81. Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
  82. context.startActivity(marketIntent);
  83. }
  84. };
  85. AlertDialog alert = new AlertDialog.Builder(context).setMessage(update)
  86. .setTitle(update_title).setPositiveButton(update_positive, onPositive)
  87. .setNegativeButton(update_negative, onNegative).create();
  88. return alert;
  89. }
  90. /**
  91. * Returns a storage alert dialog.
  92. *
  93. * @param context
  94. * @param onNeutral
  95. * @return A storage alert dialog.
  96. */
  97. public static AlertDialog createStorageAlert(final Context context, OnClickListener onNeutral) {
  98. AlertDialog alert = new AlertDialog.Builder(context).setMessage(sdcard)
  99. .setTitle(sdcard_title).setNeutralButton(sdcard_neutral, onNeutral).create();
  100. return alert;
  101. }
  102. /**
  103. * Creates an alert requesting that the user install a language.
  104. *
  105. * @param context
  106. * @param onPositive action to perform if the user accepts
  107. * @param onNegative action to perform if the user declines
  108. * @return alert dialog
  109. */
  110. public static AlertDialog createLanguagesAlert(final Context context,
  111. final OnClickListener onPositive, OnClickListener onNegative) {
  112. OnClickListener onRealPositive = new OnClickListener() {
  113. @Override
  114. public void onClick(DialogInterface dialog, int which) {
  115. Intent languagesIntent = new Intent(Intents.Languages.ACTION);
  116. context.startActivity(languagesIntent);
  117. onPositive.onClick(dialog, which);
  118. }
  119. };
  120. AlertDialog alert = new AlertDialog.Builder(context).setMessage(languages)
  121. .setTitle(languages_title).setPositiveButton(languages_positive, onRealPositive)
  122. .setNegativeButton(languages_negative, onNegative).create();
  123. return alert;
  124. }
  125. }