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:de.uni.stuttgart.informatik.ToureNPlaner.UI.Activities.MapScreen.MapScreen.java

private void setupSearchMenu(MenuItem searchMenu) {
    search = searchMenu;/*ww  w  .  j a  va  2  s  .c o m*/
    MenuItemCompat.setOnActionExpandListener(searchMenu, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            final EditText field = (EditText) MenuItemCompat.getActionView(item)
                    .findViewById(R.id.search_field);
            field.requestFocus();
            InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            keyboard.toggleSoftInput(0, 0);
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            EditText field = (EditText) MenuItemCompat.getActionView(item).findViewById(R.id.search_field);
            InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            keyboard.hideSoftInputFromWindow(field.getWindowToken(), 0);
            return true;
        }
    });
    MenuItemCompat.getActionView(searchMenu).findViewById(R.id.search_field)
            .setOnKeyListener(new View.OnKeyListener() {
                @SuppressWarnings("unchecked")
                @Override
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_ENTER) {
                        EditText field = ((EditText) MenuItemCompat.getActionView(search)
                                .findViewById(R.id.search_field));
                        MenuItemCompat.collapseActionView(search);
                        Projection projection = mapView.getProjection();
                        GeoPoint topLeft = projection.fromPixels(0, 0);
                        GeoPoint bottomRight = projection.fromPixels(mapView.getWidth(), mapView.getHeight());
                        GeoCodingHandler.createDefaultHandler(geoCodingListener, field.getText().toString(),
                                new RectF((float) topLeft.getLongitude(), (float) topLeft.getLatitude(),
                                        (float) bottomRight.getLongitude(), (float) bottomRight.getLatitude()))
                                .execute();
                    }
                    return false;
                }
            });
}

From source file:com.fbartnitzek.tasteemall.filter.AttributeFilterTextTabFragment.java

@Nullable
@Override/*from   w  ww. j  a  v a  2s. c o  m*/
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {

    super.onCreateView(inflater, container, savedInstanceState);

    mEditFilter = (EditText) mRootView.findViewById(R.id.attribute_filter);
    mEditFilter.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            mAttributeFilter = s.toString();
            //                Log.v(LOG_TAG, "afterTextChanged, hashCode=" + this.hashCode() + ", " + "s = [" + s + "]");
            getLoaderManager().restartLoader(ATTRIBUTE_VALUES_LOADER_ID, null,
                    AttributeFilterTextTabFragment.this);
        }
    });

    mEditFilter.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            //                Log.v(LOG_TAG, "onEditorAction, hashCode=" + this.hashCode() + ", " + "v = [" + v + "], actionId = [" + actionId + "], event = [" + event + "]");
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                InputMethodManager imm = (InputMethodManager) getContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mEditFilter.getWindowToken(), 0);
                return true;
            }
            return false;
        }
    });

    // focus editFilter - thx for: http://stackoverflow.com/a/26012003/5477716
    mEditFilter.requestFocus();
    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

    mValuesRecycler = (RecyclerView) mRootView.findViewById(R.id.attribute_filter_list);
    mValuesRecycler.setLayoutManager(new LinearLayoutManager(getContext()));

    mAttributeValuesAdapter = new AttributeValuesAdapter(this);
    mValuesRecycler.setAdapter(mAttributeValuesAdapter);

    return mRootView;
}

From source file:com.gao.im.ui.CCPActivityBase.java

/**
 * //from   w  w w .j  ava2 s  .  co  m
 */
public void displaySoftKeyboard() {
    final FragmentActivity activity = mActionBarActivity;
    // Display the soft keyboard
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null) {
        View localView = activity.getCurrentFocus();
        if (localView != null && localView.getWindowToken() != null) {
            inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
}

From source file:com.jiandanbaoxian.fragment.DialogFragmentCreater.java

/**
 * Dialog//from w ww . ja  v a  2 s .  com
 *
 * @param mContext
 * @return
 */
private Dialog showInputPasswordDialog(final Context mContext) {
    View convertView = LayoutInflater.from(mContext).inflate(R.layout.fragment_right_control, null);
    tv_forget_psw = (TextView) convertView.findViewById(R.id.tv_forget_psw);
    tv_forget_psw.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mContext.startActivity(new Intent(mContext, MyModifyPasswordActivity.class));
        }
    });
    inputView = (GridPasswordView) convertView.findViewById(R.id.pswView);
    inputView.setOnPasswordChangedListener(new GridPasswordView.OnPasswordChangedListener() {
        @Override
        public void onChanged(String psw) {

        }

        @Override
        public void onMaxLength(String psw) {
            if (onPasswordDialogClickListener != null) {
                onPasswordDialogClickListener.getPassword(psw);
            }
        }
    });

    final Dialog dialog = new Dialog(mContext, R.style.CustomDialog);
    //        dialog.setCanceledOnTouchOutside(false);//??
    dialog.setContentView(convertView);

    dialog.getWindow().setWindowAnimations(R.style.dialog_right_control_style);
    //dialog 
    dialog.setOnShowListener(new android.content.DialogInterface.OnShowListener() {
        @Override
        public void onShow(final android.content.DialogInterface dialog) {

            new AsyncTask<Integer, Void, Void>() {
                @Override
                protected Void doInBackground(Integer... params) {
                    try {
                        Thread.sleep(params[0]);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                protected void onPostExecute(Void value) {
                    super.onPostExecute(value);
                    if (outerDialog.isShowing())
                        if (inputView != null) {
                            inputView.requestFocus();
                            InputMethodManager imm = (InputMethodManager) inputView.getContext()
                                    .getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
                        }
                }
            }.execute(600);
        }
    });

    outerDialog = dialog;
    return dialog;
}

From source file:com.novemser.voicetest.ui.MainActivity.java

public void sendMessage(View view) {
    msg = mMsg.getText().toString();//from  w  w w . j  a  v a2 s .c om
    if (TextUtils.isEmpty(msg)) {
        Toast.makeText(this, getResources().getText(R.string.noTextWarning), Toast.LENGTH_LONG).show();
        return;
    }

    ChatMessage to = new ChatMessage(ChatMessage.Type.OUTPUT, msg);
    to.setDate(new Date());
    mDatas.add(to);

    mAdapter.notifyDataSetChanged();
    mChatView.setSelection(mDatas.size() - 1);

    mMsg.setText("");

    // 
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    // InputMethodManager
    if (imm.isActive()) {
        // ?
        imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
        // ?????
    }

    understander.understandText(msg, textUnderstanderListener);
}

From source file:com.darly.im.ui.CCPActivityBase.java

/**
 *
 *//*from   w ww.ja  va  2  s.c o m*/
public void toggleSoftInput() {
    final FragmentActivity activity = mActionBarActivity;
    // Display the soft keyboard
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null) {
        View localView = activity.getCurrentFocus();
        if (localView != null && localView.getWindowToken() != null) {
            inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
}

From source file:com.amazon.appstream.sampleclient.SampleClientActivity.java

/**
 * Switch to the "game" view. Sets the content view to the one
 * for your game; in the example, the content view contains only
 * a keyboard icon./*w  w  w .  ja  va2  s.  com*/
 */
public void showGame() {
    setContentView(R.layout.game);

    mActivityRootView = (FrameLayout) findViewById(R.id.outer_frame);

    // If we have a touchscreen, then configure all the buttons.
    if (mTouchscreenAvailable) {
        // This little bit of magic is required to detect when the user hides the keyboard.
        // Unfortunately, the setSystemUiVisibility() has a minimum requirement of Honeycomb (3.0/API11).
        // As such, we have raised the minimum API to 11.
        //
        // A workaround that you could try if you need API10 support is to NOT specify a fullscreen
        // theme for the app. The keyboard detection code below doesn't work when the theme is fullscreen.
        // In fact, you could request a non-fullscreen theme on API10, though you may have to also disable
        // requestWindowFeature(Window.FEATURE_NO_TITLE) in onCreate().
        mActivityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @SuppressLint("NewApi")
            @Override
            public void onGlobalLayout() {
                int heightDiff = mActivityRootView.getRootView().getHeight() - mActivityRootView.getHeight();
                if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                    Log.v(TAG, "keyboard found");
                    mKeyboardActive = true;
                    mKeyboardOffset = 0;
                } else if (mKeyboardActive) {
                    Log.v(TAG, "keyboard not found");
                    mKeyboardActive = false;
                    AppStreamInterface.setKeyboardOffset(0);
                    runOnUiThread(mClearFullscreen);
                }
            }
        });

        mKeyboardToggle = (ImageButton) findViewById(R.id.keyboard_toggle);
        mKeyboardToggle.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!mKeyboardActive) {
                    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
                    mActivityRootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
                } else {
                    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
                    mActivityRootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
                }

                InputMethodManager imm = (InputMethodManager) SampleClientActivity.this
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                AppStreamInterface.setKeyboardOffset(0);
            }
        });
    }

    // Keep the screen on when we're visible.
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    mGlView = new GL2JNIView(getApplication());
    mActivityRootView.addView(mGlView, 0);
}

From source file:info.guardianproject.otr.app.im.app.ContactListActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();

    boolean handled = false;

    if (!mIsFiltering) {
        handled = mFilterView.dispatchKeyEvent(event);
        if (!handled && (KeyEvent.KEYCODE_BACK == keyCode) && (KeyEvent.ACTION_DOWN == event.getAction())) {
            showFilterView();//from   w  w  w  .  j  ava  2 s.c om
            handled = true;
        }
    } else {

        handled = mContactListView.dispatchKeyEvent(event);

        if (!handled && KeyEvent.KEYCODE_SEARCH == keyCode && (KeyEvent.ACTION_DOWN == event.getAction())) {
            InputMethodManager inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMgr.toggleSoftInput(0, 0);

            if (!mIsFiltering)
                showFilterView();

            onSearchRequested();
        } else if (!handled && isReadable(keyCode, event) && (KeyEvent.ACTION_DOWN == event.getAction())) {

            if (!mIsFiltering)
                showFilterView();

            handled = mFilterView.dispatchKeyEvent(event);
        }

    }

    if (!handled) {
        handled = super.dispatchKeyEvent(event);
    }

    return handled;
}

From source file:no.digipost.android.gui.MainContentActivity.java

private void showCreateEditDialog(int content, boolean editFolder) {

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    Fragment prev = getFragmentManager().findFragmentByTag(EditFolderFragment.fragmentName);
    if (prev != null) {
        ft.remove(prev);/*from   www .  jav a2s.  com*/
    }
    ft.addToBackStack(null);
    DialogFragment editFolderFragment = EditFolderFragment.newInstance(content,
            account.getValidationRules().getFolderName(), editFolder);
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    editFolderFragment.show(ft, EditFolderFragment.fragmentName);
}

From source file:com.granita.tasks.EditTaskFragment.java

private void updateView() {
    /*/*from   ww  w.java  2s.c om*/
     * If the model loads very slowly then this function may be called after onDetach. In this case check if Activity is <code>null</code> and return if
     * <code>true</code>. Also return if we don't have values or the values are still loading.
     */
    Activity activity = getActivity();
    if (activity == null || mValues == null || mValues.isLoading()) {
        return;
    }

    final LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    if (mEditor != null) {
        // remove values, to ensure all listeners get released
        mEditor.setValues(null);
    }
    mContent.removeAllViews();

    mEditor = (TaskEdit) inflater.inflate(R.layout.task_edit, mContent, false);
    mEditor.setModel(mModel);
    mEditor.setValues(mValues);
    mContent.addView(mEditor);

    // update focus to title
    String title = mValues.getAsString(Tasks.TITLE);

    // set focus to first element of the editor
    if (mEditor != null) {
        mEditor.requestFocus();
        if (title == null || title.length() == 0) {
            // open soft input as there is no title
            InputMethodManager imm = (InputMethodManager) this.getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
                imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
            }
        }
    }

    updateColor((float) mRootView.getScrollY() / mTaskListBar.getMeasuredHeight());
}