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:org.interactiverobotics.headset_launcher.MediaButtonMonitorService.java

@Override
public void onCreate() {

    Log.d(TAG, "Create");

    //   ?   //from w  w  w  .  java2  s  .  c o m

    mMediaButtonReceiver = new ComponentName(this, MediaButtonReceiver.class);

    // ,  ?   API 18+
    //
    //        final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    //
    //        mediaButtonIntent.setComponent(mMediaButtonReceiver);
    //
    //        mPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);

    mMediaSession = new MediaSessionCompat(this, TAG, mMediaButtonReceiver, /* pendingIntent */ null);

    mMediaSession.setCallback(new MediaSessionCompat.Callback() {

        @Override
        public boolean onMediaButtonEvent(Intent mediaButtonEvent) {

            if (Intent.ACTION_MEDIA_BUTTON.equals(mediaButtonEvent.getAction())) {

                final KeyEvent keyEvent = (KeyEvent) mediaButtonEvent
                        .getParcelableExtra(Intent.EXTRA_KEY_EVENT);

                if (KeyEvent.KEYCODE_HEADSETHOOK == keyEvent.getKeyCode()) {

                    if (KeyEvent.ACTION_DOWN == keyEvent.getAction()) {

                        Log.d(TAG, "Media button down!");

                        // ? 

                        startService(new Intent(MediaButtonMonitorService.this, LauncherService.class));
                    }

                } else {

                    Log.e(TAG, "Unknown keycode: " + keyEvent.getKeyCode());
                }

            } else {

                Log.e(TAG, "Unknown intent: " + mediaButtonEvent.getAction());
            }

            return true;
        }

    });

    mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS);

    mMediaSession.setActive(true);
}

From source file:cl.ipp.katbag.fragment.Add.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mainActivity = (MainActivity) super.getActivity();
    v = inflater.inflate(R.layout.fragment_add, container, false);

    // rescues parameters
    Bundle bundle = getArguments();/* ww  w. j  ava2  s .  com*/
    if (bundle != null) {
        type_app = bundle.getString("type_app");
    }

    progress = (ProgressBar) v.findViewById(R.id.progress);

    setTitleAndImageForTypeApp();

    name_app = (EditText) v.findViewById(R.id.name_app);
    name_app.setFilters(new InputFilter[] { KatbagUtilities.katbagAlphaNumericFilter,
            new InputFilter.LengthFilter(MAX_LENGTH) });
    name_app.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                validateName();
            }

            return false;
        }
    });

    config_app_worlds = (RelativeLayout) v.findViewById(R.id.config_app_worlds);
    config_app_drawings = (RelativeLayout) v.findViewById(R.id.config_app_drawings);
    config_app_developments = (RelativeLayout) v.findViewById(R.id.config_app_developments);
    config_app_pages = (RelativeLayout) v.findViewById(R.id.config_app_pages);

    config_app_worlds.setOnClickListener(this);
    config_app_drawings.setOnClickListener(this);
    config_app_developments.setOnClickListener(this);
    config_app_pages.setOnClickListener(this);

    if (type_app.contentEquals(MainActivity.TYPE_APP_GAME)) {
        config_app_worlds.setVisibility(View.VISIBLE);
        config_app_developments.setVisibility(View.VISIBLE);
        config_app_drawings.setVisibility(View.VISIBLE);
        config_app_pages.setVisibility(View.GONE);

    } else if (type_app.contentEquals(MainActivity.TYPE_APP_BOOK)) {
        config_app_worlds.setVisibility(View.VISIBLE);
        config_app_developments.setVisibility(View.GONE);
        config_app_drawings.setVisibility(View.VISIBLE);
        config_app_pages.setVisibility(View.VISIBLE);

    } else if (type_app.contentEquals(MainActivity.TYPE_APP_COMICS)) {
        config_app_worlds.setVisibility(View.VISIBLE);
        config_app_developments.setVisibility(View.GONE);
        config_app_drawings.setVisibility(View.VISIBLE);
        config_app_pages.setVisibility(View.VISIBLE);
    }

    return v;
}

From source file:com.mobivery.greent.MVYBatteryManagerActivityFragment.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (MVYBatterySaverManager.getInstance().areConnectionsManaged()) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_BACK:
                m_isSendingToBackground = true;
                MVYBatterySaverManager.getInstance().sendAppToBackground();
                break;
            }//from  ww  w. j  av  a2 s .co m
        }
    }
    return super.dispatchKeyEvent(event);
}

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();//from w  ww  .  j a  v a 2  s  .  co 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:de.uni.stuttgart.informatik.ToureNPlaner.UI.Dialogs.TextDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    input = new EditText(getActivity());
    String message = getArguments().getString("title");
    CharSequence content;//from w  w  w  .  j a  v a2 s .  c om
    if (savedInstanceState == null) {
        content = getArguments().getCharSequence("content");
    } else {
        content = savedInstanceState.getCharSequence("content");
    }
    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    input.setText(content, TextView.BufferType.SPANNABLE);
    return new AlertDialog.Builder(getActivity()).setTitle(message).setView(input)
            .setPositiveButton(getResources().getText(android.R.string.ok),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            doPositiveClick();
                        }
                    })
            .setNegativeButton(getResources().getText(android.R.string.cancel),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            doNegativeClick();
                        }
                    })
            .setOnKeyListener(new DialogInterface.OnKeyListener() {

                @Override
                public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                    if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (i == KeyEvent.KEYCODE_ENTER)) {
                        dialogInterface.dismiss();
                        doPositiveClick();
                        return true;
                    }
                    return false;
                }
            }).create();
}

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

/**
 * ?/* w  w  w. j a  va 2  s.c  o m*/
 * @param keyCode
 * @param event
 * @return
 */
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mBaseActivity.onKeyDown(keyCode, event)) {
        return true;
    }
    if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && event.getAction() == KeyEvent.ACTION_DOWN) {
        finish();
        return true;
    }
    return false;
}

From source file:andlabs.lounge.lobby.ui.ChatFragment.java

@Override
public View onCreateView(final LayoutInflater infl, ViewGroup p, Bundle b) {
    final View chat = infl.inflate(R.layout.fragment_chat, p, false);
    mChatEditText = ((EditText) chat.findViewById(R.id.msg_field));
    ((ImageButton) chat.findViewById(R.id.btn_send)).setOnClickListener(this);
    ((ListView) chat.findViewById(R.id.list)).setAdapter(new BaseAdapter() {

        @Override/* ww  w  .  j ava  2 s. co 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);
            ((TextView) view.findViewById(R.id.sender)).setText(msg.getPlayerName());
            ((TextView) view.findViewById(R.id.msg_text)).setText(msg.getMessage());
            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.csipsimple.ui.incall.DtmfDialogFragment.java

@Override
public void onTrigger(int keyCode, int dialTone) {
    Log.i(TAG, "onTrigger, keyCode: " + keyCode + ", dialTone: " + dialTone);
    if (dialPadTextView != null) {
        // Update text view
        KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
        char nbr = event.getNumber();
        StringBuilder sb = new StringBuilder(dialPadTextView.getText());
        sb.append(nbr);/* www. ja  v  a  2  s. c o  m*/
        dialPadTextView.setText(sb.toString());
    } else {
        Log.e(TAG, "dialpadTextView is null");
    }
    if (getActivity() instanceof OnDtmfListener) {
        Integer callId = getArguments().getInt(EXTRA_CALL_ID);
        if (callId != null) {
            ((OnDtmfListener) getActivity()).OnDtmf(callId, keyCode, dialTone);
        } else {
            Log.w(THIS_FILE, "Impossible to find the call associated to this view");
        }
    }

}

From source file:com.fusionx.lightirc.ui.IRCFragment.java

@Override
public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
    final CharSequence text = mMessageBox.getText();
    if ((event == null || actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE
            || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
            && StringUtils.isNotEmpty(text)) {
        final String message = text.toString();
        mMessageBox.setText("");
        onSendMessage(message);/*from w ww  .j a va 2 s. c  om*/
        return true;
    }
    return false;
}

From source file:com.dwdesign.tweetings.activity.SearchActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    SharedPreferences mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);

    if (mPreferences.getBoolean(PREFERENCE_KEY_VOLUME_NAVIGATION, false)) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_VOLUME_UP: {
                Intent broadcast = new Intent();
                broadcast.setAction(BROADCAST_VOLUME_UP);
                sendBroadcast(broadcast);
                //scrollToPrevious();
                return true;
            }/* w w  w . j  a v a2  s .c o  m*/
            case KeyEvent.KEYCODE_VOLUME_DOWN: {
                Intent broadcast = new Intent();
                broadcast.setAction(BROADCAST_VOLUME_DOWN);
                sendBroadcast(broadcast);
                //scrollToNext();
                return true;
            }
            }
        }
        if (event.getAction() == KeyEvent.ACTION_UP && (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP
                || event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN)) {
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}