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.catrobat.catroid.ui.fragment.FormulaEditorListFragment.java

@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
    FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getSherlockActivity()
            .getSupportFragmentManager().findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG);
    if (formulaEditor != null) {
        formulaEditor.addResourceToActiveFormula(itemsIds[position]);
        formulaEditor.updateButtonsOnKeyboardAndInvalidateOptionsMenu();
    }//from   w w w . java2  s  .  co  m
    KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
    onKey(null, keyEvent.getKeyCode(), keyEvent);
}

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);//from www . j ava  2  s.  c  om
        return true;
    }
    return false;
}

From source file:github.daneren2005.dsub.util.Notifications.java

private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded,
        boolean playing, boolean remote) {

    // Use the same text for the ticker and the expanded notification
    String title = song.getTitle();
    String arist = song.getArtist();
    String album = song.getAlbum();

    // Set the album art.
    try {/*from  ww  w.j  ava 2  s.  co m*/
        ImageLoader imageLoader = SubsonicActivity.getStaticImageLoader(context);
        Bitmap bitmap = null;
        if (imageLoader != null) {
            bitmap = imageLoader.getCachedImage(context, song, false);
        }
        if (bitmap == null) {
            // set default album art
            rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
        } else {
            rv.setImageViewBitmap(R.id.notification_image, bitmap);
        }
    } catch (Exception x) {
        Log.w(TAG, "Failed to get notification cover art", x);
        rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
    }

    // set the text for the notifications
    rv.setTextViewText(R.id.notification_title, title);
    rv.setTextViewText(R.id.notification_artist, arist);
    rv.setTextViewText(R.id.notification_album, album);

    boolean persistent = Util.getPreferences(context)
            .getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false);
    if (persistent) {
        if (expanded) {
            rv.setImageViewResource(R.id.control_pause,
                    playing ? R.drawable.notification_pause : R.drawable.notification_start);
        } else {
            rv.setImageViewResource(R.id.control_previous,
                    playing ? R.drawable.notification_pause : R.drawable.notification_start);
            rv.setImageViewResource(R.id.control_pause, R.drawable.notification_forward);
            rv.setImageViewResource(R.id.control_next, R.drawable.notification_close);
        }
    }

    // Create actions for media buttons
    PendingIntent pendingIntent;
    int previous = 0, pause = 0, next = 0, close = 0;
    if (persistent && !expanded) {
        pause = R.id.control_previous;
        next = R.id.control_pause;
        close = R.id.control_next;
    } else {
        previous = R.id.control_previous;
        pause = R.id.control_pause;
        next = R.id.control_next;
    }

    if ((remote || persistent) && close == 0 && expanded) {
        close = R.id.notification_close;
        rv.setViewVisibility(close, View.VISIBLE);
    }

    if (previous > 0) {
        Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS");
        prevIntent.setComponent(new ComponentName(context, DownloadService.class));
        prevIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
        pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
        rv.setOnClickPendingIntent(previous, pendingIntent);
    }
    if (pause > 0) {
        if (playing) {
            Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE");
            pauseIntent.setComponent(new ComponentName(context, DownloadService.class));
            pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                    new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
            pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0);
            rv.setOnClickPendingIntent(pause, pendingIntent);
        } else {
            Intent prevIntent = new Intent("KEYCODE_MEDIA_START");
            prevIntent.setComponent(new ComponentName(context, DownloadService.class));
            prevIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                    new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY));
            pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
            rv.setOnClickPendingIntent(pause, pendingIntent);
        }
    }
    if (next > 0) {
        Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT");
        nextIntent.setComponent(new ComponentName(context, DownloadService.class));
        nextIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT));
        pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0);
        rv.setOnClickPendingIntent(next, pendingIntent);
    }
    if (close > 0) {
        Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP");
        prevIntent.setComponent(new ComponentName(context, DownloadService.class));
        prevIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP));
        pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
        rv.setOnClickPendingIntent(close, pendingIntent);
    }
}

From source file:com.scooter1556.sms.android.fragment.tv.TvAudioPlayerFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override//  w  w  w . j  av  a  2  s.  c o m
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
                    if (lastPlaybackState != null) {
                        if (lastPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING) {
                            mediaController.getTransportControls().pause();
                        } else {
                            mediaController.getTransportControls().play();
                        }
                    }

                    return true;
                }
            }
            return false;
        }
    });
}

From source file:com.irccloud.android.activity.QuickReplyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quick_reply);

    if (getIntent().hasExtra("cid") && getIntent().hasExtra("bid")) {
        onNewIntent(getIntent());/*from ww w  .j  av a  2 s  . c o m*/
    } else {
        finish();
        return;
    }

    final ImageButton send = (ImageButton) findViewById(R.id.sendBtn);
    final EditText message = (EditText) findViewById(R.id.messageTxt);
    message.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
            if (actionId == EditorInfo.IME_ACTION_SEND && message.getText() != null
                    && message.getText().length() > 0)
                send.performClick();
            return true;
        }
    });
    message.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER
                    && message.getText() != null && message.getText().length() > 0)
                send.performClick();
            return false;
        }
    });
    send.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (message.getText() != null && message.getText().length() > 0) {
                Intent i = new Intent(RemoteInputService.ACTION_REPLY);
                i.setComponent(new ComponentName(getPackageName(), RemoteInputService.class.getName()));
                i.putExtras(getIntent());
                i.putExtra("reply", message.getText().toString());
                startService(i);
                finish();
            }
        }
    });

    ListView listView = (ListView) findViewById(R.id.conversation);
    listView.setAdapter(adapter);
}

From source file:net.lacolaco.smileessence.activity.MainActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() != KeyEvent.ACTION_DOWN) {
        return super.dispatchKeyEvent(event);
    }//from  w ww.  j a v a  2 s  .c om
    switch (event.getKeyCode()) {
    case KeyEvent.KEYCODE_BACK: {
        finish();
        return false;
    }
    default: {
        return super.dispatchKeyEvent(event);
    }
    }
}

From source file:cn.eoe.android.libraries.ui.activity.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        if (isExit) {
            System.exit(0);/*  ww w .j  a va 2  s.  c  om*/
        }
        Toast.makeText(this, "??", Toast.LENGTH_SHORT).show();
        countDownTimer.start();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:io.github.calvinmikael.anymanga.WebViewFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*from  ww  w. j a  v  a 2  s  .  c  om*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_web_view, container, false);
    mProgressBar = (ProgressBar) view.findViewById(R.id.progressBar);
    mProgressBar.setVisibility(View.GONE);

    mWebView = (ObservableWebView) view.findViewById(R.id.webView);
    mWebView.setScrollViewCallbacks(this);
    WebSettings settings = mWebView.getSettings();

    settings.setLoadsImagesAutomatically(true);
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            if (!mProgressBar.isShown()) {
                mProgressBar.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (mProgressBar.isShown()) {
                mProgressBar.setVisibility(View.GONE);
            }
        }
    });
    mWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onShowCustomView(View view, CustomViewCallback callback) {
            // if a view already exists then immediately terminate the new one
            if (mCustomView != null) {
                onHideCustomView();
                return;
            }

            // Save the current state
            mCustomView = view;
            mOriginalSystemUiVisibility = getActivity().getWindow().getDecorView().getSystemUiVisibility();

            // Save the custom view callback
            mCustomViewCallback = callback;

            // Add the custom view to the view hierarchy
            FrameLayout decorView = (FrameLayout) getActivity().getWindow().getDecorView();
            decorView.addView(mCustomView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));

            mTabStrip = (PagerSlidingTabStrip) getActivity().findViewById(R.id.tabs);
            mTabStrip.setVisibility(View.GONE);

            // Go fullscreen
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                getActivity().getWindow().getDecorView()
                        .setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
            } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT
                    && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN);
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                getActivity().getWindow().getDecorView()
                        .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                                | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
            }
        }

        @Override
        public void onHideCustomView() {
            // Remove the custom view
            FrameLayout decorView = (FrameLayout) getActivity().getWindow().getDecorView();
            decorView.removeView(mCustomView);
            mCustomView = null;

            mTabStrip.setVisibility(View.VISIBLE);
            // Restore the original form
            getActivity().getWindow().getDecorView().setSystemUiVisibility(mOriginalSystemUiVisibility);

            // Call the custom view callback
            mCustomViewCallback.onCustomViewHidden();
            mCustomViewCallback = null;
        }
    });
    // The back button must be handled within the mWebView for the
    // mWebView to have back behavior based on the current mPage
    // if back behavior is not handled with this listener then
    // back behavior will be entirely dependent on the first mPage
    mWebView.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()
                    && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                mWebView.goBack();
                return true;
            }

            return false;
        }
    });

    if (savedInstanceState != null) {
        mWebView.restoreState(savedInstanceState);
    } else {
        if (mPage == 1) {
            mWebView.loadUrl(getString(R.string.website_kissmanga));
        } else if (mPage == 2) {
            mWebView.loadUrl(getString(R.string.website_mangapark));
        } else if (mPage == 3) {
            mWebView.loadUrl(getString(R.string.website_line_webtoon));
        }
    }

    return view;
}

From source file:org.xwalk.core.xwview.shell.XWalkViewShellActivity.java

private void initializeUrlField() {
    mUrlTextView = (EditText) findViewById(R.id.url);
    mUrlTextView.setOnEditorActionListener(new OnEditorActionListener() {
        @Override/* ww  w  .ja v  a2 s . c  om*/
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((actionId != EditorInfo.IME_ACTION_GO)
                    && (event == null || event.getKeyCode() != KeyEvent.KEYCODE_ENTER
                            || event.getAction() != KeyEvent.ACTION_DOWN)) {
                return false;
            }

            if (mActiveView == null)
                return true;
            mActiveView.load(sanitizeUrl(mUrlTextView.getText().toString()), null);
            mUrlTextView.clearFocus();
            setKeyboardVisibilityForUrl(false);
            return true;
        }
    });
    mUrlTextView.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            setKeyboardVisibilityForUrl(hasFocus);
            mNextButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
            mPrevButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
            mStopButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
            mReloadButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
            if (!hasFocus) {
                if (mActiveView == null)
                    return;
                mUrlTextView.setText(mActiveView.getUrl());
            }
        }
    });
}

From source file:net.sourceforge.kalimbaradio.androidapp.util.NotificationUtil.java

private static RemoteViews createBigContentView(Context context, MusicDirectory.Entry song, Bitmap albumArt,
        boolean playing) {

    RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded);
    contentView.setTextViewText(R.id.notification_title, song.getTitle());
    contentView.setTextViewText(R.id.notification_artist, song.getArtist());
    contentView.setTextViewText(R.id.notification_album, song.getAlbum());
    contentView.setImageViewBitmap(R.id.notification_image, albumArt);
    contentView.setImageViewResource(R.id.notification_playpause,
            playing ? R.drawable.media_pause : R.drawable.media_start);

    Intent intent = new Intent("1");
    intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    intent.putExtra(Intent.EXTRA_KEY_EVENT,
            new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
    contentView.setOnClickPendingIntent(R.id.notification_playpause,
            PendingIntent.getService(context, 0, intent, 0));

    intent = new Intent("2");
    intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT));
    contentView.setOnClickPendingIntent(R.id.notification_next,
            PendingIntent.getService(context, 0, intent, 0));

    intent = new Intent("3");
    intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    intent.putExtra(Intent.EXTRA_KEY_EVENT,
            new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
    contentView.setOnClickPendingIntent(R.id.notification_prev,
            PendingIntent.getService(context, 0, intent, 0));

    intent = new Intent("4");
    intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    intent.putExtra(Constants.INTENT_EXTRA_NAME_HIDE_NOTIFICATION, true);
    contentView.setOnClickPendingIntent(R.id.notification_close,
            PendingIntent.getService(context, 0, intent, 0));

    return contentView;
}