AndroidVoiceMessageView.java
Go to the documentation of this file.
00001 package org.ros.android.androidVoiceMessage;
00002 
00003 import java.util.ArrayList;
00004 
00005 import android.content.Context;
00006 import android.graphics.Canvas;
00007 import android.graphics.Color;
00008 import android.graphics.Paint;
00009 import android.graphics.Typeface;
00010 import android.graphics.Paint.Style;
00011 import android.view.SurfaceHolder;
00012 import android.view.SurfaceView;
00013 
00014 
00015 public class AndroidVoiceMessageView extends SurfaceView implements
00016                 SurfaceHolder.Callback, Runnable {
00017 
00018         private SurfaceHolder holder;
00019         private Thread thread;
00020         private Paint paint;
00021         private Canvas canvas;
00022         private int width;
00023         private float originalY;
00024         private float scale;
00025 
00026         private ArrayList<Float> volumeArray;
00027 
00028         public AndroidVoiceMessageView(Context context) {
00029                 super(context);
00030                 // initialize
00031                 volumeArray = new ArrayList<Float>();
00032                 width = getWidth();
00033                 originalY = getHeight();
00034                 scale = 3;
00035 
00036                 paint = new Paint();
00037                 paint.setStyle(Style.FILL);
00038                 paint.setTextSize(32);
00039                 paint.setTypeface(Typeface.create(Typeface.SERIF, Typeface.BOLD_ITALIC));
00040 
00041         }
00042         
00043         public void setView(SurfaceView surfaceView){
00044                 holder = surfaceView.getHolder();
00045                 holder.addCallback(this);
00046                 holder.setFixedSize(480, 262);
00047         }
00048 
00049         public void surfaceCreated(SurfaceHolder holder) {
00050                 thread = new Thread(this);
00051                 thread.start();
00052         }
00053 
00054         public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
00055                 width = w;
00056 
00057         }
00058 
00059         public void surfaceDestroyed(SurfaceHolder holder) {
00060                 thread = null;
00061         }
00062 
00063         public void run() {
00064                 while (true) {
00065                         try {
00066                                 int size = volumeArray.size();
00067                                 canvas = holder.lockCanvas();
00068                                 canvas.drawColor(Color.BLACK);
00069                                 paint.setColor(Color.GRAY);
00070                                         canvas.drawLine(0, originalY, width, originalY, paint);
00071                                 
00072                                 paint.setColor(Color.WHITE);
00073                                         for (int i = 0; i < size - 2; i++) {
00074                                                 canvas.drawLine(i*3, volumeArray.get(i)*scale + originalY, (i + 1)*3,
00075                                                                 volumeArray.get(i + 1)*scale + originalY, paint);
00076                                         }
00077                         
00078                                 holder.unlockCanvasAndPost(canvas);
00079 
00080                         } catch (Exception e) {
00081 
00082                         }
00083                 }
00084         }
00085 
00086         public void addValues(float value) {
00087                 volumeArray.add(value);
00088                 if (volumeArray.size() > width/3+1) {
00089                         volumeArray.remove(0);
00090                 }
00091         }
00092 
00093 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


android_voice_message
Author(s): Damon Kohler
autogenerated on Sun Mar 24 2013 07:29:33