Android Open Source - BluetoothHidEmu Button Click 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   ww w.ja v  a 2 s . c  o m*/
import andraus.bluetoothhidemu.sock.SocketManager;
import andraus.bluetoothhidemu.sock.payload.HidPointerPayload;
import andraus.bluetoothhidemu.util.DoLog;
import andraus.bluetoothhidemu.view.ViewUtils;
import android.content.Context;
import android.graphics.LightingColorFilter;
import android.os.Vibrator;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.ImageView;

/**
 * 
 */
public class ButtonClickListener implements OnClickListener, OnLongClickListener {
    
    private static final String TAG = BluetoothHidEmuActivity.TAG;
    
    private SocketManager mSocketManager = null;
    
    private HidPointerPayload mHidPayload = null;
    
    private Vibrator mVibrator;
    
    private int mButton = HidPointerPayload.MOUSE_BUTTON_NONE;
    private boolean mIsLockable = true;
    
    private boolean mIsButtonLocked = false;

    /**
     * 
     * @param context
     * @param socketManager
     * @param button
     * @param isLockable
     */
    public ButtonClickListener(Context context, SocketManager socketManager, int button, boolean isLockable, HidPointerPayload hidPayload) {
        super();

        mSocketManager = socketManager;
        mHidPayload = hidPayload;
        mButton = button;
        mIsLockable = isLockable;
        
        mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        
    }
    

    /**
     * 
     */
    @Override
    public void onClick(View view) {
        drawButton(view,  false);
        
        view.startAnimation(ViewUtils.getClickAnimation());
        if (mVibrator != null) {
            mVibrator.vibrate(Constants.CLICK_VIBRATE_MS);
        }
        
        if (!mIsButtonLocked) {
            mHidPayload.movePointer(0, 0);
            mHidPayload.clickButton(mButton);
            mSocketManager.sendPayload(mHidPayload);
        } else {
            mIsButtonLocked = false;
        }
        mHidPayload.movePointer(0, 0);
        mHidPayload.releaseButton(mButton);
        mSocketManager.sendPayload(mHidPayload);

    }

    /**
     * 
     */
    @Override
    public boolean onLongClick(View view) {
        
        if (mIsLockable) {
            if (mIsButtonLocked) {
                onClick(view);
            } else {
                drawButton(view, true);
                mIsButtonLocked = true;
                DoLog.d(TAG, "set button locked to " + mIsButtonLocked);
                mHidPayload.movePointer(0, 0);
                mHidPayload.clickButton(mButton);
                mSocketManager.sendPayload(mHidPayload);
            }
        } else {
            onClick(view);
        }
        
        return true;
    }

    /**
     * Set properties for the button to be drawn as normal or "on hold".
     * @param view
     * @param isHold
     */
    private void drawButton(View view, boolean isHold) {
        ImageView imgView = (ImageView) view;
        if (isHold) {
            imgView.setColorFilter(new LightingColorFilter(0xff4a6c9b, 0xff000055));
        } else {
            imgView.clearColorFilter();
        }
    }

}




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