Java Code Examples for android.hardware.SensorManager#DATA_Y

The following examples show how to use android.hardware.SensorManager#DATA_Y . 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: ShakeDetectEventListener.java    From android-wear-gopro-remote with Apache License 2.0 6 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {

        long curTime = System.currentTimeMillis();
        // if a shake in last X seconds ignore.
        if (lastShake != 0 && (curTime - lastShake) < IGNORE_EVENTS_AFTER_SHAKE) return;

        float x = event.values[SensorManager.DATA_X];
        float y = event.values[SensorManager.DATA_Y];
        float z = event.values[SensorManager.DATA_Z];
        if (last_x != 0 && last_y != 0 && last_z != 0 && (last_x != x || last_y != y || last_z != z)) {
            DataPoint dp = new DataPoint(last_x-x, last_y-y, last_z-z, curTime);
            //Log.i("XYZ",Float.toString(dp.x)+"   "+Float.toString(dp.y)+"   "+Float.toString(dp.z)+"   ");
            dataPoints.add(dp);

            if ((curTime - lastUpdate) > SHAKE_CHECK_THRESHOLD) {
                lastUpdate = curTime;
                checkForShake();
            }
        }
        last_x = x;
        last_y = y;
        last_z = z;
    }
}
 
Example 2
Source File: JCVideoPlayer.java    From JCVideoPlayer with MIT License 6 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {//可以得到传感器实时测量出来的变化值
    float x = event.values[SensorManager.DATA_X];
    float y = event.values[SensorManager.DATA_Y];
    float z = event.values[SensorManager.DATA_Z];
    if (x < -11) {
        //direction right
    } else if (x > 11) {
        //direction left
        if (JCVideoPlayerManager.listener() != null) {
            JCVideoPlayerManager.listener().autoFullscreenLeft();
        }
    } else if (y > 11) {
        if (JCVideoPlayerManager.listener() != null) {
            JCVideoPlayerManager.listener().autoQuitFullscreen();
        }
    }

}
 
Example 3
Source File: ShakeDetectActivity.java    From ListView-Swipe-to-Delete with Apache License 2.0 6 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
	if (event.sensor.getType() == SensorManager.SENSOR_ACCELEROMETER) {

		long curTime = System.currentTimeMillis();
		// if a shake in last X seconds ignore.
		if (lastShake != 0 && (curTime - lastShake) < IGNORE_EVENTS_AFTER_SHAKE) return;

		float x = event.values[SensorManager.DATA_X];
		float y = event.values[SensorManager.DATA_Y];
		float z = event.values[SensorManager.DATA_Z];
		if (last_x != 0 && last_y != 0 && last_z != 0 && (last_x != x || last_y != y || last_z != z)) {
			DataPoint dp = new DataPoint(last_x-x, last_y-y, last_z-z, curTime);
			//Log.i("XYZ",Float.toString(dp.x)+"   "+Float.toString(dp.y)+"   "+Float.toString(dp.z)+"   ");
			dataPoints.add(dp);

			if ((curTime - lastUpdate) > SHAKE_CHECK_THRESHOLD) {
				lastUpdate = curTime;
				checkForShake();
			}
		}
		last_x = x;
		last_y = y;
		last_z = z;
	}		
}
 
Example 4
Source File: Jzvd.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {//可以得到传感器实时测量出来的变化值
    final float x = event.values[SensorManager.DATA_X];
    float y = event.values[SensorManager.DATA_Y];
    float z = event.values[SensorManager.DATA_Z];
    //过滤掉用力过猛会有一个反向的大数值
    if (x < -12 || x > 12) {
        if ((System.currentTimeMillis() - lastAutoFullscreenTime) > 2000) {
            if (Jzvd.CURRENT_JZVD != null) Jzvd.CURRENT_JZVD.autoFullscreen(x);
            lastAutoFullscreenTime = System.currentTimeMillis();
        }
    }
}
 
Example 5
Source File: AccelerationData.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
public void swapAxis(final float[] pValues) {
	final float x = -pValues[SensorManager.DATA_Y];
	final float y = -pValues[SensorManager.DATA_X];
	pValues[SensorManager.DATA_X] = x;
	pValues[SensorManager.DATA_Y] = y;
}
 
Example 6
Source File: AccelerationData.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
public void swapAxis(final float[] pValues) {
	final float x = pValues[SensorManager.DATA_X];
	final float y = -pValues[SensorManager.DATA_Y];
	pValues[SensorManager.DATA_X] = x;
	pValues[SensorManager.DATA_Y] = y;
}
 
Example 7
Source File: AccelerationData.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
public void swapAxis(final float[] pValues) {
	final float x = -pValues[SensorManager.DATA_X];
	final float y = pValues[SensorManager.DATA_Y];
	pValues[SensorManager.DATA_X] = x;
	pValues[SensorManager.DATA_Y] = y;
}
 
Example 8
Source File: AccelerationData.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void swapAxis(final float[] pValues) {
	final float x = -pValues[SensorManager.DATA_Y];
	final float y = pValues[SensorManager.DATA_X];
	pValues[SensorManager.DATA_X] = x;
	pValues[SensorManager.DATA_Y] = y;
}
 
Example 9
Source File: GSenseView.java    From appcan-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {

    long now = System.currentTimeMillis();
    {
        long diff = 0;
        if (mLastTime != 0)
            diff = now - mLastTime;
        if (Math.abs(event.values[SensorManager.DATA_X]) > 1.5f) { //
            if (Math.abs(event.values[SensorManager.DATA_X]) < 10.0f)
                diff = 1;
            if (mLastTime != 0)
                ballXVelocity = ballXVelocity + (-event.values[SensorManager.DATA_X] * diff * 20);
        } else {
            ballXVelocity = ballXVelocity + (event.values[SensorManager.DATA_X]); //
        }

        if (Math.abs(event.values[SensorManager.DATA_Y]) > 1.5f) { //
            if (Math.abs(event.values[SensorManager.DATA_Y]) < 10.0f)
                diff = 1;
            if (mLastTime != 0)
                ballYVelocity = ballYVelocity + (event.values[SensorManager.DATA_Y] * diff * 10);
        } else {
            ballYVelocity = ballYVelocity + (-event.values[SensorManager.DATA_Y]);
        }
        mLastTime = now;
        left += ballXVelocity / 200;
        top += ballYVelocity / 200;
        invalidate();
    }
}
 
Example 10
Source File: AccelerationData.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void swapAxis(final float[] pValues) {
	final float x = -pValues[SensorManager.DATA_X];
	final float y = -pValues[SensorManager.DATA_Y];
	pValues[SensorManager.DATA_X] = x;
	pValues[SensorManager.DATA_Y] = y;
}
 
Example 11
Source File: MxVideoPlayer.java    From MxVideoPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) { // 可以得到传感器实时测量出来的变化值
    final float x = event.values[SensorManager.DATA_X];
    float y = event.values[SensorManager.DATA_Y];
    // 过滤掉用力过猛会有一个反向的大数值
    if (((x > -15 && x < -10) || (x < 15 && x > 10)) && Math.abs(y) < 1.5) {
        if ((System.currentTimeMillis() - mLastAutoFullscreenTime) > 1200) {
            MxMediaPlayerListener currentListener = MxVideoPlayerManager.getCurrentListener();
            if (currentListener != null) {
                currentListener.autoFullscreen(x);
            }
            mLastAutoFullscreenTime = System.currentTimeMillis();
        }
    }
}
 
Example 12
Source File: DragableView.java    From appcan-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    long curTime = System.currentTimeMillis();
    // 每100毫秒检测一次
    if ((curTime - lastUpdate) > 100) {
        long diffTime = (curTime - lastUpdate);
        lastUpdate = curTime;
        x = event.values[SensorManager.DATA_X];
        y = event.values[SensorManager.DATA_Y];
        z = event.values[SensorManager.DATA_Z];
        float speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;
        if (speed > SHAKE_THRESHOLD) {
            // 检测到摇晃后执行的代码
            setVisibility(View.GONE);
            setClickable(false);
            sensorManager.unregisterListener(this, sensor);
            if (!isAddedSenseView) {
                windowManager.addView(gSenseView, gSenseView.getLayoutParams());
                isAddedSenseView = true;
                gSenseView.startSense();
                gSenseView.addBallFallIntoCallback(new OnBallFallIntoCallback() {
                    @Override
                    public void onFallInto() {
                        windowManager.removeViewImmediate(gSenseView);
                        isAddedSenseView = false;
                        if (listener != null) {
                            listener.onGSBallFalled();
                        }
                    }
                });

            }

        }
        last_x = x;
        last_y = y;
        last_z = z;
    }
}
 
Example 13
Source File: ShakeListener.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    Log.i("TAG", "x:" + event.values[SensorManager.DATA_X] + "  y:" +
            event.values[SensorManager.DATA_Y] + "  z:" +
            event.values[SensorManager.DATA_Z]);

    if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
        return;
    }

    long now = System.currentTimeMillis();

    if ((now - mLastForce) > SHAKE_TIMEOUT) {
        mShakeCount = 0;
    }

    if ((now - mLastTime) > TIME_THRESHOLD) {
        long diff = now - mLastTime;
        // 把X,Y,Z方向的距离除以时间,得出速度
        float speed = Math.abs(event.values[SensorManager.DATA_X] + event.values[SensorManager.DATA_Y] + event.values[SensorManager.DATA_Z] - mLastX - mLastY - mLastZ) / diff * 10000;
        if (speed > FORCE_THRESHOLD) {//如果速度大于某个值
            // 先把摇晃的次数+1,再判断是否超过了要换的次数,并且间隙大于特定的值
            if ((++mShakeCount >= SHAKE_COUNT) && (now - mLastShake > SHAKE_DURATION)) {
                mLastShake = now;
                mShakeCount = 0;
                if (mShakeListener != null) {//回调我们的listener
                    mShakeListener.onShake();
                }
            }
            mLastForce = now;
        }
        mLastTime = now;
        mLastX = event.values[SensorManager.DATA_X];
        mLastY = event.values[SensorManager.DATA_Y];
        mLastZ = event.values[SensorManager.DATA_Z];
    }
}
 
Example 14
Source File: JZVideoPlayer.java    From JZVideoDemo with MIT License 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {//可以得到传感器实时测量出来的变化值
    final float x = event.values[SensorManager.DATA_X];
    float y = event.values[SensorManager.DATA_Y];
    float z = event.values[SensorManager.DATA_Z];
    //过滤掉用力过猛会有一个反向的大数值
    if (x < -12 || x > 12) {
        if ((System.currentTimeMillis() - lastAutoFullscreenTime) > 2000) {
            if (JZVideoPlayerManager.getCurrentJzvd() != null) {
                JZVideoPlayerManager.getCurrentJzvd().autoFullscreen(x);
            }
            lastAutoFullscreenTime = System.currentTimeMillis();
        }
    }
}
 
Example 15
Source File: AccelerationData.java    From tilt-game-android with MIT License 4 votes vote down vote up
public float getY() {
	return this.mValues[SensorManager.DATA_Y];
}
 
Example 16
Source File: AccelerationData.java    From tilt-game-android with MIT License 4 votes vote down vote up
public void setY(final float pY) {
	this.mValues[SensorManager.DATA_Y] = pY;
}
 
Example 17
Source File: OrientationData.java    From tilt-game-android with MIT License 4 votes vote down vote up
public float getPitch() {
	return super.mValues[SensorManager.DATA_Y];
}
 
Example 18
Source File: OrientationData.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public float getPitch() {
	return super.mValues[SensorManager.DATA_Y];
}
 
Example 19
Source File: AccelerationData.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public float getY() {
	return this.mValues[SensorManager.DATA_Y];
}
 
Example 20
Source File: AccelerationData.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public void setY(final float pY) {
	this.mValues[SensorManager.DATA_Y] = pY;
}