PageRenderTime 50ms CodeModel.GetById 32ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/ItemID/src/com/ideal/itemid/VoiceRecorderConfirmationView.java

http://eyes-free.googlecode.com/
Java | 136 lines | 106 code | 11 blank | 19 comment | 4 complexity | a231ed3baa5702d8f518ee8c7b976fc7 MD5 | raw file
  1/*
  2 * Copyright (C) 2010 The IDEAL Group
  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
 17package com.ideal.itemid;
 18
 19import android.content.Context;
 20import android.content.Intent;
 21import android.graphics.Canvas;
 22import android.graphics.Color;
 23import android.graphics.Paint;
 24import android.graphics.Typeface;
 25import android.media.MediaPlayer;
 26import android.net.Uri;
 27import android.view.KeyEvent;
 28import android.view.MotionEvent;
 29import android.widget.TextView;
 30
 31/**
 32 * The confirmation View for IDEAL Item ID Label Maker. Handles the touch
 33 * events and confirms the recording that the user has made.
 34 */
 35public class VoiceRecorderConfirmationView extends TextView {
 36    private VoiceRecorderActivity parent;
 37
 38    private MediaPlayer mPlayer;
 39
 40    public VoiceRecorderConfirmationView(Context context) {
 41        super(context);
 42        parent = (VoiceRecorderActivity) context;
 43        setClickable(true);
 44        setFocusable(true);
 45        setFocusableInTouchMode(true);
 46        requestFocus();
 47        parent.mTts.speak("Touch and hold the screen to preview your recording, let go when done.",
 48                0, null);
 49    }
 50
 51    @Override
 52    public boolean onTouchEvent(MotionEvent event) {
 53        int action = event.getAction();
 54        long[] pattern = {
 55                0, 1, 40, 41
 56        };
 57        switch (action) {
 58            case MotionEvent.ACTION_DOWN:
 59                parent.mVibe.vibrate(pattern, -1);
 60                mPlayer = MediaPlayer.create(parent, Uri.parse("/sdcard/idealItemId/"
 61                        + parent.FILE_TIMESTAMP + ".amr"));
 62                mPlayer.start();
 63                break;
 64            case MotionEvent.ACTION_UP:
 65                if (mPlayer != null) {
 66                    mPlayer.stop();
 67                    mPlayer.release();
 68                }
 69                parent.mTts
 70                        .speak(
 71                                "Press back to re-record, press call or search to confirm, then enter the e-mail address you wish to send the QR code label to.",
 72                                0, null);
 73                parent.mVibe.vibrate(pattern, -1);
 74                break;
 75            default:
 76                break;
 77        }
 78        invalidate();
 79        return true;
 80    }
 81
 82    @Override
 83    public void onDraw(Canvas canvas) {
 84        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
 85        paint.setColor(Color.WHITE);
 86        paint.setTextAlign(Paint.Align.CENTER);
 87        paint.setTypeface(Typeface.DEFAULT_BOLD);
 88
 89        int x = 5;
 90        int y = getHeight() - 40;
 91        paint.setTextSize(20);
 92        paint.setTextAlign(Paint.Align.LEFT);
 93        y -= paint.ascent() / 2;
 94        canvas.drawText("Press CALL/SEARCH to confirm", x, y, paint);
 95        x = 5;
 96        y = getHeight() - 20;
 97        paint.setTextSize(20);
 98        paint.setTextAlign(Paint.Align.LEFT);
 99        y -= paint.ascent() / 2;
100        canvas.drawText("Press BACK to try again", x, y, paint);
101    }
102
103    @Override
104    public boolean onKeyDown(int keyCode, KeyEvent event) {
105        switch (keyCode) {
106            case KeyEvent.KEYCODE_SEARCH:
107            case KeyEvent.KEYCODE_CALL:
108                parent.mTts.playEarcon("[tock]", 0, null);
109                long[] pattern = {
110                        0, 1, 40, 41
111                };
112                parent.mVibe.vibrate(pattern, -1);
113
114                final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
115                emailIntent.setType("text/html");
116                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {
117                    ""
118                });
119                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
120                        "Your printable QR code label for IDEAL Item ID");
121                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
122                        "http://qrcode.kaywa.com/img.php?s=8&d=audio%3A%2F%2F"
123                                + parent.FILE_TIMESTAMP + ".amr" + "\n\n" + "<img src='"
124                                + "http://qrcode.kaywa.com/img.php?s=8&d=audio%3A%2F%2F"
125                                + parent.FILE_TIMESTAMP + ".amr" + "'>");
126
127                parent.startActivity(emailIntent);
128                parent.finish();
129                return true;
130            case KeyEvent.KEYCODE_BACK:
131                parent.showRecordingView();
132                return true;
133        }
134        return false;
135    }
136}