Java Code Examples for android.app.Dialog#setOnKeyListener()

The following examples show how to use android.app.Dialog#setOnKeyListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicPopup.java    From a with GNU General Public License v3.0 6 votes vote down vote up
private void initDialog() {
    contentLayout = new FrameLayout(activity);
    contentLayout.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
    contentLayout.setFocusable(true);
    contentLayout.setFocusableInTouchMode(true);
    dialog = new Dialog(activity);
    dialog.setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
    dialog.setCancelable(true);//按返回键取消窗体
    dialog.setOnKeyListener(this);
    dialog.setOnDismissListener(this);
    Window window = dialog.getWindow();
    if (window != null) {
        window.setGravity(Gravity.BOTTOM);
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        //AndroidRuntimeException: requestFeature() must be called before adding content
        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.setContentView(contentLayout);
    }
    setSize(screenWidthPixels, WRAP_CONTENT);
}
 
Example 2
Source File: FilterConfig.java    From personaldnsfilter with GNU General Public License v2.0 6 votes vote down vote up
public FilterConfig(TableLayout table, Button categoryUp, Button categoryDn, TextView categoryField ) {

		configTable = table;
		editDialog = new Dialog(table.getContext(), R.style.Theme_dialog_TitleBar);

		editDialog.setOnKeyListener(this);
		editDialog.setContentView(R.layout.filterentryeditdialog);
		editDialog.setTitle(table.getContext().getResources().getString(R.string.editFilterDialogTitle));
		editOk = editDialog.findViewById(R.id.filterEditOkBtn);
		editDelete = editDialog.findViewById(R.id.filterEditDelBtn);
		editCancel = editDialog.findViewById(R.id.filterEditCancelBtn);
		editOk.setOnClickListener(this);
		editDelete.setOnClickListener(this);
		editCancel.setOnClickListener(this);
		
		this.categoryUp = categoryUp;
		this.categoryDown = categoryDn;
		this.categoryField = categoryField;
		categoryField.setText(ALL_ACTIVE);

		categoryMap = new TreeMap();
	}
 
Example 3
Source File: AwesomeFragment.java    From AndroidNavigation with MIT License 6 votes vote down vote up
protected void setupDialog() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setStatusBarTranslucent(true);
    } else {
        setStatusBarTranslucent(presentableActivity.isStatusBarTranslucent());
    }

    Window window = getWindow();
    if (window != null) {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }

    Dialog dialog = getDialog();
    if (dialog != null) {
        dialog.setOnKeyListener((dialogInterface, keyCode, event) -> {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                if (!dispatchBackPressed() && isCancelable()) {
                    hideDialog();
                }
                return true;
            }
            return false;
        });
    }
}
 
Example 4
Source File: BasicPopup.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
private void initDialog() {
    contentLayout = new FrameLayout(activity);
    contentLayout.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
    contentLayout.setFocusable(true);
    contentLayout.setFocusableInTouchMode(true);
    dialog = new Dialog(activity);
    dialog.setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
    dialog.setCancelable(true);//按返回键取消窗体
    dialog.setOnKeyListener(this);
    dialog.setOnDismissListener(this);
    Window window = dialog.getWindow();
    if (window != null) {
        window.setGravity(Gravity.BOTTOM);
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        //AndroidRuntimeException: requestFeature() must be called before adding content
        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.setContentView(contentLayout);
    }
    setSize(screenWidthPixels, WRAP_CONTENT);
}
 
Example 5
Source File: BaseBottomSheetDialog.java    From mvvm-template with GNU General Public License v3.0 6 votes vote down vote up
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.setOnShowListener(dialogInterface -> {
        if (ViewHelper.isTablet(getActivity())) {
            if (dialog.getWindow() != null) {
                dialog.getWindow().setLayout(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.MATCH_PARENT);
            }
        }
        onDialogIsShowing();
    });
    dialog.setOnKeyListener((dialog1, keyCode, event) -> {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            isAlreadyHidden = true;
            onDismissedByScrolling();
        }
        return false;
    });
    return dialog;
}
 
Example 6
Source File: DialogMaker.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
@NonNull
public static DialogMaker makeDialog(Context context) {
    DialogMaker dialogMaker = new DialogMaker();
    dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.gif_dialog);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setCancelable(false);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

    dialog.setOnKeyListener(new Dialog.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                dialog.dismiss();
            }
            return true;
        }
    });

    return dialogMaker;
}
 
Example 7
Source File: ZidooRecorderTool.java    From zidoorecorder with Apache License 2.0 6 votes vote down vote up
public void initView(Context mContext) {
	this.mContext = mContext;
	SoundTool.initSound(mContext);
	mDialog = new Dialog(mContext, R.style.dialogViewStyle);
	LayoutInflater inflater = LayoutInflater.from(mContext);
	View view = inflater.inflate(R.layout.dialog_view, null);
	initDialogView(view);
	mDialog.setContentView(view);
	Window window = mDialog.getWindow();
	// ���ö���
	// window.setWindowAnimations(R.style.dialogViewAnim);
	// ����
	// window.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.dialog_back));
	WindowManager.LayoutParams lp = window.getAttributes();
	lp.width = WindowManager.LayoutParams.MATCH_PARENT;
	lp.height = WindowManager.LayoutParams.MATCH_PARENT;
	// window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
	mDialog.setOnKeyListener(mOnKeyListener);
	view.setOnHoverListener(mOnTouchListener);
	// setView();

	mHandler.sendEmptyMessage(1);
	mHandler.sendEmptyMessage(7);
	mHandler.sendMessage(mHandler.obtainMessage(9, 0, 0));
	initUsbData();
}
 
Example 8
Source File: BasicPopup.java    From AndroidPicker with MIT License 6 votes vote down vote up
private void initDialog() {
    contentLayout = new FrameLayout(activity);
    contentLayout.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
    contentLayout.setFocusable(true);
    contentLayout.setFocusableInTouchMode(true);
    dialog = new Dialog(activity);
    dialog.setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
    dialog.setCancelable(true);//按返回键取消窗体
    dialog.setOnKeyListener(this);
    dialog.setOnDismissListener(this);
    Window window = dialog.getWindow();
    if (window != null) {
        window.setGravity(Gravity.BOTTOM);
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        //AndroidRuntimeException: requestFeature() must be called before adding content
        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.setContentView(contentLayout);
    }
    setSize(screenWidthPixels, WRAP_CONTENT);
}
 
Example 9
Source File: InputTextDialogFragment.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    // hides the actual dialog title, we have one already...
    dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    // we want to listen to clicks on back button
    dialog.setOnKeyListener(this);
    return dialog;
}
 
Example 10
Source File: ExpandableMenuOverlay.java    From ExpandableButtonMenu with Apache License 2.0 5 votes vote down vote up
public void init(AttributeSet attrs) {
    // We create a fake dialog which dims the screen and we display the expandable menu as content
    mDialog = new Dialog(getContext(), android.R.style.Theme_Translucent_NoTitleBar);
    mDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

    WindowManager.LayoutParams lp = mDialog.getWindow().getAttributes();
    lp.dimAmount = dimAmount;
    mDialog.getWindow().setAttributes(lp);

    mButtonMenu = new ExpandableButtonMenu(getContext(), attrs);
    mButtonMenu.setButtonMenuParentOverlay(this);

    mDialog.setContentView(mButtonMenu);
    mDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialogInterface) {
            setVisibility(View.INVISIBLE);
            mButtonMenu.toggle();
        }
    });

    // Catch events when keyboard button are clicked. Used to dismiss the menu
    // on 'back' button
    mDialog.setOnKeyListener(this);

    // Clicking this view will expand the button menu
    setOnClickListener(this);

}
 
Example 11
Source File: GamePadActivity.java    From bombsquad-remote-android with Apache License 2.0 4 votes vote down vote up
public Dialog doCaptureKey() {

    final Dialog d = new Dialog(_gamePadActivity);
    d.setContentView(R.layout.prefs_capture_key);
    d.setCanceledOnTouchOutside(true);
    d.setOnKeyListener(new Dialog.OnKeyListener() {
      @Override
      public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
        _setActionKey(keyCode);
        d.dismiss();
        return true;
      }
    });

    Button b = d.findViewById(R.id.buttonResetToDefault);
    b.setOnClickListener(new Button.OnClickListener() {
      @Override
      public void onClick(View v) {
        switch (_captureKey) {
          case PICK_UP:
            _setActionKey(KeyEvent.KEYCODE_BUTTON_Y);
            break;
          case JUMP:
            _setActionKey(KeyEvent.KEYCODE_BUTTON_A);
            break;
          case PUNCH:
            _setActionKey(KeyEvent.KEYCODE_BUTTON_X);
            break;
          case BOMB:
            _setActionKey(KeyEvent.KEYCODE_BUTTON_B);
            break;
          case RUN1:
            _setActionKey(KeyEvent.KEYCODE_BUTTON_L1);
            break;
          case RUN2:
            _setActionKey(KeyEvent.KEYCODE_BUTTON_R1);
            break;
          case START:
            _setActionKey(KeyEvent.KEYCODE_BUTTON_START);
            break;
          default:
            LogThread.log("Error: unrecognized key in doActionKey", null,
                d.getContext());
            break;
        }
        d.dismiss();
      }
    });

    d.setTitle(R.string.capturing);
    d.show();
    return d;
  }
 
Example 12
Source File: LoginDialogFragment.java    From openshop.io-android with MIT License 4 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    Dialog d = getDialog();
    if (d != null) {
        int width = ViewGroup.LayoutParams.MATCH_PARENT;
        int height = ViewGroup.LayoutParams.MATCH_PARENT;
        Window window = d.getWindow();
        window.setLayout(width, height);
        window.setWindowAnimations(R.style.dialogFragmentAnimation);
        d.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (BuildConfig.DEBUG)
                    Timber.d("onKey: %d (Back=%d). Event:%d (Down:%d, Up:%d)", keyCode, KeyEvent.KEYCODE_BACK, event.getAction(),
                            KeyEvent.ACTION_DOWN, KeyEvent.ACTION_UP);
                if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                    switch (actualFormState) {
                        case REGISTRATION:
                            if (event.getAction() == KeyEvent.ACTION_UP) {
                                setVisibilityOfRegistrationForm(false);
                            }
                            return true;
                        case FORGOTTEN_PASSWORD:
                            if (event.getAction() == KeyEvent.ACTION_UP) {
                                setVisibilityOfEmailForgottenForm(false);
                            }
                            return true;
                        case EMAIL:
                            if (event.getAction() == KeyEvent.ACTION_UP) {
                                setVisibilityOfEmailForm(false);
                            }
                            return true;
                        default:
                            return false;
                    }
                }
                return false;
            }
        });
    }
}