Code example for Sensor

Methods: getName, getType

0
            // we can't really use sensor.getName() here, since the value it 
            // returns (although resembles the purpose) is a bit vaguer than it 
            // should be. Also choose an appropriate format for the strings that 
            // display sensor's value, and strings that are sent to the 
            // emulator. 
            switch (sensor.getType()) {
                case Sensor.TYPE_ACCELEROMETER:
                    mUiName = "Accelerometer";
                    // 3 floats. 
                    mTextFmt = "%+.2f %+.2f %+.2f";
                    mEmulatorFriendlyName = "acceleration";
                    mExpectedLen = 3;
                    break; 
                case 9: // Sensor.TYPE_GRAVITY is missing in API 7 
                    // 3 floats. 
                    mUiName = "Gravity";
                    mTextFmt = "%+.2f %+.2f %+.2f";
                    mEmulatorFriendlyName = "gravity";
                    mExpectedLen = 3;
                    break; 
                case Sensor.TYPE_GYROSCOPE:
                    mUiName = "Gyroscope";
                    // 3 floats. 
                    mTextFmt = "%+.2f %+.2f %+.2f";
                    mEmulatorFriendlyName = "gyroscope";
                    mExpectedLen = 3;
                    break; 
                case Sensor.TYPE_LIGHT:
                    mUiName = "Light";
                    // 1 integer. 
                    mTextFmt = "%.0f";
                    mEmulatorFriendlyName = "light";
                    mExpectedLen = 1;
                    break; 
                case 10: // Sensor.TYPE_LINEAR_ACCELERATION is missing in API 7 
                    mUiName = "Linear acceleration";
                    // 3 floats. 
                    mTextFmt = "%+.2f %+.2f %+.2f";
                    mEmulatorFriendlyName = "linear-acceleration";
                    mExpectedLen = 3;
                    break; 
                case Sensor.TYPE_MAGNETIC_FIELD:
                    mUiName = "Magnetic field";
                    // 3 floats. 
                    mTextFmt = "%+.2f %+.2f %+.2f";
                    mEmulatorFriendlyName = "magnetic-field";
                    mExpectedLen = 3;
                    break; 
                case Sensor.TYPE_ORIENTATION:
                    mUiName = "Orientation";
                    // 3 integers. 
                    mTextFmt = "%+03.0f %+03.0f %+03.0f";
                    mEmulatorFriendlyName = "orientation";
                    mExpectedLen = 3;
                    break; 
                case Sensor.TYPE_PRESSURE:
                    mUiName = "Pressure";
                    // 1 integer. 
                    mTextFmt = "%.0f";
                    mEmulatorFriendlyName = "pressure";
                    mExpectedLen = 1;
                    break; 
                case Sensor.TYPE_PROXIMITY:
                    mUiName = "Proximity";
                    // 1 integer. 
                    mTextFmt = "%.0f";
                    mEmulatorFriendlyName = "proximity";
                    mExpectedLen = 1;
                    break; 
                case 11: // Sensor.TYPE_ROTATION_VECTOR is missing in API 7 
                    mUiName = "Rotation";
                    // 3 floats. 
                    mTextFmt = "%+.2f %+.2f %+.2f";
                    mEmulatorFriendlyName = "rotation";
                    mExpectedLen = 3;
                    break; 
                case Sensor.TYPE_TEMPERATURE:
                    mUiName = "Temperature";
                    // 1 integer. 
                    mTextFmt = "%.0f";
                    mEmulatorFriendlyName = "temperature";
                    mExpectedLen = 1;
                    break; 
                default: 
                    mUiName = "<Unknown>";
                    mTextFmt = "N/A";
                    mEmulatorFriendlyName = "unknown";
                    mExpectedLen = 0;
                    if (DEBUG) Log.e(TAG, "Unknown sensor type " + mSensor.getType() +
                            " for sensor " + mSensor.getName());
                    break; 
            } 
        } 
 
        public String getUiName() {