Example usage for android.view.inputmethod InputMethodManager SHOW_FORCED

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

Introduction

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

Prototype

int SHOW_FORCED

To view the source code for android.view.inputmethod InputMethodManager SHOW_FORCED.

Click Source Link

Document

Flag for #showSoftInput to indicate that the user has forced the input method open (such as by long-pressing menu) so it should not be closed until they explicitly do so.

Usage

From source file:com.daiv.android.twitter.ui.compose.Compose.java

public void setUpSimilar() {
    attachImage[0] = (ImageView) findViewById(R.id.picture1);
    attachImage[1] = (ImageView) findViewById(R.id.picture2);
    attachImage[2] = (ImageView) findViewById(R.id.picture3);
    attachImage[3] = (ImageView) findViewById(R.id.picture4);
    attachButton = (ImageButton) findViewById(R.id.attach);
    emojiButton = (ImageButton) findViewById(R.id.emoji);
    emojiKeyboard = (EmojiKeyboard) findViewById(R.id.emojiKeyboard);
    reply = (EditText) findViewById(R.id.tweet_content);
    charRemaining = (TextView) findViewById(R.id.char_remaining);

    findViewById(R.id.prompt_pos).setOnClickListener(new View.OnClickListener() {
        @Override/*from   w  ww.ja  v  a 2s  . c o  m*/
        public void onClick(View v) {
            Log.v("Test_input", "clicked the view");
            ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(reply,
                    InputMethodManager.SHOW_FORCED);
        }
    });

    NetworkedCacheableImageView pic = (NetworkedCacheableImageView) findViewById(R.id.profile_pic);
    HoloTextView currentName = (HoloTextView) findViewById(R.id.current_name);

    if (settings.roundContactImages) {
        pic.loadImage(settings.myProfilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
    } else {
        pic.loadImage(settings.myProfilePicUrl, false, null);
    }
    currentName.setText("@" + settings.myScreenName);

    //numberAttached.setText("0 " + getString(R.string.attached_images));

    charRemaining.setText(140 - reply.getText().length() + "");

    reply.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            countHandler.removeCallbacks(getCount);
            countHandler.postDelayed(getCount, 300);
        }
    });
}

From source file:com.eugene.fithealthmaingit.UI.ManualEntrySaveMealFragment.java

private void updateItems() {
    mToolbar.setNavigationIcon(R.mipmap.ic_arrow_back);
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override//  ww w.java 2s .c  o m
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), ChooseAddMealActivity.class);
            intent.putExtra(Globals.MEAL_TYPE, mealType);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
    });
    mToolbar.inflateMenu(R.menu.menu_user_info);
    mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            if (menuItem.getItemId() == R.id.action_save)
                saveMeal();
            return false;
        }
    });
    mServingSizeUpdated.setText("1");

    LinearLayout changeServing = (LinearLayout) v.findViewById(R.id.changeServing);
    changeServing.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());

            alert.setTitle("Update Serving Size: ");
            alert.setMessage("Servings Consumed");

            final EditText input = new EditText(getActivity());
            input.setText(mServingg.getText().toString());
            input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            input.selectAll();
            input.setGravity(Gravity.CENTER_HORIZONTAL);
            alert.setView(input, 64, 0, 64, 0);
            alert.setPositiveButton("Update", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    double values = Double.valueOf(input.getText().toString());
                    mServingg.setText(df.format(values));
                    mServingSizeUpdated.setText(df.format(values));
                    mCalUpdate.setText(dfW.format(Double.valueOf(mCalories) * values));
                    mCalorieProgress = Double.valueOf(mCalories) * values;
                    mFattieUpdate.setText(df.format(Double.valueOf(mFat) * values));
                    mFatProgress = Double.valueOf(mFat) * values;
                    mSaturatedFatUpdate.setText(df.format(Double.valueOf(mSaturatedFat) * values));
                    mCholesterolUpdate.setText(df.format(Double.valueOf(mCholesterol) * values));
                    mSodiumUpdate.setText(df.format(Double.valueOf(mSodium) * values));
                    mCarbUpdate.setText(df.format(Double.valueOf(mCarbohydrates) * values));
                    mCarbProgress = Double.valueOf(mCarbohydrates) * values;
                    mFiberUpdate.setText(df.format(Double.valueOf(mFiber) * values));
                    mSugarUpdate.setText(df.format(Double.valueOf(mSugar) * values));
                    mProUpdate.setText(df.format(Double.valueOf(mProtein) * values));
                    mProteinProgress = Double.valueOf(mProtein) * values;
                    mVitAUpdate.setText(df.format(Double.valueOf(mVitA) * values));
                    mVitCUpdate.setText(df.format(Double.valueOf(mVitC) * values));
                    mCalciumUpdate.setText(df.format(Double.valueOf(mCalcium) * values));
                    mIronUpdate.setText(df.format(Double.valueOf(mIron) * values));
                    progressBars();
                    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(input.getWindowToken(), 0);
                }
            });

            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(input.getWindowToken(), 0);
                }
            });
            alert.setCancelable(false);
            alert.show();
            ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                    .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS);
        }
    });

}

From source file:com.eugene.fithealthmaingit.UI.ChooseAddMealTabsFragment.java

private void handleSearchManual() {
    if (card_search_manual.getVisibility() == View.VISIBLE) {
        searchManual.setVisibility(View.VISIBLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            final Animator animatorHide = ViewAnimationUtils.createCircularReveal(card_search_manual,
                    card_search_manual.getWidth() - (int) convertDpToPixel(24, getActivity()),
                    (int) convertDpToPixel(23, getActivity()),
                    (float) Math.hypot(card_search_manual.getWidth(), card_search_manual.getHeight()), 0);
            animatorHide.addListener(new Animator.AnimatorListener() {
                @Override//from  w ww  . j  a v a2  s.  c  o m
                public void onAnimationStart(Animator animation) {

                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    card_search_manual.setVisibility(View.GONE);
                    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(searchManual.getWindowToken(), 0);
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });

            animatorHide.setDuration(200);
            animatorHide.start();
        } else {
            card_search_manual.setVisibility(View.GONE);
            ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(searchManual.getWindowToken(), 0);
        }
    } else {
        searchManual.setVisibility(View.INVISIBLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            final Animator animator = ViewAnimationUtils.createCircularReveal(card_search_manual,
                    card_search_manual.getWidth() - (int) convertDpToPixel(24, getActivity()),
                    (int) convertDpToPixel(23, getActivity()), 0,
                    (float) Math.hypot(card_search_manual.getWidth(), card_search_manual.getHeight()));
            animator.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                    manualSearch.requestFocus();
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                            .toggleSoftInput(InputMethodManager.SHOW_FORCED,
                                    InputMethodManager.HIDE_IMPLICIT_ONLY);
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });
            card_search_manual.setVisibility(View.VISIBLE);
            if (card_search_manual.getVisibility() == View.VISIBLE) {
                animator.setDuration(300);
                animator.start();
                card_search_manual.setEnabled(true);
            }
        } else {
            manualSearch.requestFocus();
            ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                    .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
            card_search_manual.setVisibility(View.VISIBLE);
        }
    }
}

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.geecko.QuickLyric.fragment.LyricsViewFragment.java

private void startEditTagsMode() {
    ImageButton editButton = (ImageButton) getActivity().findViewById(R.id.edit_tags_btn);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        editButton.setImageResource(R.drawable.ic_edit_anim);
        ((Animatable) editButton.getDrawable()).start();
    } else/*from   www.  j  av a  2  s  .  c o m*/
        editButton.setImageResource(R.drawable.ic_done);

    ((DrawerLayout) ((MainActivity) getActivity()).drawer)
            .setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    mRefreshLayout.setEnabled(false);
    getActivity().findViewById(R.id.refresh_fab).setEnabled(false);
    ((RefreshIcon) getActivity().findViewById(R.id.refresh_fab)).hide();
    ((Toolbar) getActivity().findViewById(R.id.toolbar)).getMenu().clear();

    TextSwitcher textSwitcher = ((TextSwitcher) getActivity().findViewById(R.id.switcher));
    EditText songTV = (EditText) getActivity().findViewById(R.id.song);
    TextView artistTV = ((TextView) getActivity().findViewById(R.id.artist));

    EditText newLyrics = (EditText) getActivity().findViewById(R.id.edit_lyrics);
    newLyrics.setTypeface(LyricsTextFactory.FontCache.get("light", getActivity()));
    newLyrics.setText(((TextView) textSwitcher.getCurrentView()).getText(), TextView.BufferType.EDITABLE);

    textSwitcher.setVisibility(View.GONE);
    newLyrics.setVisibility(View.VISIBLE);

    songTV.setInputType(InputType.TYPE_CLASS_TEXT);
    artistTV.setInputType(InputType.TYPE_CLASS_TEXT);
    songTV.setBackgroundResource(R.drawable.abc_textfield_search_material);
    artistTV.setBackgroundResource(R.drawable.abc_textfield_search_material);

    if (songTV.requestFocus()) {
        InputMethodManager imm = (InputMethodManager) getActivity().getApplicationContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.SHOW_IMPLICIT);
    }
}

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);/* ww  w  .  j a v  a 2s  . c  om*/
    }
    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:org.woltage.irssiconnectbot.ConsoleActivity.java

@Override
@TargetApi(11)/*www .j  a va 2  s .  c  om*/
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    if (!InstallMosh.isInstallStarted()) {
        new InstallMosh(this);
    }

    configureStrictMode();
    hardKeyboard = getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY;

    hardKeyboard = hardKeyboard && !Build.MODEL.contains("Transformer");

    this.setContentView(R.layout.act_console);
    BugSenseHandler.setup(this, "d27a12dc");

    clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    // hide action bar if requested by user
    try {
        ActionBar actionBar = getActionBar();
        if (!prefs.getBoolean(PreferenceConstants.ACTIONBAR, true)) {
            actionBar.hide();
        }
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
    } catch (NoSuchMethodError error) {
        Log.w(TAG, "Android sdk version pre 11. Not touching ActionBar.");
    }

    // hide status bar if requested by user
    if (prefs.getBoolean(PreferenceConstants.FULLSCREEN, false)) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    // TODO find proper way to disable volume key beep if it exists.
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // handle requested console from incoming intent
    requested = getIntent().getData();

    inflater = LayoutInflater.from(this);

    flip = (ViewFlipper) findViewById(R.id.console_flip);
    empty = (TextView) findViewById(android.R.id.empty);

    stringPromptGroup = (RelativeLayout) findViewById(R.id.console_password_group);
    stringPromptInstructions = (TextView) findViewById(R.id.console_password_instructions);
    stringPrompt = (EditText) findViewById(R.id.console_password);
    stringPrompt.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP)
                return false;
            if (keyCode != KeyEvent.KEYCODE_ENTER)
                return false;

            // pass collected password down to current terminal
            String value = stringPrompt.getText().toString();

            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return false;
            helper.setResponse(value);

            // finally clear password for next user
            stringPrompt.setText("");
            updatePromptVisible();

            return true;
        }
    });

    booleanPromptGroup = (RelativeLayout) findViewById(R.id.console_boolean_group);
    booleanPrompt = (TextView) findViewById(R.id.console_prompt);

    booleanYes = (Button) findViewById(R.id.console_prompt_yes);
    booleanYes.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return;
            helper.setResponse(Boolean.TRUE);
            updatePromptVisible();
        }
    });

    booleanNo = (Button) findViewById(R.id.console_prompt_no);
    booleanNo.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return;
            helper.setResponse(Boolean.FALSE);
            updatePromptVisible();
        }
    });

    // preload animations for terminal switching
    slide_left_in = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
    slide_left_out = AnimationUtils.loadAnimation(this, R.anim.slide_left_out);
    slide_right_in = AnimationUtils.loadAnimation(this, R.anim.slide_right_in);
    slide_right_out = AnimationUtils.loadAnimation(this, R.anim.slide_right_out);

    fade_out_delayed = AnimationUtils.loadAnimation(this, R.anim.fade_out_delayed);
    fade_stay_hidden = AnimationUtils.loadAnimation(this, R.anim.fade_stay_hidden);

    // Preload animation for keyboard button
    keyboard_fade_in = AnimationUtils.loadAnimation(this, R.anim.keyboard_fade_in);
    keyboard_fade_out = AnimationUtils.loadAnimation(this, R.anim.keyboard_fade_out);

    inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    final RelativeLayout keyboardGroup = (RelativeLayout) findViewById(R.id.keyboard_group);

    if (Build.MODEL.contains("Transformer")
            && getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY
            && prefs.getBoolean(PreferenceConstants.ACTIONBAR, true)) {
        keyboardGroup.setEnabled(false);
        keyboardGroup.setVisibility(View.INVISIBLE);
    }

    mKeyboardButton = (ImageView) findViewById(R.id.button_keyboard);
    mKeyboardButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;

            inputManager.showSoftInput(flip, InputMethodManager.SHOW_FORCED);
            keyboardGroup.setVisibility(View.GONE);
        }
    });

    final ImageView symButton = (ImageView) findViewById(R.id.button_sym);
    symButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;

            TerminalView terminal = (TerminalView) flip;

            TerminalKeyListener handler = terminal.bridge.getKeyHandler();
            handler.showCharPickerDialog(terminal);
            keyboardGroup.setVisibility(View.GONE);
        }
    });

    mInputButton = (ImageView) findViewById(R.id.button_input);
    mInputButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;

            final TerminalView terminal = (TerminalView) flip;
            Thread promptThread = new Thread(new Runnable() {
                public void run() {
                    String inj = getCurrentPromptHelper().requestStringPrompt(null, "");
                    terminal.bridge.injectString(inj);
                }
            });
            promptThread.setName("Prompt");
            promptThread.setDaemon(true);
            promptThread.start();

            keyboardGroup.setVisibility(View.GONE);
        }
    });

    final ImageView ctrlButton = (ImageView) findViewById(R.id.button_ctrl);
    ctrlButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;
            TerminalView terminal = (TerminalView) flip;

            TerminalKeyListener handler = terminal.bridge.getKeyHandler();
            handler.metaPress(TerminalKeyListener.META_CTRL_ON);
            terminal.bridge.tryKeyVibrate();

            keyboardGroup.setVisibility(View.GONE);
        }
    });

    final ImageView escButton = (ImageView) findViewById(R.id.button_esc);
    escButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;
            TerminalView terminal = (TerminalView) flip;

            TerminalKeyListener handler = terminal.bridge.getKeyHandler();
            handler.sendEscape();
            terminal.bridge.tryKeyVibrate();
            keyboardGroup.setVisibility(View.GONE);
        }
    });

    // detect fling gestures to switch between terminals
    final GestureDetector detect = new GestureDetector(new ICBSimpleOnGestureListener(this));

    flip.setLongClickable(true);
    flip.setOnTouchListener(new ICBOnTouchListener(this, keyboardGroup, detect));

}

From source file:com.eugene.fithealthmaingit.UI.SaveSearchAddItemActivityMain.java

private void updateItems() {

    mServingSizeUpdated.setText("1");

    LinearLayout changeServing = (LinearLayout) findViewById(R.id.changeServing);
    changeServing.setOnClickListener(new View.OnClickListener() {
        @Override//from  www. j  a  va2  s. c o m
        public void onClick(View v) {
            AlertDialog.Builder alert = new AlertDialog.Builder(SaveSearchAddItemActivityMain.this);

            alert.setTitle("Update Serving Size: ");
            alert.setMessage("Servings Consumed");

            final EditText input = new EditText(SaveSearchAddItemActivityMain.this);
            input.setText(mServingg.getText().toString());
            input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            input.selectAll();
            input.setGravity(Gravity.CENTER_HORIZONTAL);
            alert.setView(input, 64, 0, 64, 0);
            alert.setPositiveButton("Update", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    double values = Double.valueOf(input.getText().toString());
                    mServingg.setText(df.format(values));
                    mServingSizeUpdated.setText(df.format(values));
                    mCalUpdate.setText(dfW.format(Double.valueOf(mCalories) * values));
                    mCalorieProgress = Double.valueOf(mCalories) * values;
                    mFattieUpdate.setText(df.format(Double.valueOf(mFat) * values));
                    mFatProgress = Double.valueOf(mFat) * values;
                    mSaturatedFatUpdate.setText(df.format(Double.valueOf(mSaturatedFat) * values));
                    mCholesterolUpdate.setText(df.format(Double.valueOf(mCholesterol) * values));
                    mSodiumUpdate.setText(df.format(Double.valueOf(mSodium) * values));
                    mCarbUpdate.setText(df.format(Double.valueOf(mCarbohydrates) * values));
                    mCarbProgress = Double.valueOf(mCarbohydrates) * values;
                    mFiberUpdate.setText(df.format(Double.valueOf(mFiber) * values));
                    mSugarUpdate.setText(df.format(Double.valueOf(mSugar) * values));
                    mProUpdate.setText(df.format(Double.valueOf(mProtein) * values));
                    mProteinProgress = Double.valueOf(mProtein) * values;
                    mVitAUpdate.setText(df.format(Double.valueOf(mVitA) * values));
                    mVitCUpdate.setText(df.format(Double.valueOf(mVitC) * values));
                    mCalciumUpdate.setText(df.format(Double.valueOf(mCalcium) * values));
                    mIronUpdate.setText(df.format(Double.valueOf(mIron) * values));
                    progressBars();
                    ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(input.getWindowToken(), 0);
                }
            });

            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(input.getWindowToken(), 0);
                }
            });
            alert.setCancelable(false);
            alert.show();
            ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                    .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS);
        }
    });

}

From source file:com.xabber.android.ui.activity.ContactList.java

private void setUpSearchView(final Menu menu) {
    searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setQueryHint(getString(R.string.contact_search_hint));

    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override//from   w  w w .j  a  v a2  s .  c  om
        public boolean onClose() {
            menu.findItem(R.id.action_search).collapseActionView();
            return true;
        }
    });

    MenuItemCompat.setOnActionExpandListener(menu.findItem(R.id.action_search),
            new MenuItemCompat.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem item) {
                    searchView.requestFocus();
                    ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(
                            InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem item) {
                    searchView.setQuery("", true);
                    searchView.clearFocus();
                    return true;
                }
            });

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            Fragment fragmentById = getSupportFragmentManager().findFragmentById(R.id.container);
            ((ContactListFragment) fragmentById).getFilterableAdapter().getFilter().filter(newText);
            return true;
        }
    });
}

From source file:com.xabber.android.ui.activity.ContactListActivity.java

private void setUpSearchView(final Menu menu) {
    searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setQueryHint(getString(R.string.contact_search_hint));

    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override//  w  ww  .j  av a 2s. co m
        public boolean onClose() {
            menu.findItem(R.id.action_search).collapseActionView();
            return true;
        }
    });

    MenuItemCompat.setOnActionExpandListener(menu.findItem(R.id.action_search),
            new MenuItemCompat.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem item) {
                    searchView.requestFocus();
                    ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(
                            InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem item) {
                    searchView.setQuery("", true);
                    searchView.clearFocus();
                    return true;
                }
            });

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            Fragment fragmentById = getFragmentManager().findFragmentById(R.id.container);
            ((ContactListFragment) fragmentById).getFilterableAdapter().getFilter().filter(newText);
            return true;
        }
    });
}