Android Open Source - RemoteControl My Edit Text






From Project

Back to project page RemoteControl.

License

The source code is released under:

MIT License

If you think the Android project RemoteControl 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 ch.sebastianhaeni.remotecontrol;
/* w  w  w  .  j av a 2 s.c o m*/
import java.util.Random;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputConnectionWrapper;
import android.widget.EditText;

public class MyEditText extends EditText {

  private Random r = new Random();
  private String _ipAddress;
  private Context _context;

  public MyEditText(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    _context = context;
  }

  public MyEditText(Context context, AttributeSet attrs) {
    super(context, attrs);
    _context = context;
  }

  public MyEditText(Context context) {
    super(context);
    _context = context;
  }

  public void setIpAddress(String ipAddress) {
    _ipAddress = ipAddress;
  }

  public void setRandomBackgroundColor() {
    setBackgroundColor(Color.rgb(r.nextInt(256), r.nextInt(256), r.nextInt(256)));
  }

  @Override
  public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    return new MyInputConnection(super.onCreateInputConnection(outAttrs), true);
  }

  private class MyInputConnection extends InputConnectionWrapper {

    public MyInputConnection(InputConnection target, boolean mutable) {
      super(target, mutable);
    }

    @Override
    public boolean deleteSurroundingText(int beforeLength, int afterLength) {
      (new NetworkThread(_context, _ipAddress, "keyboard_backspace:" + beforeLength, "KEYBOARD_REMOVED")).start();
      return super.deleteSurroundingText(beforeLength, afterLength);
    }

    @Override
    public boolean sendKeyEvent(KeyEvent event) {
      if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
        MyEditText.this.setRandomBackgroundColor();
      }
      return super.sendKeyEvent(event);
    }

  }

}




Java Source Code List

ch.sebastianhaeni.remotecontrol.KeyboardActivity.java
ch.sebastianhaeni.remotecontrol.MouseActivity.java
ch.sebastianhaeni.remotecontrol.MyEditText.java
ch.sebastianhaeni.remotecontrol.NetworkThread.java
ch.sebastianhaeni.remotecontrol.ServerSelectionActivity.java
ch.sebastianhaeni.remotecontrol.UDPListenerService.java
ch.sebastianhaeni.remotecontrol.VolumeActivity.java