package jp.ito.camera;

import java.util.Map;
import java.util.TreeMap;

import android.content.Context;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

//壛懍搙僙儞僒乕偺棙梡
public class SensorView extends View {
    private Map<String, Integer>	_map = new TreeMap<String, Integer>();
    public volatile int _x = 0;
    public volatile int _y = 0;
    public volatile int _z = 0;
    public volatile int _diffX = 0;
    public volatile int _diffY = 0;
    public volatile int _diffZ = 0;
//    public int _level = 6;

    //僐儞僗僩儔僋僞
    public SensorView(Context context) {
        super(context);
        setBackgroundColor(Color.LTGRAY);
    }
    
    //昤夋
    @Override 
    protected void onDraw(Canvas canvas) {
        //儁僀儞僩
        Paint paint=new Paint();       
        paint.setAntiAlias(true);
        paint.setTextSize(12);
        
        //抣偺昞帵
        canvas.drawText("X幉壛懍搙 : "+_x+" ("+_diffX+")",10,14*1,paint);
        canvas.drawText(getBar((int)_x), 10, 14*2, paint);
        canvas.drawText("Y幉壛懍搙 : "+_y+" ("+_diffY+")",10,14*3,paint);
        canvas.drawText(getBar((int)_y), 10, 14*4, paint);
        canvas.drawText("Z幉壛懍搙 : "+_z+" ("+_diffZ+")",10,14*5,paint);        
        canvas.drawText(getBar((int)_z), 10, 14*6, paint);
//        canvas.drawText("曽埵:"    +_orientation[0], 10,14*4,paint);
//        canvas.drawText("僺僢僠:"   +_orientation[1], 10,14*5,paint);
//        canvas.drawText("儘乕儖:"   +_orientation[2], 10,14*6,paint);
    }

    private String getBar(int level){
    	if ( level < -5 ) {
    		return "仩仩仩仩仩仩";
    	} else if ( level < -4 ) {
    		return "丂仩仩仩仩仩";
    	} else if ( level < -3 ) {
    		return "丂丂仩仩仩仩";
    	} else if ( level < -2 ) {
    		return "丂丂丂仩仩仩";
    	} else if ( level < -1 ) {
    		return "丂丂丂丂仩仩";
    	} else if ( level < 0 ) {
    		return "丂丂丂丂丂仩";
    	} else if ( level < 1 ) {
    		return "丂丂丂丂丂丂仭";
    	} else if ( level < 2 ) {
    		return "丂丂丂丂丂丂仭仭";
    	} else if ( level < 3 ) {
    		return "丂丂丂丂丂丂仭仭仭";
    	} else if ( level < 4 ) {
    		return "丂丂丂丂丂丂仭仭仭仭";
    	} else if ( level < 5 ) {
    		return "丂丂丂丂丂丂仭仭仭仭仭";
    	} else if ( level < 6 ) {
    		return "丂丂丂丂丂丂仭仭仭仭仭仭";
    	} else if ( level < 7 ) {
    		return "丂丂丂丂丂丂仭仭仭仭仭仭仭";
    	} else if ( level < 8 ) {
    		return "丂丂丂丂丂丂仭仭仭仭仭仭仭仭";
    	} else if ( level < 9 ) {
    		return "丂丂丂丂丂丂仭仭仭仭仭仭仭仭仭";
    	}
    	return "丂丂丂丂丂丂仭仭仭仭仭仭仭仭仭仭";
    }
    public String getMessage(){
    	StringBuffer sb = new StringBuffer();
		sb.append("嵟嬤俁擔娫偺奐暵婰榐\n");
    	for (Map.Entry<String, Integer> e : _map.entrySet()){
    		sb.append("\t" + e.getKey() + "\n");
    	}
		sb.append("\n\n");
    	return sb.toString();
    }
}
