/remindme/src/com/google/marvin/remindme/ConfirmationView.java

http://eyes-free.googlecode.com/ · Java · 90 lines · 56 code · 14 blank · 20 comment · 1 complexity · 34ee0a670fde7bef504054f18e3e717b MD5 · raw file

  1. /*
  2. * Copyright (C) 2008 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.google.marvin.remindme;
  17. import android.content.Context;
  18. import android.graphics.Canvas;
  19. import android.graphics.Color;
  20. import android.graphics.Paint;
  21. import android.graphics.Typeface;
  22. import android.os.Vibrator;
  23. import android.view.KeyEvent;
  24. import android.widget.TextView;
  25. /**
  26. * Implements the user interface for doing slide dialing.
  27. *
  28. * @author clchen@google.com (Charles L. Chen) Created 8-2-2008
  29. */
  30. public class ConfirmationView extends TextView {
  31. public RemindMe parent;
  32. private Vibrator vibe;
  33. public ConfirmationView(Context context) {
  34. super(context);
  35. parent = (RemindMe) context;
  36. vibe = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
  37. setClickable(true);
  38. setFocusable(true);
  39. setFocusableInTouchMode(true);
  40. requestFocus();
  41. }
  42. @Override
  43. public void onDraw(Canvas canvas) {
  44. Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
  45. paint.setColor(Color.WHITE);
  46. paint.setTextAlign(Paint.Align.CENTER);
  47. paint.setTypeface(Typeface.DEFAULT_BOLD);
  48. int x = 5;
  49. int y = getHeight() - 40;
  50. paint.setTextSize(20);
  51. paint.setTextAlign(Paint.Align.LEFT);
  52. y -= paint.ascent() / 2;
  53. canvas.drawText("Press CALL to confirm", x, y, paint);
  54. x = 5;
  55. y = getHeight() - 20;
  56. paint.setTextSize(20);
  57. paint.setTextAlign(Paint.Align.LEFT);
  58. y -= paint.ascent() / 2;
  59. canvas.drawText("Press BACK to try again", x, y, paint);
  60. }
  61. @Override
  62. public boolean onKeyDown(int keyCode, KeyEvent event) {
  63. switch (keyCode) {
  64. case KeyEvent.KEYCODE_CALL:
  65. parent.tts.playEarcon("[tock]", 0, null);
  66. long[] pattern = {0, 1, 40, 41};
  67. vibe.vibrate(pattern, -1);
  68. parent.confirmAlarm();
  69. return true;
  70. case KeyEvent.KEYCODE_BACK:
  71. parent.showNumberEntryView();
  72. return true;
  73. }
  74. return false;
  75. }
  76. }