안드로이드 개발 질문/답변
(글 수 45,052)
Compass를 만들고 있습니다.
방위가 바뀔때마다 이미지로 방위를 표시하는대요
아래 빨간색을 보시면 String 값으로 Log는 잘찍히는대
setBackground를 하면 에러가 납니다.
이미지로 처리하는 방법 부탁드리겠습니다.ㅠㅠ
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
float startPoint = 0f;
float endPoint = 360f;
float gap = 22.5f;
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
for (int i = 0; i < 3; i++) {
valuesAccelerometer[i] = event.values[i];
aValues[i] = event.values[i];
}
break;
case Sensor.TYPE_MAGNETIC_FIELD:
for (int i = 0; i < 3; i++) {
valuesMagneticField[i] = event.values[i];
mValues[i] = event.values[i];
}
break;
}
boolean success = SensorManager.getRotationMatrix(matrixR, matrixI,
valuesAccelerometer, valuesMagneticField);
if (success) {
SensorManager.getOrientation(matrixR, matrixValues);
azimuth = Math.toDegrees(matrixValues[0]);
msValues = calculateOrientation(mValues);
//Log.d("msValues : ",msValues[0] +"");
String compass_resource = "";
View view = mLock_root.findViewById(R.id.compass_azimuth);
for(int i=0; i < CompassStr.length; i++) {
startPoint= i*gap;
endPoint = (i+1)*gap;
// Log.d(TAG, startPoint + "");
// Log.d(TAG, endPoint + "");
if(view != null){
if(startPoint < msValues[0] && msValues[0] < endPoint) {
compass_resource = CompassStr[i];
setBackground(compass_resource,view);
Log.d(TAG,"compass_resource : " + compass_resource);
//Log.d(TAG,i+"");
}
}
}
// if( mCompass_azimuth != null){
// }else{
// Log.d(TAG,"mCompass_azimuth!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
// }
mCompassView.update(matrixValues[0], azimuth);
}
}
private void setBackground(String str,View view){
int bgDrawable = 0;
for (int i = 0; i < CompassStr.length; i++) {
if(str.equals(CompassStr[i])){
bgDrawable = compass_image[i];
// mCompass_azimuth.setBackgroundResource(compass_image[i]);
}
}
view.setBackgroundResource(bgDrawable);
}