com.blankj.utilcode.util.KeyboardUtils Java Examples

The following examples show how to use com.blankj.utilcode.util.KeyboardUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChatActivity.java    From Socket.io-FLSocketIM-Android with MIT License 6 votes vote down vote up
private void showEmotionOrOther(MessageBtnType type, boolean show) {

        if (show) {
            KeyboardUtils.hideSoftInput(this);
            inputBackLayout.setVisibility(View.VISIBLE);

            LinearLayout.LayoutParams par = (LinearLayout.LayoutParams) inputBackLayout.getLayoutParams();
            switch (type) {
                case MsgBtnEmotion:
                    int height = chatEmotionFragment.getChatEmotionHeight();
                    par.height = chatEmotionFragment.getChatEmotionHeight();
                    viewPager.setCurrentItem(0);
                    break;
                case MsgBtnOther:
                    par.height = FLUtil.dip2px(mContext, 150);
                    viewPager.setCurrentItem(1);
                    break;
            }
            inputBackLayout.setLayoutParams(par);
        } else {

            inputBackLayout.setVisibility(View.GONE);
        }
    }
 
Example #2
Source File: ChatActivity.java    From Socket.io-FLSocketIM-Android with MIT License 6 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();

    ClientManager.chattingUserId = "";
    EventBus.getDefault().unregister(this);
    KeyboardUtils.hideSoftInput(this);

    Socket socket = SocketManager.socket;
    socket.off("__join");
    socket.off("_ice_candidate");
    socket.off("_peers");
    socket.off("_new_peer");
    socket.off("_remove_peer");
    socket.off("_offer");
    socket.off("_answer");
    socket.off("cancelVideoChat");

}
 
Example #3
Source File: CmmtPopup.java    From EasyPopup with Apache License 2.0 5 votes vote down vote up
public CmmtPopup hideSoftInput() {
    if (mEditText != null) {
        mEditText.post(new Runnable() {
            @Override
            public void run() {
                    KeyboardUtils.hideSoftInput(mEditText);
            }
        });
    }
    return this;
}
 
Example #4
Source File: PreventKeyboardBlockUtil.java    From PreventKeyboardBlockUtil with Apache License 2.0 5 votes vote down vote up
public void unRegister() {
    isRegister = false;
    KeyboardUtils.hideSoftInput(mActivity);
    keyBoardHeight = 0;
    sendHandlerMsg(0);

    if(keyboardHeightProvider != null){
        keyboardHeightProvider.setKeyboardHeightObserver(null);
        keyboardHeightProvider.close();
    }
}
 
Example #5
Source File: CmmtPopup.java    From EasyPopup with Apache License 2.0 5 votes vote down vote up
public CmmtPopup showSoftInput() {
    if (mEditText != null) {
        mEditText.post(new Runnable() {
            @Override
            public void run() {
                KeyboardUtils.showSoftInput(mEditText);
            }
        });
    }
    return this;
}
 
Example #6
Source File: FloatEditText.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
public void bindFloatView(final BaseContentFloatView floatView) {
    setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            WindowManager.LayoutParams params = floatView.getLayoutParams();
            if ((params.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) {
                params.flags = params.flags & ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
                params.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
                WindowHelper.updateViewLayout(floatView, params);
                KeyboardUtils.showSoftInput(v);
            }
        }
    });
}
 
Example #7
Source File: KeyboardActivity.java    From Android-UtilCode with Apache License 2.0 5 votes vote down vote up
@Override
public void onWidgetClick(View view) {
    switch (view.getId()) {
        case R.id.btn_hide_soft_input:
            KeyboardUtils.hideSoftInput(this);
            break;
        case R.id.btn_show_soft_input:
            KeyboardUtils.showSoftInput((EditText) findViewById(R.id.et));
            break;
        case R.id.btn_toggle_soft_input:
            KeyboardUtils.toggleSoftInput();
            break;
    }
}
 
Example #8
Source File: ShooterSubActivity.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@OnClick({R.id.update_api_key_tv, R.id.update_quota_tv, R.id.search_tv})
public void onViewClicked(View view) {
    switch (view.getId()) {
        case R.id.update_api_key_tv:
            new CommonEditTextDialog(this, CommonEditTextDialog.SAVE_SHOOTER_API_SECRET, data -> {
                AppConfig.getInstance().setShooterApiSecret(data[0]);
                updateApiSecretStatus();
            }).show();
            break;
        case R.id.update_quota_tv:
            if (isApiSecretExist) {
                presenter.updateQuota();
            } else {
                ToastUtils.showShort("请先设置API密钥");
            }
            break;
        case R.id.search_tv:
            KeyboardUtils.hideSoftInput(searchSubtitleEt);
            if (isApiSecretExist) {
                String text = searchSubtitleEt.getText().toString();
                if (!TextUtils.isEmpty(text)) {
                    mPage = 0;
                    presenter.searchSubtitle(text, mPage);
                } else {
                    ToastUtils.showShort("搜索内容不能为空");
                }
            } else {
                ToastUtils.showShort("请先设置API密钥");
            }
            break;
    }
}
 
Example #9
Source File: SearchActivity.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        if (historyRl.getVisibility() == View.GONE || !isSearch)
            SearchActivity.this.finish();
        else {
            AnimHelper.doHideAnimator(historyRl);
            KeyboardUtils.hideSoftInput(searchEt);
            searchEt.clearFocus();
        }
    }
    return true;
}
 
Example #10
Source File: SearchActivity.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@OnClick({R.id.return_iv, R.id.subgroup_tv, R.id.type_tv, R.id.search_iv})
public void onViewClicked(View view) {
    KeyboardUtils.hideSoftInput(searchEt);
    switch (view.getId()) {
        case R.id.return_iv:
            if (historyRl.getVisibility() == View.GONE || !isSearch)
                SearchActivity.this.finish();
            else {
                AnimHelper.doHideAnimator(historyRl);
                searchEt.clearFocus();
            }
            break;
        case R.id.subgroup_tv:
            presenter.querySubGroupList();
            break;
        case R.id.type_tv:
            presenter.queryTypeList();
            break;
        case R.id.search_iv:
            String searchText = searchEt.getText().toString().trim();
            if (StringUtils.isEmpty(searchText)) {
                ToastUtils.showShort("请输入搜索条件");
                return;
            }
            search(searchText);
            break;
    }
}
 
Example #11
Source File: SearchActivity.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public void initListener() {
    searchEt.setOnFocusChangeListener((v, hasFocus) -> {
        if (hasFocus) {
            AnimHelper.doShowAnimator(historyRl);
        }
    });

    historyRl.setOnClickListener(v -> {
        AnimHelper.doHideAnimator(historyRl);
        searchEt.clearFocus();
        KeyboardUtils.hideSoftInput(searchEt);
    });

    searchEt.setOnEditorActionListener((v, actionId, event) -> {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            String searchText = searchEt.getText().toString().trim();
            if (StringUtils.isEmpty(searchText)) {
                ToastUtils.showShort("请输入搜索条件");
                return false;
            }
            search(searchText);
            return true;
        }
        return false;
    });
}
 
Example #12
Source File: SearchActivity.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public void initView() {
    historyList = new ArrayList<>();
    resultList = new ArrayList<>();
    animeTitle = getIntent().getStringExtra("anime_title");
    searchWord = getIntent().getStringExtra("search_word");
    boolean isAnime = getIntent().getBooleanExtra("is_anime", false);

    historyAdapter = new BaseRvAdapter<SearchHistoryBean>(historyList) {
        @NonNull
        @Override
        public AdapterItem<SearchHistoryBean> onCreateItem(int viewType) {
            return new SearchHistoryItem();
        }
    };
    resultAdapter = new BaseRvAdapter<MagnetBean.ResourcesBean>(resultList) {
        @NonNull
        @Override
        public AdapterItem<MagnetBean.ResourcesBean> onCreateItem(int viewType) {
            return new MagnetItem();
        }
    };
    resultRv.setAdapter(resultAdapter);

    historyRv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    historyRv.setNestedScrollingEnabled(false);
    historyRv.setItemViewCacheSize(10);
    historyRv.setAdapter(historyAdapter);

    resultRv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    resultRv.setNestedScrollingEnabled(false);
    resultRv.setItemViewCacheSize(10);
    resultRv.setAdapter(resultAdapter);

    presenter.getSearchHistory(isAnime);
    if (!isAnime) {
        searchEt.postDelayed(() ->
                KeyboardUtils.showSoftInput(searchEt), 200);
    }
}
 
Example #13
Source File: ChatActivity.java    From Socket.io-FLSocketIM-Android with MIT License 5 votes vote down vote up
private void setBtnType(MessageBtnType btnType) {
    this.btnType = btnType;

    voiceBtn.setImageResource(R.drawable.keyboard_voice);
    emotionBtn.setImageResource(R.drawable.keyboard_emotion);
    addOtherBtn.setImageResource(R.drawable.keyboard_add);

    if (btnType == MessageBtnType.MsgBtnVoice) {

        inputTextMessage.setVisibility(View.GONE);
        sendVoiceBtn.setVisibility(View.VISIBLE);
    } else {
        inputTextMessage.setVisibility(View.VISIBLE);
        sendVoiceBtn.setVisibility(View.GONE);
    }

    switch (btnType){

        case MsgBtnVoice:
            voiceBtn.setImageResource(R.drawable.keyboard_keyboard);
            showEmotionOrOther(btnType, false);
            KeyboardUtils.hideSoftInput(this);
            break;

        case MsgBtnEmotion:
            emotionBtn.setImageResource(R.drawable.keyboard_keyboard);
            showEmotionOrOther(btnType,true);
            break;

        case MsgBtnOther:
            addOtherBtn.setImageResource(R.drawable.keyboard_keyboard);
            showEmotionOrOther(btnType, true);
            break;
        case MsgBtnText:
            showEmotionOrOther(btnType, false);
            break;
    }
}
 
Example #14
Source File: DanmuBlockView.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
@Override
public void onClick(View v) {
    int id = v.getId();
    if (id == R.id.block_view_cancel_iv){
        if (listener != null)
            listener.onCloseView();
    }else if (id == R.id.add_block_bt){
        String blockText = blockEt.getText().toString().trim();
        if (TextUtils.isEmpty(blockText)){
            Toast.makeText(getContext(), "屏蔽关键字不能为空", Toast.LENGTH_LONG).show();
        }else if (blockList.contains(blockText)){
            Toast.makeText(getContext(), "当前关键字已屏蔽", Toast.LENGTH_LONG).show();
        }else if (traverseBlock(blockText)){
            Toast.makeText(getContext(), "当前关键字已在屏蔽范围内", Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getContext(), "添加屏蔽成功", Toast.LENGTH_LONG).show();
            blockEt.setText("");
            KeyboardUtils.hideSoftInput(blockEt);

            if (blockText.endsWith(";")){
                blockText = blockText.substring(0, blockText.length() - 1);
            }
            if (blockText.startsWith(";")){
                blockText = blockText.substring(1);
            }
            String[] blockData;
            if (listener != null){
                if (blockText.contains(";")){
                    blockData = blockText.split(";");
                }else {
                    blockData = new String[]{blockText};
                }

                //添加到显示界面
                blockList.addAll(Arrays.asList(blockData));
                labelsView.setLabels(blockList);
                if (listener != null)
                    listener.addBlock(Arrays.asList(blockData));
            }

        }
    }else if (id == R.id.delete_block_bt){
        List<String> selectLabelList = labelsView.getSelectLabelDatas();
        if (selectLabelList.size() == 0){
            ToastUtils.showShort("未选中屏蔽数据");
            return;
        }
        for (String text : selectLabelList){
            blockList.remove(text);
        }
        labelsView.setLabels(blockList);
        if (listener != null){
            listener.removeBlock(selectLabelList);
        }
    }
}
 
Example #15
Source File: FloatEditText.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDetachedFromWindow() {
    KeyboardUtils.hideSoftInput(this);
    super.onDetachedFromWindow();
}
 
Example #16
Source File: SearchEditText.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
public void reset() {
    mStartSearchText = "";
    setText("");
    KeyboardUtils.hideSoftInput(this);
}
 
Example #17
Source File: SearchEditText.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDetachedFromWindow() {
    removeCallbacks(mAction);
    KeyboardUtils.hideSoftInput(this);
    super.onDetachedFromWindow();
}
 
Example #18
Source File: LoginActivity.java    From Socket.io-FLSocketIM-Android with MIT License 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {

    KeyboardUtils.hideSoftInput(this);
    return super.onTouchEvent(event);
}