Example usage for android.view.inputmethod InputMethodManager isActive

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

Introduction

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

Prototype

public boolean isActive(View view) 

Source Link

Document

Return true if the given view is the currently active view for the input method.

Usage

From source file:com.ferdi2005.secondgram.AndroidUtilities.java

public static boolean isKeyboardShowed(View view) {
    if (view == null) {
        return false;
    }//from  www.j a v a 2s  .com
    try {
        InputMethodManager inputManager = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        return inputManager.isActive(view);
    } catch (Exception e) {
        FileLog.e(e);
    }
    return false;
}

From source file:com.freerdp.freerdpcore.presentation.SessionActivity.java

private void showKeyboard(boolean showSystemKeyboard, boolean showExtendedKeyboard) {
    // no matter what we are doing ... hide the zoom controls
    // TODO: this is not working correctly as hiding the keyboard issues a onScrollChange notification showing the control again ...
    uiHandler.removeMessages(UIHandler.HIDE_ZOOMCONTROLS);
    if (zoomControls.getVisibility() == View.VISIBLE)
        zoomControls.hide();/*from w ww  .j  av  a  2  s. c  om*/

    InputMethodManager mgr;
    if (showSystemKeyboard) {
        // hide extended keyboard
        keyboardView.setVisibility(View.GONE);

        // show system keyboard
        mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (!mgr.isActive(sessionView))
            Log.e(TAG, "Failed to show system keyboard: SessionView is not the active view!");
        mgr.showSoftInput(sessionView, 0);

        // show modifiers keyboard
        modifiersKeyboardView.setVisibility(View.VISIBLE);
    } else if (showExtendedKeyboard) {
        // hide system keyboard
        mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        mgr.hideSoftInputFromWindow(sessionView.getWindowToken(), 0);

        // show extended keyboard
        keyboardView.setKeyboard(specialkeysKeyboard);
        keyboardView.setVisibility(View.VISIBLE);
        modifiersKeyboardView.setVisibility(View.VISIBLE);
    } else {
        // hide both
        mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        mgr.hideSoftInputFromWindow(sessionView.getWindowToken(), 0);
        keyboardView.setVisibility(View.GONE);
        modifiersKeyboardView.setVisibility(View.GONE);

        // clear any active key modifiers)
        keyboardMapper.clearlAllModifiers();
    }

    sysKeyboardVisible = showSystemKeyboard;
    extKeyboardVisible = showExtendedKeyboard;
}

From source file:org.akop.ararat.view.CrosswordView.java

private void resetInputMode() {
    setFocusableInTouchMode(mIsEditable && mInputMode != INPUT_MODE_NONE);

    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        if (imm.isActive(this)) {
            imm.hideSoftInputFromWindow(getWindowToken(), 0);
        }/*  w  w w. ja va2s . com*/
        imm.restartInput(this);
    }
}

From source file:info.guardianproject.otr.app.im.app.ChatView.java

@Override
protected void onFinishInflate() {
    //  mStatusIcon = (ImageView) findViewById(R.id.statusIcon);
    //   mDeliveryIcon = (ImageView) findViewById(R.id.deliveryIcon);
    // mTitle = (TextView) findViewById(R.id.title);
    mHistory = (ListView) findViewById(R.id.history);
    mComposeMessage = (EditText) findViewById(R.id.composeMessage);
    mSendButton = (ImageButton) findViewById(R.id.btnSend);
    mHistory.setOnItemClickListener(mOnItemClickListener);
    mButtonAttach = (ImageButton) findViewById(R.id.btnAttach);
    mViewAttach = findViewById(R.id.attachPanel);

    mStatusWarningView = findViewById(R.id.warning);
    mWarningText = (TextView) findViewById(R.id.warningText);

    mProgressTransfer = (ProgressBar) findViewById(R.id.progressTransfer);
    // mOtrSwitch = (CompoundButton)findViewById(R.id.otrSwitch);
    mProgressBarOtr = (ProgressBar) findViewById(R.id.progressBarOtr);

    mButtonAttach.setOnClickListener(new OnClickListener() {

        @Override//from w  w w .  ja  v a  2  s .c om
        public void onClick(View v) {

            if (mViewAttach.getVisibility() == View.GONE)
                mViewAttach.setVisibility(View.VISIBLE);
            else
                mViewAttach.setVisibility(View.GONE);
        }

    });

    ((ImageButton) findViewById(R.id.btnAttachAudio)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mNewChatActivity.startAudioPicker();
        }

    });

    ((ImageButton) findViewById(R.id.btnAttachPicture)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mNewChatActivity.startImagePicker();
        }

    });

    ((ImageButton) findViewById(R.id.btnTakePicture)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mNewChatActivity.startPhotoTaker();
        }

    });

    ((ImageButton) findViewById(R.id.btnAttachFile)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mNewChatActivity.startFilePicker();
        }

    });

    mHistory.setOnItemLongClickListener(new OnItemLongClickListener() {

        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

            if (arg1 instanceof MessageView) {

                String textToCopy = ((MessageView) arg1).getLastMessage();

                int sdk = android.os.Build.VERSION.SDK_INT;
                if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) mNewChatActivity
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setText(textToCopy); //
                } else {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) mNewChatActivity
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("chat", textToCopy);
                    clipboard.setPrimaryClip(clip); //
                }

                Toast.makeText(mNewChatActivity, mContext.getString(R.string.toast_chat_copied_to_clipboard),
                        Toast.LENGTH_SHORT).show();

                return true;

            }

            return false;
        }

    });

    mWarningText.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            showVerifyDialog();
        }
    });

    //mOtrSwitch.setOnCheckedChangeListener(mOtrListener);

    mComposeMessage.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                    sendMessage();
                    return true;

                case KeyEvent.KEYCODE_ENTER:
                    if (event.isAltPressed()) {
                        mComposeMessage.append("\n");
                        return true;
                    }
                }
            }
            return false;
        }
    });

    mComposeMessage.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null) {
                if (event.isAltPressed()) {
                    return false;
                }
            }

            InputMethodManager imm = (InputMethodManager) mContext
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null && imm.isActive(v)) {
                imm.hideSoftInputFromWindow(getWindowToken(), 0);
            }
            sendMessage();
            return true;
        }
    });

    // TODO: this is a hack to implement BUG #1611278, when dispatchKeyEvent() works with
    // the soft keyboard, we should remove this hack.
    mComposeMessage.addTextChangedListener(new TextWatcher() {
        public void beforeTextChanged(CharSequence s, int start, int before, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int after) {
            //log("TextWatcher: " + s);
            userActionDetected();
        }

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

    mSendButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            sendMessage();
        }
    });

    Button btnApproveSubscription = (Button) findViewById(R.id.btnApproveSubscription);
    btnApproveSubscription.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            mNewChatActivity.approveSubscription(mProviderId, mRemoteAddress);

            mHandler.postDelayed(new Runnable() {
                public void run() {
                    bindChat(mLastChatId);
                }
            }, 2000);

        }

    });

    Button btnDeclineSubscription = (Button) findViewById(R.id.btnDeclineSubscription);
    btnDeclineSubscription.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {

            mHandler.postDelayed(new Runnable() {
                public void run() {
                    mNewChatActivity.declineSubscription(mProviderId, mRemoteAddress);

                }
            }, 500);

        }

    });

    /*
    mActionBox = (View)findViewById(R.id.actionBox);
    ImageButton btnActionBox = (ImageButton)findViewById(R.id.btnActionBox);
    btnActionBox.setOnClickListener(new OnClickListener ()
    {
            
    @Override
    public void onClick(View v) {
            
        mEmojiPager.setVisibility(View.GONE);
            
            
        if (mActionBox.getVisibility() == View.GONE)
            mActionBox.setVisibility(View.VISIBLE);
        else
            mActionBox.setVisibility(View.GONE);
    }
            
    });
            
    View btnEndChat = findViewById(R.id.btnEndChat);
    btnEndChat.setOnClickListener(new OnClickListener ()
    {
            
    @Override
    public void onClick(View v) {
            
        ChatView.this.closeChatSession();
    }
            
    });
            
    View btnProfile = findViewById(R.id.btnProfile);
    btnProfile.setOnClickListener(new OnClickListener ()
    {
            
    @Override
    public void onClick(View v) {
            
        viewProfile();
    }
            
    });
            
    View btnSharePicture = findViewById(R.id.btnSendPicture);
    btnSharePicture.setOnClickListener(new OnClickListener ()
    {
            
    @Override
    public void onClick(View v) {
            
        if (mLastSessionStatus != null && mLastSessionStatus == SessionStatus.ENCRYPTED)
        {
            mNewChatActivity.startImagePicker();
        }
        else
        {
            mHandler.showServiceErrorAlert(getContext().getString(R.string.please_enable_chat_encryption_to_share_files));
        }
    }
            
    });
            
    View btnShareFile = findViewById(R.id.btnSendFile);
    btnShareFile.setOnClickListener(new OnClickListener ()
    {
            
    @Override
    public void onClick(View v) {
            
        if (mLastSessionStatus != null && mLastSessionStatus == SessionStatus.ENCRYPTED)
        {
            mNewChatActivity.startFilePicker();
        }
        else
        {
            mHandler.showServiceErrorAlert(getContext().getString(R.string.please_enable_chat_encryption_to_share_files));
            
        }
    }
            
    });
    */

    initEmoji();

    mMessageAdapter = new MessageAdapter(mNewChatActivity, null);
    mHistory.setAdapter(mMessageAdapter);
}

From source file:org.awesomeapp.messenger.ui.ConversationView.java

protected void initViews() {
    //  mStatusIcon = (ImageView) mActivity.findViewById(R.id.statusIcon);
    //   mDeliveryIcon = (ImageView) mActivity.findViewById(R.id.deliveryIcon);
    // mTitle = (TextView) mActivity.findViewById(R.id.title);
    mHistory = (RecyclerView) mActivity.findViewById(R.id.history);
    LinearLayoutManager llm = new LinearLayoutManager(mHistory.getContext());
    llm.setStackFromEnd(true);/*from   www .  j  a  v a2 s .co  m*/
    mHistory.setLayoutManager(llm);

    mComposeMessage = (EditText) mActivity.findViewById(R.id.composeMessage);
    mSendButton = (ImageButton) mActivity.findViewById(R.id.btnSend);
    mMicButton = (ImageButton) mActivity.findViewById(R.id.btnMic);
    mButtonTalk = (TextView) mActivity.findViewById(R.id.buttonHoldToTalk);

    mButtonDeleteVoice = (ImageView) mActivity.findViewById(R.id.btnDeleteVoice);
    mViewDeleteVoice = mActivity.findViewById(R.id.viewDeleteVoice);

    mButtonDeleteVoice.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
                int resolvedColor = mHistory.getResources().getColor(android.R.color.holo_red_light);
                mButtonDeleteVoice.setBackgroundColor(resolvedColor);
            }

            return false;
        }
    });

    mButtonAttach = (ImageButton) mActivity.findViewById(R.id.btnAttach);
    mViewAttach = mActivity.findViewById(R.id.attachPanel);

    mStatusWarningView = mActivity.findViewById(R.id.warning);
    mWarningText = (TextView) mActivity.findViewById(R.id.warningText);

    mButtonAttach.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            toggleAttachMenu();
        }

    });

    mActivity.findViewById(R.id.btnAttachPicture).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mActivity.startImagePicker();
        }

    });

    mActivity.findViewById(R.id.btnTakePicture).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mActivity.startPhotoTaker();
        }

    });

    /**
    mActivity.findViewById(R.id.btnAttachFile).setOnClickListener(new View.OnClickListener() {
            
    @Override
    public void onClick(View v) {
        mActivity.startFilePicker();
    }
            
    });*/

    mActivity.findViewById(R.id.btnAttachSticker).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            toggleAttachMenu();
            showStickers();
        }

    });

    mMicButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            //this is the tap to change to hold to talk mode
            if (mMicButton.getVisibility() == View.VISIBLE) {
                mComposeMessage.setVisibility(View.GONE);
                mMicButton.setVisibility(View.GONE);

                // Check if no view has focus:
                View view = mActivity.getCurrentFocus();
                if (view != null) {
                    InputMethodManager imm = (InputMethodManager) mActivity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                }

                mSendButton.setImageResource(R.drawable.ic_keyboard_black_36dp);
                mSendButton.setVisibility(View.VISIBLE);
                mButtonTalk.setVisibility(View.VISIBLE);

            }
        }

    });

    final GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
        public void onLongPress(MotionEvent e) {

            //this is for recording audio directly from one press
            mActivity.startAudioRecording();

        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {

            if (mActivity.isAudioRecording()) {
                boolean send = true;//inViewInBounds(mMicButton, (int) motionEvent.getX(), (int) motionEvent.getY());
                mActivity.stopAudioRecording(send);
            }

            return super.onSingleTapUp(e);
        }
    });

    mMicButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            return gestureDetector.onTouchEvent(motionEvent);

        }
    });

    mButtonTalk.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View btnTalk, MotionEvent theMotion) {
            switch (theMotion.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mActivity.startAudioRecording();
                mButtonTalk.setText(mActivity.getString(R.string.recording_release));
                mViewDeleteVoice.setVisibility(View.VISIBLE);

                break;
            case MotionEvent.ACTION_MOVE:
                boolean inBounds = inViewInBounds(btnTalk, (int) theMotion.getX(), (int) theMotion.getY());
                if (!inBounds)
                    mButtonTalk.setText(mActivity.getString(R.string.recording_delete));
                else {
                    mButtonTalk.setText(mActivity.getString(R.string.recording_release));
                    mViewDeleteVoice.setVisibility(View.VISIBLE);
                }
                break;
            case MotionEvent.ACTION_UP:
                mButtonTalk.setText(mActivity.getString(R.string.push_to_talk));
                boolean send = inViewInBounds(btnTalk, (int) theMotion.getX(), (int) theMotion.getY());
                mActivity.stopAudioRecording(send);
                mViewDeleteVoice.setVisibility(View.GONE);

                break;
            }
            return true;
        }
    });
    /**
    mHistory.setOnItemLongClickListener(new OnItemLongClickListener ()
    {
            
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override
    public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            
            
     if (arg1 instanceof MessageView)
     {
            
         String textToCopy = ((MessageView)arg1).getLastMessage();
            
         int sdk = android.os.Build.VERSION.SDK_INT;
         if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
             android.text.ClipboardManager clipboard = (android.text.ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
             clipboard.setText(textToCopy); //
         } else {
             android.content.ClipboardManager clipboard = (android.content.ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
             android.content.ClipData clip = android.content.ClipData.newPlainText("chat",textToCopy);
             clipboard.setPrimaryClip(clip); //
         }
            
         Toast.makeText(mActivity, mContext.getString(R.string.toast_chat_copied_to_clipboard), Toast.LENGTH_SHORT).show();
            
         return true;
            
     }
            
        return false;
    }
            
    });**/

    mWarningText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showVerifyDialog();
        }
    });

    mComposeMessage.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            sendTypingStatus(true);

            return false;
        }
    });

    mComposeMessage.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {

            sendTypingStatus(hasFocus);

        }
    });

    mComposeMessage.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                    sendMessage();
                    return true;

                case KeyEvent.KEYCODE_ENTER:
                    if (event.isAltPressed()) {
                        mComposeMessage.append("\n");
                        return true;
                    }
                }

            }

            return false;
        }
    });

    mComposeMessage.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null) {
                if (event.isAltPressed()) {
                    return false;
                }
            }

            InputMethodManager imm = (InputMethodManager) mContext
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null && imm.isActive(v)) {
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
            sendMessage();
            return true;
        }
    });

    // TODO: this is a hack to implement BUG #1611278, when dispatchKeyEvent() works with
    // the soft keyboard, we should remove this hack.
    mComposeMessage.addTextChangedListener(new TextWatcher() {
        public void beforeTextChanged(CharSequence s, int start, int before, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int after) {

        }

        public void afterTextChanged(Editable s) {
            doWordSearch();
            userActionDetected();
        }
    });

    mSendButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            if (mComposeMessage.getVisibility() == View.VISIBLE)
                sendMessage();
            else {
                mSendButton.setImageResource(R.drawable.ic_send_holo_light);

                if (mLastSessionStatus == SessionStatus.ENCRYPTED)
                    mSendButton.setImageResource(R.drawable.ic_send_secure);

                mSendButton.setVisibility(View.GONE);
                mButtonTalk.setVisibility(View.GONE);
                mComposeMessage.setVisibility(View.VISIBLE);
                mMicButton.setVisibility(View.VISIBLE);

            }
        }
    });

    mMessageAdapter = new ConversationRecyclerViewAdapter(mActivity, null);
    mHistory.setAdapter(mMessageAdapter);

}