0
所以我剛剛測試了一個應用程序,我一直在三星平板電腦上測試電話設備。orientation tablet vs phone
基於accelermoter數據的應用程序更新的圖形和我注意到,在平板電腦上是治療的風景與人像..其自然人像模式設備上很好..
任何想法,我哪有那麼它ajust這適用於兩個:
public class ARLaunch extends Activity {
/** Open Camera View **/
private CamLayer camPreview;
/** Open Camera View **/
private GLLayer glView;
private WakeLock mWakeLock;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requesting to turn the title OFF
requestWindowFeature(Window.FEATURE_NO_TITLE);
// making it full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
//Set Screen Orientation
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
try{
final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
this.mWakeLock = pm.newWakeLock(
PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag");
//Create Intance of Camera
camPreview = new CamLayer(this.getApplicationContext());
//Create Instance of OpenGL
glView = new GLLayer(this);
//FrameLayOut for holding everything
FrameLayout frame = new FrameLayout(this);
// set as main view
setContentView(frame);
// add Camera to view
frame.addView(camPreview, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
frame.addView(glView);
} catch(Exception e){}
}
/** Remember to resume the glSurface */
@Override
protected void onResume() {
super.onResume();
try{
this.mWakeLock.acquire();
} catch (Exception ex){}
glView.onResume();
glView.setZOrderOnTop(true);
}
/** Also pause the glSurface */
@Override
protected void onPause() {
super.onPause();
try{
this.mWakeLock.release();
} catch (Exception ex){}
glView.onPause();
}
public void displayOri(float acc, float ori){
}
}
public class PhoneOrientation {
private SensorManager sensorMan;
private Sensor sensorAcce;
private Sensor sensorMagn;
private SensorEventListener listener;
private float matrix[]=new float[16];
private Context ctx;
public PhoneOrientation(Context context) {
ctx = context;
}
public void start(Context context) {
listener = new SensorEventListener() {
private float orientation[]=new float[3];
private float acceleration[]=new float[3];
public void onAccuracyChanged(Sensor arg0, int arg1){}
public void onSensorChanged(SensorEvent evt) {
int type=evt.sensor.getType();
//Smoothing the sensor data a bit seems like a good idea.
if (type == Sensor.TYPE_MAGNETIC_FIELD) {
orientation[0]=(orientation[0]*1+evt.values[0])*0.5f;
orientation[1]=(orientation[1]*1+evt.values[1])*0.5f;
orientation[2]=(orientation[2]*1+evt.values[2])*0.5f;
} else if (type == Sensor.TYPE_ACCELEROMETER) {
acceleration[0]=(acceleration[0]*2+evt.values[0])*0.33334f;
acceleration[1]=(acceleration[1]*2+evt.values[1])*0.33334f;
acceleration[2]=(acceleration[2]*2+evt.values[2])*0.33334f;
}
if ((type==Sensor.TYPE_MAGNETIC_FIELD) || (type==Sensor.TYPE_ACCELEROMETER)) {
float newMat[]=new float[16];
//Toast toast = Toast.makeText(ctx.getApplicationContext(), "accel", Toast.LENGTH_SHORT);
//toast.show();
SensorManager.getRotationMatrix(newMat, null, acceleration, orientation);
SensorManager.remapCoordinateSystem(newMat,
SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X,
newMat);
matrix=newMat;
}
}
};
sensorMan = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
sensorAcce = sensorMan.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
sensorMagn = sensorMan.getSensorList(Sensor.TYPE_MAGNETIC_FIELD).get(0);
sensorMan.registerListener(listener, sensorAcce, SensorManager.SENSOR_DELAY_GAME);
sensorMan.registerListener(listener, sensorMagn, SensorManager.SENSOR_DELAY_GAME);
}
public float[] getMatrix() {
return matrix;
}
public void finish() {
sensorMan.unregisterListener(listener);
}
}
嗯,我不知道這篇文章是否真的幫助我..我已經編輯了我的代碼,以上顯示我的手機方向類.. – erik 2012-07-10 17:06:10
實際上得到它的工作謝謝! – erik 2012-07-10 19:30:52
和喚醒鎖從來沒有真正的工作..但你的解決方案..謝謝 – erik 2012-07-10 19:31:56