Android Open Source - BluetoothHidEmu Keyboard Text Watcher






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;
/*  w  w w  .  j  a va  2s  .  co m*/
import andraus.bluetoothhidemu.sock.SocketManager;
import andraus.bluetoothhidemu.sock.payload.HidKeyboardPayload;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;

/**
 * TextWatcher to monitor text events.
 */
public class KeyboardTextWatcher implements TextWatcher {
    
    //private static final String TAG = BluetoothHidEmuActivity.TAG;
    
    private static final int MSG_START_COUNT = 0;
    
    private SocketManager mSocketManager = null;
    
    private HidKeyboardPayload mHidPayload = new HidKeyboardPayload();

    /**
     * 
     * @param socketManager
     */
    public KeyboardTextWatcher(SocketManager socketManager) {
        super();
        mSocketManager = socketManager;
    }
    
    @Override
    public void afterTextChanged(Editable content) {
        //DoLog.d(TAG, String.format("afterTextChanged(%s)",content));
        
        mHandler.removeMessages(MSG_START_COUNT);
        
        Message msg = Message.obtain(mHandler);
        msg.obj = content;
        msg.what = MSG_START_COUNT;
        
        mHandler.sendMessageDelayed(msg, 10000 /* ms */ );

    }

    @Override
    public void beforeTextChanged(CharSequence charSeq, int start, int count, int after) {
        //DoLog.d(TAG, String.format("%s - beforeTextChanged(%s, %d, %d, %d)", this, charSeq, start, count, after));

    }

    @Override
    public void onTextChanged(CharSequence charSeq, int start, int before, int count) {
        //DoLog.d(TAG, String.format("onTextChanged(%s, %d, %d, %d)", charSeq, start, before, count));
        
        if (count > 0) {
            // character added
            char character = charSeq.charAt(start);
            mHidPayload.assemblePayload(character);
            mSocketManager.sendPayload(mHidPayload);
            mHidPayload.assemblePayload(Character.MIN_VALUE);
            mSocketManager.sendPayload(mHidPayload);
        }

    }
    
    /**
     * Handler used to clean-up the local echo EditText, after some time of innactivity
     */
    private final Handler mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            
            switch (msg.what) {
            case MSG_START_COUNT:
                
                Editable content = (Editable) msg.obj;
                content.clear();
                
                break;
                
            }
            
        }
        
    };

}




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