Android Open Source - CheckListView Edit Text Multi Line No Enter






From Project

Back to project page CheckListView.

License

The source code is released under:

Apache License

If you think the Android project CheckListView 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 it.feio.android.checklistview.models;
//from  w ww .j  a va  2 s.c  o m
import android.content.Context;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputConnectionWrapper;

import com.neopixl.pixlui.components.edittext.EditText;

import it.feio.android.checklistview.interfaces.EditTextEventListener;

/**
 * Class used to avoid carriage return in multi-line EditText.
 */
public class EditTextMultiLineNoEnter extends EditText {
  
  private EditTextEventListener mEditTextEventListener;

  public EditTextMultiLineNoEnter(Context context) {
    super(context);
  }

  @Override
  public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    InputConnection connection = super.onCreateInputConnection(outAttrs);
    // By default setting android:inputType="textMultiLine" will remove any
    // imeAction like NEXT, DONE...
    // So here is where this behaviour is changed
    if ((outAttrs.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
      outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
    }
    return new DelCatcherInputConnection(connection, true);
  }
  

  /**
   * Sets event linstener to catch delete key pressions
   */
  public void setEditTextEventListener(EditTextEventListener mEditTextEventListener) {
    this.mEditTextEventListener = mEditTextEventListener;
  }


  /**
   * Overriding InputConnectionWrapper to throw delete key pressions
   */
  private class DelCatcherInputConnection extends InputConnectionWrapper {

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

        @Override
        public boolean sendKeyEvent(KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN
                    && event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
              mEditTextEventListener.onDeletePressed();
            }
            return super.sendKeyEvent(event);
        }
        
        @Override
        public boolean deleteSurroundingText(int beforeLength, int afterLength) {
          mEditTextEventListener.onDeletePressed();
          return super.deleteSurroundingText(beforeLength, afterLength);
        }

    }

}




Java Source Code List

it.feio.android.checklistview.App.java
it.feio.android.checklistview.ChecklistManager.java
it.feio.android.checklistview.Settings.java
it.feio.android.checklistview.demo.MainActivity.java
it.feio.android.checklistview.demo.SettingsActivity.java
it.feio.android.checklistview.dragging.ChecklistViewDragShadowBuilder.java
it.feio.android.checklistview.dragging.ChecklistViewItemOnDragListener.java
it.feio.android.checklistview.dragging.ChecklistViewOnTouchListener.java
it.feio.android.checklistview.exceptions.ViewNotSupportedException.java
it.feio.android.checklistview.interfaces.CheckListChangedListener.java
it.feio.android.checklistview.interfaces.CheckListEventListener.java
it.feio.android.checklistview.interfaces.Constants.java
it.feio.android.checklistview.interfaces.EditTextEventListener.java
it.feio.android.checklistview.models.CheckListViewItem.java
it.feio.android.checklistview.models.CheckListView.java
it.feio.android.checklistview.models.EditTextMultiLineNoEnter.java
it.feio.android.checklistview.utils.AlphaManager.java
it.feio.android.checklistview.utils.DensityUtil.java