Example usage for android.view KeyEvent KEYCODE_BACK

List of usage examples for android.view KeyEvent KEYCODE_BACK

Introduction

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

Prototype

int KEYCODE_BACK

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

Click Source Link

Document

Key code constant: Back key.

Usage

From source file:com.huofu.RestaurantOS.ui.splash.activate.java

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

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (flagInQrcodeDialog)//???????
        {/*from  w w  w .  ja  va  2  s.c  o m*/
            stopQrScanTimer();
            flagInQrcodeDialog = false;
            flagWaitingCmd = false;
            rl_activate_qrscan_ready.setVisibility(View.INVISIBLE);
            rl_activate_input.setVisibility(View.VISIBLE);
            rl_activate_input.startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.small_2_big));
            return true;
        }

    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.givon.anhao.activity.AnhaoMainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (mSlideMenu.isOpened()) {
            mSlideMenu.closeMenu();/*ww w .j  a va  2  s .co m*/
            return true;
        } else {
            // moveTaskToBack(false);
            finish();
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

private void LaunchMsimDialog(final boolean bCheckEcmMode) {

    AlertDialog.Builder builder = new AlertDialog.Builder(ComposeMessageActivity.this);
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.multi_sim_sms_sender, (ViewGroup) findViewById(R.id.layout_root));
    builder.setView(layout);/*from w  ww  .j a  v  a 2 s.  co m*/
    builder.setOnKeyListener(new DialogInterface.OnKeyListener() {
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            switch (keyCode) {
            case KeyEvent.KEYCODE_BACK: {
                dismissMsimDialog();
                return true;
            }
            case KeyEvent.KEYCODE_SEARCH: {
                return true;
            }
            }
            return false;
        }
    });

    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dismissMsimDialog();
        }
    });

    ContactList recipients = isRecipientsEditorVisible() ? mRecipientsEditor.constructContactsFromInput(false)
            : getRecipients();
    builder.setTitle(
            getResources().getString(R.string.to_address_label) + recipients.formatNamesAndNumbers(","));

    mMsimDialog = builder.create();
    mMsimDialog.setCanceledOnTouchOutside(true);

    int[] smsBtnIds = { R.id.BtnSubOne, R.id.BtnSubTwo, R.id.BtnSubThree };
    int phoneCount = MSimTelephonyManager.getDefault().getPhoneCount();
    Button[] smsBtns = new Button[phoneCount];

    for (int i = 0; i < phoneCount; i++) {
        final int subscription = i;
        int subID = i + 1;
        smsBtns[i] = (Button) layout.findViewById(smsBtnIds[i]);
        smsBtns[i].setVisibility(View.VISIBLE);
        smsBtns[i].setText(MSimTelephonyManager.getDefault().getSimOperatorName(i) + "-" + subID);
        smsBtns[i].setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.d(TAG, "Sub slected " + subscription);
                processMsimSendMessage(subscription, bCheckEcmMode);
            }
        });
    }
    mMsimDialog.show();
}

From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java

boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_MENU:
        onKeyDownPanel(Window.FEATURE_OPTIONS_PANEL, event);
        // We need to return true here and not let it bubble up to the Window.
        // For empty menus, PhoneWindow's KEYCODE_BACK handling will steals all events,
        // not allowing the Activity to call onBackPressed().
        return true;
    case KeyEvent.KEYCODE_BACK:
        // Certain devices allow opening the options menu via a long press of the back
        // button. We keep a record of whether the last event is from a long press.
        mLongPressBackDown = (event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0;
        break;/*from   ww  w. j a v a 2 s  .com*/
    }

    // On API v7-10 we need to manually call onKeyShortcut() as this is not called
    // from the Activity
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        // We do not return true here otherwise dispatchKeyEvent will not reach the Activity
        // (which results in the back button not working)
        onKeyShortcut(keyCode, event);
    }
    return false;
}

From source file:com.example.android.bluepayandroidsdk.MainActivity.java

private void showSwipeTopDialog() {
    hideSwipeTopDialog();//from   w  w  w  .  j a  v a 2 s  . com
    try {

        if (dlgSwipeTopShow == null)
            dlgSwipeTopShow = new UniMagTopDialog(this);

        Window win = dlgSwipeTopShow.getWindow();
        win.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
        dlgSwipeTopShow.setTitle("Swipe Card");
        dlgSwipeTopShow.setContentView(R.layout.dlgswipetopview);
        TextView myTV = (TextView) dlgSwipeTopShow.findViewById(R.id.TView_Info);
        Button myBtn = (Button) dlgSwipeTopShow.findViewById(R.id.btnCancel);

        myTV.setText(popupDialogMsg);
        myBtn.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                if (itemStartSC != null)
                    itemStartSC.setEnabled(true);
                //stop swipe
                myUniMagReader.stopSwipeCard();
                if (readerType == 2)
                    isWaitingForCommandResult = true;

                if (dlgSwipeTopShow != null) {
                    statusText = "Swipe card cancelled.";
                    msrData = null;
                    dlgSwipeTopShow.dismiss();
                }
            }
        });
        dlgSwipeTopShow.setOnKeyListener(new DialogInterface.OnKeyListener() {
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if ((keyCode == KeyEvent.KEYCODE_BACK)) {
                    return false;
                }
                return true;
            }
        });
        dlgSwipeTopShow.show();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:android.support.v17.leanback.app.DetailsSupportFragment.java

/**
 * This method does the following//from  w  w  w. j  av  a 2  s.c om
 * <ul>
 * <li>sets up focus search handling logic in the root view to enable transitioning between
 * half screen/full screen/no video mode.</li>
 *
 * <li>Sets up the key listener in the root view to intercept events like UP/DOWN and
 * transition to appropriate mode like half/full screen video.</li>
 * </ul>
 */
void setupDpadNavigation() {
    mRootView.setOnChildFocusListener(new BrowseFrameLayout.OnChildFocusListener() {

        @Override
        public boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
            return false;
        }

        @Override
        public void onRequestChildFocus(View child, View focused) {
            if (child != mRootView.getFocusedChild()) {
                if (child.getId() == R.id.details_fragment_root) {
                    if (!mPendingFocusOnVideo) {
                        slideInGridView();
                        showTitle(true);
                    }
                } else if (child.getId() == R.id.video_surface_container) {
                    slideOutGridView();
                    showTitle(false);
                } else {
                    showTitle(true);
                }
            }
        }
    });
    mRootView.setOnFocusSearchListener(new BrowseFrameLayout.OnFocusSearchListener() {
        @Override
        public View onFocusSearch(View focused, int direction) {
            if (mRowsSupportFragment.getVerticalGridView() != null
                    && mRowsSupportFragment.getVerticalGridView().hasFocus()) {
                if (direction == View.FOCUS_UP) {
                    if (mDetailsBackgroundController != null
                            && mDetailsBackgroundController.canNavigateToVideoSupportFragment()
                            && mVideoSupportFragment != null && mVideoSupportFragment.getView() != null) {
                        return mVideoSupportFragment.getView();
                    } else if (getTitleView() != null && getTitleView().hasFocusable()) {
                        return getTitleView();
                    }
                }
            } else if (getTitleView() != null && getTitleView().hasFocus()) {
                if (direction == View.FOCUS_DOWN) {
                    if (mRowsSupportFragment.getVerticalGridView() != null) {
                        return mRowsSupportFragment.getVerticalGridView();
                    }
                }
            }
            return focused;
        }
    });

    // If we press BACK on remote while in full screen video mode, we should
    // transition back to half screen video playback mode.
    mRootView.setOnDispatchKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // This is used to check if we are in full screen video mode. This is somewhat
            // hacky and relies on the behavior of the video helper class to update the
            // focusability of the video surface view.
            if (mVideoSupportFragment != null && mVideoSupportFragment.getView() != null
                    && mVideoSupportFragment.getView().hasFocus()) {
                if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE) {
                    if (getVerticalGridView().getChildCount() > 0) {
                        getVerticalGridView().requestFocus();
                        return true;
                    }
                }
            }

            return false;
        }
    });
}

From source file:com.softanalle.scma.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    logger.debug("onKeyDown(keyCode=" + keyCode + ")");
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK: {
        //Handle the back button
        //if(keyCode == KeyEvent.KEYCODE_BACK) {
        //Ask the user if they want to quit
        new AlertDialog.Builder(this).setIcon(R.drawable.ic_dialog_alert).setTitle("Exit?")
                .setMessage("You are about to exit the Application. " + "Do you really want to exit?")
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override//from w  w w.j a  va2  s .c o m
                    public void onClick(DialogInterface dialog, int which) {
                        //Stop the activity
                        //maintenancetabs.this.finish();
                        int pid = android.os.Process.myPid();
                        android.os.Process.killProcess(pid);
                    }
                }).setNegativeButton("No", null).show();
        return true;
    }

    // eat zoom -events
    case KeyEvent.KEYCODE_ZOOM_IN: {
        return true;
    }
    case KeyEvent.KEYCODE_ZOOM_OUT: {
        return true;
    }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.cellbots.logger.LoggerActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        boolean shouldExitApp;
        synchronized (mIsRecording) {
            shouldExitApp = !mIsRecording;
        }// ww w . j ava  2  s.  c o  m
        // cleanup();
        if (shouldExitApp) {
            finish();
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.intel.xdk.device.Device.java

public void showRemoteSite(final String strURL, final int closeX_pt, final int closeY_pt, final int closeX_ls,
        final int closeY_ls, final int closeW, final int closeH, final String closeImage) {
    if (strURL == null || strURL.length() == 0)
        return;//w w  w  .ja v  a 2  s  .c o  m

    remoteCloseXPort = closeX_pt;
    remoteCloseYPort = closeY_pt;
    remoteCloseXLand = closeX_ls;
    remoteCloseYLand = closeY_ls;

    //hack to adjust image size
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

    remoteCloseW = (int) ((float) closeW * dm.density);
    remoteCloseH = (int) ((float) closeH * dm.density);

    //Set position, width, height of closeImage according to currentOrientation
    if (this.getOrientation() == 0 || this.getOrientation() == 180) {
        //Portrait
        AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams(
                remoteCloseW == 0 ? 48 : remoteCloseW, remoteCloseH == 0 ? 48 : remoteCloseH, remoteCloseXPort,
                remoteCloseYPort);
        remoteClose.setLayoutParams(params);
    } else {
        AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams(
                remoteCloseW == 0 ? 48 : remoteCloseW, remoteCloseH == 0 ? 48 : remoteCloseH, remoteCloseXLand,
                remoteCloseYLand);
        remoteClose.setLayoutParams(params);
    }

    activity.runOnUiThread(new Runnable() {

        public void run() {

            if (remoteView == null) {

                remoteView = new WebView(activity);
                remoteView.setInitialScale(0);
                remoteView.setVerticalScrollBarEnabled(false);
                remoteView.setWebViewClient(new WebViewClient());
                final WebSettings settings = remoteView.getSettings();
                settings.setJavaScriptEnabled(true);
                settings.setJavaScriptCanOpenWindowsAutomatically(true);
                settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);

                remoteLayout.addView(remoteView,
                        new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER));

                remoteView.requestFocusFromTouch();

                remoteView.setOnKeyListener(new View.OnKeyListener() {
                    @Override
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
                        if (event.getAction() != KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
                            remoteClose.performClick();
                            return true;
                        } else {
                            return false;
                        }
                    }
                });
            }
            // load the url
            remoteView.loadUrl(strURL);
            // show the view
            remoteLayout.setVisibility(View.VISIBLE);
            // set the flag
            isShowingRemoteSite = true;
            // isShowingRemoteSite = true;
            // get focus
            remoteView.requestFocus(View.FOCUS_DOWN);
            remoteClose.bringToFront();
        }
    });

}

From source file:cgeo.geocaching.cgeocaches.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (adapter.isSelectMode()) {
            adapter.setSelectMode(false);
            return true;
        }/* ww w  . j ava 2  s . c  om*/
    }
    return super.onKeyDown(keyCode, event);
}