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:nu.yona.app.ui.signup.SignupActivity.java

/**
 * Show keyboard./* w  ww.  j ava  2 s. c  o  m*/
 *
 * @param editText the edit text
 */
@Override
public void showKeyboard(EditText editText) {
    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    inputMethodManager.toggleSoftInputFromWindow(editText.getApplicationWindowToken(),
            InputMethodManager.SHOW_FORCED, 0);
}

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

/**
 * @see android.app.Activity#onOptionsItemSelected(MenuItem item)
 *//*from  ww  w .java 2s  . c o m*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_refresh:
        serverList.refresh();
        lastRefresh = System.currentTimeMillis();
        return true;
    case R.id.menu_add_server:
        Intent addServer = new Intent(this, AddServerActivity.class);
        startActivityForResult(addServer, AddServerActivity.ADD_SERVER_ACTIVITY_ID);
        return true;
    case R.id.menu_search:
        InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        mgr.showSoftInput(getListView(), InputMethodManager.SHOW_FORCED);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

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

/**
 * Dialog/*from  w  ww  . ja  va  2 s.c om*/
 *
 * @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.google.dotorg.crisisresponse.translationcards.RecordingActivity.java

private void moveToLabelStep() {
    setContentView(R.layout.recording_label);
    recycleBitmap();/* w  w w .j ava  2 s  . c  o  m*/
    currentBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.recording_label_image);
    currentBitmapView = (ImageView) findViewById(R.id.recording_label_image);
    currentBitmapView.setImageBitmap(currentBitmap);
    final EditText labelField = (EditText) findViewById(R.id.recording_label_field);
    if (label != null) {
        labelField.setText(label);
        labelField.setTextColor(Color.BLACK);
        labelField.setSelection(label.length());
        setLabelNextButtonEnabled(true);
    }
    if (inEditMode) {
        ImageView deleteButton = (ImageView) findViewById(R.id.recording_label_delete_image);
        deleteButton.setVisibility(View.VISIBLE);
        deleteButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DbManager dbm = new DbManager(RecordingActivity.this);
                dbm.deleteTranslation(translationId);
                if (!isAsset) {
                    File oldFile = new File(filename);
                    oldFile.delete();
                    if (!savedIsAsset && (savedFilename != null) && !savedFilename.equals(filename)) {
                        oldFile = new File(savedFilename);
                        oldFile.delete();
                    }
                }
                setResult(RESULT_OK);
                finish();
            }
        });
        findViewById(R.id.recording_label_step_marker).setVisibility(View.GONE);
    }
    labelField.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus
                    && labelField.getText().toString().equals(getString(R.string.recording_label_hint_text))) {
                labelField.setText("");
                labelField.setTextColor(Color.BLACK);
            } else if (!hasFocus && labelField.getText().toString().equals("")) {
                labelField.setText(getString(R.string.recording_label_hint_text));
                labelField.setTextColor(getResources().getColor(R.color.borderColor));
            }
            if (hasFocus) {
                InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                inputMethodManager.toggleSoftInputFromWindow(labelField.getApplicationWindowToken(),
                        InputMethodManager.SHOW_FORCED, 0);
            }
        }
    });
    labelField.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Do nothing here.
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() != 0 && !s.equals(getString(R.string.recording_label_hint_text))) {
                setLabelNextButtonEnabled(true);
            } else {
                setLabelNextButtonEnabled(false);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
            // Do nothing here.
        }
    });
    View nextButton = (View) findViewById(R.id.recording_label_next);
    nextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            label = labelField.getText().toString();
            if (label.length() == 0 || label.equals(getString(R.string.recording_label_hint_text))) {
                return;
            }
            moveToAudioStep();
        }
    });
    stepHistory.push(Step.LABEL);
}

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

private void handleSearchForSdkBelow11() {

    MenuItem menuItem = menu.findItem(R.id.menu_search);
    menuItem.setVisible(false);//from w ww .  j  a v a  2s  .  com
    // 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:com.eugene.fithealthmaingit.UI.ChooseAddMealSearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_search_add_item_fatsecret, container, false);
    // Change the notification bar color
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window w = getActivity().getWindow();
        w.setStatusBarColor(getResources().getColor(R.color.light_grey));
    }//from  w ww .  j  av a2 s. c o  m
    // Get MealType (snack, breakfast, lunch, dinner)
    Bundle extras = getActivity().getIntent().getExtras();
    if (extras != null) {
        mealType = extras.getString(Globals.MEAL_TYPE);
    }
    // Initialize FatSecretSearchMethod
    mFatSecretSearch = new FatSecretSearchMethod();

    mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swiperefresh);
    mSwipeRefreshLayout.setColorSchemeResources(R.color.primary, R.color.red, R.color.primary_dark);
    mSwipeRefreshLayout.setProgressViewOffset(true, Equations.dpToPx(getActivity(), 0),
            Equations.dpToPx(getActivity(), 112));
    mSwipeRefreshLayout.setEnabled(false);

    mEtSearch = (EditText) v.findViewById(R.id.etSearch);
    // LogQuickSearch adapter to add items that have not been saved already
    mRecentLogAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.all());
    // List for adding items to the
    mItem = new ArrayList<>();
    // Set to prevent duplicates being saved in LogQuickSearch
    set = new HashSet<>();
    /**
     * set mListViewSearchResults adapter to SearchAdapterItemResult
     */
    llSearch = (LinearLayout) v.findViewById(R.id.llSearch);
    listSearch = (ListView) v.findViewById(R.id.listSearch);
    searchLine = v.findViewById(R.id.searchLine);
    logQuickSearchAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.all());
    mEtSearchAdapter = new SearchAdapterItemResult(getActivity(), mItem);

    mListViewSearchResults = (ListView) v.findViewById(R.id.listView);
    ViewGroup header = (ViewGroup) inflater.inflate(R.layout.list_search_header, mListViewSearchResults, false);
    mListViewSearchResults.addHeaderView(header, null, false);
    mListViewSearchResults.setAdapter(mEtSearchAdapter);
    mListViewSearchResults.setOnScrollListener(this);
    mListViewSearchResults.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent i = new Intent(getActivity(), SaveSearchAddItemActivityMain.class);
            i.putExtra(Globals.MEAL_TYPE, mealType);
            i.putExtra(Globals.MEAL_ID, mItem.get(position - 1).getID());
            i.putExtra(Globals.MEAL_BRAND, mItem.get(position - 1).getBrand());
            i.putExtra(Globals.MEAL_FAVORITE, "false");
            startActivity(i);
        }
    });
    // Toolbar
    mToolbarSearch = (Toolbar) v.findViewById(R.id.toolbar_search);
    mToolbarSearch.inflateMenu(R.menu.menu_search);
    mToolbarSearch.setNavigationIcon(R.mipmap.ic_arrow_back_grey);
    mToolbarSearch.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getActivity().getSupportFragmentManager().popBackStack();
        }
    });
    mToolbarSearch.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            if (menuItem.getItemId() == R.id.action_clear) {
                mEtSearch.setText("");
            }
            if (menuItem.getItemId() == R.id.action_voice) {
                promptSpeechInput();
            }
            return false;
        }
    });
    mEtSearch.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) {
            if (mEtSearch.getText().toString().length() >= 1) {
                mToolbarSearch.getMenu().clear();
                mToolbarSearch.inflateMenu(R.menu.menu_search_clear);
                logQuickSearchAdapter = new LogQuickSearchAdapter(getActivity(), 0,
                        LogQuickSearch.FilterByName(mEtSearch.getText().toString()));
                listSearch.setAdapter(logQuickSearchAdapter);
            } else {
                mToolbarSearch.getMenu().clear();
                mToolbarSearch.inflateMenu(R.menu.menu_search);
                logQuickSearchAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.all());
                listSearch.setAdapter(logQuickSearchAdapter);
            }
            mItem.clear();
            updateListView();
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    // Quick Search Clicked, start search based on list Item clicked from last fragment
    Bundle extrasFromRecentCliced = this.getArguments();
    if (extrasFromRecentCliced != null) {
        String mealName = extrasFromRecentCliced.getString("MealName");
        if (mealName != null) {
            mEtSearch.setText(mealName);
            mToolbarSearch.getMenu().clear();
            mToolbarSearch.inflateMenu(R.menu.menu_search_clear);
            searchFood(mealName, 0);
        }
    } else {
        mEtSearch.requestFocus();
        ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
    }
    /**
     * Handles softKeyboard search icon being clicked
     */
    mEtSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                        .hideSoftInputFromWindow(mEtSearch.getWindowToken(), 0);
                listSearch.setVisibility(View.GONE);
                searchLine.setVisibility(View.GONE);
                searchFood(mEtSearch.getText().toString(), 0);
                mItem.clear();
                mEtSearchAdapter.notifyDataSetChanged();
                mEtSearch.clearFocus();
                return true;
            }
            return false;
        }
    });

    listSearch.setAdapter(logQuickSearchAdapter);
    listSearch.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            LogQuickSearch logQuickSearch = logQuickSearchAdapter.getItem(position);
            mEtSearch.setText(logQuickSearch.getName());
            ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(mEtSearch.getWindowToken(), 0);
            listSearch.setVisibility(View.GONE);
            searchLine.setVisibility(View.GONE);
            searchFood(logQuickSearch.getName(), 0);
            mItem.clear();
            mEtSearchAdapter.notifyDataSetChanged();
            mEtSearch.clearFocus();
        }
    });
    updateListView();
    return v;
}

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 v a  2  s  .  c om*/
 */
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:com.pentacog.mctracker.MCServerTrackerActivity.java

/**
* @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
*///from w w  w.ja  v  a 2 s .  c  om
@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:util.Utils.java

/**
 * // w ww .j  a va2s .  c o  m
 *
 * @param context   Context
 * @param tokenView View
 */
public static void openInputMethod(Context context, View tokenView) {
    tokenView.setFocusable(true);
    tokenView.requestFocus();
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInputFromWindow(tokenView.getWindowToken(), 0, InputMethodManager.SHOW_FORCED);
}

From source file:com.huijimuhe.commonlayout.xc.detail.xcDetailContainerFragment.java

protected void showKeyBoard() {
    InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
}