Notice
Recent Posts
Recent Comments
Link
관리 메뉴

설.현.아빠

방향 센서 0점 조정하기. 본문

안드로이드/Device & Sensor

방향 센서 0점 조정하기.

설.현.아빠 2011. 7. 20. 17:26



@Override       

public void onSensorChanged(SensorEvent event) {

if(mCtx.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {

// 0점 조정

if(portBaseX > event.values[0]){

event.values[0]=360-(portBaseX-event.values[0]);

}

else if(portBaseX <= event.values[0]){

event.values[0]=event.values[0]-portBaseX;

}

if(event.values[0]<340 && event.values[0]>=270){

//오른쪽

currType = 4;

if(!TypeCheck(currType,lastType)){

imageView.setImageDrawable(images.get(currType));

lastType = 4;

}

else if(event.values[0]>20 && event.values[0]<270){

//왼쪽

currType = 3;

if(!TypeCheck(currType,lastType)){

imageView.setImageDrawable(images.get(currType));

lastType = 3;

}

}

else{

//가운데

currType = 0;

if(!TypeCheck(currType,lastType)){

imageView.setImageDrawable(images.get(currType));

lastType = 0;

}

}

}

}

Comments