Search in sources :

Example 51 with KeyEvent

use of android.view.KeyEvent in project weiciyuan by qii.

the class UserAvatarDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    String path = getArguments().getString("path");
    final Rect ori = getArguments().getParcelable("rect");
    Bitmap bitmap = BitmapFactory.decodeFile(path);
    final View content = getActivity().getLayoutInflater().inflate(R.layout.useravatardialog_layout, null);
    final ImageView avatar = ((ImageView) content.findViewById(R.id.imageview));
    avatar.setImageBitmap(bitmap);
    avatar.setClickable(true);
    content.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            animateClose(avatar, ori);
        }
    });
    Dialog dialog = new Dialog(getActivity(), R.style.UserAvatarDialog) {

        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                animateClose(avatar, ori);
                return true;
            }
            return super.onKeyDown(keyCode, event);
        }
    };
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(content);
    content.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            content.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            if (ori == null) {
                return;
            }
            int[] avatarLocation = new int[2];
            avatar.getLocationOnScreen(avatarLocation);
            final int transX = ori.left - avatarLocation[0];
            final int transY = ori.top - avatarLocation[1];
            final float scaleX = (float) ori.width() / (float) avatar.getWidth();
            final float scaleY = (float) ori.height() / (float) avatar.getHeight();
            avatar.setTranslationX(transX);
            avatar.setTranslationY(transY);
            avatar.setPivotX(0);
            avatar.setPivotY(0);
            avatar.setScaleX(scaleX);
            avatar.setScaleY(scaleY);
            avatar.animate().translationX(0).translationY(0).scaleY(1).scaleX(1).alpha(1.0f).setDuration(300).withEndAction(new Runnable() {

                @Override
                public void run() {
                }
            });
        }
    });
    dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    return dialog;
}
Also used : KeyEvent(android.view.KeyEvent) Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) Dialog(android.app.Dialog) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) ViewTreeObserver(android.view.ViewTreeObserver)

Example 52 with KeyEvent

use of android.view.KeyEvent in project xabber-android by redsolution.

the class ChatViewerFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.chat_viewer_fragment, container, false);
    contactTitleView = view.findViewById(R.id.contact_title);
    abstractContact = RosterManager.getInstance().getBestContact(account, user);
    contactTitleView.findViewById(R.id.avatar).setOnClickListener(this);
    toolbar = (Toolbar) view.findViewById(R.id.toolbar_default);
    toolbar.inflateMenu(R.menu.chat);
    toolbar.setOnMenuItemClickListener(this);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            NavUtils.navigateUpFromSameTask(getActivity());
        }
    });
    setHasOptionsMenu(true);
    sendButton = (ImageButton) view.findViewById(R.id.button_send_message);
    sendButton.setColorFilter(ColorManager.getInstance().getAccountPainter().getGreyMain());
    AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
    securityButton = (ImageButton) view.findViewById(R.id.button_security);
    if (abstractChat instanceof RegularChat) {
        securityButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                showSecurityMenu();
            }
        });
    } else {
        securityButton.setVisibility(View.GONE);
    }
    chatMessageAdapter = new ChatMessageAdapter(getActivity(), account, user, this, this);
    recyclerView = (RecyclerView) view.findViewById(R.id.chat_messages_recycler_view);
    recyclerView.setAdapter(chatMessageAdapter);
    layoutManager = new LinearLayoutManager(getActivity());
    layoutManager.setStackFromEnd(true);
    recyclerView.setLayoutManager(layoutManager);
    // to avoid strange bug on some 4.x androids
    view.findViewById(R.id.input_layout).setBackgroundColor(ColorManager.getInstance().getChatInputBackgroundColor());
    inputView = (EditText) view.findViewById(R.id.chat_input);
    view.findViewById(R.id.button_send_message).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            sendMessage();
        }
    });
    inputView.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent event) {
            if (SettingsManager.chatsSendByEnter() && event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                sendMessage();
                return true;
            }
            return false;
        }
    });
    inputView.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!skipOnTextChanges && stopTypingTimer != null) {
                stopTypingTimer.cancel();
            }
        }

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

        @Override
        public void afterTextChanged(Editable text) {
            setUpInputViewButtons();
            if (skipOnTextChanges) {
                return;
            }
            ChatStateManager.getInstance().onComposing(account, user, text);
            stopTypingTimer = new Timer();
            stopTypingTimer.schedule(new TimerTask() {

                @Override
                public void run() {
                    Application.getInstance().runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            ChatStateManager.getInstance().onPaused(account, user);
                        }
                    });
                }
            }, STOP_TYPING_DELAY);
        }
    });
    final ImageButton emojiButton = (ImageButton) view.findViewById(R.id.button_emoticon);
    final View rootView = view.findViewById(R.id.root_view);
    // Give the topmost view of your activity layout hierarchy. This will be used to measure soft keyboard height
    final EmojiconsPopup popup = new EmojiconsPopup(rootView, getActivity());
    //Will automatically set size according to the soft keyboard size
    popup.setSizeForSoftKeyboard();
    //If the emoji popup is dismissed, change emojiButton to smiley icon
    popup.setOnDismissListener(new PopupWindow.OnDismissListener() {

        @Override
        public void onDismiss() {
            changeEmojiKeyboardIcon(emojiButton, R.drawable.ic_mood_black_24dp);
        }
    });
    //If the text keyboard closes, also dismiss the emoji popup
    popup.setOnSoftKeyboardOpenCloseListener(new EmojiconsPopup.OnSoftKeyboardOpenCloseListener() {

        @Override
        public void onKeyboardOpen(int keyBoardHeight) {
        }

        @Override
        public void onKeyboardClose() {
            if (popup.isShowing())
                popup.dismiss();
        }
    });
    //On emoji clicked, add it to edittext
    popup.setOnEmojiconClickedListener(new EmojiconGridView.OnEmojiconClickedListener() {

        @Override
        public void onEmojiconClicked(Emojicon emojicon) {
            if (inputView == null || emojicon == null) {
                return;
            }
            int start = inputView.getSelectionStart();
            int end = inputView.getSelectionEnd();
            if (start < 0) {
                inputView.append(emojicon.getEmoji());
            } else {
                inputView.getText().replace(Math.min(start, end), Math.max(start, end), emojicon.getEmoji(), 0, emojicon.getEmoji().length());
            }
        }
    });
    //On backspace clicked, emulate the KEYCODE_DEL key event
    popup.setOnEmojiconBackspaceClickedListener(new EmojiconsPopup.OnEmojiconBackspaceClickedListener() {

        @Override
        public void onEmojiconBackspaceClicked(View v) {
            KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
            inputView.dispatchKeyEvent(event);
        }
    });
    // To toggle between text keyboard and emoji keyboard keyboard(Popup)
    emojiButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //If popup is not showing => emoji keyboard is not visible, we need to show it
            if (!popup.isShowing()) {
                //If keyboard is visible, simply show the emoji popup
                if (popup.isKeyBoardOpen()) {
                    popup.showAtBottom();
                    changeEmojiKeyboardIcon(emojiButton, R.drawable.ic_keyboard_black_24dp);
                } else //else, open the text keyboard first and immediately after that show the emoji popup
                {
                    inputView.setFocusableInTouchMode(true);
                    inputView.requestFocus();
                    popup.showAtBottomPending();
                    final InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                    inputMethodManager.showSoftInput(inputView, InputMethodManager.SHOW_IMPLICIT);
                    changeEmojiKeyboardIcon(emojiButton, R.drawable.ic_keyboard_black_24dp);
                }
            } else //If popup is showing, simply dismiss it to show the undelying text keyboard
            {
                popup.dismiss();
            }
        }
    });
    attachButton = (ImageButton) view.findViewById(R.id.button_attach);
    attachButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onAttachButtonPressed();
        }
    });
    return view;
}
Also used : EmojiconGridView(github.ankushsachdeva.emojicon.EmojiconGridView) PopupWindow(android.widget.PopupWindow) ChatMessageAdapter(com.xabber.android.ui.adapter.ChatMessageAdapter) InputMethodManager(android.view.inputmethod.InputMethodManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RegularChat(com.xabber.android.data.message.RegularChat) KeyEvent(android.view.KeyEvent) ImageButton(android.widget.ImageButton) TimerTask(java.util.TimerTask) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) EmojiconsPopup(github.ankushsachdeva.emojicon.EmojiconsPopup) AbstractChat(com.xabber.android.data.message.AbstractChat) ImageView(android.widget.ImageView) View(android.view.View) EmojiconGridView(github.ankushsachdeva.emojicon.EmojiconGridView) RecyclerView(android.support.v7.widget.RecyclerView) Timer(java.util.Timer) Emojicon(github.ankushsachdeva.emojicon.emoji.Emojicon)

Example 53 with KeyEvent

use of android.view.KeyEvent in project roboguice by roboguice.

the class AstroboyMasterConsole method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    // @Inject, @InjectResource, and @InjectExtra injection happens during super.onCreate()
    super.onCreate(savedInstanceState);
    sayText.setOnEditorActionListener(new OnEditorActionListener() {

        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            // Have the remoteControl tell Astroboy to say something
            remoteControl.say(textView.getText().toString());
            textView.setText(null);
            return true;
        }
    });
    brushTeethButton.setOnClickListener(new OnClickListener() {

        public void onClick(View view) {
            remoteControl.brushTeeth();
        }
    });
    selfDestructButton.setOnClickListener(new OnClickListener() {

        public void onClick(View view) {
            // Self destruct the remoteControl
            vibrator.vibrate(2000);
            remoteControl.selfDestruct();
        }
    });
    // Fighting the forces of evil deserves its own activity
    fightEvilButton.setOnClickListener(new OnClickListener() {

        public void onClick(View view) {
            startActivity(new Intent(AstroboyMasterConsole.this, FightForcesOfEvilActivity.class));
        }
    });
}
Also used : KeyEvent(android.view.KeyEvent) OnClickListener(android.view.View.OnClickListener) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) TextView(android.widget.TextView) Intent(android.content.Intent) ContentView(roboguice.inject.ContentView) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) View(android.view.View)

Example 54 with KeyEvent

use of android.view.KeyEvent in project android-app by spark.

the class SignUpActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent nextActivityToSkipTo = getNextActivityToSkipTo();
    // NOTE EARLY RETURN HERE
    if (nextActivityToSkipTo != null) {
        if (!isFinishing()) {
            startActivity(nextActivityToSkipTo);
        }
        finish();
        return;
    }
    setContentView(R.layout.activity_sign_up);
    mEmailView = Ui.findView(this, R.id.email);
    mPasswordView = Ui.findView(this, R.id.password);
    Ui.setTextFromHtml(this, R.id.already_have_account, R.string.i_already_have_an_account);
    TextView finePrint = Ui.setTextFromHtml(this, R.id.fine_print, R.string.sign_up_fine_print);
    finePrint.setMovementMethod(LinkMovementMethod.getInstance());
    mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == R.id.login || id == EditorInfo.IME_NULL) {
                attemptLogin();
                return true;
            }
            return false;
        }
    });
    accountAction = Ui.findView(this, R.id.sign_up_button);
    accountAction.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            attemptLogin();
        }
    });
    // keyboard pops up
    for (View view : list(mPasswordView, mEmailView)) {
        view.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    scrollAccountForm();
                }
                return false;
            }
        });
    }
    findViewById(R.id.already_have_account).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(SignUpActivity.this, LoginActivity.class));
            finish();
        }
    });
}
Also used : KeyEvent(android.view.KeyEvent) OnTouchListener(android.view.View.OnTouchListener) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) TextView(android.widget.TextView) OnClickListener(android.view.View.OnClickListener) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) MotionEvent(android.view.MotionEvent)

Example 55 with KeyEvent

use of android.view.KeyEvent in project platform_frameworks_base by android.

the class PasswordEntryKeyboardHelper method sendKeyEventsToTarget.

private void sendKeyEventsToTarget(int character) {
    ViewRootImpl viewRootImpl = mTargetView.getViewRootImpl();
    KeyEvent[] events = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD).getEvents(new char[] { (char) character });
    if (events != null) {
        final int N = events.length;
        for (int i = 0; i < N; i++) {
            KeyEvent event = events[i];
            event = KeyEvent.changeFlags(event, event.getFlags() | KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);
            viewRootImpl.dispatchInputEvent(event);
        }
    }
}
Also used : ViewRootImpl(android.view.ViewRootImpl) KeyEvent(android.view.KeyEvent)

Aggregations

KeyEvent (android.view.KeyEvent)499 View (android.view.View)135 TextView (android.widget.TextView)100 Intent (android.content.Intent)49 DialogInterface (android.content.DialogInterface)36 KeyCharacterMap (android.view.KeyCharacterMap)35 EditText (android.widget.EditText)35 ImageView (android.widget.ImageView)33 OnEditorActionListener (android.widget.TextView.OnEditorActionListener)32 Editable (android.text.Editable)31 Instrumentation (android.app.Instrumentation)30 Paint (android.graphics.Paint)27 OnClickListener (android.view.View.OnClickListener)27 Button (android.widget.Button)26 AlertDialog (android.app.AlertDialog)21 Message (android.os.Message)21 TextWatcher (android.text.TextWatcher)21 LayoutInflater (android.view.LayoutInflater)21 InputMethodManager (android.view.inputmethod.InputMethodManager)20 Test (org.junit.Test)20