Example usage for android.view.inputmethod EditorInfo IME_ACTION_SEARCH

List of usage examples for android.view.inputmethod EditorInfo IME_ACTION_SEARCH

Introduction

In this page you can find the example usage for android.view.inputmethod EditorInfo IME_ACTION_SEARCH.

Prototype

int IME_ACTION_SEARCH

To view the source code for android.view.inputmethod EditorInfo IME_ACTION_SEARCH.

Click Source Link

Document

Bits of #IME_MASK_ACTION : the action key performs a "search" operation, taking the user to the results of searching for the text they have typed (in whatever context is appropriate).

Usage

From source file:org.odk.collect.android.activities.GoogleDriveActivity.java

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

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setProgressBarVisibility(true);//from   w w w.  j ava2s.  c om
    setContentView(R.layout.drive_layout);
    listView = (ListView) findViewById(android.R.id.list);
    listView.setOnItemClickListener(this);
    emptyView = (TextView) findViewById(android.R.id.empty);

    initToolbar();

    parentId = null;
    alertShowing = false;
    toDownload = new ArrayList<>();

    if (savedInstanceState != null && savedInstanceState.containsKey(MY_DRIVE_KEY)) {
        // recover state on rotate
        myDrive = savedInstanceState.getBoolean(MY_DRIVE_KEY);
        String[] patharray = savedInstanceState.getStringArray(PATH_KEY);
        currentPath = buildPath(patharray);

        parentId = savedInstanceState.getString(PARENT_KEY);
        alertMsg = savedInstanceState.getString(ALERT_MSG_KEY);
        alertShowing = savedInstanceState.getBoolean(ALERT_SHOWING_KEY);

        ArrayList<DriveListItem> dl = savedInstanceState.getParcelableArrayList(DRIVE_ITEMS_KEY);
        adapter = new FileArrayAdapter(GoogleDriveActivity.this, R.layout.two_item_image, dl);
        listView.setAdapter(adapter);
        adapter.setEnabled(true);
    } else {
        // new
        myDrive = false;

        if (!isDeviceOnline()) {
            createAlertDialog(getString(R.string.no_connection));
        }
    }

    // restore any task state
    if (getLastCustomNonConfigurationInstance() instanceof RetrieveDriveFileContentsAsyncTask) {
        retrieveDriveFileContentsAsyncTask = (RetrieveDriveFileContentsAsyncTask) getLastNonConfigurationInstance();
        setProgressBarIndeterminateVisibility(true);
    } else {
        getFileTask = (GetFileTask) getLastNonConfigurationInstance();
        if (getFileTask != null) {
            getFileTask.setGoogleDriveFormDownloadListener(this);
        }
    }
    if (getFileTask != null && getFileTask.getStatus() == AsyncTask.Status.FINISHED) {
        try {
            dismissDialog(PROGRESS_DIALOG);
        } catch (Exception e) {
            Timber.i("Exception was thrown while dismissing a dialog.");
        }
    }
    if (alertShowing) {
        try {
            dismissDialog(PROGRESS_DIALOG);
        } catch (Exception e) {
            // don't care...
            Timber.i("Exception was thrown while dismissing a dialog.");
        }
        createAlertDialog(alertMsg);
    }

    rootButton = (Button) findViewById(R.id.root_button);
    if (myDrive) {
        rootButton.setText(getString(R.string.go_shared));
    } else {
        rootButton.setText(getString(R.string.go_drive));
    }
    rootButton.setOnClickListener(this);

    backButton = (Button) findViewById(R.id.back_button);
    backButton.setEnabled(parentId != null);
    backButton.setOnClickListener(this);

    downloadButton = (Button) findViewById(R.id.download_button);
    downloadButton.setOnClickListener(this);

    searchText = (EditText) findViewById(R.id.search_text);
    searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                executeSearch();
                return true;
            }
            return false;
        }
    });
    searchButton = (ImageButton) findViewById(R.id.search_button);
    searchButton.setOnClickListener(this);

    // Initialize credentials and service object.
    credential = GoogleAccountCredential
            .usingOAuth2(getApplicationContext(), Collections.singletonList(DriveScopes.DRIVE))
            .setBackOff(new ExponentialBackOff());

    HttpTransport transport = AndroidHttp.newCompatibleTransport();
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    driveService = new com.google.api.services.drive.Drive.Builder(transport, jsonFactory, credential)
            .setApplicationName("ODK-Collect").build();

    getResultsFromApi();
}

From source file:org.cocos2dx.lib.Cocos2dxEditBoxDialog.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    getWindow().setBackgroundDrawable(new ColorDrawable(0x80000000));

    LinearLayout layout = new LinearLayout(mParentActivity);
    layout.setOrientation(LinearLayout.VERTICAL);

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);

    mTextViewTitle = new TextView(mParentActivity);
    LinearLayout.LayoutParams textviewParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    textviewParams.leftMargin = textviewParams.rightMargin = convertDipsToPixels(10);
    mTextViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    layout.addView(mTextViewTitle, textviewParams);

    mInputEditText = new EditText(mParentActivity);
    LinearLayout.LayoutParams editTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    editTextParams.leftMargin = editTextParams.rightMargin = convertDipsToPixels(10);

    layout.addView(mInputEditText, editTextParams);

    setContentView(layout, layoutParams);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    mInputMode = mMsg.inputMode;//  w  ww  .  ja v  a  2  s  .c o  m
    mInputFlag = mMsg.inputFlag;
    mReturnType = mMsg.returnType;
    mMaxLength = mMsg.maxLength;

    mTextViewTitle.setText(mMsg.title);
    mInputEditText.setText(mMsg.content);

    int oldImeOptions = mInputEditText.getImeOptions();
    mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    oldImeOptions = mInputEditText.getImeOptions();

    switch (mInputMode) {
    case kEditBoxInputModeAny:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE;
        break;
    case kEditBoxInputModeEmailAddr:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
        break;
    case kEditBoxInputModeNumeric:
        mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
        break;
    case kEditBoxInputModePhoneNumber:
        mInputModeContraints = InputType.TYPE_CLASS_PHONE;
        break;
    case kEditBoxInputModeUrl:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
        break;
    case kEditBoxInputModeDecimal:
        mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                | InputType.TYPE_NUMBER_FLAG_SIGNED;
        break;
    case kEditBoxInputModeSingleLine:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT;
        break;
    default:

        break;
    }

    if (mIsMultiline) {
        mInputModeContraints |= InputType.TYPE_TEXT_FLAG_MULTI_LINE;
    }

    mInputEditText.setInputType(mInputModeContraints | mInputFlagConstraints);

    switch (mInputFlag) {
    case kEditBoxInputFlagPassword:
        mInputFlagConstraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
        break;
    case kEditBoxInputFlagSensitive:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
        break;
    case kEditBoxInputFlagInitialCapsWord:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_WORDS;
        break;
    case kEditBoxInputFlagInitialCapsSentence:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
        break;
    case kEditBoxInputFlagInitialCapsAllCharacters:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
        break;
    default:
        break;
    }
    mInputEditText.setInputType(mInputFlagConstraints | mInputModeContraints);

    switch (mReturnType) {
    case kKeyboardReturnTypeDefault:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE);
        break;
    case kKeyboardReturnTypeDone:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_DONE);
        break;
    case kKeyboardReturnTypeSend:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEND);
        break;
    case kKeyboardReturnTypeSearch:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEARCH);
        break;
    case kKeyboardReturnTypeGo:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_GO);
        break;
    default:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE);
        break;
    }

    if (mMaxLength > 0) {
        mInputEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mMaxLength) });
    }

    Handler initHandler = new Handler();
    initHandler.postDelayed(new Runnable() {
        public void run() {
            mInputEditText.requestFocus();
            mInputEditText.setSelection(mInputEditText.length());
            openKeyboard();
        }
    }, 200);

    mInputEditText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // if user didn't set keyboard type,
            // this callback will be invoked twice with 'KeyEvent.ACTION_DOWN' and 'KeyEvent.ACTION_UP'
            if (actionId != EditorInfo.IME_NULL || (actionId == EditorInfo.IME_NULL && event != null
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
                //Log.d("EditBox", "actionId: "+actionId +",event: "+event);
                mParentActivity.setEditBoxResult(mInputEditText.getText().toString());
                closeKeyboard();
                dismiss();
                return true;
            }
            return false;
        }
    });
}

From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentSearch.java

private void HandleSearch() {
    image_search_back.setOnClickListener(new View.OnClickListener() {
        @Override// w ww.  j av  a  2 s  .  co  m
        public void onClick(View v) {
            clearItems();
            InitiateSearch.handleToolBar(getActivity(), card_search, view_search, listView, edit_text_search,
                    line_divider);
            searchBack.setVisibility(View.GONE);
            endFragment();
        }
    });
    edit_text_search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                if (edit_text_search.getText().toString().trim().length() > 0) {
                    clearItems();
                    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(edit_text_search.getWindowToken(), 0);
                    UpdateQuickSearch(edit_text_search.getText().toString());
                    listView.setVisibility(View.GONE);
                    searchFood(edit_text_search.getText().toString(), 0);
                }
                return true;
            }
            return false;
        }
    });

}

From source file:org.mozilla.gecko.AwesomeBar.java

private void updateGoButton(String text) {
    if (text.length() == 0) {
        mGoButton.setVisibility(View.GONE);
        return;//from w w w . j a v a 2s.  c  o m
    }

    mGoButton.setVisibility(View.VISIBLE);

    int imageResource = R.drawable.ic_awesomebar_go;
    int imeAction = EditorInfo.IME_ACTION_GO;
    if (isSearchUrl(text)) {
        imageResource = R.drawable.ic_awesomebar_search;
        imeAction = EditorInfo.IME_ACTION_SEARCH;
    }
    mGoButton.setImageResource(imageResource);

    if ((mText.getImeOptions() & EditorInfo.IME_MASK_ACTION) != imeAction) {
        InputMethodManager imm = (InputMethodManager) mText.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        mText.setImeOptions(imeAction);
        imm.restartInput(mText);
    }
}

From source file:com.se.cronus.AbstractCActivity.java

protected void setUpActionBar() {
    ImageView icon = new ImageView(this);
    icon.setBackgroundResource(com.se.cronus.R.drawable.temp_cronos_logo);
    act = this.getActionBar();
    act.setBackgroundDrawable(new ColorDrawable(CUtils.CRONUS_GREEN_DARK));
    act.setIcon(com.se.cronus.R.drawable.temp_cronos_logo);
    act.setCustomView(com.se.cronus.R.layout.action_bar);
    act.setDisplayHomeAsUpEnabled(true);
    act.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
    ((ViewGroup) act.getCustomView().getParent()).addView(icon);
    // extra icons
    search = (ImageView) findViewById(com.se.cronus.R.id.action_search_b);
    refresh = (ImageView) findViewById(com.se.cronus.R.id.action_refresh);
    searchTextE = (EditText) findViewById(com.se.cronus.R.id.action_search_et);
    searchTextV = (TextView) findViewById(com.se.cronus.R.id.action_search_tv);
    item = (ImageView) findViewById(com.se.cronus.R.id.action_item);

    searchTextE.setTextColor(Color.WHITE);
    searchTextE.setTextSize(15);//from  w  ww.  jav a 2 s. c  om
    searchTextE.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

    searchTextV.setTextColor(Color.WHITE);
    searchTextV.setTextSize(15);

    ImageView logo = (ImageView) findViewById(com.se.cronus.R.id.temp_cronos_logo);
    logo.setLayoutParams(new RelativeLayout.LayoutParams(act.getHeight(), act.getHeight()));

}

From source file:com.uzmap.pkg.uzmodules.UISearchBar.SearchBarActivity.java

private void setOnclick() {
    mRecordImage.setOnClickListener(new OnClickListener() {
        @Override/*from   w ww.  j a  va  2 s.  co  m*/
        public void onClick(View v) {
            try {
                JSONObject ret = new JSONObject();
                ret.put("eventType", "record");
                mUZContext.success(ret, false);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });

    deleteTextImg.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            mEditText.setText("");
            if (config.showRecordBtn) {
                mRecordImage.setVisibility(View.VISIBLE);
            } else {
                mRecordImage.setVisibility(View.GONE);
            }
        }
    });

    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long longid) {
            if (position == list.size() - 1) {
                hide();
                id = 0;
                list.clear();
                list.add(relativeLayoutClean);
                adapter.notifyDataSetChanged();
                editor.clear();
                editor.commit();
            } else {
                int tv_listId = UZResourcesIDFinder.getResIdID("tv_listview");
                TextView tv = (TextView) view.findViewById(tv_listId);
                String searchText = tv.getText().toString();
                try {
                    JSONObject ret = new JSONObject();
                    ret.put("eventType", "history");
                    ret.put("text", searchText);
                    mUZContext.success(ret, false);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                SearchBarActivity.this.finish();
            }
        }
    });

    mEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            if (!TextUtils.isEmpty(arg0)) {
                mRecordImage.setVisibility(View.GONE);
                deleteTextImg.setVisibility(View.VISIBLE);
            } else {
                deleteTextImg.setVisibility(View.GONE);
                if (config.showRecordBtn) {
                    mRecordImage.setVisibility(View.VISIBLE);
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

        }

        @Override
        public void afterTextChanged(Editable arg0) {

        }
    });

    mEditText.setOnEditorActionListener(new OnEditorActionListener() {

        @SuppressWarnings("unchecked")
        @Override
        public boolean onEditorAction(TextView arg0, int actionId, KeyEvent event) {

            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                id++;
                String text = mEditText.getText().toString();
                if (!TextUtils.isEmpty(text)) {

                    if (recordCount <= 0) {

                        try {
                            JSONObject ret = new JSONObject();
                            ret.put("eventType", "search");
                            ret.put("text", text);
                            mUZContext.success(ret, false);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        SearchBarActivity.this.finish();
                        clearText();

                        return false;
                    }

                    int index = id % recordCount;
                    if (id > recordCount) {

                        editor.remove(1 + "");
                        editor.commit();
                        Map<String, String> map = (Map<String, String>) mPref.getAll();
                        if (map != null) {
                            if (map.size() != 0) {
                                for (int i = 1; i <= (map.size() + 1); i++) {
                                    for (Entry<String, String> iterable_element : map.entrySet()) {
                                        String key = iterable_element.getKey();
                                        if ((i + "").equals(key)) {
                                            editor.putString((i - 1) + "", iterable_element.getValue());
                                            editor.commit();
                                        }
                                    }
                                }
                            }
                        }
                        editor.putString(recordCount + "", text);
                        editor.commit();
                    } else {
                        editor.putString((index == 0 ? recordCount : index) + "", text);
                        editor.commit();
                    }

                    try {
                        JSONObject ret = new JSONObject();
                        ret.put("eventType", "search");
                        ret.put("text", text);
                        mUZContext.success(ret, false);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    SearchBarActivity.this.finish();
                    clearText();
                }

            }
            return false;
        }
    });

    mTextView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            SearchBarActivity.this.finish();
            clearText();

        }
    });
}

From source file:org.rm3l.ddwrt.tiles.admin.nvram.AdminNVRAMTile.java

public AdminNVRAMTile(@NotNull SherlockFragment parentFragment, @NotNull Bundle arguments,
        @Nullable Router router) {/*from  w  w w .j  a v a  2s .  com*/
    super(parentFragment, arguments, router, R.layout.tile_admin_nvram, R.id.tile_admin_nvram_togglebutton);

    sortIds.put(R.id.tile_admin_nvram_sort_default, 11);
    sortIds.put(R.id.tile_admin_nvram_sort_asc, 12);
    sortIds.put(R.id.tile_admin_nvram_sort_desc, 13);

    this.mNvramInfoDefaultSorting = new NVRAMInfo();
    mRecyclerView = (RecyclerView) layout.findViewById(R.id.tile_admin_nvram_ListView);

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    // allows for optimizations if all items are of the same size:
    mRecyclerView.setHasFixedSize(true);

    // use a linear layout manager
    mLayoutManager = new LinearLayoutManager(mParentFragmentActivity);
    mLayoutManager.scrollToPosition(0);
    mRecyclerView.setLayoutManager(mLayoutManager);

    // specify an adapter (see also next example)
    mAdapter = new NVRAMDataRecyclerViewAdapter(mParentFragmentActivity, router, mNvramInfoDefaultSorting);
    mRecyclerView.setAdapter(mAdapter);

    //Create Options Menu
    final ImageButton tileMenu = (ImageButton) layout.findViewById(R.id.tile_admin_nvram_menu);

    if (!isThemeLight(mParentFragmentActivity, mRouter.getUuid())) {
        //Set menu background to white
        tileMenu.setImageResource(R.drawable.abs__ic_menu_moreoverflow_normal_holo_dark);
    }

    tileMenu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final PopupMenu popup = new PopupMenu(mParentFragmentActivity, v);
            popup.setOnMenuItemClickListener(AdminNVRAMTile.this);
            final MenuInflater inflater = popup.getMenuInflater();

            final Menu menu = popup.getMenu();

            inflater.inflate(R.menu.tile_admin_nvram_options, menu);

            //Disable menu item from preference
            Integer currentSort = null;
            if (mParentFragmentPreferences != null) {
                currentSort = sortIds.inverse().get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT),
                        sortIds.get(R.id.tile_admin_nvram_sort_default)));
            }

            if (currentSort == null) {
                currentSort = R.id.tile_admin_nvram_sort_default;
            }

            final MenuItem currentSortMenuItem = menu.findItem(currentSort);
            if (currentSortMenuItem != null) {
                currentSortMenuItem.setEnabled(false);
            }

            // Locate MenuItem with ShareActionProvider
            final MenuItem shareMenuItem = menu.findItem(R.id.tile_admin_nvram_share);

            // Fetch and store ShareActionProvider
            mShareActionProvider = (ShareActionProvider) shareMenuItem.getActionProvider();

            popup.show();
        }

    });

    //Handle for Search EditText
    final EditText filterEditText = (EditText) this.layout.findViewById(R.id.tile_admin_nvram_filter);
    //Initialize with existing search data
    filterEditText.setText(mParentFragmentPreferences != null
            ? mParentFragmentPreferences.getString(getFormattedPrefKey(LAST_SEARCH), EMPTY_STRING)
            : EMPTY_STRING);

    filterEditText.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final int DRAWABLE_LEFT = 0;
            final int DRAWABLE_TOP = 1;
            final int DRAWABLE_RIGHT = 2;
            final int DRAWABLE_BOTTOM = 3;

            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (event.getRawX() >= (filterEditText.getRight()
                        - filterEditText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                    //'Clear' button - clear data, and reset everything out
                    //Reset everything
                    filterEditText.setText(EMPTY_STRING);

                    final Properties mNvramInfoDefaultSortingData = mNvramInfoDefaultSorting.getData();
                    //Update adapter in the preferences
                    if (mParentFragmentPreferences != null) {
                        final Integer currentSort = sortIds.inverse()
                                .get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT), -1));
                        if (currentSort == null || currentSort <= 0) {
                            mNvramInfoToDisplay = new HashMap<>(mNvramInfoDefaultSortingData);
                        } else {
                            switch (currentSort) {
                            case R.id.tile_admin_nvram_sort_asc:
                                //asc
                                mNvramInfoToDisplay = new TreeMap<>(COMPARATOR_STRING_CASE_INSENSITIVE);
                                break;
                            case R.id.tile_admin_nvram_sort_desc:
                                //desc
                                mNvramInfoToDisplay = new TreeMap<>(COMPARATOR_REVERSE_STRING_CASE_INSENSITIVE);
                                break;
                            case R.id.tile_admin_nvram_sort_default:
                            default:
                                mNvramInfoToDisplay = new HashMap<>();
                                break;
                            }
                            mNvramInfoToDisplay.putAll(mNvramInfoDefaultSortingData);
                        }
                    } else {
                        mNvramInfoToDisplay = new HashMap<>(mNvramInfoDefaultSortingData);
                    }

                    ((NVRAMDataRecyclerViewAdapter) mAdapter).setEntryList(mNvramInfoToDisplay);
                    mAdapter.notifyDataSetChanged();

                    if (mParentFragmentPreferences != null) {
                        final SharedPreferences.Editor editor = mParentFragmentPreferences.edit();
                        editor.putString(getFormattedPrefKey(LAST_SEARCH), EMPTY_STRING);
                        editor.apply();
                    }
                    return true;
                }
            }
            return false;
        }
    });

    filterEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                final String textToFind = filterEditText.getText().toString();
                if (isNullOrEmpty(textToFind)) {
                    //extra-check, even though we can be pretty sure the button is enabled only if textToFind is present
                    return true;
                }
                final String existingSearch = mParentFragmentPreferences != null
                        ? mParentFragmentPreferences.getString(getFormattedPrefKey(LAST_SEARCH), null)
                        : null;

                if (mParentFragmentPreferences != null) {
                    if (textToFind.equalsIgnoreCase(existingSearch)) {
                        //No need to go further as this is already the string we are looking for
                        return true;
                    }
                    final SharedPreferences.Editor editor = mParentFragmentPreferences.edit();
                    editor.putString(getFormattedPrefKey(LAST_SEARCH), textToFind);
                    editor.apply();
                }

                //Filter out (and sort by user-preference)
                final Properties mNvramInfoDefaultSortingData = mNvramInfoDefaultSorting.getData();
                //Update adapter in the preferences
                final Map<Object, Object> mNvramInfoToDisplayCopy;
                if (mParentFragmentPreferences != null) {
                    final Integer currentSort = sortIds.inverse()
                            .get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT), -1));
                    if (currentSort == null || currentSort <= 0) {
                        mNvramInfoToDisplayCopy = new HashMap<>(mNvramInfoDefaultSortingData);
                    } else {
                        switch (currentSort) {
                        case R.id.tile_admin_nvram_sort_asc:
                            //asc
                            mNvramInfoToDisplayCopy = new TreeMap<>(COMPARATOR_STRING_CASE_INSENSITIVE);
                            break;
                        case R.id.tile_admin_nvram_sort_desc:
                            //desc
                            mNvramInfoToDisplayCopy = new TreeMap<>(COMPARATOR_REVERSE_STRING_CASE_INSENSITIVE);
                            break;
                        case R.id.tile_admin_nvram_sort_default:
                        default:
                            mNvramInfoToDisplayCopy = new HashMap<>();
                            break;
                        }
                        //noinspection ConstantConditions
                        for (Map.Entry<Object, Object> entry : mNvramInfoDefaultSortingData.entrySet()) {
                            final Object key = entry.getKey();
                            final Object value = entry.getValue();
                            if (key == null) {
                                continue;
                            }
                            if (containsIgnoreCase(key.toString(), textToFind)
                                    || containsIgnoreCase(value.toString(), textToFind)) {
                                mNvramInfoToDisplayCopy.put(key, value);
                            }
                        }
                    }
                } else {
                    mNvramInfoToDisplayCopy = new HashMap<>();
                    //noinspection ConstantConditions
                    for (Map.Entry<Object, Object> entry : mNvramInfoDefaultSortingData.entrySet()) {
                        final Object key = entry.getKey();
                        final Object value = entry.getValue();
                        if (key == null) {
                            continue;
                        }
                        if (containsIgnoreCase(key.toString(), textToFind)
                                || containsIgnoreCase(value.toString(), textToFind)) {
                            mNvramInfoToDisplayCopy.put(key, value);
                        }
                    }
                }

                ((NVRAMDataRecyclerViewAdapter) mAdapter).setEntryList(mNvramInfoToDisplayCopy);
                mAdapter.notifyDataSetChanged();

                return true;
            }
            return false;
        }
    });

}

From source file:org.kde.kdeconnect.Plugins.RemoteKeyboardPlugin.RemoteKeyboardPlugin.java

private boolean handleSpecialKey(int key, boolean shift, boolean ctrl, boolean alt) {
    int keyEvent = specialKeyMap.get(key, 0);
    if (keyEvent == 0)
        return false;
    InputConnection inputConn = RemoteKeyboardService.instance.getCurrentInputConnection();
    //        Log.d("RemoteKeyboardPlugin", "Handling special key " + key + " translated to " + keyEvent + " shift=" + shift + " ctrl=" + ctrl + " alt=" + alt);

    // special sequences:
    if (ctrl && (keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT)) {
        // Ctrl + right -> next word
        ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0);
        int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT);
        if (pos == -1)
            pos = currentTextLength(extractedText);
        else/* www.j av  a 2  s.  c  o m*/
            pos++;
        int startPos = pos;
        int endPos = pos;
        if (shift) { // Shift -> select word (otherwise jump)
            Pair<Integer, Integer> sel = currentSelection(extractedText);
            int cursor = currentCursorPos(extractedText);
            //                Log.d("RemoteKeyboardPlugin", "Selection (to right): " + sel.first + " / " + sel.second + " cursor: " + cursor);
            startPos = cursor;
            if (sel.first < cursor || // active selection from left to right -> grow
                    sel.first > sel.second) // active selection from right to left -> shrink
                startPos = sel.first;
        }
        inputConn.setSelection(startPos, endPos);
    } else if (ctrl && keyEvent == KeyEvent.KEYCODE_DPAD_LEFT) {
        // Ctrl + left -> previous word
        ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0);
        int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT);
        if (pos == -1)
            pos = 0;
        else
            pos++;
        int startPos = pos;
        int endPos = pos;
        if (shift) {
            Pair<Integer, Integer> sel = currentSelection(extractedText);
            int cursor = currentCursorPos(extractedText);
            //                Log.d("RemoteKeyboardPlugin", "Selection (to left): " + sel.first + " / " + sel.second + " cursor: " + cursor);
            startPos = cursor;
            if (cursor < sel.first || // active selection from right to left -> grow
                    sel.first < sel.second) // active selection from right to left -> shrink
                startPos = sel.first;
        }
        inputConn.setSelection(startPos, endPos);
    } else if (shift && (keyEvent == KeyEvent.KEYCODE_DPAD_LEFT || keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT
            || keyEvent == KeyEvent.KEYCODE_DPAD_UP || keyEvent == KeyEvent.KEYCODE_DPAD_DOWN
            || keyEvent == KeyEvent.KEYCODE_MOVE_HOME || keyEvent == KeyEvent.KEYCODE_MOVE_END)) {
        // Shift + up/down/left/right/home/end
        long now = SystemClock.uptimeMillis();
        inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0));
        inputConn.sendKeyEvent(
                new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON));
        inputConn.sendKeyEvent(
                new KeyEvent(now, now, KeyEvent.ACTION_UP, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON));
        inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0));
    } else if (keyEvent == KeyEvent.KEYCODE_NUMPAD_ENTER || keyEvent == KeyEvent.KEYCODE_ENTER) {
        // Enter key
        EditorInfo editorInfo = RemoteKeyboardService.instance.getCurrentInputEditorInfo();
        //            Log.d("RemoteKeyboardPlugin", "Enter: " + editorInfo.imeOptions);
        if (editorInfo != null
                && (((editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0) || ctrl)) { // Ctrl+Return overrides IME_FLAG_NO_ENTER_ACTION (FIXME: make configurable?)
            // check for special DONE/GO/etc actions first:
            int[] actions = { EditorInfo.IME_ACTION_GO, EditorInfo.IME_ACTION_NEXT, EditorInfo.IME_ACTION_SEND,
                    EditorInfo.IME_ACTION_SEARCH, EditorInfo.IME_ACTION_DONE }; // note: DONE should be last or we might hide the ime instead of "go"
            for (int i = 0; i < actions.length; i++) {
                if ((editorInfo.imeOptions & actions[i]) == actions[i]) {
                    //                        Log.d("RemoteKeyboardPlugin", "Enter-action: " + actions[i]);
                    inputConn.performEditorAction(actions[i]);
                    return true;
                }
            }
        } else {
            // else: fall back to regular Enter-event:
            //                Log.d("RemoteKeyboardPlugin", "Enter: normal keypress");
            inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent));
            inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent));
        }
    } else {
        // default handling:
        inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent));
        inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent));
    }

    return true;
}

From source file:us.phyxsi.gameshelf.ui.SearchActivity.java

private void setupSearchView() {
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    // hint, inputType & ime options seem to be ignored from XML! Set in code
    searchView.setQueryHint(getString(R.string.search_hint));
    searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    searchView.setImeOptions(searchView.getImeOptions() | EditorInfo.IME_ACTION_SEARCH
            | EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_FULLSCREEN);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/*from   www .  jav a  2  s.  c o m*/
        public boolean onQueryTextSubmit(String query) {
            getByTitle(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            if (TextUtils.isEmpty(query)) {
                clearResults();
            }
            return true;
        }
    });
}

From source file:com.edible.ocr.CaptureActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    checkFirstLaunch();//from   w  ww  .  j a  v a2s. co m

    if (isFirstLaunch) {
        setDefaultPreferences();
    }
    currentContext = this;
    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.capture);
    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    cameraButtonView = findViewById(R.id.camera_button_view);
    resultView = findViewById(R.id.result_view);

    statusViewBottom = (TextView) findViewById(R.id.status_view_bottom);
    registerForContextMenu(statusViewBottom);
    statusViewTop = (TextView) findViewById(R.id.status_view_top);
    registerForContextMenu(statusViewTop);
    handler = null;
    lastResult = null;
    hasSurface = false;
    beepManager = new BeepManager(this);

    // Camera shutter button
    if (DISPLAY_SHUTTER_BUTTON) {
        shutterButton = (ShutterButton) findViewById(R.id.shutter_button);
        shutterButton.setOnShutterButtonListener(this);

    }
    settingButton = (Button) findViewById(R.id.setting_button);
    settingButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(currentContext, PreferencesActivity.class);
            startActivity(intent);
        }
    });

    aboutButton = (Button) findViewById(R.id.about_button);
    aboutButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(currentContext, HelpActivity.class);
            intent.putExtra(HelpActivity.REQUESTED_PAGE_KEY, HelpActivity.ABOUT_PAGE);
            startActivity(intent);
        }
    });
    final EditText editText = (EditText) findViewById(R.id.typed_result);
    editText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                // add capture button function 
                Intent openDetail = new Intent(currentContext, DetailInfo.class);
                String req = editText.getText().toString();
                //             openDetail.putExtra("request", "Filet Steak");
                openDetail.putExtra("request", req);
                editText.setText("");
                startActivity(openDetail);
                handled = true;
            }
            return handled;
        }
    });
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    //DB_textview = (TextView)findViewById(R.id.DB_text_view);
    //new HttpAsyncTask().execute("https://www.googleapis.com/language/translate/v2?key=" + KEY + "&q=hello%20world&source=en&target=de");
    /* For Client Server Connection */
    getButton = (Button) findViewById(R.id.get_text_button);
    getButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent openDetail = new Intent(currentContext, DetailInfo.class);
            String req = (String) ocrResultView.getText();
            //         openDetail.putExtra("request", "Filet Steak");
            openDetail.putExtra("request", req);
            startActivity(openDetail);

        }

    });
    ocrResultView = (TextView) findViewById(R.id.ocr_result_text_view);
    registerForContextMenu(ocrResultView);
    translationView = (TextView) findViewById(R.id.translation_text_view);
    registerForContextMenu(translationView);

    progressView = (View) findViewById(R.id.indeterminate_progress_indicator_view);

    cameraManager = new CameraManager(getApplication());
    viewfinderView.setCameraManager(cameraManager);

    // Set listener to change the size of the viewfinder rectangle.
    viewfinderView.setOnTouchListener(new View.OnTouchListener() {
        int lastX = -1;
        int lastY = -1;

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                lastX = -1;
                lastY = -1;
                return true;
            case MotionEvent.ACTION_MOVE:
                int currentX = (int) event.getX();
                int currentY = (int) event.getY();

                try {
                    Rect rect = cameraManager.getFramingRect();

                    final int BUFFER = 50;
                    final int BIG_BUFFER = 60;
                    if (lastX >= 0) {
                        // Adjust the size of the viewfinder rectangle. Check if the touch event occurs in the corner areas first, because the regions overlap.
                        if (((currentX >= rect.left - BIG_BUFFER && currentX <= rect.left + BIG_BUFFER)
                                || (lastX >= rect.left - BIG_BUFFER && lastX <= rect.left + BIG_BUFFER))
                                && ((currentY <= rect.top + BIG_BUFFER && currentY >= rect.top - BIG_BUFFER)
                                        || (lastY <= rect.top + BIG_BUFFER
                                                && lastY >= rect.top - BIG_BUFFER))) {
                            // Top left corner: adjust both top and left sides
                            cameraManager.adjustFramingRect(2 * (lastX - currentX), 2 * (lastY - currentY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.right - BIG_BUFFER && currentX <= rect.right + BIG_BUFFER)
                                || (lastX >= rect.right - BIG_BUFFER && lastX <= rect.right + BIG_BUFFER))
                                && ((currentY <= rect.top + BIG_BUFFER && currentY >= rect.top - BIG_BUFFER)
                                        || (lastY <= rect.top + BIG_BUFFER
                                                && lastY >= rect.top - BIG_BUFFER))) {
                            // Top right corner: adjust both top and right sides
                            cameraManager.adjustFramingRect(2 * (currentX - lastX), 2 * (lastY - currentY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.left - BIG_BUFFER && currentX <= rect.left + BIG_BUFFER)
                                || (lastX >= rect.left - BIG_BUFFER && lastX <= rect.left + BIG_BUFFER))
                                && ((currentY <= rect.bottom + BIG_BUFFER
                                        && currentY >= rect.bottom - BIG_BUFFER)
                                        || (lastY <= rect.bottom + BIG_BUFFER
                                                && lastY >= rect.bottom - BIG_BUFFER))) {
                            // Bottom left corner: adjust both bottom and left sides
                            cameraManager.adjustFramingRect(2 * (lastX - currentX), 2 * (currentY - lastY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.right - BIG_BUFFER && currentX <= rect.right + BIG_BUFFER)
                                || (lastX >= rect.right - BIG_BUFFER && lastX <= rect.right + BIG_BUFFER))
                                && ((currentY <= rect.bottom + BIG_BUFFER
                                        && currentY >= rect.bottom - BIG_BUFFER)
                                        || (lastY <= rect.bottom + BIG_BUFFER
                                                && lastY >= rect.bottom - BIG_BUFFER))) {
                            // Bottom right corner: adjust both bottom and right sides
                            cameraManager.adjustFramingRect(2 * (currentX - lastX), 2 * (currentY - lastY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.left - BUFFER && currentX <= rect.left + BUFFER)
                                || (lastX >= rect.left - BUFFER && lastX <= rect.left + BUFFER))
                                && ((currentY <= rect.bottom && currentY >= rect.top)
                                        || (lastY <= rect.bottom && lastY >= rect.top))) {
                            // Adjusting left side: event falls within BUFFER pixels of left side, and between top and bottom side limits
                            cameraManager.adjustFramingRect(2 * (lastX - currentX), 0);
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.right - BUFFER && currentX <= rect.right + BUFFER)
                                || (lastX >= rect.right - BUFFER && lastX <= rect.right + BUFFER))
                                && ((currentY <= rect.bottom && currentY >= rect.top)
                                        || (lastY <= rect.bottom && lastY >= rect.top))) {
                            // Adjusting right side: event falls within BUFFER pixels of right side, and between top and bottom side limits
                            cameraManager.adjustFramingRect(2 * (currentX - lastX), 0);
                            viewfinderView.removeResultText();
                        } else if (((currentY <= rect.top + BUFFER && currentY >= rect.top - BUFFER)
                                || (lastY <= rect.top + BUFFER && lastY >= rect.top - BUFFER))
                                && ((currentX <= rect.right && currentX >= rect.left)
                                        || (lastX <= rect.right && lastX >= rect.left))) {
                            // Adjusting top side: event falls within BUFFER pixels of top side, and between left and right side limits
                            cameraManager.adjustFramingRect(0, 2 * (lastY - currentY));
                            viewfinderView.removeResultText();
                        } else if (((currentY <= rect.bottom + BUFFER && currentY >= rect.bottom - BUFFER)
                                || (lastY <= rect.bottom + BUFFER && lastY >= rect.bottom - BUFFER))
                                && ((currentX <= rect.right && currentX >= rect.left)
                                        || (lastX <= rect.right && lastX >= rect.left))) {
                            // Adjusting bottom side: event falls within BUFFER pixels of bottom side, and between left and right side limits
                            cameraManager.adjustFramingRect(0, 2 * (currentY - lastY));
                            viewfinderView.removeResultText();
                        }
                    }
                } catch (NullPointerException e) {
                    Log.e(TAG, "Framing rect not available", e);
                }
                v.invalidate();
                lastX = currentX;
                lastY = currentY;
                return true;
            case MotionEvent.ACTION_UP:
                lastX = -1;
                lastY = -1;
                return true;
            }
            return false;
        }
    });

    isEngineReady = false;

}