Example usage for android.view KeyEvent ACTION_DOWN

List of usage examples for android.view KeyEvent ACTION_DOWN

Introduction

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

Prototype

int ACTION_DOWN

To view the source code for android.view KeyEvent ACTION_DOWN.

Click Source Link

Document

#getAction value: the key has been pressed down.

Usage

From source file:com.timothy.android.api.activity.SlidingActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        if ((System.currentTimeMillis() - exitTime) > 2000) {
            Toast.makeText(getApplicationContext(), this.getResources().getString(R.string.msg_exit_hint),
                    Toast.LENGTH_SHORT).show();
            exitTime = System.currentTimeMillis();
        } else {// w  ww.  java  2 s.c o m
            finish();
            ActivityManage.finishProgram();
            System.exit(0);
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.videolan.vlc.gui.MRLPanelFragment.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == EditorInfo.IME_ACTION_DONE || keyCode == EditorInfo.IME_ACTION_GO
            || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
        return processUri();
    }//from  www  .  j a v  a  2  s. c om
    return false;
}

From source file:com.mstar.tv.tvplayer.philips.option.OptionFirstFragment.java

@Override
public void onStart() {
    super.onStart();
    listView = getListView();/*from  w  w w.java2 s . c om*/
    if (getFragmentManager().findFragmentById(R.id.first_fragment) != null) {
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    }
    listView.setDivider(null);
    listView.setDividerHeight(5);
    listView.setSelector(android.R.color.transparent);
    listView.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            settingAdapter.setSelectViewPosition(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    listView.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            // TODO Auto-generated method stub

            if (OptionKarrays.isFromLauncher) {
                if (!isWifiOpen() && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {//wifi has not open
                    if (listView.getSelectedItemPosition() == 1 && keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {//???
                        listView.setSelection(3);
                        return true;
                    } else if (listView.getSelectedItemPosition() == 3 && keyCode == KeyEvent.KEYCODE_DPAD_UP) {
                        listView.setSelection(1);
                        return true;
                    }
                }
            }
            return false;
        }
    });
}

From source file:eu.andlabs.studiolounge.chat.ChatFragment.java

@Override
public View onCreateView(final LayoutInflater infl, ViewGroup p, Bundle b) {
    final View chat = infl.inflate(R.layout.chat, p, false);
    mChatEditText = ((EditText) chat.findViewById(R.id.msg_field));
    ((ImageButton) chat.findViewById(R.id.btn_msgSend)).setOnClickListener(this);
    ((ListView) chat.findViewById(R.id.list)).setAdapter(new BaseAdapter() {
        @Override//  w ww .j a  v  a 2  s .c  o  m
        public int getCount() {
            return mConversation.size();
        }

        @Override
        public View getView(int position, View view, ViewGroup parent) {
            if (view == null)
                view = infl.inflate(R.layout.chat_list_entry, null);
            final ChatMessage msg = mConversation.get(position);
            final Player player = new Player(msg.player);
            ((TextView) view.findViewById(R.id.sender)).setText(player.getShortPlayername());
            ((TextView) view.findViewById(R.id.msg_text)).setText(msg.text);
            return view;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }
    });
    // http://code.google.com/p/android/issues/detail?id=2516
    mChatEditText.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
                onClick(null);
                return true;
            }
            return false;
        }
    });
    return chat;
}

From source file:com.dragedy.playermusic.service.MediaButtonIntentReceiver.java

public static boolean handleIntent(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return false;
        }//ww w  . j a  va  2s. c  o m

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventTime = event.getEventTime();

        String command = null;
        switch (keycode) {
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = MusicService.ACTION_STOP;
            break;
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = MusicService.ACTION_TOGGLE_PAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = MusicService.ACTION_SKIP;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = MusicService.ACTION_REWIND;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = MusicService.ACTION_PAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = MusicService.ACTION_PLAY;
            break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (event.getRepeatCount() == 0) {
                    // Only consider the first event in a sequence, not the repeat events,
                    // so that we don't trigger in cases where the first event went to
                    // a different app (e.g. when the user ends a phone call by
                    // long pressing the headset button)

                    // The service may or may not be running, but we need to send it
                    // a command.
                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventTime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        if (DEBUG)
                            Log.v(TAG, "Got headset click, count = " + mClickCounter);
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0,
                                context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventTime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:com.gigaset.home.Home.java

/**
 * Catch keys to avoid back through HOME in Back Stack
 *//* w ww  .j  a v  a  2 s .co m*/
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_BACK:
            return true;
        case KeyEvent.KEYCODE_HOME:
            return true;
        }
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_BACK:
            if (!event.isCanceled()) {
                // Do BACK behavior.
            }
            return true;
        case KeyEvent.KEYCODE_HOME:
            if (!event.isCanceled()) {
                // Do HOME behavior.
                myPager.setCurrentItem(HomePagerAdapter.SCREEN_CENTER);
            }
            return true;
        }
    }

    return super.dispatchKeyEvent(event);
}

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

/**
 * ?//  w ww.j  a  v a2  s . c om
 * @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: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  w  w  w  . j a v a  2 s . c  o 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.catrobat.catroid.ui.dialogs.TextDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_text_dialog, null);
    input = (EditText) dialogView.findViewById(R.id.dialog_text_edit_text);
    inputTitle = (TextView) dialogView.findViewById(R.id.dialog_text_text_view);

    if (getHint() != null) {
        input.setHint(getHint());//from  w ww. jav a  2s  . c  o  m
    }

    input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                getDialog().getWindow()
                        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });

    initialize();

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle())
            .setNegativeButton(R.string.cancel_button, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create();

    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                boolean okButtonResult = handleOkButton();
                onOkButtonHandled();
                if (okButtonResult) {
                    dismiss();
                }
                return okButtonResult;
            }

            return false;
        }
    });

    dialog.setCanceledOnTouchOutside(true);
    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
            buttonPositive.setEnabled(getPositiveButtonEnabled());

            setPositiveButtonClickCustomListener();

            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);

            initTextChangedListener();
        }
    });

    return dialog;
}

From source file:com.android.example.github.ui.search.SearchFragment.java

private void initSearchInputListener() {
    binding.get().input.setOnEditorActionListener((v, actionId, event) -> {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            doSearch(v);// w  w  w  .ja v  a  2 s .  c o  m
            return true;
        }
        return false;
    });
    binding.get().input.setOnKeyListener((v, keyCode, event) -> {
        if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
            doSearch(v);
            return true;
        }
        return false;
    });
}