java类android.view.inputmethod.InputMethodManager的实例源码

DialogUtils.java 文件源码 项目:AndroidBackendlessChat 阅读 33 收藏 0 点赞 0 评论 0
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (EditorInfo.IME_ACTION_DONE == actionId) {
        if (mEditText.getText().toString().isEmpty())
        {
            SuperToast toast = chatSDKUiHelper.getAlertToast();
            toast.setGravity(Gravity.TOP, 0, 0);
            toast.setText("Please enter chat name");
            toast.show();
            return true;
        }

        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(
                Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);

        // Return input text to activity
        listener.onFinished(mEditText.getText().toString());
        this.dismiss();
        return true;
    }
    return false;
}
SDLActivity.java 文件源码 项目:simpleSDL 阅读 35 收藏 0 点赞 0 评论 0
@Override
public void run() {
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(w, h + HEIGHT_PADDING);
    params.leftMargin = x;
    params.topMargin = y;

    if (mTextEdit == null) {
        mTextEdit = new DummyEdit(getContext());

        mLayout.addView(mTextEdit, params);
    } else {
        mTextEdit.setLayoutParams(params);
    }

    mTextEdit.setVisibility(View.VISIBLE);
    mTextEdit.requestFocus();

    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(mTextEdit, 0);

    mScreenKeyboardShown = true;
}
AndroidUtils.java 文件源码 项目:Typesetter 阅读 28 收藏 0 点赞 0 评论 0
public static void hideKeyboard(@NonNull Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}
PswInputView.java 文件源码 项目:DizzyPassword 阅读 30 收藏 0 点赞 0 评论 0
@Override
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
    super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
    if (mFocusAnim != null) {
        mFocusAnim.end();
    }
    if (gainFocus) {
        mFocusAnim = ObjectAnimator.ofFloat(this, "FocusLine", mFocusLineLength, (float) (getWidth() - 2 * mRoundRadius));
        input.showSoftInput(this, InputMethodManager.SHOW_FORCED);
    } else {
        mFocusAnim = ObjectAnimator.ofFloat(this, "FocusLine", mFocusLineLength, 0);
        input.hideSoftInputFromInputMethod(this.getWindowToken(), 0);
    }
    mFocusAnim.setDuration(1000).setInterpolator(new OvershootInterpolator());
    mFocusAnim.start();
}
KeyboardUtils.java 文件源码 项目:AppCommonFrame 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Hides the soft keyboard from screen
 *
 * @param view Usually the EditText, but in dynamically  layouts you should pass the layout
 * instead of the EditText
 * @return true, if keyboard has been hidden, otherwise false (i.e. the keyboard was not displayed
 * on the screen or no Softkeyboard because device has hardware keyboard)
 */
public static boolean hideKeyboard(View view) {

  if (view == null) {
    throw new NullPointerException("View is null!");
  }

  try {
    InputMethodManager imm =
        (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

    if (imm == null) {
      return false;
    }

    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
  } catch (Exception e) {
    return false;
  }

  return true;
}
TextInputView.java 文件源码 项目:Nird2 阅读 25 收藏 0 点赞 0 评论 0
public void showSoftKeyboard() {
    if (isKeyboardOpen()) return;

    if (ui.emojiDrawer.isShowing()) {
        postOnKeyboardOpen(new Runnable() {
            @Override
            public void run() {
                hideEmojiDrawer();
            }
        });
    }
    ui.editText.post(new Runnable() {
        @Override
        public void run() {
            ui.editText.requestFocus();
            InputMethodManager imm =
                    (InputMethodManager) getContext()
                            .getSystemService(INPUT_METHOD_SERVICE);
            imm.showSoftInput(ui.editText, SHOW_IMPLICIT);
        }
    });
}
QuranKeyboardIME.java 文件源码 项目:QuranKeyboard 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Main initialization of the input method component.  Be sure to call
 * to super class.
 */
@Override public void onCreate() {
    super.onCreate();
    mInputMethodManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
    mWordSeparators = getResources().getString(R.string.word_separators);
    mSuggestions = EMPTY_LIST;
    mQuranSuggestions = EMPTY_MLIST;
    mSavedPreSpaces = 0;

    try {
        mQuranSearch = new QuranSearch(this);
    } catch (IOException |SecurityException e) {
        mQuranSearch = null;
        Toast.makeText(this, "Quran Search disabled, File not found!", Toast.LENGTH_LONG).show();
        // TODO disable/gray the Moshaf/shift key & disable/grey Prefs
        if (DEBUG) e.printStackTrace();
    }

    if (mQuranSearch != null) {
        PreferenceManager.setDefaultValues(this, R.xml.ime_preferences, false);

        setUthmaniTypeFace(Typeface.createFromAsset(getAssets(), "UthmanicHafs.otf"));
    }
}
AddValueFragment.java 文件源码 项目:Android_watch_magpie 阅读 27 收藏 0 点赞 0 评论 0
private void setCancelAction(Button cancelButton, final EditText dateEditText,
                             final EditText timeEditText, final TextInputLayout... textInputLayouts) {
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            for (TextInputLayout textInputLayout : textInputLayouts) {
                textInputLayout.getEditText().setText("");
                textInputLayout.clearFocus();
                // Hide the keyboard
                InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(textInputLayout.getEditText().getWindowToken(), 0);
            }
            dateEditText.setText("");
            timeEditText.setText("");
        }
    });
}
GuiUtils.java 文件源码 项目:MobileAppForPatient 阅读 41 收藏 0 点赞 0 评论 0
public static void setKeypadVisibility(Context context, EditText inputNote, int visibility) {
    InputMethodManager imm = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    switch (visibility) {
        case View.VISIBLE:
            // 開啟鍵盤
            imm.showSoftInput(inputNote, InputMethodManager.SHOW_IMPLICIT);
            break;
        case View.GONE:
        case View.INVISIBLE:
            // 關閉鍵盤
            imm.hideSoftInputFromWindow(inputNote.getWindowToken(), 0);
            break;
    } /* end of switch */
}
PostActivity.java 文件源码 项目:EditorImageAndText 阅读 39 收藏 0 点赞 0 评论 0
/**
 * EditText获取焦点并显示软键盘
 */
public void showSoftInputFromWindow(EditText editText) {
    //添加文字edittext弹出软键盘
    editText.setFocusable(true);
    editText.setFocusableInTouchMode(true);
    editText.requestFocus();
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            InputMethodManager imm = (InputMethodManager) PostActivity.this
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
        }

    }, 100);//这里的时间大概是自己测试的
}
MaterialSearchView.java 文件源码 项目:Aequorea 阅读 32 收藏 0 点赞 0 评论 0
public void showKeyboard(View view) {
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1 && view.hasFocus()) {
        view.clearFocus();
    }
    view.requestFocus();
    InputMethodManager imm = (InputMethodManager) view.getContext()
        .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        imm.showSoftInput(view, 0);
    }
}
RichInputMethodManager.java 文件源码 项目:AOSP-Kayboard-7.1.2 阅读 28 收藏 0 点赞 0 评论 0
private boolean switchToNextInputMethodAndSubtype(final IBinder token) {
    final InputMethodManager imm = mImmWrapper.mImm;
    final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();
    final int currentIndex = getImiIndexInList(getInputMethodInfoOfThisIme(), enabledImis);
    if (currentIndex == INDEX_NOT_FOUND) {
        Log.w(TAG, "Can't find current IME in enabled IMEs: IME package="
                + getInputMethodInfoOfThisIme().getPackageName());
        return false;
    }
    final InputMethodInfo nextImi = getNextNonAuxiliaryIme(currentIndex, enabledImis);
    final List<InputMethodSubtype> enabledSubtypes = getEnabledInputMethodSubtypeList(nextImi,
            true /* allowsImplicitlySelectedSubtypes */);
    if (enabledSubtypes.isEmpty()) {
        // The next IME has no subtype.
        imm.setInputMethod(token, nextImi.getId());
        return true;
    }
    final InputMethodSubtype firstSubtype = enabledSubtypes.get(0);
    imm.setInputMethodAndSubtype(token, nextImi.getId(), firstSubtype);
    return true;
}
LModActivity.java 文件源码 项目:ModPE-IDE-Source 阅读 32 收藏 0 点赞 0 评论 0
@SuppressWarnings("ConstantConditions")
private void closeKeyBoard() throws NullPointerException {
    InputMethodManager inputManager =
            (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    IBinder windowToken = getCurrentFocus().getWindowToken();
    int hideType = InputMethodManager.HIDE_NOT_ALWAYS;
    inputManager.hideSoftInputFromWindow(windowToken, hideType);
}
IjkPlayer.java 文件源码 项目:live_master 阅读 29 收藏 0 点赞 0 评论 0
private void HideSoftInput(IBinder token) {
    if (token != null) {
        InputMethodManager manager = (InputMethodManager) activity.getSystemService(activity.INPUT_METHOD_SERVICE);
        manager.hideSoftInputFromWindow(token,
                InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
AddHostActivity.java 文件源码 项目:zabbkit-android 阅读 29 收藏 0 点赞 0 评论 0
private void performAdd() {
    InputMethodManager imm = (InputMethodManager) getSystemService(
            Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(editUrl.getWindowToken(), 0);

    showDialog();
    final Map<String, Object> params = new ArrayMap<String, Object>();
    params.put(Constants.PREFS_USER, editLogin.getText().toString());
    params.put(Constants.PREFS_PASSWORD, editPass.getText().toString());
    Communicator.getInstance().login(params,
            collectUrl(editUrl.getText().toString()), this);
}
PCKeyboard.java 文件源码 项目:behe-keyboard 阅读 40 收藏 0 点赞 0 评论 0
/**
 * Main initialization of the input method component. Be sure to call
 * to super class.
 */

@Override public void onCreate() {
    super.onCreate();
    mInputMethodManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
    mWordSeparators = getResources().getString(R.string.word_separators);
    final TextServicesManager tsm = (TextServicesManager) getSystemService(
            Context.TEXT_SERVICES_MANAGER_SERVICE);
    mScs = tsm.newSpellCheckerSession(null, null, this, true);
}
PswInputView.java 文件源码 项目:DizzyPassword 阅读 36 收藏 0 点赞 0 评论 0
/**
     * 初始化相关参数
     */
    void init(AttributeSet attrs) {
        final float dp = getResources().getDisplayMetrics().density;
        this.setFocusable(true);
        this.setFocusableInTouchMode(true);
        input = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        result = new ArrayList<>();
        if (attrs != null) {
            TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.PswInputView);
//            mBorderColor = ta.getColor(R.styleable.PswInputView_border_color, getResources().getColor(R.color.color_13));
            mBorderColor = ta.getColor(R.styleable.PswInputView_border_color, ThemeUtils.getPrimaryColor(AppManager.getAppManager().currentActivity()));
            mDotColor = ta.getColor(R.styleable.PswInputView_dot_color, getResources().getColor(R.color.color_bg));
            count = ta.getInt(R.styleable.PswInputView_count, 6);
            ta.recycle();
        } else {
            mBorderColor = Color.LTGRAY;
            mDotColor = Color.GRAY;
            count = 6;//默认6位密码
        }
        size = (int) (dp * 30);//默认30dp一格
        //color
        mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mBorderPaint.setStrokeWidth(2);
        mBorderPaint.setStyle(Paint.Style.STROKE);
        mBorderPaint.setColor(mBorderColor);
        mDotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mDotPaint.setStrokeWidth(3);
        mDotPaint.setStyle(Paint.Style.FILL);
        mDotPaint.setColor(mDotColor);
        mRoundRect = new RectF();
        mRoundRadius = (int) (5 * dp);
        mFocusLineLength = 0;
        this.setOnKeyListener(new MyKeyListener());
    }
TextInputView.java 文件源码 项目:Nird2 阅读 29 收藏 0 点赞 0 评论 0
public void showSoftKeyboard() {
    if (isKeyboardOpen()) return;

    if (ui.emojiDrawer.isShowing()) {
        postOnKeyboardOpen(new Runnable() {
            @Override
            public void run() {
                hideEmojiDrawer();
            }
        });
    }
    ui.editText.post(new Runnable() {
        @Override
        public void run() {
            ui.editText.requestFocus();
            InputMethodManager imm =
                    (InputMethodManager) getContext()
                            .getSystemService(INPUT_METHOD_SERVICE);
            imm.showSoftInput(ui.editText, SHOW_IMPLICIT);
        }
    });
}
ViewUtils.java 文件源码 项目:android-project-gallery 阅读 45 收藏 0 点赞 0 评论 0
/**
 * 隐藏输入法, 在Activity的维度
 * 
 * @param activity
 */
public static void hideSoftInput(Activity activity)
{
    try
    {
        ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
    catch (Exception e)
    {
        // 避免可能不对手机的兼容异常
        e.printStackTrace();
    }
}
DeviceUtils.java 文件源码 项目:mvparms 阅读 39 收藏 0 点赞 0 评论 0
/**
 * 隐藏软键盘
 *
 * @param context
 * @param view
 */
public static void hideSoftKeyboard(Context context, View view) {
    if (view == null)
        return;
    InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(
            Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager.isActive())
        inputMethodManager.hideSoftInputFromWindow(
                view.getWindowToken(), 0);
}
SearchView.java 文件源码 项目:boohee_v5.6 阅读 38 收藏 0 点赞 0 评论 0
void showSoftInputUnchecked(InputMethodManager imm, View view, int flags) {
    if (this.showSoftInputUnchecked != null) {
        try {
            this.showSoftInputUnchecked.invoke(imm, new Object[]{Integer.valueOf(flags), null});
            return;
        } catch (Exception e) {
        }
    }
    imm.showSoftInput(view, flags);
}
CreateIssueActivity.java 文件源码 项目:civify-app 阅读 31 收藏 0 点赞 0 评论 0
private void hideSoftKeyboard() {
    InputMethodManager inputMethodManager =
            (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager
            .hideSoftInputFromWindow(findViewById(android.R.id.content).getWindowToken(), 0);

}
RPBaseFragment.java 文件源码 项目:redpacketui-open 阅读 24 收藏 0 点赞 0 评论 0
/**
 * close soft keyboard
 */
protected void closeSoftKeyboard() {
    View view = getActivity().getWindow().peekDecorView();
    if (view != null) {
        InputMethodManager manager = (InputMethodManager) mContext.getSystemService(Activity.INPUT_METHOD_SERVICE);
        manager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}
BaseActivity.java 文件源码 项目:instamaterial 阅读 34 收藏 0 点赞 0 评论 0
protected void hideKeyboard() {
  View view = getCurrentFocus();
  if (view != null) {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
  }
}
NumberPicker.java 文件源码 项目:android-numberpickercompat 阅读 36 收藏 0 点赞 0 评论 0
/**
 * Hides the soft input if it is active for the input text.
 */
private void hideSoftInput() {
    InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null && inputMethodManager.isActive(mInputText)) {
        inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
        mInputText.setVisibility(View.INVISIBLE);
    }
}
IInputMethodManagerBinderHook.java 文件源码 项目:DroidPlugin 阅读 29 收藏 0 点赞 0 评论 0
@Override
protected void onInstall(ClassLoader classLoader) throws Throwable {
    super.onInstall(classLoader);
    Object obj = FieldUtils.readStaticField(InputMethodManager.class, "sInstance");
    if (obj != null) {
        FieldUtils.writeStaticField(InputMethodManager.class, "sInstance", null);
    }
    mHostContext.getSystemService(Context.INPUT_METHOD_SERVICE);
}
ViewUtil.java 文件源码 项目:GitHub 阅读 39 收藏 0 点赞 0 评论 0
/**
 * 隐藏软键盘
 */
public static void hideKeyboard(Activity c) {
    try {
        InputMethodManager imm = (InputMethodManager) c
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(c.getCurrentFocus().getWindowToken(), 0);
    } catch (NullPointerException e) {
    }
}
Main.java 文件源码 项目:CryptoVoice 阅读 27 收藏 0 点赞 0 评论 0
private void setMainView(){
    setContentView(R.layout.activity_main);
    TextView tv = (TextView) findViewById(R.id.textView2);
    final EditText number = (EditText) findViewById(R.id.editText);
    number.requestFocus();
    InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
    sb = Snackbar.make(findViewById(R.id.content_main), "Unknown error", Snackbar.LENGTH_INDEFINITE);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    final IControlChannelListener main = this;
    tv.setText(Integer.toString(cc.getNumber()));
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(cc.activeCall()){
                cc.hangup();
                return;
            }
            if (number.getText().length() != 0){
                cc.dial(Integer.parseInt(number.getText().toString()));
                setInCallView();
            }
        }
    });
    final Button contactSelect =  (Button) findViewById(R.id.buttonContact);
    contactSelect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
            startActivityForResult(contactPickerIntent, RESULT_PICK_CONTACT);
        }
    });
    if(wakeLock.isHeld()) {
        wakeLock.release();
    }
}
ShowFragment.java 文件源码 项目:ShangHanLun 阅读 33 收藏 0 点赞 0 评论 0
public void hideKeyboard() {
    searchEditText.clearFocus();
    // getActivity().getWindow().setSoftInputMode(
    // WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    InputMethodManager imm = (InputMethodManager) getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(searchEditText.getWindowToken(), 0);
    // this is a valuable method.
    // imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(),0);
    // tableView.requestFocus();
}
EaseBaseFragment.java 文件源码 项目:Tribe 阅读 31 收藏 0 点赞 0 评论 0
protected void hideSoftKeyboard() {
    if (getActivity().getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
        if (getActivity().getCurrentFocus() != null)
            inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号