Java Code Examples for android.hardware.SensorManager#SENSOR_STATUS_ACCURACY_HIGH

The following examples show how to use android.hardware.SensorManager#SENSOR_STATUS_ACCURACY_HIGH . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrientationSensor.java    From geopaparazzi with GNU General Public License v3.0 6 votes vote down vote up
public int register(Activity activity, int sensorSpeed) {
    parentActivity = activity;  // current activity required for call to getWindowManager().getDefaultDisplay().getRotation()
    m_NormGravityVector = new float[3];
    m_NormMagFieldValues = new float[3];
    m_OrientationOK = false;
    int count = 0;
    Sensor sensorGravity = sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
    if (sensorGravity != null) {
        sensorManager.registerListener(this, sensorGravity, sensorSpeed);
        m_GravityAccuracy = SensorManager.SENSOR_STATUS_ACCURACY_HIGH;
        count++;
    } else {
        m_GravityAccuracy = SENSOR_UNAVAILABLE;
    }
    Sensor sensorMagField = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    if (sensorMagField != null) {
        sensorManager.registerListener(this, sensorMagField, sensorSpeed);
        m_MagneticFieldAccuracy = SensorManager.SENSOR_STATUS_ACCURACY_HIGH;
        count++;
    } else {
        m_MagneticFieldAccuracy = SENSOR_UNAVAILABLE;
    }
    return count;
}
 
Example 2
Source File: MagAccelListener.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    if (accuracy == 0)
        accuracy = SensorManager.SENSOR_STATUS_ACCURACY_LOW;
    switch (sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            mAccelerometerAccuracy = accuracy;
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            mMagneticAccuracy = accuracy;
            break;
        default:
            break;
    }
    if (mAccelerometerAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_LOW || mMagneticAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_LOW)
        mRotationUpdateDelegate.onAccuracyChanged(SensorManager.SENSOR_STATUS_ACCURACY_LOW);
    else if (mAccelerometerAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM ||
            mMagneticAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {
        mRotationUpdateDelegate.onAccuracyChanged(SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM);
    } else if (mAccelerometerAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_HIGH &&
            mMagneticAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_HIGH) {
        
        mRotationUpdateDelegate.onAccuracyChanged(SensorManager.SENSOR_STATUS_ACCURACY_HIGH);
    }
    
}
 
Example 3
Source File: MagAccelListener.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    if (accuracy == 0)
        accuracy = SensorManager.SENSOR_STATUS_ACCURACY_LOW;
    switch (sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            mAccelerometerAccuracy = accuracy;
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            mMagneticAccuracy = accuracy;
            break;
        default:
            break;
    }
    if (mAccelerometerAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_LOW || mMagneticAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_LOW)
        mRotationUpdateDelegate.onAccuracyChanged(SensorManager.SENSOR_STATUS_ACCURACY_LOW);
    else if (mAccelerometerAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM ||
            mMagneticAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {
        mRotationUpdateDelegate.onAccuracyChanged(SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM);
    } else if (mAccelerometerAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_HIGH &&
            mMagneticAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_HIGH) {
        
        mRotationUpdateDelegate.onAccuracyChanged(SensorManager.SENSOR_STATUS_ACCURACY_HIGH);
    }
    
}
 
Example 4
Source File: SensorDetailFragment.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
private void populateAccuracyRow( int accuracy ) {
	if( mAccuracy == null || mAccuracyRow == null )
		return;
	String accuracyText = "";

	switch( accuracy ) {
		case SensorManager.SENSOR_STATUS_ACCURACY_HIGH: {
			accuracyText = "High";
			break;
		}
		case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM: {
			accuracyText = "Medium";
			break;
		}
		case SensorManager.SENSOR_STATUS_ACCURACY_LOW: {
			accuracyText = "Low";
			break;
		}
		default: {
			accuracyText = "Unreliable";
		}
	}

	mAccuracy.setText( accuracyText );
	mAccuracyRow.setVisibility( View.VISIBLE );
}
 
Example 5
Source File: ARSurfaceView.java    From geoar-app with Apache License 2.0 5 votes vote down vote up
public void onAccuracyChanged(Sensor sensor, int accuracy) {
	if (accuracy != SensorManager.SENSOR_STATUS_ACCURACY_HIGH) {
		if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
			InfoView.setStatus(R.string.magnetic_field_not_calibrated,
					5000, magnet);
		} else if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
			InfoView.setStatus(R.string.accel_not_calibrated, 5000, accel);
		}
	}
}
 
Example 6
Source File: OrientationManager.java    From PTVGlass with MIT License 5 votes vote down vote up
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        mHasInterference = (accuracy < SensorManager.SENSOR_STATUS_ACCURACY_HIGH);
        notifyAccuracyChanged();
    }
}
 
Example 7
Source File: CalibrationFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    if (accuracy == 0)
        accuracy = SensorManager.SENSOR_STATUS_ACCURACY_LOW;
    switch (sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            mAccelerometerAccuracy = accuracy;
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            mMagneticAccuracy = accuracy;
            break;
        default:
            break;
    }
    if (mAccelerometerAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_LOW || mMagneticAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_LOW)
        mAccuracy.setText(Html.fromHtml(
                String.format("%s: <font color='#ff0000'>%s</font>", getString(R.string.accuracy), getString(R.string.accuracy_low))));
    else if (mAccelerometerAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM ||
            mMagneticAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {
        mAccuracy.setText(Html.fromHtml(
                String.format("%s: <font color='#e6e600'>%s</font>", getString(R.string.accuracy), getString(R.string.accuracy_medium))));
    } else if (mAccelerometerAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_HIGH &&
            mMagneticAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_HIGH) {
        mAccuracy.setText(Html.fromHtml(
                String.format("%s: <font color='#00ff00'>%s</font>", getString(R.string.accuracy), getString(R.string.accuracy_high))));

        mAccuracy.postDelayed(() -> {
            if (!isStateSaved())
                getParentFragment().getChildFragmentManager().beginTransaction().remove(CalibrationFragment.this).commit();
        }, 3000);

    }
}
 
Example 8
Source File: MagneticCompass.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onAccuracyChanged(int accuracy) {
    if (accuracy != SensorManager.SENSOR_STATUS_ACCURACY_HIGH && !mCalibrationStarted) {
        mCalibrationStarted = true;
        getChildFragmentManager().beginTransaction().replace(R.id.calib, new CalibrationFragment(), "calibration").commit();
    }
}
 
Example 9
Source File: CalibrationFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    if (accuracy == 0)
        accuracy = SensorManager.SENSOR_STATUS_ACCURACY_LOW;
    switch (sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            mAccelerometerAccuracy = accuracy;
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            mMagneticAccuracy = accuracy;
            break;
        default:
            break;
    }
    if (mAccelerometerAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_LOW || mMagneticAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_LOW)
        mAccuracy.setText(Html.fromHtml(
                String.format("%s: <font color='#ff0000'>%s</font>", getString(R.string.accuracy), getString(R.string.accuracy_low))));
    else if (mAccelerometerAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM ||
            mMagneticAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {
        mAccuracy.setText(Html.fromHtml(
                String.format("%s: <font color='#e6e600'>%s</font>", getString(R.string.accuracy), getString(R.string.accuracy_medium))));
    } else if (mAccelerometerAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_HIGH &&
            mMagneticAccuracy == SensorManager.SENSOR_STATUS_ACCURACY_HIGH) {
        mAccuracy.setText(Html.fromHtml(
                String.format("%s: <font color='#00ff00'>%s</font>", getString(R.string.accuracy), getString(R.string.accuracy_high))));

        mAccuracy.postDelayed(() -> {
            if (!isStateSaved())
                getParentFragment().getChildFragmentManager().beginTransaction().remove(CalibrationFragment.this).commit();
        }, 3000);

    }
}
 
Example 10
Source File: VirtualSensorListener.java    From VirtualSensor with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == this.registeredSensor.getType()) {
        event.accuracy = SensorManager.SENSOR_STATUS_ACCURACY_HIGH;
        realListener.onSensorChanged(event);
    }
}
 
Example 11
Source File: PBarometer.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
public void start() {
    super.start();

    mListener = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            ReturnObject r = new ReturnObject();
            r.put("bar", event.values[0]);
            mCallback.event(r);
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            switch (accuracy) {
                case SensorManager.SENSOR_STATUS_UNRELIABLE:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
                    break;
            }
        }

    };

    isEnabled = mSensormanager.registerListener(mListener, sensor, speed);
}
 
Example 12
Source File: PStep.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
@PhonkMethod(description = "Start the step counter. Not superacurate and only few devices", example = "")
@PhonkMethodParam(params = {"function(value)"})
public void start() {
    super.start();

    mListener = new SensorEventListener() {
        @Override
        public void onSensorChanged(SensorEvent event) {
            mCallback.event(null);
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            switch (accuracy) {
                case SensorManager.SENSOR_STATUS_UNRELIABLE:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
                    break;
            }
        }

    };

    isEnabled = mSensormanager.registerListener(mListener, sensor, speed);
}
 
Example 13
Source File: SensorGraphView.java    From SensorDashboard with Apache License 2.0 5 votes vote down vote up
private int dataPointAccuracyToDotSize(int accuracy) {

        switch (accuracy) {
            case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
                return CIRCLE_SIZE_ACCURACY_HIGH;
            case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
                return CIRCLE_SIZE_ACCURACY_MEDIUM;
            case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
                return CIRCLE_SIZE_ACCURACY_LOW;
            default:
                return CIRCLE_SIZE_DEFAULT;
        }

    }
 
Example 14
Source File: PRotationVector.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
public void start() {
    super.start();

    mListener = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            if (mCallback != null) {
                ReturnObject r = new ReturnObject();
                r.put("x", event.values[0]);
                r.put("y", event.values[1]);
                r.put("z", event.values[2]);
                mCallback.event(r);
            }
        }


        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            switch (accuracy) {
                case SensorManager.SENSOR_STATUS_UNRELIABLE:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
                    break;
            }
        }

    };

    isEnabled = mSensormanager.registerListener(mListener, sensor, speed);
}
 
Example 15
Source File: PAccelerometer.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
public void start() {
    super.start();

    mListener = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            if (mCallback != null) {
                ReturnObject r = new ReturnObject();
                r.put("x", event.values[0]);
                r.put("y", event.values[1]);
                r.put("z", event.values[2]);
                float force = (float) Math.sqrt(Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2) + Math.pow(event.values[2], 2));
                r.put("force", force);
                mCallback.event(r);
                MLog.d(TAG, "accelerometer changed");
            }
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            switch (accuracy) {
                case SensorManager.SENSOR_STATUS_UNRELIABLE:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
                    break;
            }
        }

    };

    isEnabled = mSensormanager.registerListener(mListener, sensor, speed);
}
 
Example 16
Source File: OrientationManager.java    From PTVGlass with MIT License 5 votes vote down vote up
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        mHasInterference = (accuracy < SensorManager.SENSOR_STATUS_ACCURACY_HIGH);
        notifyAccuracyChanged();
    }
}
 
Example 17
Source File: OrientationManager.java    From SpeedHud with Apache License 2.0 5 votes vote down vote up
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        mHasInterference = (accuracy < SensorManager.SENSOR_STATUS_ACCURACY_HIGH);
        notifyAccuracyChanged();
    }
}
 
Example 18
Source File: PMagneticField.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
@PhonkMethod(description = "Start the magneticField sensor", example = "")
@PhonkMethodParam(params = {"function(value)"})
public void start() {
    super.start();

    mListener = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            ReturnObject r = new ReturnObject();
            r.put("x", event.values[0]);
            r.put("y", event.values[1]);
            r.put("z", event.values[2]);
            mCallbackMagneticChange.event(r);
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            switch (accuracy) {
                case SensorManager.SENSOR_STATUS_UNRELIABLE:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
                    break;
            }
        }

    };

    isEnabled = mSensormanager.registerListener(mListener, sensor, speed);
}
 
Example 19
Source File: PLightIntensity.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
@PhonkMethod(description = "Start the light sensor. Returns the intensity. The value per device might vary", example = "")
@PhonkMethodParam(params = {"function(intensity)"})
public void start() {
    super.start();

    mListener = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            ReturnObject r = new ReturnObject();
            r.put("intensity", event.values[0]);
            mCallbackLightChange.event(r);
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            switch (accuracy) {
                case SensorManager.SENSOR_STATUS_UNRELIABLE:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
                    break;
            }
        }

    };

    isEnabled = mSensormanager.registerListener(mListener, sensor, speed);
}
 
Example 20
Source File: PGravity.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
public void start() {
    super.start();

    mListener = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            if (mCallback != null) {
                ReturnObject r = new ReturnObject();
                r.put("x", event.values[0]);
                r.put("y", event.values[1]);
                r.put("z", event.values[2]);
                float force = (float) Math.sqrt(Math.pow(event.values[0], 2) + Math.pow(event.values[1], 2) + Math.pow(event.values[2], 2));
                r.put("force", force);
                mCallback.event(r);
            }
        }


        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            switch (accuracy) {
                case SensorManager.SENSOR_STATUS_UNRELIABLE:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
                    break;
                case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
                    break;
            }
        }

    };

    isEnabled = mSensormanager.registerListener(mListener, sensor, speed);
}