Example usage for android.view KeyEvent getAction

List of usage examples for android.view KeyEvent getAction

Introduction

In this page you can find the example usage for android.view KeyEvent getAction.

Prototype

public final int getAction() 

Source Link

Document

Retrieve the action of this key event.

Usage

From source file:com.mifos.mifosxdroid.LoginActivity.java

@OnEditorAction(R.id.et_password)
public boolean passwordSubmitted(KeyEvent keyEvent) {
    if (keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
        login(false);//  ww  w.j av a2 s. co  m
        return true;
    }
    return false;
}

From source file:com.gao.im.ui.CCPFragment.java

/**
 * ?// www .  ja v  a2  s  .co  m
 * @param keyCode
 * @param event
 * @return
 */
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && event.getAction() == KeyEvent.ACTION_DOWN) {
        finish();
        return true;
    }
    return false;
}

From source file:com.velli.passwordmanager.FragmentLockScreen.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER) {
        onClick(mButtonOk);/* w ww  . j av  a  2 s  .c  om*/
    }
    return false;
}

From source file:com.notepadlite.NoteEditActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override//from   w w w  .j av  a  2 s  .  c  o  m
public boolean dispatchKeyShortcutEvent(KeyEvent event) {
    super.dispatchKeyShortcutEvent(event);
    if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) {
        NoteEditFragment fragment = (NoteEditFragment) getSupportFragmentManager()
                .findFragmentByTag("NoteEditFragment");
        fragment.dispatchKeyShortcutEvent(event.getKeyCode());

        return true;
    }
    return super.dispatchKeyShortcutEvent(event);
}

From source file:org.linesofcode.alltrack.graph.AddValueActivity.java

private void initializeContent() {
    calendar = Calendar.getInstance();
    dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
    timeFormat = new SimpleDateFormat(TIME_PATTERN, Locale.getDefault());

    dateView = (TextView) findViewById(R.id.add_value_date);
    timeView = (TextView) findViewById(R.id.add_value_time);

    Button okButton = (Button) findViewById(R.id.add_value_ok);
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override//from ww w.j av  a2s  .  co  m
        public void onClick(View v) {
            addValue();
        }
    });

    Button cancelButton = (Button) findViewById(R.id.add_value_cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setResult(Activity.RESULT_CANCELED, new Intent(ADD_VALUE_ACTION_CODE));
            finish();
        }
    });

    EditText value = (EditText) findViewById(R.id.add_value_value);
    value.setOnKeyListener(new View.OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_ENTER:
                    addValue();
                    return true;
                }
            }
            return false;
        }
    });

    dateView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDatePicker();
        }
    });

    timeView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showTimePicker();
        }
    });

    updateDateTimeFields();

    Bundle extras = getIntent().getExtras();
    graphId = extras.getInt("graphId");
    position = extras.getInt("position");
    Log.d(TAG, "Starting addValue Activity for graph [" + graphId + "] in position [" + position + "].");
    graph = graphService.getById(graphId);
}

From source file:org.videolan.vlc.gui.dialogs.PickTimeFragment.java

@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
    if (event.getAction() != KeyEvent.ACTION_DOWN)
        return false;
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_DOWN:
        updateViews(keyCode);//from   w w  w  .j ava  2  s  . c  o  m
        return true;
    }
    return false;
}

From source file:com.redditandroiddevelopers.ircclient.ChannelFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View base = inflater.inflate(R.layout.chat_fragment, container, false);
    mChatContents = (TextView) base.findViewById(R.id.chat);
    mChatInput = (EditText) base.findViewById(R.id.edit);
    scroller = (ScrollView) base.findViewById(R.id.scroller);

    configureMessageHandler();//ww  w .jav a  2s  .c  o  m

    if (ircClient == null) {
        ircClient = new IRCClient(nick, handler);
    }

    if (!ircClient.isConnected()) {
        ircClient.setLoginPublic(userName);
        connect();
        ircClient.identify(userPass);
    }

    mChatInput.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                String inputText = mChatInput.getText().toString();
                if (inputText.equals("/disconnect") || inputText == "/disconnect") {
                    ircClient.quitServer("I work when i want. You're not the boss of me.");
                } else if (inputText.matches("^/nick .*")) {
                    nick = ircClient.getNick();
                    String[] args = inputText.split(" ");
                    String newNick = args[1];
                    ircClient.changeNick(newNick);
                    boolean changeNickSuccessful = !(nick.equals(newNick)); // TODO: Not functioning properly
                    if (!changeNickSuccessful) {
                        showError(newNick + " already in use.");
                    }
                    nick = ircClient.getNick();
                } else if (inputText.matches("^/join .*")) {
                    String[] args = inputText.split(" ");
                    String newChannel = args[1];
                    ircClient.joinChannel(newChannel);
                    channel = newChannel;
                } else {
                    if (inputText == "" || (inputText.equals("")) || inputText == null) {
                        showError("Invalid input");
                    } else {
                        sendMessage(inputText);
                    }
                }

                mChatInput.setText("");
                return true;
            }
            return false;
        }
    });

    return base;
}

From source file:com.stoutner.privacybrowser.CreateHomeScreenShortcut.java

@Override
@NonNull//from  w  w  w  .j a  v  a  2s.c  o m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Create a drawable version of the favorite icon.
    Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebViewActivity.favoriteIcon);

    // Use AlertDialog.Builder to create the AlertDialog
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
    LayoutInflater customDialogInflater = getActivity().getLayoutInflater();
    alertDialogBuilder.setTitle(R.string.shortcut_name);
    alertDialogBuilder.setIcon(favoriteIconDrawable);
    alertDialogBuilder.setView(customDialogInflater.inflate(R.layout.create_home_screen_shortcut_dialog, null));
    alertDialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            buttonListener.onCreateHomeScreenShortcutCancel(CreateHomeScreenShortcut.this);
        }
    });
    alertDialogBuilder.setPositiveButton(R.string.create, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            buttonListener.onCreateHomeScreenShortcutCreate(CreateHomeScreenShortcut.this);
        }
    });

    // Assign the alertDialogBuilder to an AlertDialog.
    final AlertDialog alertDialog = alertDialogBuilder.create();

    // Show the keyboard when the dialog is displayed on the screen.
    alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

    // We need to show alertDialog before we can setOnKeyListener below.
    alertDialog.show();

    EditText shortcutNameEditText = (EditText) alertDialog.findViewById(R.id.shortcutNameEditText);

    // Allow the "enter" key on the keyboard to create the shortcut.
    shortcutNameEditText.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button, select the PositiveButton "Create".
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // Trigger the create listener.
                buttonListener.onCreateHomeScreenShortcutCreate(CreateHomeScreenShortcut.this);

                // Manually dismiss alertDialog.
                alertDialog.dismiss();

                // Consume the event.
                return true;
            } else {
                // If any other key was pressed, do not consume the event.
                return false;
            }
        }
    });

    // onCreateDialog requires the return of an AlertDialog.
    return alertDialog;
}

From source file:com.android.settings.SeekBarPreference.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (event.getAction() != KeyEvent.ACTION_DOWN) {
        return false;
    }/*w  w w . j a v  a2 s  .co  m*/

    SeekBar seekBar = (SeekBar) v.findViewById(com.android.internal.R.id.seekbar);
    if (seekBar == null) {
        return false;
    }
    return seekBar.onKeyDown(keyCode, event);
}

From source file:com.anjalimacwan.activity.NoteEditActivity.java

@Override
public boolean dispatchKeyShortcutEvent(KeyEvent event) {
    super.dispatchKeyShortcutEvent(event);
    if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) {
        NoteEditFragment fragment = (NoteEditFragment) getSupportFragmentManager()
                .findFragmentByTag("NoteEditFragment");
        fragment.dispatchKeyShortcutEvent(event.getKeyCode());

        return true;
    }//from   w  ww  .j  a v a  2  s .c  o  m
    return super.dispatchKeyShortcutEvent(event);
}