Example usage for android.view.inputmethod EditorInfo IME_MASK_ACTION

List of usage examples for android.view.inputmethod EditorInfo IME_MASK_ACTION

Introduction

In this page you can find the example usage for android.view.inputmethod EditorInfo IME_MASK_ACTION.

Prototype

int IME_MASK_ACTION

To view the source code for android.view.inputmethod EditorInfo IME_MASK_ACTION.

Click Source Link

Document

Set of bits in #imeOptions that provide alternative actions associated with the "enter" key.

Usage

From source file:net.zhdev.ctrlvkeyboard.CtrlVKeyboard.java

/**
 * Inserts text in the current focused text editor if possible and if it is a valid one.
 *
 * @param text          the text to be inserted
 * @param clearBefore   whether the text editor should be cleared before inserting the text
 * @param endWithAction whether the IME action should be performed at the end
 * @return {@code true} if the text was inserted and the actions performed, {@code false}
 * otherwise/*from   w w  w .j  a  v  a2 s  . c o m*/
 */
private boolean type(String text, boolean clearBefore, boolean endWithAction) {
    boolean result = false;

    if (text == null) {
        text = "";
    }

    EditorInfo info = getCurrentInputEditorInfo();

    if (info != null) {
        // If the view accepts text as input
        if ((info.inputType & EditorInfo.TYPE_MASK_CLASS) != EditorInfo.TYPE_NULL) {
            InputConnection ic = getCurrentInputConnection();

            if (ic != null) {
                boolean enterShouldHaveAction = true;
                ic.beginBatchEdit();
                if (endWithAction) {
                    enterShouldHaveAction = (info.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0;
                    if (!enterShouldHaveAction) {
                        text += "\n";
                    }
                }
                if (clearBefore) {
                    ic.deleteSurroundingText(Integer.MAX_VALUE, Integer.MAX_VALUE);
                }
                ic.commitText(text, 1);
                result = ic.endBatchEdit();

                if (result && endWithAction && enterShouldHaveAction) {
                    result = ic.performEditorAction(info.imeOptions & EditorInfo.IME_MASK_ACTION);
                }
            }
        }
    }
    return result;
}

From source file:org.mozilla.gecko.AwesomeBar.java

private void updateGoButton(String text) {
    if (text.length() == 0) {
        mGoButton.setVisibility(View.GONE);
        return;/*from w w w. ja va  2s. c  o  m*/
    }

    mGoButton.setVisibility(View.VISIBLE);

    int imageResource = R.drawable.ic_awesomebar_go;
    int imeAction = EditorInfo.IME_ACTION_GO;
    if (isSearchUrl(text)) {
        imageResource = R.drawable.ic_awesomebar_search;
        imeAction = EditorInfo.IME_ACTION_SEARCH;
    }
    mGoButton.setImageResource(imageResource);

    if ((mText.getImeOptions() & EditorInfo.IME_MASK_ACTION) != imeAction) {
        InputMethodManager imm = (InputMethodManager) mText.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        mText.setImeOptions(imeAction);
        imm.restartInput(mText);
    }
}

From source file:com.android.ex.chips.RecipientEditTextView.java

@Override
public InputConnection onCreateInputConnection(final EditorInfo outAttrs) {
    final InputConnection connection = super.onCreateInputConnection(outAttrs);
    final int imeActions = outAttrs.imeOptions & EditorInfo.IME_MASK_ACTION;
    if ((imeActions & EditorInfo.IME_ACTION_DONE) != 0) {
        // clear the existing action
        outAttrs.imeOptions ^= imeActions;
        // set the DONE action
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_DONE;
    }/*from   w  ww .  j a v  a  2s .com*/
    if ((outAttrs.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0)
        outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
    outAttrs.actionId = EditorInfo.IME_ACTION_DONE;
    outAttrs.actionLabel = getContext().getString(R.string.done);
    return connection;
}

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

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    outAttrs.actionLabel = null;//from www.j av a 2s.  c om
    outAttrs.inputType = InputType.TYPE_NULL; //InputType.TYPE_CLASS_TEXT;
    outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_FULLSCREEN;
    outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI;
    outAttrs.imeOptions &= ~EditorInfo.IME_MASK_ACTION;
    outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
    outAttrs.packageName = getContext().getPackageName();

    CrosswordInputConnection inputConnection = new CrosswordInputConnection(this);
    inputConnection.setOnInputEventListener(mInputEventListener);

    return inputConnection;
}

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

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    Log.v(LOG_TAG, "onCreateInputConnection()");

    CrosswordInputConnection inputConnection = null;
    if (mInputMode != INPUT_MODE_NONE) {
        outAttrs.actionLabel = null;//w  w w  .  j  av a  2  s. com
        outAttrs.inputType = InputType.TYPE_NULL;
        outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN;
        outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI;
        outAttrs.imeOptions &= ~EditorInfo.IME_MASK_ACTION;
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
        outAttrs.packageName = getContext().getPackageName();

        inputConnection = new CrosswordInputConnection(this);
        inputConnection.setOnInputEventListener(mInputEventListener);
    }

    return inputConnection;
}

From source file:im.vector.activity.VectorRoomActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_vector_room);

    if (CommonActivityUtils.shouldRestartApp(this)) {
        Log.e(LOG_TAG, "onCreate : Restart the application.");
        CommonActivityUtils.restartApp(this);
        return;//  w w w .  j  a va 2  s.co  m
    }

    final Intent intent = getIntent();
    if (!intent.hasExtra(EXTRA_ROOM_ID)) {
        Log.e(LOG_TAG, "No room ID extra.");
        finish();
        return;
    }

    mSession = getSession(intent);

    if (mSession == null) {
        Log.e(LOG_TAG, "No MXSession.");
        finish();
        return;
    }

    String roomId = intent.getStringExtra(EXTRA_ROOM_ID);

    // ensure that the preview mode is really expected
    if (!intent.hasExtra(EXTRA_ROOM_PREVIEW_ID)) {
        sRoomPreviewData = null;
        Matrix.getInstance(this).clearTmpStoresList();
    }

    if (CommonActivityUtils.isGoingToSplash(this, mSession.getMyUserId(), roomId)) {
        Log.d(LOG_TAG, "onCreate : Going to splash screen");
        return;
    }

    // bind the widgets of the room header view. The room header view is displayed by
    // clicking on the title of the action bar
    mRoomHeaderView = (RelativeLayout) findViewById(R.id.action_bar_header);
    mActionBarHeaderRoomTopic = (TextView) findViewById(R.id.action_bar_header_room_topic);
    mActionBarHeaderRoomName = (TextView) findViewById(R.id.action_bar_header_room_title);
    mActionBarHeaderActiveMembers = (TextView) findViewById(R.id.action_bar_header_room_members);
    mActionBarHeaderRoomAvatar = (ImageView) mRoomHeaderView.findViewById(R.id.avatar_img);
    mActionBarHeaderInviteMemberView = mRoomHeaderView.findViewById(R.id.action_bar_header_invite_members);
    mRoomPreviewLayout = findViewById(R.id.room_preview_info_layout);
    mVectorPendingCallView = (VectorPendingCallView) findViewById(R.id.room_pending_call_view);
    mVectorOngoingConferenceCallView = (VectorOngoingConferenceCallView) findViewById(
            R.id.room_ongoing_conference_call_view);

    // hide the header room as soon as the bottom layout (text edit zone) is touched
    findViewById(R.id.room_bottom_layout).setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            enableActionBarHeader(HIDE_ACTION_BAR_HEADER);
            return false;
        }
    });

    // use a toolbar instead of the actionbar
    // to be able to display an expandable header
    mToolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.room_toolbar);
    this.setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // set the default custom action bar layout,
    // that will be displayed from the custom action bar layout
    setActionBarDefaultCustomLayout();

    mCallId = intent.getStringExtra(EXTRA_START_CALL_ID);
    mEventId = intent.getStringExtra(EXTRA_EVENT_ID);
    mDefaultRoomName = intent.getStringExtra(EXTRA_DEFAULT_NAME);
    mDefaultTopic = intent.getStringExtra(EXTRA_DEFAULT_TOPIC);

    // the user has tapped on the "View" notification button
    if ((null != intent.getAction()) && (intent.getAction().startsWith(NotificationUtils.TAP_TO_VIEW_ACTION))) {
        // remove any pending notifications
        NotificationManager notificationsManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationsManager.cancelAll();
    }

    Log.d(LOG_TAG, "Displaying " + roomId);

    mEditText = (EditText) findViewById(R.id.editText_messageBox);

    // hide the header room as soon as the message input text area is touched
    mEditText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            enableActionBarHeader(HIDE_ACTION_BAR_HEADER);
        }
    });

    // IME's DONE button is treated as a send action
    mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
            int imeActionId = actionId & EditorInfo.IME_MASK_ACTION;

            if (EditorInfo.IME_ACTION_DONE == imeActionId) {
                sendTextMessage();
            }

            return false;
        }
    });

    mSendingMessagesLayout = findViewById(R.id.room_sending_message_layout);
    mSendImageView = (ImageView) findViewById(R.id.room_send_image_view);
    mSendButtonLayout = findViewById(R.id.room_send_layout);
    mSendButtonLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!TextUtils.isEmpty(mEditText.getText())) {
                sendTextMessage();
            } else {
                // hide the header room
                enableActionBarHeader(HIDE_ACTION_BAR_HEADER);

                FragmentManager fm = getSupportFragmentManager();
                IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm
                        .findFragmentByTag(TAG_FRAGMENT_ATTACHMENTS_DIALOG);

                if (fragment != null) {
                    fragment.dismissAllowingStateLoss();
                }

                final Integer[] messages = new Integer[] { R.string.option_send_files,
                        R.string.option_take_photo, };

                final Integer[] icons = new Integer[] { R.drawable.ic_material_file, // R.string.option_send_files
                        R.drawable.ic_material_camera, // R.string.option_take_photo
                };

                fragment = IconAndTextDialogFragment.newInstance(icons, messages, null,
                        ContextCompat.getColor(VectorRoomActivity.this, R.color.vector_text_black_color));
                fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() {
                    @Override
                    public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) {
                        Integer selectedVal = messages[position];

                        if (selectedVal == R.string.option_send_files) {
                            VectorRoomActivity.this.launchFileSelectionIntent();
                        } else if (selectedVal == R.string.option_take_photo) {
                            if (CommonActivityUtils.checkPermissions(
                                    CommonActivityUtils.REQUEST_CODE_PERMISSION_TAKE_PHOTO,
                                    VectorRoomActivity.this)) {
                                launchCamera();
                            }
                        }
                    }
                });

                fragment.show(fm, TAG_FRAGMENT_ATTACHMENTS_DIALOG);
            }
        }
    });

    mEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(android.text.Editable s) {
            if (null != mRoom) {
                MXLatestChatMessageCache latestChatMessageCache = VectorRoomActivity.this.mLatestChatMessageCache;
                String textInPlace = latestChatMessageCache.getLatestText(VectorRoomActivity.this,
                        mRoom.getRoomId());

                // check if there is really an update
                // avoid useless updates (initializations..)
                if (!mIgnoreTextUpdate && !textInPlace.equals(mEditText.getText().toString())) {
                    latestChatMessageCache.updateLatestMessage(VectorRoomActivity.this, mRoom.getRoomId(),
                            mEditText.getText().toString());
                    handleTypingNotification(mEditText.getText().length() != 0);
                }

                manageSendMoreButtons();
                refreshCallButtons();
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    mVectorPendingCallView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            IMXCall call = VectorCallViewActivity.getActiveCall();
            if (null != call) {
                final Intent intent = new Intent(VectorRoomActivity.this, VectorCallViewActivity.class);
                intent.putExtra(VectorCallViewActivity.EXTRA_MATRIX_ID,
                        call.getSession().getCredentials().userId);
                intent.putExtra(VectorCallViewActivity.EXTRA_CALL_ID, call.getCallId());

                VectorRoomActivity.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        VectorRoomActivity.this.startActivity(intent);
                    }
                });
            } else {
                // if the call is no more active, just remove the view
                mVectorPendingCallView.onCallTerminated();
            }
        }
    });

    mActionBarHeaderInviteMemberView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            launchRoomDetails(VectorRoomDetailsActivity.PEOPLE_TAB_INDEX);
        }
    });

    // notifications area
    mNotificationsArea = findViewById(R.id.room_notifications_area);
    mNotificationIconImageView = (ImageView) mNotificationsArea.findViewById(R.id.room_notification_icon);
    mNotificationTextView = (TextView) mNotificationsArea.findViewById(R.id.room_notification_message);

    mCanNotPostTextView = findViewById(R.id.room_cannot_post_textview);
    mStartCallLayout = findViewById(R.id.room_start_call_layout);

    mStartCallLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isUserAllowedToStartConfCall()) {
                displayVideoCallIpDialog();
            } else {
                displayConfCallNotAllowed();
            }
        }
    });

    mStopCallLayout = findViewById(R.id.room_end_call_layout);
    mStopCallLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            IMXCall call = mSession.mCallsManager.getCallWithRoomId(mRoom.getRoomId());

            if (null != call) {
                call.hangup(null);
            }
        }
    });

    mMyUserId = mSession.getCredentials().userId;

    CommonActivityUtils.resumeEventStream(this);

    mRoom = mSession.getDataHandler().getRoom(roomId, false);

    FragmentManager fm = getSupportFragmentManager();
    mVectorMessageListFragment = (VectorMessageListFragment) fm
            .findFragmentByTag(TAG_FRAGMENT_MATRIX_MESSAGE_LIST);

    if (mVectorMessageListFragment == null) {
        Log.d(LOG_TAG, "Create VectorMessageListFragment");

        // this fragment displays messages and handles all message logic
        mVectorMessageListFragment = VectorMessageListFragment.newInstance(mMyUserId, roomId, mEventId,
                (null == sRoomPreviewData) ? null : VectorMessageListFragment.PREVIEW_MODE_READ_ONLY,
                org.matrix.androidsdk.R.layout.fragment_matrix_message_list_fragment);
        fm.beginTransaction().add(R.id.anchor_fragment_messages, mVectorMessageListFragment,
                TAG_FRAGMENT_MATRIX_MESSAGE_LIST).commit();
    } else {
        Log.d(LOG_TAG, "Reuse VectorMessageListFragment");
    }

    mVectorRoomMediasSender = new VectorRoomMediasSender(this, mVectorMessageListFragment,
            Matrix.getInstance(this).getMediasCache());
    mVectorRoomMediasSender.onRestoreInstanceState(savedInstanceState);

    manageRoomPreview();

    addRoomHeaderClickListeners();

    // in timeline mode (i.e search in the forward and backward room history)
    // or in room preview mode
    // the edition items are not displayed
    if (!TextUtils.isEmpty(mEventId) || (null != sRoomPreviewData)) {
        mNotificationsArea.setVisibility(View.GONE);
        findViewById(R.id.bottom_separator).setVisibility(View.GONE);
        findViewById(R.id.room_notification_separator).setVisibility(View.GONE);
        findViewById(R.id.room_notifications_area).setVisibility(View.GONE);

        View v = findViewById(R.id.room_bottom_layout);
        ViewGroup.LayoutParams params = v.getLayoutParams();
        params.height = 0;
        v.setLayoutParams(params);
    }

    mLatestChatMessageCache = Matrix.getInstance(this).getDefaultLatestChatMessageCache();

    // some medias must be sent while opening the chat
    if (intent.hasExtra(EXTRA_ROOM_INTENT)) {
        final Intent mediaIntent = intent.getParcelableExtra(EXTRA_ROOM_INTENT);

        // sanity check
        if (null != mediaIntent) {
            mEditText.postDelayed(new Runnable() {
                @Override
                public void run() {
                    intent.removeExtra(EXTRA_ROOM_INTENT);
                    sendMediasIntent(mediaIntent);
                }
            }, 1000);
        }
    }

    mVectorOngoingConferenceCallView.initRoomInfo(mSession, mRoom);
    mVectorOngoingConferenceCallView
            .setCallClickListener(new VectorOngoingConferenceCallView.ICallClickListener() {

                private void startCall(boolean isVideo) {
                    if (CommonActivityUtils.checkPermissions(
                            isVideo ? CommonActivityUtils.REQUEST_CODE_PERMISSION_VIDEO_IP_CALL
                                    : CommonActivityUtils.REQUEST_CODE_PERMISSION_AUDIO_IP_CALL,
                            VectorRoomActivity.this)) {
                        startIpCall(isVideo);
                    }
                }

                @Override
                public void onVoiceCallClick() {
                    startCall(false);
                }

                @Override
                public void onVideoCallClick() {
                    startCall(true);
                }
            });

    View avatarLayout = findViewById(R.id.room_self_avatar);

    if (null != avatarLayout) {
        mAvatarImageView = (ImageView) avatarLayout.findViewById(R.id.avatar_img);
    }

    refreshSelfAvatar();

    // in case a "Send as" dialog was in progress when the activity was destroyed (life cycle)
    mVectorRoomMediasSender.resumeResizeMediaAndSend();

    // header visibility has launched
    enableActionBarHeader(intent.getBooleanExtra(EXTRA_EXPAND_ROOM_HEADER, false) ? SHOW_ACTION_BAR_HEADER
            : HIDE_ACTION_BAR_HEADER);

    // the both flags are only used once
    intent.removeExtra(EXTRA_EXPAND_ROOM_HEADER);

    Log.d(LOG_TAG, "End of create");
}

From source file:im.neon.activity.VectorRoomActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_vector_room);

    if (CommonActivityUtils.shouldRestartApp(this)) {
        Log.e(LOG_TAG, "onCreate : Restart the application.");
        CommonActivityUtils.restartApp(this);
        return;/*from ww  w.  j  a va  2 s.  c om*/
    }

    final Intent intent = getIntent();
    if (!intent.hasExtra(EXTRA_ROOM_ID)) {
        Log.e(LOG_TAG, "No room ID extra.");
        finish();
        return;
    }

    mSession = MXCActionBarActivity.getSession(this, intent);

    if (mSession == null) {
        Log.e(LOG_TAG, "No MXSession.");
        finish();
        return;
    }

    String roomId = intent.getStringExtra(EXTRA_ROOM_ID);

    // ensure that the preview mode is really expected
    if (!intent.hasExtra(EXTRA_ROOM_PREVIEW_ID)) {
        sRoomPreviewData = null;
        Matrix.getInstance(this).clearTmpStoresList();
    }

    if (CommonActivityUtils.isGoingToSplash(this, mSession.getMyUserId(), roomId)) {
        Log.d(LOG_TAG, "onCreate : Going to splash screen");
        return;
    }

    //setDragEdge(SwipeBackLayout.DragEdge.LEFT);

    // bind the widgets of the room header view. The room header view is displayed by
    // clicking on the title of the action bar
    mRoomHeaderView = (RelativeLayout) findViewById(R.id.action_bar_header);
    mActionBarHeaderRoomTopic = (TextView) findViewById(R.id.action_bar_header_room_topic);
    mActionBarHeaderRoomName = (TextView) findViewById(R.id.action_bar_header_room_title);
    mActionBarHeaderActiveMembers = (TextView) findViewById(R.id.action_bar_header_room_members);
    mActionBarHeaderRoomAvatar = (ImageView) mRoomHeaderView.findViewById(R.id.avatar_img);
    mActionBarHeaderInviteMemberView = mRoomHeaderView.findViewById(R.id.action_bar_header_invite_members);
    mRoomPreviewLayout = findViewById(R.id.room_preview_info_layout);
    mVectorPendingCallView = (VectorPendingCallView) findViewById(R.id.room_pending_call_view);
    mVectorOngoingConferenceCallView = (VectorOngoingConferenceCallView) findViewById(
            R.id.room_ongoing_conference_call_view);
    mE2eImageView = (ImageView) findViewById(R.id.room_encrypted_image_view);

    // hide the header room as soon as the bottom layout (text edit zone) is touched
    findViewById(R.id.room_bottom_layout).setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            enableActionBarHeader(HIDE_ACTION_BAR_HEADER);
            return false;
        }
    });

    // use a toolbar instead of the actionbar
    // to be able to display an expandable header
    mToolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.room_toolbar);
    this.setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // set the default custom action bar layout,
    // that will be displayed from the custom action bar layout
    setActionBarDefaultCustomLayout();

    mCallId = intent.getStringExtra(EXTRA_START_CALL_ID);
    mEventId = intent.getStringExtra(EXTRA_EVENT_ID);
    mDefaultRoomName = intent.getStringExtra(EXTRA_DEFAULT_NAME);
    mDefaultTopic = intent.getStringExtra(EXTRA_DEFAULT_TOPIC);

    // the user has tapped on the "View" notification button
    if ((null != intent.getAction()) && (intent.getAction().startsWith(NotificationUtils.TAP_TO_VIEW_ACTION))) {
        // remove any pending notifications
        NotificationManager notificationsManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationsManager.cancelAll();
    }

    Log.d(LOG_TAG, "Displaying " + roomId);

    mEditText = (EditText) findViewById(R.id.editText_messageBox);

    // hide the header room as soon as the message input text area is touched
    mEditText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            enableActionBarHeader(HIDE_ACTION_BAR_HEADER);
        }
    });

    // IME's DONE button is treated as a send action
    mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
            int imeActionId = actionId & EditorInfo.IME_MASK_ACTION;

            if (EditorInfo.IME_ACTION_DONE == imeActionId) {
                sendTextMessage();
            }

            return false;
        }
    });

    mSendingMessagesLayout = findViewById(R.id.room_sending_message_layout);
    mSendImageView = (ImageView) findViewById(R.id.room_send_image_view);
    mSendButtonLayout = findViewById(R.id.room_send_layout);
    mSendButtonLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!TextUtils.isEmpty(mEditText.getText())) {
                sendTextMessage();
            } else {
                // hide the header room
                enableActionBarHeader(HIDE_ACTION_BAR_HEADER);

                FragmentManager fm = getSupportFragmentManager();
                IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm
                        .findFragmentByTag(TAG_FRAGMENT_ATTACHMENTS_DIALOG);

                if (fragment != null) {
                    fragment.dismissAllowingStateLoss();
                }

                final Integer[] messages = new Integer[] { R.string.option_send_files,
                        R.string.option_take_photo_video, };

                final Integer[] icons = new Integer[] { R.drawable.ic_material_file, // R.string.option_send_files
                        R.drawable.ic_material_camera, // R.string.option_take_photo
                };

                fragment = IconAndTextDialogFragment.newInstance(icons, messages, null,
                        ContextCompat.getColor(VectorRoomActivity.this, R.color.vector_text_black_color));
                fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() {
                    @Override
                    public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) {
                        Integer selectedVal = messages[position];

                        if (selectedVal == R.string.option_send_files) {
                            VectorRoomActivity.this.launchFileSelectionIntent();
                        } else if (selectedVal == R.string.option_take_photo_video) {
                            if (CommonActivityUtils.checkPermissions(
                                    CommonActivityUtils.REQUEST_CODE_PERMISSION_TAKE_PHOTO,
                                    VectorRoomActivity.this)) {
                                launchCamera();
                            }
                        }
                    }
                });

                fragment.show(fm, TAG_FRAGMENT_ATTACHMENTS_DIALOG);
            }
        }
    });

    mEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(android.text.Editable s) {
            if (null != mRoom) {
                MXLatestChatMessageCache latestChatMessageCache = VectorRoomActivity.this.mLatestChatMessageCache;
                String textInPlace = latestChatMessageCache.getLatestText(VectorRoomActivity.this,
                        mRoom.getRoomId());

                // check if there is really an update
                // avoid useless updates (initializations..)
                if (!mIgnoreTextUpdate && !textInPlace.equals(mEditText.getText().toString())) {
                    latestChatMessageCache.updateLatestMessage(VectorRoomActivity.this, mRoom.getRoomId(),
                            mEditText.getText().toString());
                    handleTypingNotification(mEditText.getText().length() != 0);
                }

                manageSendMoreButtons();
                refreshCallButtons();
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    mVectorPendingCallView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            IMXCall call = VectorCallViewActivity.getActiveCall();
            if (null != call) {
                final Intent intent = new Intent(VectorRoomActivity.this, VectorCallViewActivity.class);
                intent.putExtra(VectorCallViewActivity.EXTRA_MATRIX_ID,
                        call.getSession().getCredentials().userId);
                intent.putExtra(VectorCallViewActivity.EXTRA_CALL_ID, call.getCallId());

                VectorRoomActivity.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        VectorRoomActivity.this.startActivity(intent);
                    }
                });
            } else {
                // if the call is no more active, just remove the view
                mVectorPendingCallView.onCallTerminated();
            }
        }
    });

    mActionBarHeaderInviteMemberView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            launchRoomDetails(VectorRoomDetailsActivity.PEOPLE_TAB_INDEX);
        }
    });

    // notifications area
    mNotificationsArea = findViewById(R.id.room_notifications_area);
    mNotificationIconImageView = (ImageView) mNotificationsArea.findViewById(R.id.room_notification_icon);
    mNotificationTextView = (TextView) mNotificationsArea.findViewById(R.id.room_notification_message);

    mCanNotPostTextView = findViewById(R.id.room_cannot_post_textview);

    // increase the clickable area to open the keyboard.
    // when there is no text, it is quite small and some user thought the edition was disabled.
    findViewById(R.id.room_sending_message_layout).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mEditText.requestFocus()) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT);
            }
        }
    });

    mStartCallLayout = findViewById(R.id.room_start_call_layout);
    mStartCallLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if ((null != mRoom) && mRoom.isEncrypted() && (mRoom.getActiveMembers().size() > 2)) {
                // display the dialog with the info text
                AlertDialog.Builder permissionsInfoDialog = new AlertDialog.Builder(VectorRoomActivity.this);
                Resources resource = getResources();
                permissionsInfoDialog
                        .setMessage(resource.getString(R.string.room_no_conference_call_in_encrypted_rooms));
                permissionsInfoDialog.setIcon(android.R.drawable.ic_dialog_alert);
                permissionsInfoDialog.setPositiveButton(resource.getString(R.string.ok), null);
                permissionsInfoDialog.show();

            } else if (isUserAllowedToStartConfCall()) {
                displayVideoCallIpDialog();
            } else {
                displayConfCallNotAllowed();
            }
        }
    });

    mStopCallLayout = findViewById(R.id.room_end_call_layout);
    mStopCallLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            IMXCall call = mSession.mCallsManager.getCallWithRoomId(mRoom.getRoomId());

            if (null != call) {
                call.hangup(null);
            }
        }
    });

    findViewById(R.id.room_button_margin_right).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // extend the right side of right button
            // to avoid clicking in the void
            if (mStopCallLayout.getVisibility() == View.VISIBLE) {
                mStopCallLayout.performClick();
            } else if (mStartCallLayout.getVisibility() == View.VISIBLE) {
                mStartCallLayout.performClick();
            } else if (mSendButtonLayout.getVisibility() == View.VISIBLE) {
                mSendButtonLayout.performClick();
            }
        }
    });

    mMyUserId = mSession.getCredentials().userId;

    CommonActivityUtils.resumeEventStream(this);

    mRoom = mSession.getDataHandler().getRoom(roomId, false);

    FragmentManager fm = getSupportFragmentManager();
    mVectorMessageListFragment = (VectorMessageListFragment) fm
            .findFragmentByTag(TAG_FRAGMENT_MATRIX_MESSAGE_LIST);

    if (mVectorMessageListFragment == null) {
        Log.d(LOG_TAG, "Create VectorMessageListFragment");

        // this fragment displays messages and handles all message logic
        mVectorMessageListFragment = VectorMessageListFragment.newInstance(mMyUserId, roomId, mEventId,
                (null == sRoomPreviewData) ? null : VectorMessageListFragment.PREVIEW_MODE_READ_ONLY,
                org.matrix.androidsdk.R.layout.fragment_matrix_message_list_fragment);
        fm.beginTransaction().add(R.id.anchor_fragment_messages, mVectorMessageListFragment,
                TAG_FRAGMENT_MATRIX_MESSAGE_LIST).commit();
    } else {
        Log.d(LOG_TAG, "Reuse VectorMessageListFragment");
    }

    mVectorRoomMediasSender = new VectorRoomMediasSender(this, mVectorMessageListFragment,
            Matrix.getInstance(this).getMediasCache());
    mVectorRoomMediasSender.onRestoreInstanceState(savedInstanceState);

    manageRoomPreview();

    addRoomHeaderClickListeners();

    // in timeline mode (i.e search in the forward and backward room history)
    // or in room preview mode
    // the edition items are not displayed
    if (!TextUtils.isEmpty(mEventId) || (null != sRoomPreviewData)) {
        mNotificationsArea.setVisibility(View.GONE);
        findViewById(R.id.bottom_separator).setVisibility(View.GONE);
        findViewById(R.id.room_notification_separator).setVisibility(View.GONE);
        findViewById(R.id.room_notifications_area).setVisibility(View.GONE);

        View v = findViewById(R.id.room_bottom_layout);
        ViewGroup.LayoutParams params = v.getLayoutParams();
        params.height = 0;
        v.setLayoutParams(params);
    }

    mLatestChatMessageCache = Matrix.getInstance(this).getDefaultLatestChatMessageCache();

    // some medias must be sent while opening the chat
    if (intent.hasExtra(EXTRA_ROOM_INTENT)) {
        final Intent mediaIntent = intent.getParcelableExtra(EXTRA_ROOM_INTENT);

        // sanity check
        if (null != mediaIntent) {
            mEditText.postDelayed(new Runnable() {
                @Override
                public void run() {
                    intent.removeExtra(EXTRA_ROOM_INTENT);
                    sendMediasIntent(mediaIntent);
                }
            }, 1000);
        }
    }

    mVectorOngoingConferenceCallView.initRoomInfo(mSession, mRoom);
    mVectorOngoingConferenceCallView
            .setCallClickListener(new VectorOngoingConferenceCallView.ICallClickListener() {

                private void startCall(boolean isVideo) {
                    if (CommonActivityUtils.checkPermissions(
                            isVideo ? CommonActivityUtils.REQUEST_CODE_PERMISSION_VIDEO_IP_CALL
                                    : CommonActivityUtils.REQUEST_CODE_PERMISSION_AUDIO_IP_CALL,
                            VectorRoomActivity.this)) {
                        startIpCall(isVideo);
                    }
                }

                @Override
                public void onVoiceCallClick() {
                    startCall(false);
                }

                @Override
                public void onVideoCallClick() {
                    startCall(true);
                }
            });

    View avatarLayout = findViewById(R.id.room_self_avatar);

    if (null != avatarLayout) {
        mAvatarImageView = (ImageView) avatarLayout.findViewById(R.id.avatar_img);
    }

    refreshSelfAvatar();

    // in case a "Send as" dialog was in progress when the activity was destroyed (life cycle)
    mVectorRoomMediasSender.resumeResizeMediaAndSend();

    // header visibility has launched
    enableActionBarHeader(intent.getBooleanExtra(EXTRA_EXPAND_ROOM_HEADER, false) ? SHOW_ACTION_BAR_HEADER
            : HIDE_ACTION_BAR_HEADER);

    // the both flags are only used once
    intent.removeExtra(EXTRA_EXPAND_ROOM_HEADER);

    Log.d(LOG_TAG, "End of create");
}

From source file:com.facebook.react.views.textinput.ReactTextInputManager.java

@Override
protected void addEventEmitters(final ThemedReactContext reactContext, final ReactEditText editText) {
    editText.addTextChangedListener(new ReactTextInputTextWatcher(reactContext, editText));
    editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class)
                    .getEventDispatcher();
            if (hasFocus) {
                eventDispatcher.dispatchEvent(new ReactTextInputFocusEvent(editText.getId()));
            } else {
                eventDispatcher.dispatchEvent(new ReactTextInputBlurEvent(editText.getId()));

                eventDispatcher.dispatchEvent(
                        new ReactTextInputEndEditingEvent(editText.getId(), editText.getText().toString()));
            }//www  .ja v a 2  s  . c  om
        }
    });

    editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent keyEvent) {
            // Any 'Enter' action will do
            if ((actionId & EditorInfo.IME_MASK_ACTION) > 0 || actionId == EditorInfo.IME_NULL) {
                EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class)
                        .getEventDispatcher();
                eventDispatcher.dispatchEvent(
                        new ReactTextInputSubmitEditingEvent(editText.getId(), editText.getText().toString()));
            }

            if (editText.getBlurOnSubmit()) {
                editText.clearFocus();
            }

            return true;
        }
    });
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewBase.java

public void setKeyboardActionType(final int imeOptions) {
    if ((imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0)
        //IME_FLAG_NO_ENTER_ACTION:
        // Flag of imeOptions: used in conjunction with one of the actions masked by IME_MASK_ACTION.
        // If this flag is not set, IMEs will normally replace the "enter" key with the action supplied.
        // This flag indicates that the action should not be available in-line as a replacement for the "enter" key.
        // Typically this is because the action has such a significant impact or is not recoverable enough
        // that accidentally hitting it should be avoided, such as sending a message.
        // Note that TextView will automatically set this flag for you on multi-line text views.
        mKeyboardActionType = EditorInfo.IME_ACTION_NONE;
    else/*from  www.j  av  a 2s .  co m*/
        mKeyboardActionType = (imeOptions & EditorInfo.IME_MASK_ACTION);

    // setting the icon/text
    setSpecialKeysIconsAndLabels();
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java

public void setKeyboardActionType(final int imeOptions) {
    Log.d(TAG, "setKeyboardActionType imeOptions:" + imeOptions + " action:"
            + (imeOptions & EditorInfo.IME_MASK_ACTION));
    if ((imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0)// this is
        // usually a
        // multi-line
        // edittext
        // box//from   w ww  .  j a  v a2  s  .c om
        mKeyboardActionType = EditorInfo.IME_ACTION_UNSPECIFIED;
    else
        mKeyboardActionType = (imeOptions & EditorInfo.IME_MASK_ACTION);

    // setting the icon/text
    setSpecialKeysIconsAndLabels();
}