当前位置: 首页>>代码示例>>Java>>正文


Java SensorManager类代码示例

本文整理汇总了Java中android.hardware.SensorManager的典型用法代码示例。如果您正苦于以下问题:Java SensorManager类的具体用法?Java SensorManager怎么用?Java SensorManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SensorManager类属于android.hardware包,在下文中一共展示了SensorManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onSensorChanged

import android.hardware.SensorManager; //导入依赖的package包/类
public void onSensorChanged(SensorEvent event) {
    if (event.accuracy == SensorManager.SENSOR_STATUS_ACCURACY_LOW) return;

    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        arrayCopy(event.values, geomagnetic);
    }
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        arrayCopy(event.values, gravity);
    }
    if (SensorManager.getRotationMatrix(R, I, gravity, geomagnetic)) {
        SensorManager.getOrientation(R, orientation);
        azimuth += easing * (orientation[0] - azimuth);
        pitch += easing * (orientation[1] - pitch);
        roll += easing * (orientation[2] - roll);
    }
}
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:17,代码来源:CompassSketch.java

示例2: AmbientLightMonitor

import android.hardware.SensorManager; //导入依赖的package包/类
public AmbientLightMonitor(Context context) {
    prefs = new PreferenceManager(context);

    context.bindService(new Intent(context,
            MonitorService.class), mConnection, Context.BIND_ABOVE_CLIENT);

    sensorMgr = (SensorManager) context.getSystemService(Activity.SENSOR_SERVICE);
    //noinspection RedundantCast
    sensor = (Sensor) sensorMgr.getDefaultSensor(Sensor.TYPE_LIGHT);

    if (sensor == null) {
        Log.i("AccelerometerFrament", "Warning: no accelerometer");
    } else {
        sensorMgr.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
    }

}
 
开发者ID:guardianproject,项目名称:haven,代码行数:18,代码来源:AmbientLightMonitor.java

示例3: onCreate

import android.hardware.SensorManager; //导入依赖的package包/类
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    mySensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    myAccelerometer = mySensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mySensorManager.registerListener(this, myAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);

    int level = getIntent().getIntExtra("level", 1);

    soundEngine = new com.homescreenarcade.mazeman.SoundEngine(this);
    gameEngine = new com.homescreenarcade.mazeman.GameEngine(this, soundEngine, level);
    
    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    gameView = new com.homescreenarcade.mazeman.GameSurfaceView(this, gameEngine, width, height);

    setContentView(gameView);
   
    
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:24,代码来源:GameActivity.java

示例4: A

import android.hardware.SensorManager; //导入依赖的package包/类
public static String A(Context context) {
    try {
        SensorManager sensorManager = (SensorManager) context.getSystemService("sensor");
        if (sensorManager != null) {
            List sensorList = sensorManager.getSensorList(-1);
            if (sensorList != null) {
                StringBuilder stringBuilder = new StringBuilder();
                for (int i = 0; i < sensorList.size(); i++) {
                    stringBuilder.append(((Sensor) sensorList.get(i)).getType());
                    if (i != sensorList.size() - 1) {
                        stringBuilder.append(",");
                    }
                }
                return stringBuilder.toString();
            }
        }
    } catch (Object th) {
        f.e(th);
    }
    return "";
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:22,代码来源:k.java

示例5: M

import android.hardware.SensorManager; //导入依赖的package包/类
public static String M(Context context) {
    if (e(cE)) {
        return cE;
    }
    try {
        SensorManager sensorManager = (SensorManager) context.getSystemService("sensor");
        if (sensorManager != null) {
            List sensorList = sensorManager.getSensorList(-1);
            if (sensorList != null) {
                StringBuilder stringBuilder = new StringBuilder(sensorList.size() * 10);
                for (int i = 0; i < sensorList.size(); i++) {
                    stringBuilder.append(((Sensor) sensorList.get(i)).getType());
                    if (i != sensorList.size() - 1) {
                        stringBuilder.append(",");
                    }
                }
                cE = stringBuilder.toString();
            }
        }
    } catch (Throwable th) {
        cT.b(th);
    }
    return cE;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:25,代码来源:l.java

示例6: onCreate

import android.hardware.SensorManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.NoActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ButterKnife.bind(this);
    assetIdEdit.addTextChangedListener(watcher);
    assetIdEdit.setOnEditorActionListener((textView, actionId, keyEvent) -> {
        boolean handled = false;
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            submit();
            handled = true;
        }
        return handled;
    });
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    locationManager = new RxLocationManager(DemoApplication.get(this).getRxLocation());
}
 
开发者ID:BANKEX,项目名称:smart-asset-iot-android-demo,代码行数:23,代码来源:MainActivity.java

示例7: onSensorChanged

import android.hardware.SensorManager; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
  float x = event.values[0];
  float y = event.values[1];
  float z = event.values[2];

  float gX = x / SensorManager.GRAVITY_EARTH;
  float gY = y / SensorManager.GRAVITY_EARTH;
  float gZ = z / SensorManager.GRAVITY_EARTH;

  // gForce will be close to 1 when there is no movement.
  float gForce = (float) Math.sqrt(gX * gX + gY * gY + gZ * gZ);

  if (gForce > SHAKE_THRESHOLD_GRAVITY) {
    final long now = System.currentTimeMillis();
    // ignore shake events too close to each other (500ms)
    if (mShakeTimestamp + SHAKE_SLOP_TIME_MS > now) {
      return;
    }
    mShakeTimestamp = now;
    this.onShakeListener.onShake();
  }
}
 
开发者ID:jainsahab,项目名称:AndroidSnooper,代码行数:24,代码来源:ShakeDetector.java

示例8: toggleWakeUpWithProximityFeature

import android.hardware.SensorManager; //导入依赖的package包/类
private static void toggleWakeUpWithProximityFeature(boolean enabled) {
    try {
        if (enabled) {
            mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
            mProxSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
            mWakeLock = ((PowerManager) mContext.getSystemService(Context.POWER_SERVICE))
                    .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
        } else {
            unregisterProxSensorListener();
            mProxSensor = null;
            mSensorManager = null;
            mWakeLock = null;
        }
        if (DEBUG) log("toggleWakeUpWithProximityFeature: " + enabled);
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:19,代码来源:ModPower.java

示例9: start

import android.hardware.SensorManager; //导入依赖的package包/类
@Override
public boolean start(Object obj) {
	try{
		mSensorManger = (SensorManager)getmServiceContext().getSystemService(Context.SENSOR_SERVICE);
		mSensor = mSensorManger.getDefaultSensor(Sensor.TYPE_PROXIMITY);
		mSensorListener = new MySensorListener();
		request(AntiTheftService.REQUEST_SHOW_MSG, getName() + "防护已开启,将在10秒后正式生效" + SF.TIP);
		mCDTimer = new CountDownTimer(10000, 1000) {
			
			@Override
			public void onTick(long millisUntilFinished) {
			}
			
			@Override
			public void onFinish() {
				mSensorManger.registerListener(mSensorListener, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
			}
		};
		setNeedDelay(true);
		mCDTimer.start();
		return true;
	}catch(Exception e){
		request(AntiTheftService.REQUEST_SHOW_MSG, "开启\"" + getName() + "\"防护失败,可能您的设备不支持距离传感器!");
		return false;
	}
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:27,代码来源:PocketProtector.java

示例10: onCreate

import android.hardware.SensorManager; //导入依赖的package包/类
/**
 * Function to create activity view
 *
 * @param savedInstanceState
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_quran_page_read);

    sm = (SensorManager) getSystemService(SENSOR_SERVICE);
    proxSensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    lightSensor = sm.getDefaultSensor(Sensor.TYPE_LIGHT);
    sm.registerListener(this, proxSensor, SensorManager.SENSOR_DELAY_NORMAL);

    init();


    flag = 1;
    flag1 = 0;

    // globalVariable.setEmail(1);
}
 
开发者ID:fekracomputers,项目名称:QuranAndroid,代码行数:26,代码来源:QuranPageReadActivity.java

示例11: onResume

import android.hardware.SensorManager; //导入依赖的package包/类
protected void onResume()
{
	super.onResume();
	if(null == ftDev || false == ftDev.isOpen())
	{
		DLog.e(TT, "onResume - reconnect");
		createDeviceList();
		if(DevCount > 0)
		{
			connectFunction();

			setConfig(baudRate, dataBit, stopBit, parity, flowControl);
		}
	}

       mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_FASTEST);  // Register the accelerometer and determining its speed
       mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_FASTEST);   // Register the magnetometer and determining its speed
       mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_FASTEST);      // Register the Gyroscope and determining its speed
}
 
开发者ID:atarek92,项目名称:Intelligent_Indoor_Localization_System,代码行数:20,代码来源:J2xxHyperTerm.java

示例12: onCreate

import android.hardware.SensorManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);
    mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
    accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    txt = (TextView) findViewById(R.id.label_hello);
}
 
开发者ID:ANFR-France,项目名称:proto-collecte,代码行数:10,代码来源:CameraActivity.java

示例13: onSensorChanged

import android.hardware.SensorManager; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {

    // we received a sensor event. it is a good practice to check
    // that we received the proper event
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        System.arraycopy(event.values, 0, magnitudeValues, 0, magnitudeValues.length);
    } else if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        System.arraycopy(event.values, 0, accelerometerValues, 0, accelerometerValues.length);
    }

    if (magnitudeValues != null && accelerometerValues != null) {
        // Fuse accelerometer with compass
        SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, inclinationValues, accelerometerValues,
                magnitudeValues);
        // Transform rotation matrix to quaternion
        currentOrientationQuaternion.setRowMajor(currentOrientationRotationMatrix.matrix);
    }
}
 
开发者ID:peter10110,项目名称:Android-SteamVR-controller,代码行数:20,代码来源:AccelerometerCompassProvider.java

示例14: onSensorChanged

import android.hardware.SensorManager; //导入依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
  if (internalCompassListener == null) {
    return;
  }
  // check when the last time the compass was updated, return if too soon.
  long currentTime = SystemClock.elapsedRealtime();
  if (currentTime < compassUpdateNextTimestamp) {
    return;
  }
  if (lastAccuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
    Timber.d("Compass sensor is unreliable, device calibration is needed.");
    return;
  }
  if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
    updateOrientation(event.values);

    // Update the compassUpdateNextTimestamp
    compassUpdateNextTimestamp = currentTime + LocationLayerConstants.COMPASS_UPDATE_RATE_MS;
  } else if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) {
    internalCompassListener.onCompassChanged((event.values[0] + 360) % 360);
    for (CompassListener compassListener : compassListeners) {
      compassListener.onCompassChanged((event.values[0] + 360) % 360);
    }
  }
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:27,代码来源:CompassManager.java

示例15: onSensorChanged

import android.hardware.SensorManager; //导入依赖的package包/类
public void onSensorChanged(SensorEvent event) {
        int type = event.sensor.getType();
        float[] data;
        if (type == Sensor.TYPE_ACCELEROMETER) {
            data = mGData;
        } else if (type == Sensor.TYPE_MAGNETIC_FIELD) {
            data = mMData;
        } else {
            // we should not be here.
            return;
        }
        for (int i=0 ; i<3 ; i++)
            data[i] = event.values[i];

        SensorManager.getRotationMatrix(mR, mI, mGData, mMData);
// some test code which will be used/cleaned up before we ship this.
//        SensorManager.remapCoordinateSystem(mR,
//                SensorManager.AXIS_X, SensorManager.AXIS_Z, mR);
//        SensorManager.remapCoordinateSystem(mR,
//                SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, mR);
        SensorManager.getOrientation(mR, mOrientation);
        float incl = SensorManager.getInclination(mI);

        if (mCount++ > 50) {
            final float rad2deg = (float)(180.0f/Math.PI);
            mCount = 0;
            Log.d("Compass", "yaw: " + (int)(mOrientation[0]*rad2deg) +
                    "  pitch: " + (int)(mOrientation[1]*rad2deg) +
                    "  roll: " + (int)(mOrientation[2]*rad2deg) +
                    "  incl: " + (int)(incl*rad2deg)
                    );
        }
    }
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:34,代码来源:CompassActivity.java


注:本文中的android.hardware.SensorManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。