/ime/latinime/src/com/googlecode/eyesfree/inputmethod/latin/tutorial/LatinTutorialDialog.java

http://eyes-free.googlecode.com/ · Java · 68 lines · 40 code · 9 blank · 19 comment · 1 complexity · 1874443de7f3e80c8eb326066bae0634 MD5 · raw file

  1. /*
  2. * Copyright (C) 2011 Google Inc.
  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.googlecode.eyesfree.inputmethod.latin.tutorial;
  17. import android.app.Activity;
  18. import android.app.AlertDialog;
  19. import android.content.DialogInterface;
  20. import android.content.DialogInterface.OnCancelListener;
  21. import android.content.DialogInterface.OnClickListener;
  22. import android.content.Intent;
  23. import android.view.WindowManager;
  24. import com.googlecode.eyesfree.inputmethod.latin.R;
  25. /**
  26. * Shows an alert dialog asking whether the user would like to run the tutorial.
  27. * This activity is only necessary because a Service cannot show a dialog.
  28. */
  29. public class LatinTutorialDialog extends Activity {
  30. @Override
  31. protected void onResume() {
  32. super.onResume();
  33. final AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.tutorial_name)
  34. .setMessage(R.string.tutorial_first_time)
  35. .setCancelable(true).setNegativeButton(android.R.string.no, dialogClickListener)
  36. .setPositiveButton(android.R.string.ok, dialogClickListener)
  37. .setOnCancelListener(dialogCancelListener)
  38. .create();
  39. dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
  40. dialog.show();
  41. }
  42. private final OnCancelListener dialogCancelListener = new OnCancelListener() {
  43. @Override
  44. public void onCancel(DialogInterface dialog) {
  45. finish();
  46. }
  47. };
  48. private final OnClickListener dialogClickListener = new OnClickListener() {
  49. @Override
  50. public void onClick(DialogInterface dialog, int which) {
  51. switch (which) {
  52. case DialogInterface.BUTTON_POSITIVE:
  53. startActivity(new Intent(LatinIMETutorial.ACTION));
  54. break;
  55. }
  56. finish();
  57. }
  58. };
  59. }