Example usage for android.view KeyEvent ACTION_UP

List of usage examples for android.view KeyEvent ACTION_UP

Introduction

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

Prototype

int ACTION_UP

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

Click Source Link

Document

#getAction value: the key has been released.

Usage

From source file:com.oda.calculator.EventListener.java

public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
        return eat;
    }//ww  w.j av a2  s  . c o  m

    //Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }

    //Calculator.log("KEY " + keyCode + "; " + action);

    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) {
            // Tell the handler that text was updated.
            mHandler.onTextChanged();
        }
        return false;
    }

    /*
       We should act on KeyEvent.ACTION_DOWN, but strangely
       sometimes the DOWN event isn't received, only the UP.
       So the workaround is to act on UP...
       http://b/issue?id=1022478
     */

    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:com.aman.stockcalculator.EventListener.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
        return eat;
    }/*from  w w  w  .jav  a 2  s  .c  o  m*/

    //Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }

    //Calculator.log("KEY " + keyCode + "; " + action);

    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) {
            // Tell the handler that text was updated.
            mHandler.onTextChanged();
        }
        return false;
    }

    /*
       We should act on KeyEvent.ACTION_DOWN, but strangely
       sometimes the DOWN event isn't received, only the UP.
       So the workaround is to act on UP...
       http://b/issue?id=1022478
     */

    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:love.juhe.androidmonkey.MonkeyKeyEvent.java

@Override
public int fireEvent(Instrumentation testRuner) {
    String note;/*from   ww w.jav a2s . c  o  m*/
    if (mAction == KeyEvent.ACTION_UP) {
        note = "ACTION_UP";
    } else {
        note = "ACTION_DOWN";
    }

    MonkeyLog.l(":Typing Key (" + note + "): " + mKeyCode + "    // ");
    try {
        //         testRuner.sendKeySync(getEvent());
        testRuner.sendKeyDownUpSync(mKeyCode);
    } catch (Exception e) {
        MonkeyLog.l("Failed to send key (" + note + "): " + mKeyCode + "    // ");
        return MonkeyEvent.INJECT_FAIL;
    }

    return MonkeyEvent.INJECT_SUCCESS;
}

From source file:org.videolan.vlc.RemoteControlClientReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
    if (event != null && action.equalsIgnoreCase(Intent.ACTION_MEDIA_BUTTON)) {

        if (event.getKeyCode() != KeyEvent.KEYCODE_HEADSETHOOK
                && event.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
                && event.getAction() != KeyEvent.ACTION_DOWN) {
            super.onReceive(context, intent);
            return;
        }/*  www.  ja v a 2s .  c  o m*/

        Intent i = null;
        switch (event.getKeyCode()) {
        /*
         * one click => play/pause
         * long click => previous
         * double click => next
         */
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            long time = SystemClock.uptimeMillis();
            switch (event.getAction()) {
            case KeyEvent.ACTION_DOWN:
                if (event.getRepeatCount() <= 0)
                    mHeadsetDownTime = time;
                break;
            case KeyEvent.ACTION_UP:
                if (AndroidDevices.hasTsp()) { //no backward/forward on TV
                    if (time - mHeadsetDownTime >= 1000) { // long click
                        i = new Intent(PlaybackService.ACTION_REMOTE_BACKWARD, null,
                                VLCApplication.getAppContext(), PlaybackService.class);
                        break;
                    } else if (time - mHeadsetUpTime <= 500) { // double click
                        i = new Intent(PlaybackService.ACTION_REMOTE_FORWARD, null,
                                VLCApplication.getAppContext(), PlaybackService.class);
                        break;
                    }
                }
                // one click
                i = new Intent(PlaybackService.ACTION_REMOTE_PLAYPAUSE, null, VLCApplication.getAppContext(),
                        PlaybackService.class);
                mHeadsetUpTime = time;
                break;
            }
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            context.startService(new Intent(PlaybackService.ACTION_REMOTE_PLAY, null,
                    VLCApplication.getAppContext(), PlaybackService.class));
            return;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            i = new Intent(PlaybackService.ACTION_REMOTE_PAUSE, null, VLCApplication.getAppContext(),
                    PlaybackService.class);
            break;
        case KeyEvent.KEYCODE_MEDIA_STOP:
            i = new Intent(PlaybackService.ACTION_REMOTE_STOP, null, VLCApplication.getAppContext(),
                    PlaybackService.class);
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            i = new Intent(PlaybackService.ACTION_REMOTE_FORWARD, null, VLCApplication.getAppContext(),
                    PlaybackService.class);
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            i = new Intent(PlaybackService.ACTION_REMOTE_BACKWARD, null, VLCApplication.getAppContext(),
                    PlaybackService.class);
            break;
        }

        if (isOrderedBroadcast())
            abortBroadcast();
        if (i != null) {
            context.startService(i);
            return;
        }
    } else if (action.equals(PlaybackService.ACTION_REMOTE_PLAYPAUSE)) {
        intent = new Intent(context, PlaybackService.class);
        intent.setAction(PlaybackService.ACTION_REMOTE_PLAYPAUSE);
        context.startService(intent);
        return;
    }
    super.onReceive(context, intent);
}

From source file:tinkercoder.stockcalculator.calculator.EventListener.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
        return eat;
    }/* w  w w  .ja  v  a2  s  .  co  m*/

    //Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }

    //Calculator.log("KEY " + keyCode + "; " + action);

    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        return false;
    }

    /*
       We should act on KeyEvent.ACTION_DOWN, but strangely
       sometimes the DOWN event isn't received, only the UP.
       So the workaround is to act on UP...
       http://b/issue?id=1022478
     */

    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:com.towerlabs.yildizyemek.AboutWeb.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub

    if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
        if (webView.canGoBack()) {
            webView.goBack();/* w w w.java 2 s .co  m*/
        } else {
            // getActivity().finish();

            MainActivity.exitDialog();
        }

    }

    return true;
}

From source file:io.github.carlorodriguez.alarmon.MediaListView.java

public MediaListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setChoiceMode(CHOICE_MODE_SINGLE);//  ww  w. j av a2s.c o m
    setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (flipper == null || flipper.getDisplayedChild() == 0) {
                return false;
            }
            if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
                if (event.getAction() == KeyEvent.ACTION_UP) {
                    if (mPlayer != null) {
                        mPlayer.stop();
                    }
                    flipper.setInAnimation(getContext(), R.anim.slide_in_right);
                    flipper.setOutAnimation(getContext(), R.anim.slide_out_right);
                    flipper.showPrevious();
                }
                return true;
            }
            return false;
        }
    });
}

From source file:it.mb.whatshare.PatchedDialogFragment.java

/**
 * Returns a builder that will create a dialog that can only be canceled by
 * clicking OK or by pressing back./*from  w w  w . j a va 2s.c om*/
 * 
 * <p>
 * Whenever the dialog is dismissed, {@link Activity#finish()} is called on
 * the argument <tt>activity</tt>.
 * 
 * <p>
 * The builder has already the correct theme set (for making it look ok even
 * on wonderful Android pre-v11), so {@link Builder#getContext()} can be
 * used to inflate layouts with.
 * 
 * @param activity
 *            the caller activity
 * @return a builder to be used to create a dialog with
 */
protected Builder getNoUiBuilder(final FragmentActivity activity) {
    context = new ContextThemeWrapper(activity, R.style.DialogTheme);
    // @formatter:off
    return new AlertDialog.Builder(context).setCancelable(false)
            .setOnKeyListener(new DialogInterface.OnKeyListener() {
                @Override
                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP
                            && !event.isCanceled()) {
                        dialog.cancel();
                        activity.finish();
                        return true;
                    }
                    return false;
                }
            }).setPositiveButton(android.R.string.ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    activity.finish();
                }
            });
    // @formatter:on
}

From source file:ayushi.view.fragment.ContactUsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.frag_about, container, false);

    getActivity().setTitle("Contact Us");

    mToolbar = (Toolbar) rootView.findViewById(R.id.htab_toolbar);
    if (mToolbar != null) {
        ((ECartHomeActivity) getActivity()).setSupportActionBar(mToolbar);
    }//  w w w.j a v a2 s . c om

    if (mToolbar != null) {
        ((ECartHomeActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mToolbar.setNavigationIcon(R.drawable.ic_drawer);

    }

    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((ECartHomeActivity) getActivity()).getmDrawerLayout().openDrawer(GravityCompat.START);
        }
    });

    mToolbar.setTitleTextColor(Color.WHITE);

    rootView.findViewById(R.id.locations).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

        }
    });

    rootView.findViewById(R.id.contact_num).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            Intent callIntent = new Intent(Intent.ACTION_DIAL);
            callIntent.setData(Uri.parse("tel:" + "8888813275"));
            startActivity(callIntent);

        }
    });

    rootView.setFocusableInTouchMode(true);
    rootView.requestFocus();
    rootView.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {

            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {

                Utils.switchContent(R.id.frag_container, Utils.HOME_FRAGMENT,
                        ((ECartHomeActivity) (getContext())), AnimationType.SLIDE_UP);

            }
            return true;
        }
    });

    rootView.findViewById(R.id.site_dev).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://hiteshsahu.com/"));
            startActivity(browserIntent);

        }
    });

    rootView.findViewById(R.id.email).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("text/plain");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                    new String[] { "hiteshkumarsahu1990@gmail.com" });
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hello There");
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Add Message here");

            emailIntent.setType("message/rfc822");

            try {
                startActivity(Intent.createChooser(emailIntent, "Send email using..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(getActivity(), "No email clients installed.", Toast.LENGTH_SHORT).show();
            }

        }
    });

    return rootView;
}

From source file:com.hitesh_sahu.retailapp.view.fragment.ContactUsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.frag_about, container, false);

    getActivity().setTitle("Contact Us");

    mToolbar = (Toolbar) rootView.findViewById(R.id.htab_toolbar);
    if (mToolbar != null) {
        ((ECartHomeActivity) getActivity()).setSupportActionBar(mToolbar);
    }/*from ww w.  j  a  v  a 2s . c  o m*/

    if (mToolbar != null) {
        ((ECartHomeActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mToolbar.setNavigationIcon(R.drawable.ic_drawer);

    }

    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((ECartHomeActivity) getActivity()).getmDrawerLayout().openDrawer(GravityCompat.START);
        }
    });

    mToolbar.setTitleTextColor(Color.WHITE);

    rootView.findViewById(R.id.locations).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

        }
    });

    rootView.findViewById(R.id.contact_num).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            Intent callIntent = new Intent(Intent.ACTION_DIAL);
            callIntent.setData(Uri.parse("tel:" + "8888813275"));
            startActivity(callIntent);

        }
    });

    rootView.setFocusableInTouchMode(true);
    rootView.requestFocus();
    rootView.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {

            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {

                Utils.switchContent(R.id.frag_container, Utils.HOME_FRAGMENT,
                        ((ECartHomeActivity) (getContext())), AnimationType.SLIDE_UP);

            }
            return true;
        }
    });

    rootView.findViewById(R.id.site_dev).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://hiteshsahu.com/"));
            startActivity(browserIntent);

        }
    });

    rootView.findViewById(R.id.email).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("text/plain");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "hiteshkrsahu@gmail.com" });
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hello There");
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Add Message here");

            emailIntent.setType("message/rfc822");

            try {
                startActivity(Intent.createChooser(emailIntent, "Send email using..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(getActivity(), "No email clients installed.", Toast.LENGTH_SHORT).show();
            }

        }
    });

    return rootView;
}