Example usage for android.widget TextView.OnEditorActionListener TextView.OnEditorActionListener

List of usage examples for android.widget TextView.OnEditorActionListener TextView.OnEditorActionListener

Introduction

In this page you can find the example usage for android.widget TextView.OnEditorActionListener TextView.OnEditorActionListener.

Prototype

TextView.OnEditorActionListener

Source Link

Usage

From source file:org.debian.paulliu.kajiradoubra.controller.ConsoleFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mActivity = (KajiraDouBraController) getActivity();

    EditText edittext = (EditText) mActivity.findViewById(R.id.edittext_console_cmd);
    edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override/* ww  w .j av a 2 s .  co  m*/
        public boolean onEditorAction(TextView view, int actionId, android.view.KeyEvent event) {
            boolean handled = false;
            if (actionId == android.view.inputmethod.EditorInfo.IME_ACTION_SEND) {
                sendBluetoothData("l0r0");
                String cmd = String.format("(%1$s)", view.getText());
                sendBluetoothData(cmd);
                Log.i(KajiraDouBraController.LOGTAG, "send cmd " + cmd);
                handled = true;
            }
            return handled;
        }
    });
    Button button = null;
    button = (Button) mActivity.findViewById(R.id.button_console_send);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            sendBluetoothData("l0r0");
            KajiraDouBraController mActivity = (KajiraDouBraController) getActivity();
            EditText edittext = (EditText) mActivity.findViewById(R.id.edittext_console_cmd);
            String cmd = String.format("(%1$s)", edittext.getText());
            sendBluetoothData(cmd);
            Log.i(KajiraDouBraController.LOGTAG, "send cmd " + cmd);
        }
    });
}

From source file:mroza.forms.ChooseProgramActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    this.menu = menu;
    getMenuInflater().inflate(R.menu.choose_program_menu, menu);

    //Associate programs_searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    android.support.v7.widget.SearchView searchView = (android.support.v7.widget.SearchView) menu
            .findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    EditText searchPlate = (EditText) searchView
            .findViewById(android.support.v7.appcompat.R.id.search_src_text);
    searchPlate.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchPlate.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override/* w  w  w .j  a v a2s  . c  o m*/
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            //On search or enter clicked
            if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_NULL) {
                if (v.getText().toString().equals("")) {
                    refreshChildTableList();
                    clearSearchField();
                    clearFilters(true);
                    enableShowAllButton(false);
                }
            }
            return false;
        }
    });

    restoreSavedFilters();
    return true;
}

From source file:com.nit.vicky.CardBrowser.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    View mainView = getLayoutInflater().inflate(R.layout.card_browser, null);
    setContentView(mainView);/*from www .ja v  a2  s . co m*/
    Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER);

    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }
    mDeckNames = new HashMap<String, String>();
    for (long did : mCol.getDecks().allIds()) {
        mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did));
    }
    registerExternalStorageListener();

    Intent i = getIntent();
    mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false);

    mBackground = Themes.getCardBrowserBackground();

    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO);
    String sflCustomFont = preferences.getString("browserEditorFont", "");
    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);

    Resources res = getResources();
    mOrderByFields = res.getStringArray(R.array.card_browser_order_labels);
    try {
        mOrder = CARD_ORDER_NONE;
        String colOrder = mCol.getConf().getString("sortType");
        for (int c = 0; c < fSortTypes.length; ++c) {
            if (fSortTypes[c].equals(colOrder)) {
                mOrder = c;
                break;
            }
        }
        if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) {
            mOrder = 0;
        }
        mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false);
        // default to descending for non-text fields
        if (fSortTypes[mOrder].equals("noteFld")) {
            mOrderAsc = !mOrderAsc;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    mCards = new ArrayList<HashMap<String, String>>();
    mCardsListView = (ListView) findViewById(R.id.card_browser_list);

    mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item,
            new String[] { "word", "sfld", "deck", "flags" },
            new int[] { R.id.card_word, R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize,
            sflCustomFont);
    mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            if (view.getId() == R.id.card_item) {
                int which = BACKGROUND_NORMAL;
                if (text.equals("1")) {
                    which = BACKGROUND_SUSPENDED;
                } else if (text.equals("2")) {
                    which = BACKGROUND_MARKED;
                } else if (text.equals("3")) {
                    which = BACKGROUND_MARKED_SUSPENDED;
                }
                view.setBackgroundResource(mBackground[which]);
                return true;
            } else if (view.getId() == R.id.card_deck && text.length() > 0) {
                view.setVisibility(View.VISIBLE);
            }
            return false;
        }
    });

    //mCardsListView.setAdapter(mCardsAdapter);
    mCardsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, MultimediaCardEditorActivity.class);
            //editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(MultimediaCardEditorActivity.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
        }
    });
    registerForContextMenu(mCardsListView);

    mCardsGridView = (StaggeredGridView) findViewById(R.id.card_browser_gridview);
    mCardsGridView.setAdapter(mGridAdapter);
    mCardsGridView.setOnItemClickListener(new StaggeredGridView.OnItemClickListener() {
        @Override
        public void onItemClick(StaggeredGridView parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, MultimediaCardEditorActivity.class);
            //editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(MultimediaCardEditorActivity.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
            String imgURL = getImgURL(sCardBrowserCard);
            Toast.makeText(CardBrowser.this, imgURL, Toast.LENGTH_LONG).show();
        }
    });
    mSearchEditText = (EditText) findViewById(R.id.card_browser_search);
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                onSearch();
                return true;
            }
            return false;
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button);
    mSearchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSearch();
        }
    });

    mSearchTerms = "";
    if (mWholeCollection) {
        mRestrictOnDeck = "";
        setTitle(res.getString(R.string.card_browser_all_decks));
    } else {
        try {
            String deckName = mCol.getDecks().current().getString("name");
            mRestrictOnDeck = "deck:'" + deckName + "' ";
            setTitle(deckName);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }

    mSelectedTags = new HashSet<String>();

    if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) {
        searchCards();
    }
}

From source file:nf.frex.android.FrexActivity.java

private void preparePropertiesDialog(final Dialog dialog) {

    final Registry<Fractal> fractals = Registries.fractals;
    int fractalTypeIndex = fractals.getIndex(view.getFractalId());

    final Spinner fractalTypeSpinner = (Spinner) dialog.findViewById(R.id.fractal_type_spinner);
    final SeekBar iterationsSeekBar = (SeekBar) dialog.findViewById(R.id.num_iterations_seek_bar);
    final EditText iterationsEditText = (EditText) dialog.findViewById(R.id.num_iterations_edit_text);
    final CheckBox juliaModeCheckBox = (CheckBox) dialog.findViewById(R.id.julia_mode_fractal_check_box);
    final CheckBox decoratedFractal = (CheckBox) dialog.findViewById(R.id.decorated_fractal_check_box);
    final Button okButton = (Button) dialog.findViewById(R.id.ok_button);
    final Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button);

    juliaModeCheckBox.setEnabled(true);//from   www  .j av  a  2  s  . co  m

    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            fractals.getIds());
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    fractalTypeSpinner.setAdapter(arrayAdapter);
    fractalTypeSpinner.setSelection(fractalTypeIndex, true);
    fractalTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View spinnerView, int position, long id) {
            Fractal fractal = fractals.getValue(position);
            iterationsEditText.setText(fractal.getDefaultIterMax() + "");
            boolean sameFractal = view.getFractalId().equals(fractals.getId(position));
            if (!sameFractal) {
                juliaModeCheckBox.setChecked(false);
            }
            juliaModeCheckBox.setEnabled(sameFractal);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    iterationsEditText.setText(view.getIterMax() + "", TextView.BufferType.NORMAL);

    final double iterationsMin = 1;
    final double iterationsMax = 3;
    final SeekBarConfigurer iterationsSeekBarConfigurer = SeekBarConfigurer.create(iterationsSeekBar,
            iterationsMin, iterationsMax, true, view.getIterMax());
    iterationsSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                int iterMax = iterationsSeekBarConfigurer.getValueInt();
                iterationsEditText.setText(iterMax + "", TextView.BufferType.NORMAL);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    iterationsEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            try {
                int iterMax = Integer.parseInt(v.getText().toString());
                iterationsSeekBarConfigurer.setValue(iterMax);
                return true;
            } catch (NumberFormatException e) {
                return false;
            }
        }
    });

    decoratedFractal.setChecked(view.isDecoratedFractal());

    juliaModeCheckBox.setChecked(view.isJuliaModeFractal());

    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int iterMax;
            try {
                iterMax = Integer.parseInt(iterationsEditText.getText().toString());
            } catch (NumberFormatException e) {
                Toast.makeText(FrexActivity.this, getString(R.string.error_msg, e.getLocalizedMessage()),
                        Toast.LENGTH_SHORT).show();
                return;
            }
            dialog.dismiss();
            String oldConfigName = view.getConfigName();
            String newFractalId = fractals.getId(fractalTypeSpinner.getSelectedItemPosition());
            Fractal fractal = fractals.getValue(fractalTypeSpinner.getSelectedItemPosition());
            String oldFractalId = view.getFractalId();
            boolean newJuliaModeFractal = juliaModeCheckBox.isChecked();
            boolean oldJuliaModeFractal = view.isJuliaModeFractal();
            view.setFractalId(newFractalId);
            view.setIterMax(iterMax);
            view.setDecoratedFractal(decoratedFractal.isChecked());
            view.setJuliaModeFractal(newJuliaModeFractal);
            boolean fractalTypeChanged = !oldFractalId.equals(newFractalId);
            if (fractalTypeChanged) {
                if (oldConfigName.contains(oldFractalId.toLowerCase())) {
                    view.setConfigName(newFractalId.toLowerCase());
                }
                view.setRegion(fractal.getDefaultRegion());
                view.setBailOut(fractal.getDefaultBailOut());
            }
            boolean juliaModeChanged = oldJuliaModeFractal != newJuliaModeFractal;
            if (fractalTypeChanged || juliaModeChanged) {
                view.getRegionHistory().clear();
                view.getRegionHistory().add(fractal.getDefaultRegion().clone());
            }
            view.recomputeAll();
        }
    });
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
}