Android Open Source - BluetoothHidEmu Touchpad Listener






From Project

Back to project page BluetoothHidEmu.

License

The source code is released under:

Apache License

If you think the Android project BluetoothHidEmu listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package andraus.bluetoothhidemu;
/*from  w w  w .j av a 2 s .c om*/
import andraus.bluetoothhidemu.sock.SocketManager;
import andraus.bluetoothhidemu.sock.payload.HidPointerPayload;
import android.content.Context;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

/**
 * 
 */
public class TouchpadListener implements OnTouchListener {
    
    //private static final String TAG = BluetoothHidEmuActivity.TAG;
    
    private float mPointerMultiplier = 1.5f;
    
    private GestureDetector mGestureDetector = null;
    private SocketManager mSocketManager = null;
    private View mButtonView = null;
    private HidPointerPayload mHidPayload = null;

    /**
     * 
     */
    private class LocalGestureDetector extends GestureDetector.SimpleOnGestureListener {
        

        @Override
        public boolean onDown(MotionEvent e) {

            return true;
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2,
                float distanceX, float distanceY) {
            
            if (e2.getX() != -distanceX || e2.getY() != -distanceY) {
                distanceX = -1 * mPointerMultiplier * distanceX;
                distanceY = -1 * mPointerMultiplier * distanceY;
                
                if (Math.abs(distanceX) > HidPointerPayload.MAX_POINTER_MOVE) {
                    distanceX = distanceX > 0 ? HidPointerPayload.MAX_POINTER_MOVE : -HidPointerPayload.MAX_POINTER_MOVE;
                }
                if (Math.abs(distanceY) > HidPointerPayload.MAX_POINTER_MOVE) {
                    distanceY = distanceY > 0 ? HidPointerPayload.MAX_POINTER_MOVE : -HidPointerPayload.MAX_POINTER_MOVE;
                }
                //DoLog.d(TAG, String.format("moving(%d, %d)", (int)distanceX, (int)distanceY));
                mHidPayload.movePointer((int)distanceX, (int)distanceY);
                mSocketManager.sendPayload(mHidPayload);
                
            } else {
                return true;
            }

            return false;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            
            return super.onSingleTapConfirmed(e);
        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            
            mButtonView.performClick();
            return super.onSingleTapUp(e);
        }

    }
    
    /**
     * 
     * @param context
     * @param socketManager
     */
    public TouchpadListener(Context context, SocketManager socketManager, View view, HidPointerPayload hidPayload) {
        super();
        mGestureDetector = new GestureDetector(context, new LocalGestureDetector());
        mSocketManager = socketManager;
        mButtonView = view;
        mHidPayload = hidPayload;
    }
    
    /**
     * 
     */
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return mGestureDetector.onTouchEvent(event);
    }

}




Java Source Code List

andraus.bluetoothhidemu.BluetoothHidEmuActivity.java
andraus.bluetoothhidemu.ButtonClickListener.java
andraus.bluetoothhidemu.Constants.java
andraus.bluetoothhidemu.KeyboardKeyListener.java
andraus.bluetoothhidemu.KeyboardTextWatcher.java
andraus.bluetoothhidemu.SpecialKeyListener.java
andraus.bluetoothhidemu.TouchpadListener.java
andraus.bluetoothhidemu.settings.BluetoothAdapterStateReceiver.java
andraus.bluetoothhidemu.settings.BluetoothDeviceStateReceiver.java
andraus.bluetoothhidemu.settings.Settings.java
andraus.bluetoothhidemu.sock.BluetoothSocketThread.java
andraus.bluetoothhidemu.sock.SocketManager.java
andraus.bluetoothhidemu.sock.payload.HidConsumerPayload.java
andraus.bluetoothhidemu.sock.payload.HidKeyPair.java
andraus.bluetoothhidemu.sock.payload.HidKeyboardPayload.java
andraus.bluetoothhidemu.sock.payload.HidPayload.java
andraus.bluetoothhidemu.sock.payload.HidPointerPayload.java
andraus.bluetoothhidemu.sock.payload.HidSixaxisPayload.java
andraus.bluetoothhidemu.spoof.BluetoothAdapterSpooferFactory.java
andraus.bluetoothhidemu.spoof.BluetoothAdapterSpooferGeneric.java
andraus.bluetoothhidemu.spoof.BluetoothAdapterSpooferMotoReflect.java
andraus.bluetoothhidemu.spoof.BluetoothAdapterSpooferMoto.java
andraus.bluetoothhidemu.spoof.BluetoothAdapterSpoofer.java
andraus.bluetoothhidemu.spoof.CleanupExceptionHandler.java
andraus.bluetoothhidemu.spoof.Spoof.java
andraus.bluetoothhidemu.spoof.jni.BluetoothSocketJni.java
andraus.bluetoothhidemu.ui.GenericUiControls.java
andraus.bluetoothhidemu.ui.Ps3KeypadUiControls.java
andraus.bluetoothhidemu.ui.UiControls.java
andraus.bluetoothhidemu.util.DoLog.java
andraus.bluetoothhidemu.view.ArrowButton.java
andraus.bluetoothhidemu.view.BluetoothDeviceArrayAdapter.java
andraus.bluetoothhidemu.view.BluetoothDeviceView.java
andraus.bluetoothhidemu.view.EchoEditText.java
andraus.bluetoothhidemu.view.ViewUtils.java