Example usage for android.view.inputmethod InputMethodManager toggleSoftInput

List of usage examples for android.view.inputmethod InputMethodManager toggleSoftInput

Introduction

In this page you can find the example usage for android.view.inputmethod InputMethodManager toggleSoftInput.

Prototype

public void toggleSoftInput(int showFlags, int hideFlags) 

Source Link

Document

This method toggles the input method window display.

Usage

From source file:com.pentacog.mctracker.MCServerTrackerActivity.java

/**
* @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
*//*  w ww  .ja va2  s .c o  m*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_SEARCH) {
        InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        mgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.SaveCalibrationDialogFragment.java

@NonNull
@Override// w  ww  . ja  v  a  2s  . c  o m
public Dialog onCreateDialog(Bundle savedInstanceState) {

    String testCode = CaddisflyApp.getApp().getCurrentTestInfo().getId();
    final Context context = getActivity();

    LayoutInflater i = getActivity().getLayoutInflater();

    @SuppressLint("InflateParams")
    View view = i.inflate(R.layout.fragment_save_calibration, null);

    final DatePickerDialog.OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            calendar.set(Calendar.YEAR, year);
            calendar.set(Calendar.MONTH, monthOfYear);
            calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            String date = new SimpleDateFormat("dd MMM yyyy", Locale.US).format(calendar.getTime());
            editExpiryDate.setText(date);
        }
    };

    editExpiryDate = (EditText) view.findViewById(R.id.editExpiryDate);

    editBatchCode = (EditText) view.findViewById(R.id.editBatchCode);

    editRgb = (EditText) view.findViewById(R.id.editRgb);

    long milliseconds = PreferencesUtil.getLong(getActivity(),
            CaddisflyApp.getApp().getCurrentTestInfo().getId(), R.string.calibrationExpiryDateKey);
    if (milliseconds > new Date().getTime()) {

        editBatchCode.setText(PreferencesUtil.getString(context, testCode, R.string.batchNumberKey, "").trim());

        long expiryDate = PreferencesUtil.getLong(getContext(), testCode, R.string.calibrationExpiryDateKey);
        if (expiryDate >= 0) {
            calendar.setTimeInMillis(expiryDate);

            editExpiryDate.setText(new SimpleDateFormat("dd-MMM-yyyy", Locale.US).format(new Date(expiryDate)));
        }
    }

    editRgb.setText(PreferencesUtil.getString(context, testCode, R.string.ledRgbKey, "").trim());

    if (!AppPreferences.useExternalCamera()) {
        editRgb.setVisibility(View.GONE);
        view.findViewById(R.id.textRgb).setVisibility(View.GONE);
    }

    final DatePickerDialog datePickerDialog = new DatePickerDialog(context, onDateSetListener,
            calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));

    Calendar date = Calendar.getInstance();
    date.add(Calendar.DATE, 1);
    date.set(Calendar.HOUR_OF_DAY, date.getMinimum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getMinimum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getMinimum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getMinimum(Calendar.MILLISECOND));
    datePickerDialog.getDatePicker().setMinDate(date.getTimeInMillis());
    date.add(Calendar.MONTH, CaddisflyApp.getApp().getCurrentTestInfo().getMonthsValid());
    date.set(Calendar.HOUR_OF_DAY, date.getMaximum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getMaximum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getMaximum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getMaximum(Calendar.MILLISECOND));
    datePickerDialog.getDatePicker().setMaxDate(date.getTimeInMillis());

    editExpiryDate.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean b) {
            if (b) {
                closeKeyboard(getContext(), editBatchCode);
                datePickerDialog.show();
            }
        }
    });

    editExpiryDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            closeKeyboard(getContext(), editBatchCode);
            datePickerDialog.show();
        }
    });

    editName = (EditText) view.findViewById(R.id.editName);
    if (!isEditing && AppPreferences.isDiagnosticMode()) {
        editName.requestFocus();
    } else {
        editName.setVisibility(View.GONE);
        editBatchCode.requestFocus();
    }

    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

    AlertDialog.Builder b = new AlertDialog.Builder(getActivity()).setTitle(R.string.calibrationDetails)
            .setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    closeKeyboard(context, editName);
                    dismiss();
                }
            });

    b.setView(view);
    return b.create();
}

From source file:org.openintents.safe.SearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.search_fragment, null);

    frontdoor = new Intent(getActivity(), Safe.class);
    frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
    restartTimerIntent = new Intent(CryptoIntents.ACTION_RESTART_TIMER);

    etSearchCriteria = (EditText) root.findViewById(R.id.search_criteria);
    results = new ArrayList<SearchEntry>();

    Button goButton = (Button) root.findViewById(R.id.go_button);
    goButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            searchCriteria = etSearchCriteria.getText().toString().trim().toLowerCase();
            searchThreadStart();//w  ww  . j a  v  a  2  s  .  com
        }
    });

    etSearchCriteria.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // Sadly with Jelly Bean actionId can equal 0 instead of IME_ACTION_SEARCH,
            // so the hack event==null is used
            if (actionId == EditorInfo.IME_ACTION_SEARCH || event == null) {
                // hide the soft keyboard
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(0, 0);
                searchCriteria = etSearchCriteria.getText().toString().trim().toLowerCase();
                searchThreadStart();
                return true;
            }
            return false;
        }
    });

    return root;
}

From source file:io.romain.passport.ui.AddCityActivity.java

private void hideLoadingSpinner() {
    ObjectAnimator a = ObjectAnimator.ofFloat(mLoading, View.ALPHA, 1, 0);
    a.addListener(new SimpleAnimatorListener() {
        @Override/* ww w.j av  a  2s. com*/
        public void onAnimationEnd(Animator animation) {
            mLoading.setVisibility(View.GONE);
        }
    });
    ObjectAnimator b = ObjectAnimator.ofFloat(mContainer, View.ALPHA, 0, 1);
    b.addListener(new SimpleAnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            mContainer.setAlpha(0);
            mContainer.setVisibility(View.VISIBLE);
            mEditText.requestFocus();
            mEditText.setError(getString(R.string.add_city_error));

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
        }
    });

    AnimatorSet transition = new AnimatorSet();
    transition.playTogether(a, b);
    transition.setDuration(300);
    transition.setInterpolator(AnimUtils.getFastOutSlowInInterpolator(this));

    transition.start();
}

From source file:com.vaquerosisd.projectmanager.TaskList.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.task_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.actionBar_SearchTaskItem);
    Button clearSearchTask = (Button) searchItem.getActionView().findViewById(R.id.actionBar_ClearSearch);
    final AutoCompleteTextView searchTask = (AutoCompleteTextView) searchItem.getActionView()
            .findViewById(R.id.actionBar_SearchItemEditText);

    //Get all tasks names and add them to an adapter for the AutoCompleteTextView
    List<Task> allTasks = db.getAllTasks(projectId);
    String[] tasksNames = new String[allTasks.size()];
    for (int i = 0; i < allTasks.size(); i++)
        tasksNames[i] = allTasks.get(i).getTaskName();

    ArrayAdapter<String> tasksAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            tasksNames);//from  w  w  w . j a va2s .  c o  m
    searchTask.setAdapter(tasksAdapter);
    searchTask.setThreshold(1);

    //Clear text of search AutoCompleteTextView
    clearSearchTask.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            searchTask.setText("");
        }
    });

    searchTask.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
            } else {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
            }
        }
    });

    //Search task
    searchTask.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            //When the user press "DONE" key, select the task
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                String project = searchTask.getText().toString();
                searchTask(project);
                //Hide keyboard
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(searchTask.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
                return true;
            }
            return false;
        }
    });
    return true;
}

From source file:com.google.android.apps.tvremote.PairingActivity.java

public void hideKeyboard() {
    InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    manager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
}

From source file:com.google.android.apps.tvremote.PairingActivity.java

public void showKeyboard() {
    Log.e("hwang-tvremote", "hhhhhhh : onWindowFocusChanged()");
    InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    manager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}

From source file:com.peaceworld.wikisms.view.newui.BaseActivity.java

private void handleSearchForSdkBelow11() {

    MenuItem menuItem = menu.findItem(R.id.menu_search);
    menuItem.setVisible(false);/*ww w  . ja v a2  s  .c o  m*/
    // Locate the EditText in menu.xml
    editsearch = (EditText) menu.findItem(R.id.search).getActionView();
    editsearch.setOnEditorActionListener(editorActionListener);

    // Show the search menu item in menu.xml
    MenuItem menuSearch = menu.findItem(R.id.search);

    menuSearch.setOnActionExpandListener(new OnActionExpandListener() {

        // Menu Action Collapse
        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            // Empty EditText to remove text filtering
            editsearch.setText("");
            editsearch.clearFocus();
            return true;
        }

        // Menu Action Expand
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            // Focus on EditText
            editsearch.requestFocus();

            // Force the keyboard to show on EditText focus
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
            return true;
        }
    });

}

From source file:de.incoherent.suseconferenceclient.activities.HomeActivity.java

@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
    final EditText searchText = (EditText) item.getActionView();
    searchText.post(new Runnable() {
        @Override//from   ww w. j  a  va2  s. c om
        public void run() {
            Log.d("SUSEConferences", "Closing keyboard");
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
        }
    });

    return true;
}

From source file:com.spoiledmilk.ibikecph.search.SearchAutocompleteActivity.java

@Override
public void onResume() {
    super.onResume();
    initStrings();/*www.  j a v a 2  s  .  c o  m*/
    InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    progressBar.setVisibility(View.INVISIBLE);
}