0

我试图在我的应用程序中实现这样的 http://www.youtube.com/watch?v=QrXwJIco4w8

但似乎我真的不知道该怎么做..

似乎我必须使用运动跟踪和手部识别,也与前端摄像头通信,但我发现的大部分链接只显示检测外部对象而不是内部对象(表示设备内部)。

所以我想要的是如果应用程序中有对象(如图像或任何东西),那么当我将手移到相机前就像向左移动时,图像位置也会向左移动。使图像移动而不与触摸交互,而是使用相机(非触摸)

你能帮我看看怎么做吗?

谢谢

4

1 回答 1

1

我不了解相机,但我确实有使用挥动手势更改图像等的替代想法。您可以使用手机上的接近传感器。但它无法理解你的手是从左向右还是从右向左移动。所以,你可以有这样的东西:

在传感器上移动一次 - 从左到右 在传感器上移动两次 - 从右到左

您可以像这样定义接近传感器:

public class ProximityNotifier implements SensorEventListener{

private final SensorManager mSensorManager;
private final Sensor mProximitySensor;
private final Sensor mAccelSensor;
private float mProximityMax = 0.0f;
private boolean mStartProxComparison;
public float mProximityValue = 0.0f;
private long lastBlockedTimestamp = 0;
private long gapPlayPause = 0;
private long gapNext = 0;
private static float mValue0 = 0.0f;
private static float mValue1 = 0.0f;
private ProximityNotifier.Callback cb = null;
private static final String TAG = "ProximityNotifier";

public ProximityNotifier(Context ctxt, ProximityNotifier.Callback cb, long gap1, long gap2) {

    this.cb = cb;
    this.gapPlayPause = gap1;
    this.gapNext = gap2;
    mSensorManager = (SensorManager)ctxt.getSystemService(Context.SENSOR_SERVICE);
    mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    mAccelSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    if (null != mProximitySensor)
        mProximityMax = mProximitySensor.getMaximumRange();
    mProximityValue = mProximityMax;
    startProximityNotifier();
}



public interface Callback {
    void pageChange();        
}


public void startProximityNotifier() {
    if(null != mSensorManager) {
        if ((null != mProximitySensor) && (null != mAccelSensor)) {
            mSensorManager.registerListener(this, mProximitySensor, SensorManager.SENSOR_DELAY_UI);
            mSensorManager.registerListener(this, mAccelSensor, SensorManager.SENSOR_DELAY_UI);
            mStartProxComparison = true;
        }
        else
            mStartProxComparison = false;
    }
}

public void stopProximityNotifier() {
    if(null != mSensorManager) {
        if ((null != mProximitySensor) && (null != mAccelSensor)) {
            mSensorManager.unregisterListener(this, mProximitySensor);
            mSensorManager.unregisterListener(this, mAccelSensor);
        }
    }
}

public void onAccuracyChanged(Sensor sensor, int accuracy) {

}

public void onSensorChanged(SensorEvent sensorEvent) {

    if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        mValue0 = sensorEvent.values[0];
        mValue1 = sensorEvent.values[1];
    }

    if ((sensorEvent.sensor.getType() == Sensor.TYPE_PROXIMITY) &&  
            ((mValue0 < 2) && (mValue0 > -2)) &&
            ((mValue1 < 2) && (mValue1 > -2))) { 
        // check for a max -> 0 transition
        if((mStartProxComparison == true) && ((mProximityValue == mProximityMax) && (sensorEvent.values[0] == 0))) {
            lastBlockedTimestamp = SystemClock.uptimeMillis(); 
        } 

        else { 
            long now = SystemClock.uptimeMillis();
            if (lastBlockedTimestamp != 0) {
                /*if ((now - lastBlockedTimestamp) > gapPlayPause) {
                    if (cb != null) {
                        //cb.gesturePlayPause();
                    }
                }else*/ if ((now - lastBlockedTimestamp) > gapNext){
                    if (cb != null)
                        cb.pageChange();
                }
            }

            lastBlockedTimestamp = 0;
        }
        mProximityValue = sensorEvent.values[0];
    }

} 

}

在您的活动中,您可以像这样声明和使用:

mProximityNotifier = new ProximityNotifier(this, this, 400, 200);

//Callback method for Proximity Sensor
    public void pageChange() {
        //call for image change
  }

希望对你有帮助

于 2013-11-07T01:04:25.227 回答