title: Android: custom view with TYPE_CLASS_NUMBER keyboard (IME) - input doesn't work
body: <p>I faced with a strange keyboard behaviour, when I setup the keyboard type to TYPE_CLASS_NUMBER.</p>
  
  <p>I use BaseInputConnection to connect my editable object and TextWathcer to listen of any text changes.</p>
  
  <p>The problem:</p>
  
  <ol>
  <li><p>When the inputType=TYPE_CLASS_TEXT and first input symbol is any
  symbol except the number - all works fine and editable text changes.</p></li>
  <li><p>When I switch the keyboard type to TYPE_CLASS_NUMBER and trying to
  enter numbers  - nothing changes.</p></li>
  </ol>
  
  <p>For example:</p>
  
  <ol>
  <li>Input "12345"  Output ""</li>
  <li>Input "teststring123" Output "teststring123" , </li>
  <li>Input "123teststring" Output "teststring"</li>
  </ol>
  
  <p>Full Code:</p>
  
  <pre><code>public class CustomView extends View implements View.OnClickListener {
  
  private Editable editable;
  
  private InputMethodManager imm;
  
  private final CustomTextWatcher textWatcher = new CustomTextWatcher();
  
  private Paint mainPaint;
  
  private int batch;
  
  public CustomView(Context context) {
      super(context);
      init(context, null);
  }
  
  public CustomView(Context context, @Nullable AttributeSet attrs) {
      super(context, attrs);
      init(context, attrs);
  }
  
  public CustomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
      super(context, attrs, defStyleAttr);
      init(context, attrs);
  }
  
  private void init(Context context, @Nullable AttributeSet attrs) {
  
      setOnClickListener(this);
      setFocusableInTouchMode(true);
      imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
  
      editable = Editable.Factory.getInstance().newEditable("");
      editable.setSpan(textWatcher, 0, editable.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
      Selection.setSelection(editable, 0);
  
  
      mainPaint = new Paint();
      mainPaint.setColor(ContextCompat.getColor(context, R.color.colorPrimary));
      mainPaint.setTextSize(30);
  }
  
  @Override
  protected void onDraw(Canvas canvas) {
      canvas.drawText(editable.toString(), 15, 20, mainPaint);
      super.onDraw(canvas);
  }
  
  @Override
  public void onClick(View v) {
      imm.showSoftInput(this, 0);
  }
  
  @Override
  public boolean onTouchEvent(MotionEvent event) {
      if (event.getAction() == MotionEvent.ACTION_UP &amp;&amp; batch == 0) {
          int cursorPosition = 0;
  
          imm.viewClicked(this);
          imm.updateSelection(this, cursorPosition, cursorPosition, cursorPosition, cursorPosition);
          imm.updateSelection(this, cursorPosition, cursorPosition, -1, -1);
      }
      return super.onTouchEvent(event);
  }
  
  @Override
  public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
      Log.e("CustomView", " onCreateInputConnection");
  
      outAttrs.inputType = InputType.TYPE_CLASS_NUMBER;
      outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE;
      outAttrs.initialSelStart = 0;
      outAttrs.initialSelEnd = 0;
  
      return new BaseInputConnection(this, true) {
          @Override
          public Editable getEditable() {
              return editable;
          }
  
          @Override
          public boolean endBatchEdit() {
              batch++;
              return super.endBatchEdit();
          }
  
          @Override
          public boolean beginBatchEdit() {
              batch--;
              return super.beginBatchEdit();
          }
      };
  }
  
  @Override
  public boolean onCheckIsTextEditor() {
      return true;
  }
  
  
  private class CustomTextWatcher implements TextWatcher {
  
      @Override
      public void beforeTextChanged(CharSequence s, int start, int count, int after) {
      }
  
      @Override
      public void onTextChanged(CharSequence s, int start, int before, int count) {
  
      }
  
      @Override
      public void afterTextChanged(Editable s) {
          Log.e("CustomView",  "afterTextChanged " + s);
          invalidate();
      }
  }
  }
  </code></pre>