/ocr/ocrservice/src/com/googlecode/eyesfree/ocr/client/VersionAlert.java
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 17package com.googlecode.eyesfree.ocr.client; 18 19import android.app.AlertDialog; 20import android.content.Context; 21import android.content.DialogInterface; 22import android.content.DialogInterface.OnClickListener; 23import android.content.Intent; 24import android.net.Uri; 25 26/** 27 * Creates an alert dialog that directs the user to the App Market. 28 * 29 * @author alanv@google.com (Alan Viverette) 30 */ 31public class VersionAlert { 32 private final static String MARKET_URI = "market://search?q=pname:com.googlecode.eyesfree.ocr"; 33 34 public static String install = "This application requires the Mobile OCR library for text recognition."; 35 public static String install_title = "Install OCR Library"; 36 public static String install_positive = "Install"; 37 public static String install_negative = "Do not install"; 38 public static String update = "This application requires a newer version of the Mobile OCR library."; 39 public static String update_title = "Update OCR Library"; 40 public static String update_positive = "Update"; 41 public static String update_negative = "Do not update"; 42 public static String sdcard = "Please insert an SD card or turn off USB storage."; 43 public static String sdcard_title = "Insert SD Card"; 44 public static String sdcard_neutral = "OK"; 45 public static String languages = "Please install at least one Mobile OCR language pack."; 46 public static String languages_title = "Install OCR Languages"; 47 public static String languages_positive = "Select language"; 48 public static String languages_negative = "Do not install"; 49 50 private VersionAlert() { 51 // This class is not instantiable. 52 } 53 54 /** 55 * Returns an install dialog. 56 * 57 * @param context 58 * @param onNegative 59 * @return An install dialog. 60 */ 61 public static AlertDialog createInstallAlert(final Context context, OnClickListener onNegative) { 62 OnClickListener onPositive = new OnClickListener() { 63 @Override 64 public void onClick(DialogInterface dialog, int which) { 65 Uri marketUri = Uri.parse(MARKET_URI); 66 Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri); 67 context.startActivity(marketIntent); 68 } 69 }; 70 71 AlertDialog alert = new AlertDialog.Builder(context).setMessage(install) 72 .setTitle(install_title).setPositiveButton(install_positive, onPositive) 73 .setNegativeButton(install_negative, onNegative).create(); 74 75 return alert; 76 } 77 78 /** 79 * Returns an update dialog. 80 * 81 * @param context 82 * @param onNegative 83 * @return An update dialog. 84 */ 85 public static AlertDialog createUpdateAlert(final Context context, OnClickListener onNegative) { 86 OnClickListener onPositive = new OnClickListener() { 87 @Override 88 public void onClick(DialogInterface dialog, int which) { 89 Uri marketUri = Uri.parse(MARKET_URI); 90 Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri); 91 context.startActivity(marketIntent); 92 } 93 }; 94 95 AlertDialog alert = new AlertDialog.Builder(context).setMessage(update) 96 .setTitle(update_title).setPositiveButton(update_positive, onPositive) 97 .setNegativeButton(update_negative, onNegative).create(); 98 99 return alert; 100 } 101 102 /** 103 * Returns a storage alert dialog. 104 * 105 * @param context 106 * @param onNeutral 107 * @return A storage alert dialog. 108 */ 109 public static AlertDialog createStorageAlert(final Context context, OnClickListener onNeutral) { 110 AlertDialog alert = new AlertDialog.Builder(context).setMessage(sdcard) 111 .setTitle(sdcard_title).setNeutralButton(sdcard_neutral, onNeutral).create(); 112 113 return alert; 114 } 115 116 /** 117 * Creates an alert requesting that the user install a language. 118 * 119 * @param context 120 * @param onPositive action to perform if the user accepts 121 * @param onNegative action to perform if the user declines 122 * @return alert dialog 123 */ 124 public static AlertDialog createLanguagesAlert(final Context context, 125 final OnClickListener onPositive, OnClickListener onNegative) { 126 OnClickListener onRealPositive = new OnClickListener() { 127 @Override 128 public void onClick(DialogInterface dialog, int which) { 129 Intent languagesIntent = new Intent(Intents.Languages.ACTION); 130 context.startActivity(languagesIntent); 131 onPositive.onClick(dialog, which); 132 } 133 }; 134 135 AlertDialog alert = new AlertDialog.Builder(context).setMessage(languages) 136 .setTitle(languages_title).setPositiveButton(languages_positive, onRealPositive) 137 .setNegativeButton(languages_negative, onNegative).create(); 138 139 return alert; 140 } 141}