Example usage for android.view.inputmethod InputMethodManager showSoftInput

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

Introduction

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

Prototype

public boolean showSoftInput(View view, int flags) 

Source Link

Document

Synonym for #showSoftInput(View,int,ResultReceiver) without a result receiver: explicitly request that the current input method's soft input area be shown to the user, if needed.

Usage

From source file:com.duy.pascal.ui.view.console.ConsoleView.java

private void doShowSoftKeyboard() {
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(this, InputMethodManager.SHOW_FORCED);
}

From source file:com.jrummyapps.android.colorpicker.ColorPickerDialog.java

View createPickerView() {
    View contentView = View.inflate(getActivity(), R.layout.cpv_dialog_color_picker, null);
    colorPicker = contentView.findViewById(R.id.cpv_color_picker_view);
    ColorPanelView oldColorPanel = contentView.findViewById(R.id.cpv_color_panel_old);
    newColorPanel = contentView.findViewById(R.id.cpv_color_panel_new);
    ImageView arrowRight = contentView.findViewById(R.id.cpv_arrow_right);
    hexEditText = contentView.findViewById(R.id.cpv_hex);

    try {/*from  w w w.jav  a 2 s  .  c o m*/
        final TypedValue value = new TypedValue();
        TypedArray typedArray = getActivity().obtainStyledAttributes(value.data,
                new int[] { android.R.attr.textColorPrimary });
        int arrowColor = typedArray.getColor(0, Color.BLACK);
        typedArray.recycle();
        arrowRight.setColorFilter(arrowColor);
    } catch (Exception ignored) {
    }

    colorPicker.setAlphaSliderVisible(showAlphaSlider);
    oldColorPanel.setColor(getArguments().getInt(ARG_COLOR));
    colorPicker.setColor(color, true);
    newColorPanel.setColor(color);
    setHex(color);

    if (!showAlphaSlider) {
        hexEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(6) });
    }

    newColorPanel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (newColorPanel.getColor() == color) {
                colorPickerDialogListener.onColorSelected(dialogId, color);
                dismiss();
            }
        }
    });

    contentView.setOnTouchListener(this);
    colorPicker.setOnColorChangedListener(this);
    hexEditText.addTextChangedListener(this);

    hexEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null)
                    imm.showSoftInput(hexEditText, InputMethodManager.SHOW_IMPLICIT);
            }
        }
    });

    return contentView;
}

From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java

private static void showSoftInputUnchecked(View view, InputMethodManager imm, int flags) {
    try {//from   ww  w  .  j  a v a2 s.  c  om
        Method method = imm.getClass().getMethod("showSoftInputUnchecked", int.class, ResultReceiver.class);
        method.setAccessible(true);
        method.invoke(imm, flags, null);
    } catch (Exception e) {
        //Fallback to public API which hopefully does mostly the same thing
        imm.showSoftInput(view, flags);
    }
}

From source file:net.bytten.comicviewer.ComicViewerActivity.java

protected void resetContent() {
    comicDef = makeComicDef();//from   w  ww.j  a  va  2s  .  com
    provider = comicDef.getProvider();
    comicInfo = provider.createEmptyComicInfo();

    //Only hide the title bar if we're running an android less than Android 3.0
    if (VersionHacks.getSdkInt() < 11)
        requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.main);
    webview = (HackedWebView) findViewById(R.id.viewer);
    title = (TextView) findViewById(R.id.title);
    comicIdSel = (EditText) findViewById(R.id.comicIdSel);

    webview.requestFocus();
    zoom = webview.getZoomControls();

    webview.setClickable(true);
    webview.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (!"".equals(comicInfo.getAlt()))
                showDialog(DIALOG_SHOW_HOVER_TEXT);
        }
    });

    title.setText(comicInfo.getTitle());

    comicIdSel.setText(comicInfo.getId());
    if (comicDef.idsAreNumbers())
        comicIdSel.setInputType(InputType.TYPE_CLASS_NUMBER);
    comicIdSel.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            String text = comicIdSel.getText().toString();
            if (!text.equals("") && (actionId == EditorInfo.IME_ACTION_GO
                    || (actionId == EditorInfo.IME_NULL && event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
                loadComic(createComicUri(text));
                comicIdSel.setText("");
                return true;
            }
            return false;
        }
    });
    comicIdSel.setOnFocusChangeListener(new OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (hasFocus) {
                comicIdSel.setText("");
                imm.showSoftInput(comicIdSel, InputMethodManager.SHOW_IMPLICIT);
            } else {
                imm.hideSoftInputFromWindow(comicIdSel.getWindowToken(), 0);
            }
        }
    });

    ((Button) findViewById(R.id.firstBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToFirst();
        }
    });

    ((Button) findViewById(R.id.prevBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToPrev();
        }
    });

    ((Button) findViewById(R.id.nextBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToNext();
        }
    });

    ((Button) findViewById(R.id.finalBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToFinal();
        }
    });

    ((ImageView) findViewById(R.id.randomBtn)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            goToRandom();
        }
    });

    bookmarkBtn = (ImageView) findViewById(R.id.bookmarkBtn);
    bookmarkBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            toggleBookmark();
        }
    });
    refreshBookmarkBtn();
}

From source file:com.mobilis.android.nfc.activities.MagTekFragment.java

void ShowSoftKeyboard(EditText lpEditText) {
    InputMethodManager objInputManager = (InputMethodManager) getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    // only will trigger it if no physical keyboard is open
    objInputManager.showSoftInput(lpEditText, InputMethodManager.SHOW_IMPLICIT);

}

From source file:sjizl.com.ChatActivityFragment.java

public void showSoftKeyboard(View view) {
    InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    // view.requestFocus();
    inputMethodManager.showSoftInput(view, 0);
}

From source file:de.azapps.mirakel.main_activity.tasks_fragment.TasksFragment.java

public void focusNew(final boolean request_focus) {
    if (this.newTask == null) {
        return;//from  ww w  . jav a  2  s.  com
    }
    this.newTask.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(final View v, final boolean hasFocus) {
            if (TasksFragment.this.main.getCurrentPosition() != MainActivity.getTasksFragmentPosition()) {
                return;
            }
            TasksFragment.this.newTask.post(new Runnable() {
                @Override
                public void run() {
                    if (getActivity() == null) {
                        // What the fuck?? This should not happen but it happens for some users
                        return;
                    }
                    final InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    if (imm == null) {
                        Log.w(TasksFragment.TAG, "Inputmanager==null");
                        return;
                    }
                    imm.restartInput(TasksFragment.this.newTask);
                    if (request_focus && hasFocus) {
                        getActivity().getWindow()
                                .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
                        imm.showSoftInput(TasksFragment.this.newTask, InputMethodManager.SHOW_IMPLICIT);
                        getActivity().getWindow()
                                .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                    } else if (!hasFocus) {
                        TasksFragment.this.newTask.requestFocus();
                        imm.showSoftInput(TasksFragment.this.newTask, InputMethodManager.SHOW_IMPLICIT);
                    } else {
                        clearFocus();
                    }
                }
            });
        }
    });
    this.newTask.requestFocus();
    if (!this.newTask.hasFocus()) {
        this.newTask.postDelayed(new Runnable() {
            @Override
            public void run() {
                TasksFragment.this.newTask.requestFocus();
                Log.wtf(TAG, "second try");
            }
        }, 10);
    }
}

From source file:com.android.contacts.activities.DialtactsActivity.java

private void showInputMethod(View view) {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        if (!imm.showSoftInput(view, 0)) {
            Log.w(TAG, "Failed to show soft input method.");
        }//from  w w w.j  av  a  2s.com
    }
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

/**
 * Shows/hides the soft keyboard./*from ww  w .j a  v  a2  s  .  c  o m*/
 * @param view the current focused view.
 * @param show whether to show soft keyboard.
 */
public static void showSoftKeyboard(final View view, final boolean show) {
    if (view == null)
        return;
    InputMethodManager imm = (InputMethodManager) view.getContext()
            .getSystemService(Activity.INPUT_METHOD_SERVICE);

    if (imm != null) {
        boolean useForce = (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT || Build.VERSION.SDK_INT >= 8)
                ? true
                : false;
        String model = TiPlatformHelper.getInstance().getModel();
        if (model != null && model.toLowerCase().startsWith("droid")) {
            useForce = true;
        }
        if (show) {
            imm.showSoftInput(view,
                    useForce ? InputMethodManager.SHOW_FORCED : InputMethodManager.SHOW_IMPLICIT);
        } else {
            imm.hideSoftInputFromWindow(view.getWindowToken(),
                    useForce ? 0 : InputMethodManager.HIDE_IMPLICIT_ONLY);
        }
    }
}

From source file:org.protocoderrunner.apprunner.api.PUI.java

@ProtocoderScript
@APIMethod(description = "Show the virtual keyboard", example = "")
@APIParam(params = { "boolean" })
public void showVirtualKeys(boolean show) {
    initializeLayout();/*w  w  w.  j  a v  a 2  s  . c  om*/
    InputMethodManager imm = (InputMethodManager) a.get().getSystemService(a.get().INPUT_METHOD_SERVICE);

    if (show) {
        imm.showSoftInput(appRunnerActivity.get().getCurrentFocus(), InputMethodManager.SHOW_FORCED);
        uiAbsoluteLayout.setFocusable(true);
        uiAbsoluteLayout.setFocusableInTouchMode(true);

    } else {
        imm.hideSoftInputFromWindow(appRunnerActivity.get().getCurrentFocus().getWindowToken(), 0);
    }
}