簡體   English   中英

增加震動感應器的靈敏度,並增加手機搖晃時的亮度屏幕

[英]increase accelerometer sensor sensitivity, and increase the brightness screen when the phone is shaken

我想在這段代碼中實現一些指令,以提高加速度傳感器的靈敏度,並增加手機搖動時屏幕的亮度

sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensorManager.registerListener(this,         sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
lastUpdate = System.currentTimeMillis();

@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {                                     getAccelerometer(event);
}
}   
private void getAccelerometer(SensorEvent event) {
super.onResume();
float[] values = event.values;
// Movement
float x = values[0];
float y = values[1];
float z = values[2];
float accelationSquareRoot = (x * x + y * y + z * z)
/ (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH);
long actualTime = System.currentTimeMillis();
if (accelationSquareRoot >= 2) //
{
if (actualTime - lastUpdate < 200) {            
return;
}           
lastUpdate = actualTime;            
Toast.makeText(this, "Device was shuffed", Toast.LENGTH_SHORT).show();  
if (mMediaPlayer.isPlaying() == false){ 
mMediaPlayer.start();               
}
}
}
int stretch = 50;
int boundary = 5;

float x = values[0];
float y = values[1];
float z = values[2];

x *= stretch;
y *= stretch;
z *= stretch;

if (x > 5 || x < -5) 
   x = 0;
if (y > 5 || y < -5) 
   y = 0;
if (z > 5 || z < -5) 
   z = 0;

只是一個非常基本的過濾器

就屏幕亮度而言:

private void setBrightness(int brightness) {  
try {  
  IHardwareService hardware = IHardwareService.Stub.asInterface(  
  ServiceManager.getService("hardware"));  
  if (hardware != null) {  
    hardware.setScreenBacklight(brightness);  
  }  
} catch (RemoteException doe) {            
  }          
}  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM