Skip to content

Commit

Permalink
Passing the onEditorAction event so that apps can react in their own …
Browse files Browse the repository at this point in the history
…way when someone presses "done" on they keyboard.
  • Loading branch information
milos192 committed Feb 20, 2017
1 parent b184e15 commit 9e2eccd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions library/src/main/java/com/seraphim/chips/ChipsListener.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.seraphim.chips;

import android.view.KeyEvent;
import android.widget.TextView;

public interface ChipsListener<E extends ChipEntry> {
void onChipAdded(Chip<E> chip);

void onChipDeleted(Chip<E> chip);

void onTextChanged(CharSequence text);

boolean onEditorAction(TextView v, int actionId, KeyEvent event);
}
10 changes: 6 additions & 4 deletions library/src/main/java/com/seraphim/chips/ChipsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,12 @@ public void clicked(ChipEntry entry) {

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (mode == Mode.ALL && !editText.getText().toString().isEmpty() && actionId == EditorInfo.IME_ACTION_DONE) {
ChipEntry entry = factory.createChip(editText.getText().toString());
editText.setText("");
addChip(entry);
if (chipsListener == null || !chipsListener.onEditorAction(v, actionId, event)) {
if (mode == Mode.ALL && !editText.getText().toString().isEmpty() && actionId == EditorInfo.IME_ACTION_DONE) {
ChipEntry entry = factory.createChip(editText.getText().toString());
editText.setText("");
addChip(entry);
}
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.widget.TextView;

import com.seraphim.chips.Chip;
import com.seraphim.chips.ChipEntry;
Expand Down Expand Up @@ -59,6 +61,11 @@ public void onTextChanged(CharSequence text) {

}

@Override
public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
return false;
}

public class CustomFilter implements ChipsEntriesFilter {
@Override
public List<ChipEntry> filter(CharSequence constraint, List<ChipEntry> suggestions) {
Expand Down

0 comments on commit 9e2eccd

Please sign in to comment.