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.luo.luofist.base.BaseAppCompatActivity.java

/**
 * Loadding// ww  w .j  a v  a 2s. co m
 */
public void showLoadingDialog() {
    try {
        mLoadingDialog = LoadingDialog.createDialog(this);
        mLoadingDialog.setTitle(null);
        mLoadingDialog.setCancelable(false);
        mLoadingDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
                    hideLoadingDialog();
                }
                return true;
            }
        });
        if (!isFinishing()) {
            mLoadingDialog.show();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.evecom.androidecssp.base.BaseWebActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        // if (dialog != null)
        // dialog.dismiss();
        return true;
    }/*from  ww  w. j av a2s  . c o  m*/
    return super.onKeyDown(keyCode, event);
}

From source file:com.microsoft.rightsmanagement.ui.CustomerExperienceDataConsentDialogFragment.java

/**
 * Instantiate the fragment views.//from   ww  w . j  a  v  a2s.  c  o m
 * 
 * @param savedInstanceState the saved instance state
 * @return the dialog
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Logger.ms(TAG, "onCreateDialog");
    super.onCreateDialog(savedInstanceState);

    // initialize the field for cases when fragment is recreated by OS
    // During recreation, OS would use default constructor and set the state
    Bundle arguments = getArguments();
    if (arguments != null && arguments.containsKey(REQUEST_CALLBACK_ID)) {
        mRequestCallbackId = getArguments().getInt(REQUEST_CALLBACK_ID);
    }

    LayoutInflater inflater = LayoutInflater.from(getActivity().getApplicationContext());
    View view = inflater.inflate(R.layout.customer_experience_data_consent_dialog_fragment, null);
    Button positiveButton = (Button) view
            .findViewById(R.id.customer_experience_data_consent_dialog_positive_button);
    positiveButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Logger.d(TAG, "onClick listener called on yes button");
            mDialogState = DialogState.UserResponded;
            storeDebugLogPreference(true);
            dismiss();
        }
    });
    Button negativeButton = (Button) view
            .findViewById(R.id.customer_experience_data_consent_dialog_negative_button);
    negativeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Logger.d(TAG, "onClick listener called on no button");
            mDialogState = DialogState.UserResponded;
            storeDebugLogPreference(false);
            dismiss();
        }
    });
    Button neutralButton = (Button) view
            .findViewById(R.id.customer_experience_data_consent_dialog_neutral_button);
    neutralButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Logger.d(TAG, "onClick listener called on learn more");
            Intent internetIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(getString(R.string.learn_more_uri)));
            startActivity(internetIntent);
        }
    });

    OnKeyListener backKeyListener = new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                Logger.d(TAG, "onback press");
                mDialogState = DialogState.UserCancelled;
                // onback press dismiss dialog and assume no thanks
                storeDebugLogPreference(false);
                dismiss();
                return true;
            }
            return false;
        }
    };

    AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(getActivity());
    dialogbuilder.setView(view);
    dialogbuilder.setOnKeyListener(backKeyListener);
    AlertDialog dialog = dialogbuilder.create();
    Logger.me(TAG, "onCreateDialog");
    return dialog;
}

From source file:butter.droid.fragments.dialog.EpisodeDialogFragment.java

@NonNull
@Override// w  w  w  .j  a  v  a  2 s .co m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                smoothDismiss();
            }
            return true;
        }
    });
    return dialog;
}

From source file:com.gsma.rcs.ri.sharing.image.InitiateImageSharing.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (KeyEvent.KEYCODE_BACK == keyCode) {
        try {//from   w ww . j  a  va2  s.  c o m
            if (mImageSharing == null || !RcsSessionUtil.isAllowedToAbortImageSharingSession(mImageSharing)) {
                finish();
                return true;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.label_confirm_close);
            builder.setPositiveButton(R.string.label_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    quitSession();
                }
            });
            builder.setNegativeButton(R.string.label_cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            builder.setCancelable(true);
            registerDialog(builder.show());
            return true;

        } catch (RcsServiceException e) {
            showException(e);
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.googlecode.android_scripting.activity.ApiBrowser.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && searchResultMode) {
        searchResultMode = false;//  w  ww  .  j a  v  a2  s . co  m
        mExpandedPositions.clear();
        updateAndFilterMethodDescriptors("");
        mAdapter.notifyDataSetChanged();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.zhihuigu.sosoOffice.LoadActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        return true;
    }//from w  w  w. jav  a  2 s  .c  om
    return false;
}

From source file:com.android.projectz.teamrocket.thebusapp.activities.SettingsActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        this.finish();
        SettingsActivity.this.overridePendingTransition(R.anim.anim_slide_in_right,
                R.anim.anim_slide_out_right);
    }/*from  ww  w . j  a  va 2 s . c om*/
    return true;
}

From source file:com.firesoft.member.Activity.B0_SigninActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (isExit == false) {
            isExit = true;//w ww.  j a v a 2  s  .c  om
            ToastView toast = new ToastView(getApplicationContext(), getString(R.string.exit_again));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();

            handler.sendEmptyMessageDelayed(0, 3000);
            return true;
        } else {
            if (SESSION.getInstance().uid == 0) {
                finish();
            } else {
                Intent intent = new Intent(this, MainActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                finish();
            }
            return false;
        }
    }
    return true;
}

From source file:com.android.projectz.teamrocket.thebusapp.settings.SettingLanguageActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        this.finish();
        SettingLanguageActivity.this.overridePendingTransition(R.anim.anim_slide_in_right,
                R.anim.anim_slide_out_right);
    }/*from  w w w . ja  v a2  s  . c  o  m*/
    return true;
}