12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package com.feemers.android.fftdrawer;
-
- import android.content.Context;
- import android.graphics.Canvas;
- import android.graphics.Color;
- import android.util.AttributeSet;
- import android.util.Log;
- import android.view.SurfaceHolder;
- import android.view.SurfaceView;
-
- public class BarChartView extends SurfaceView implements Runnable {
-
- private Animation animation;
- private SurfaceHolder surfaceHolder;
- private Thread thread = null;
- private volatile boolean running = false;
- private int backgroudColor = 0;
- private String name = "";
- private int sleepTime = 0;
- private volatile boolean update;
-
-
- public BarChartView(Context context) {
- super(context);
- surfaceHolder = getHolder();
- }
- public BarChartView(Context context, AttributeSet attributeSet){
- super(context, attributeSet);
- surfaceHolder = getHolder();
- ReadXML(attributeSet);
- }
- private void ReadXML(AttributeSet attributeSet){
- android.content.res.TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.BarChartView);
- //String s = typedArray.getString(R.styleable.GrafikView_android_text);
- //name = (s!=null) ? s : "";
- backgroudColor = typedArray.getColor(R.styleable.BarChartView_backgroundColor, Color.BLACK);
- typedArray.recycle();
- log(", hintergrundFarbe=" + backgroudColor);
- }
-
- public void setAnimation(Animation animation){
- this.animation = animation;
- this.animation.SetBackgroundColor(backgroudColor);
- }
-
- private void log(String s) {
- Log.d(this.getClass().getSimpleName(), s);
- }
-
- public void Start(){
- running = true;
- thread = new Thread(this);
- thread.start();
- log("Thread started");
- }
-
- public void Stop(){
- running = false;
- while(true){
- try{
- thread.join();
- log("Thread stopped");
- break;
- }catch (InterruptedException e){
- e.printStackTrace();
- }
- }
- }
- public void Draw(){
- update = true;
- }
-
- @Override
- public void run() {
- while (running) {
- if (update) {
- if (!surfaceHolder.getSurface().isValid()) {
- continue;
- }
- Canvas canvas = surfaceHolder.lockCanvas();
- if (animation != null) {
- animation.Draw(canvas);
- update = false;
- }
- surfaceHolder.unlockCanvasAndPost(canvas);
- }
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
|