當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。