Java Code Examples for android.hardware.SensorManager#SENSOR_STATUS_ACCURACY_MEDIUM

The following examples show how to use android.hardware.SensorManager#SENSOR_STATUS_ACCURACY_MEDIUM . 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: 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 2
Source File: AccelListener.java    From showCaseCordova with Apache License 2.0 6 votes vote down vote up
/**
 * Sensor listener event.
 *
 * @param SensorEvent event
 */
public void onSensorChanged(SensorEvent event) {
    // Only look at accelerometer events
    if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
        return;
    }

    // If not running, then just return
    if (this.status == AccelListener.STOPPED) {
        return;
    }
    this.setStatus(AccelListener.RUNNING);

    if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {

        // Save time that event was received
        this.timestamp = System.currentTimeMillis();
        this.x = event.values[0];
        this.y = event.values[1];
        this.z = event.values[2];

        this.win();
    }
}
 
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: AccelListener.java    From cordova-android-chromeview with Apache License 2.0 6 votes vote down vote up
/**
 * Sensor listener event.
 *
 * @param SensorEvent event
 */
public void onSensorChanged(SensorEvent event) {
    // Only look at accelerometer events
    if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
        return;
    }

    // If not running, then just return
    if (this.status == AccelListener.STOPPED) {
        return;
    }
    this.setStatus(AccelListener.RUNNING);

    if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {

        // Save time that event was received
        this.timestamp = System.currentTimeMillis();
        this.x = event.values[0];
        this.y = event.values[1];
        this.z = event.values[2];

        this.win();
    }
}
 
Example 5
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 6
Source File: AccelListener.java    From jpHolo with MIT License 6 votes vote down vote up
/**
 * Sensor listener event.
 *
 * @param SensorEvent event
 */
public void onSensorChanged(SensorEvent event) {
    // Only look at accelerometer events
    if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
        return;
    }

    // If not running, then just return
    if (this.status == AccelListener.STOPPED) {
        return;
    }
    this.setStatus(AccelListener.RUNNING);

    if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {

        // Save time that event was received
        this.timestamp = System.currentTimeMillis();
        this.x = event.values[0];
        this.y = event.values[1];
        this.z = event.values[2];

        this.win();
    }
}
 
Example 7
Source File: PHumidity.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
@PhonkMethod(description = "Start the proximity sensor. Returns a proximity value. It might differ per device", example = "")
@PhonkMethodParam(params = {"function(proximity)"})
public void start() {
    super.start();

    mListener = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            ReturnObject r = new ReturnObject();
            r.put("humidity", 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 8
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 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: 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 11
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 12
Source File: PAmbientTemperature.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("temp", 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 13
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 14
Source File: PLinearAcceleration.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);
}
 
Example 15
Source File: POrientation.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
@PhonkMethod(description = "Start the orientation sensor. Returns pitch, roll, yaw", example = "")
@PhonkMethodParam(params = {"function(pitch, roll, yaw)"})
public void start() {
    super.start();

    mListener = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            ReturnObject r = new ReturnObject();
            r.put("azimuth", event.values[0]);
            r.put("pitch", event.values[1]);
            r.put("roll", event.values[2]);

            mCallbackOrientationChange.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 16
Source File: PProximity.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
@PhonkMethod(description = "Start the proximity sensor. Returns a proximity value. It might differ per device", example = "")
@PhonkMethodParam(params = {"function(proximity)"})
public void start() {
    super.start();

    mListener = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            ReturnObject r = new ReturnObject();
            r.put("distance", 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 17
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 18
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 19
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);
}
 
Example 20
Source File: PGyroscope.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("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);
}