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


Java Sensor.TYPE_ACCELEROMETER属性代码示例

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


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

示例1: onSensorChanged

@Override
public void onSensorChanged(SensorEvent event) {
    switch (event.sensor.getType()) {
        case Sensor.TYPE_ROTATION_VECTOR:
            System.arraycopy(event.values, 0, mRotation, 0, 3);
            calculateOrientation();
            break;
        case Sensor.TYPE_ACCELEROMETER:
            mAccel = LowPassFilter.lowPass(event.values.clone(), mAccel);
            calculateOrientation();
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            mMagnet = LowPassFilter.lowPass(event.values.clone(), mMagnet);
            break;
        case Sensor.TYPE_STEP_DETECTOR:
            mStep = event.values[0] == 1.0;
            announceChange(STEP_UPDATE);
            break;
    }
}
 
开发者ID:tringuyen1121,项目名称:Khonsu,代码行数:20,代码来源:SensorService.java

示例2: processSensorsData

protected void processSensorsData(SensorData data) {
    switch (data.type) {
        case Sensor.TYPE_ACCELEROMETER:
            accelerometerNewData = true;
            break;
        case Sensor.TYPE_GRAVITY:
            gravityNewData = true;
            break;
        case Sensor.TYPE_LINEAR_ACCELERATION:
            linearAccelerationNewData = true;
            break;
    }
    boolean isTmp = isNewDataAvailable();
    if (dataRecordChangedListeners != null) {
        for (DataRecordChangedListener l : dataRecordChangedListeners) {
            if (l != null) {
                l.onAccelerometerChangedListener(data, sensorGravity.getLastAccelerometerDataEntry());
            }
        }
    }
    writeData(isTmp);
}
 
开发者ID:WorldBank-Transport,项目名称:RoadLab-Pro,代码行数:22,代码来源:DataRecordHelper.java

示例3: onSensorChanged

@Override
public void onSensorChanged(SensorEvent event) {
    synchronized (this) {
        if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            lowPass(event.values, mGravity);
        }
        if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
            lowPass(event.values, mGeomagnetic);
        }
        float R[] = new float[9];
        float I[] = new float[9];
        if (SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic)) {
            float orientation[] = new float[3];
            SensorManager.getOrientation(R, orientation);
            mOrientation[0] = (float)Math.toDegrees(orientation[0]);
            adjustArrow();
        }
    }
}
 
开发者ID:wade-fs,项目名称:Military-North-Compass,代码行数:19,代码来源:Compass.java

示例4: onSensorChanged

@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,代码行数:19,代码来源:AccelerometerCompassProvider.java

示例5: parse

@Override
public double[] parse(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        accValues = new float[3];
        fixOrientation(event.values, accValues);
        accFilt.add(accValues);
    }

    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        magValues = new float[3];
        fixOrientation(event.values, magValues);
        magFilt.add(magValues);
    }

    if (magValues != null && accValues != null) {
        float[] rotationMatrix = new float[9];

        if (SensorManager.getRotationMatrix(rotationMatrix, null, accFilt.getAverage(), magFilt.getAverage())) {
            degHolder = parseRoatationMatrix(rotationMatrix);
        }
    }

    return degHolder;
}
 
开发者ID:lucasax,项目名称:Zero,代码行数:24,代码来源:AccelerationParser.java

示例6: onSensorChanged

@Override
public void onSensorChanged(SensorEvent event) {
	switch (event.sensor.getType()) {
		case Sensor.TYPE_ACCELEROMETER:
			// do something about values of accelerometer
			// 深度复制,可避免部分设备下 SensorManager.getRotationMatrix 返回false的问题
			for (int i = 0; i < 3; i++) {
				accValues[i] = event.values[i];
			}
			break;
		case Sensor.TYPE_MAGNETIC_FIELD:
			// do something about values of magnetic field
			for (int i = 0; i < 3; i++) {
				magValues[i] = event.values[i];
			}
			break;
		default:
			break;
	}
	calculateOrientation(accValues, magValues);

	// 摇一摇功能
	float x = accValues[0];
	float y = accValues[1];
	float z = accValues[2];
	int medumValue = 18;
	if (Math.abs(x) > medumValue || Math.abs(y) > medumValue || Math.abs(z) > medumValue) {
		// 检测摇动的频率,防止摇动过快
		// 检测是否快速点击间隔<3000
		if ((System.currentTimeMillis() - exitTime) < 2000) {
			return;
		} else {
			exitTime = System.currentTimeMillis();
			Toast.makeText(CalendarActivity.this, "正常模式",
					Toast.LENGTH_SHORT).show();
			finish();
		}
	}
}
 
开发者ID:613-sysu,项目名称:Days,代码行数:39,代码来源:CalendarActivity.java

示例7: onSensorChanged

@Override
public void onSensorChanged(SensorEvent sensorEvent) {
    if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        stepDetector.updateModel(isActivity);

        stepDetector.updateStep(sensorEvent.values[0], sensorEvent.values[1], sensorEvent.values[2]);
    }

}
 
开发者ID:gojuukaze,项目名称:healthgo,代码行数:9,代码来源:StepThread.java

示例8: onSensorChanged

@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        simpleStepDetector.updateAccel(
                event.timestamp, event.values[0], event.values[1], event.values[2]);
    }
}
 
开发者ID:kvsjxd,项目名称:HealthOMeter,代码行数:7,代码来源:MainActivity.java

示例9: onSensorChanged

@Override
public void onSensorChanged(SensorEvent sensorEvent) {
    synchronized (this) {
        if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            if (sensorEvent.values[0] < 4 && sensorEvent.values[0] > -4) {
                if (sensorEvent.values[1] > 0) {
                    // UP
                    configurationProvider.setSensorPosition(Configuration.SENSOR_POSITION_UP);
                    configurationProvider.setDegrees(configurationProvider.getDeviceDefaultOrientation() == Configuration.ORIENTATION_PORTRAIT ? 0 : 90);
                } else if (sensorEvent.values[1] < 0) {
                    // UP SIDE DOWN
                    configurationProvider.setSensorPosition(Configuration.SENSOR_POSITION_UP_SIDE_DOWN);
                    configurationProvider.setDegrees(configurationProvider.getDeviceDefaultOrientation() == Configuration.ORIENTATION_PORTRAIT ? 180 : 270);
                }
            } else if (sensorEvent.values[1] < 4 && sensorEvent.values[1] > -4) {
                if (sensorEvent.values[0] > 0) {
                    // LEFT
                    configurationProvider.setSensorPosition(Configuration.SENSOR_POSITION_LEFT);
                    configurationProvider.setDegrees(configurationProvider.getDeviceDefaultOrientation() == Configuration.ORIENTATION_PORTRAIT ? 90 : 180);
                } else if (sensorEvent.values[0] < 0) {
                    // RIGHT
                    configurationProvider.setSensorPosition(Configuration.SENSOR_POSITION_RIGHT);
                    configurationProvider.setDegrees(configurationProvider.getDeviceDefaultOrientation() == Configuration.ORIENTATION_PORTRAIT ? 270 : 0);
                }
            }
            onScreenRotation(configurationProvider.getDegrees());
        }
    }
}
 
开发者ID:florent37,项目名称:CameraFragment,代码行数:29,代码来源:BaseAnncaFragment.java

示例10: onSensorChanged

@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        System.arraycopy(event.values, 0, mAccelerometerReading,
                0, mAccelerometerReading.length);
    } else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        System.arraycopy(event.values, 0, mMagnetometerReading,
                0, mMagnetometerReading.length);
    }
    updateOrientationAngles();
    directionView.updateAngle(mOrientationAngles[0]);
}
 
开发者ID:Twelvelines,项目名称:AndroidMuseumBleManager,代码行数:12,代码来源:ScanFragment.java

示例11: onSensorChanged

@Override
public void onSensorChanged(SensorEvent event) {
    Sensor evtSensor = event.sensor;

    if(evtSensor.getType()==Sensor.TYPE_ACCELEROMETER)
    {
        double x = event.values[0];
        double y = event.values[1];

        double maxValue = Math.sqrt(x*x+y*y);

        double xDiv = x/maxValue;
        double yDiv = y/maxValue;

        // Calculates new falling angle
        double angle = Math.atan(yDiv/xDiv) + (x < 0 ? Math.PI : 0);

        float accY = accG*(float)Math.sin(angle);
        float accX = -accG*(float)Math.cos(angle);

        // Push new angle data to RS
        if(scriptMain != null) {
            scriptMain.set_accY((float) accY);
            scriptMain.set_accX((float) accX);
        }

    }
}
 
开发者ID:csarron,项目名称:renderscript_examples,代码行数:28,代码来源:MainActivity.java

示例12: onSensorChanged

@Override
public void onSensorChanged(SensorEvent event) {
    if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
    {
        mGravity = event.values;
    }
    if(event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
    {
        mGeomagnetic = event.values;
    }
    if(mGravity != null && mGeomagnetic != null)
    {
        float R[] = new float[9];
        float I[] = new float[9];
        boolean success = SensorManager.getRotationMatrix(R,I,mGravity,mGeomagnetic);
        if(success)
        {
            float orientation[] = new float[3];
            SensorManager.getOrientation(R, orientation);
            Log.e("NEW ORIENTATION---","---------------");
            Log.e("orientation azimut", String.valueOf(orientation[0]*60));
            Log.e("orientation pitch", String.valueOf(orientation[1]*60));
            Log.e("orientation roll", String.valueOf(orientation[2]*60));

            txt.setText("orientation azimut " + String.valueOf(orientation[0]*60) + "\n" + "orientation pitch" + String.valueOf(orientation[1]*60) + "\n" + "orientation roll"+ String.valueOf(orientation[2]*60));
        }
    }
}
 
开发者ID:ANFR-France,项目名称:proto-collecte,代码行数:28,代码来源:CameraActivity.java

示例13: onSensorChanged

public void onSensorChanged(SensorEvent event) {
    Sensor sensor = event.sensor;
    synchronized (this) {
        if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            calc_step(event);
        }
    }
}
 
开发者ID:SailFlorve,项目名称:RunHDU,代码行数:8,代码来源:StepSensorAcceleration.java

示例14: isXYZ

private boolean isXYZ(Sensor s) {
    switch (s.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
        case Sensor.TYPE_GRAVITY:
        case Sensor.TYPE_GYROSCOPE:
        case Sensor.TYPE_LINEAR_ACCELERATION:
        case Sensor.TYPE_MAGNETIC_FIELD:
        case Sensor.TYPE_ROTATION_VECTOR:
            return true;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (s.getType() == Sensor.TYPE_GAME_ROTATION_VECTOR
                || s.getType() == Sensor.TYPE_GYROSCOPE_UNCALIBRATED
                || s.getType() == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) {
            return true;
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (s.getType() == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR) {
            return true;
        }
    }

    return false;
}
 
开发者ID:if710,项目名称:2017.2-codigo,代码行数:27,代码来源:SensorListActivity.java

示例15: onSensorChanged

@Override
public void onSensorChanged(SensorEvent event) {
    int sensorType = event.sensor.getType();
    float[] values = event.values;
    if (sensorType == Sensor.TYPE_ACCELEROMETER) {
        int value = 12;
        if ((Math.abs(values[0]) >= value || Math.abs(values[1]) >= value || Math.abs(values[2]) >= value)) {
            showFragmentStackHierarchyView();
        }
    }
}
 
开发者ID:LonelyMushroom,项目名称:aarLibrary,代码行数:11,代码来源:SupportActivity.java


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