类android.content.DialogInterface.OnKeyListener源码实例Demo

下面列出了怎么用android.content.DialogInterface.OnKeyListener的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Androzic   文件: Splash.java
private void showEula()
{
	final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
	boolean hasBeenShown = prefs.getBoolean(getString(R.string.app_eulaaccepted), false);
	if (hasBeenShown == false)
	{
		final SpannableString message = new SpannableString(Html.fromHtml(getString(R.string.app_eula).replace("/n", "<br/>")));
		Linkify.addLinks(message, Linkify.WEB_URLS);

		AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(getString(R.string.app_name)).setIcon(R.drawable.icon).setMessage(message)
				.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialogInterface, int i)
					{
						prefs.edit().putBoolean(getString(R.string.app_eulaaccepted), true).commit();
						wait = false;
						dialogInterface.dismiss();
					}
				}).setOnKeyListener(new OnKeyListener() {
					@Override
					public boolean onKey(DialogInterface dialoginterface, int keyCode, KeyEvent event)
					{
						return !(keyCode == KeyEvent.KEYCODE_HOME);
					}
				}).setCancelable(false);

		AlertDialog d = builder.create();

		d.show();
		// Make the textview clickable. Must be called after show()
		((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
	}
	else
	{
		wait = false;
	}
}
 
源代码2 项目: FimiX8-RE   文件: X8UpdateHintController.java
public void showUpdateDialog() {
    if (UpdateUtil.getUpfireDtos().size() > 0) {
        SPStoreManager.getInstance().saveInt(HostConstants.SP_KEY_UPDATE_CHECK, 1);
        if (UpdateUtil.isForceUpdate()) {
            this.dialogManagerUpdate = new X8DoubleCustomDialog(this.context, this.context.getString(R.string.x8_update_fw_title), this.context.getString(R.string.x8_update_tip), this.context.getString(R.string.fimi_sdk_update_now), this.context.getString(R.string.fimi_sdk_update_return), new onDialogButtonClickListener() {
                public void onLeft() {
                    X8UpdateHintController.this.dialogManagerUpdate.dismiss();
                    X8UpdateHintController.this.context.startActivity(new Intent(X8UpdateHintController.this.context, X8UpdateDetailActivity.class));
                }

                public void onRight() {
                    X8UpdateHintController.this.context.finish();
                }
            });
            this.dialogManagerUpdate.setCanceledOnTouchOutside(false);
            this.dialogManagerUpdate.setOnKeyListener(new OnKeyListener() {
                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                    if (keyCode != 4 || event.getRepeatCount() == 0) {
                    }
                    return true;
                }
            });
            if (!this.context.isFinishing()) {
                this.dialogManagerUpdate.show();
                return;
            }
            return;
        }
        this.dialogManagerUpdate = new X8DoubleCustomDialog(this.context, this.context.getString(R.string.x8_update_fw_title), this.context.getString(R.string.x8_update_tip), this.context.getString(R.string.fimi_sdk_update_ignore), this.context.getString(R.string.fimi_sdk_update_now), new onDialogButtonClickListener() {
            public void onLeft() {
                X8UpdateHintController.this.dialogManagerUpdate.dismiss();
            }

            public void onRight() {
                X8UpdateHintController.this.dialogManagerUpdate.dismiss();
                X8UpdateHintController.this.context.startActivity(new Intent(X8UpdateHintController.this.context, X8UpdateDetailActivity.class));
            }
        });
        this.dialogManagerUpdate.setCanceledOnTouchOutside(false);
        if (!this.context.isFinishing()) {
            this.dialogManagerUpdate.show();
        }
    }
}
 
@NonNull
@Override
public MaterialAlertDialogBuilder setOnKeyListener(@Nullable OnKeyListener onKeyListener) {
  return (MaterialAlertDialogBuilder) super.setOnKeyListener(onKeyListener);
}
 
public PreferenceDialogBuilder setOnKeyListener(OnKeyListener onKeyListener) {
    mBuilder.setOnKeyListener(onKeyListener);
    return this;
}
 
public PreferenceDialogBuilder setOnKeyListener(OnKeyListener onKeyListener) {
    mBuilder.setOnKeyListener(onKeyListener);
    return this;
}
 
源代码6 项目: gokit-android   文件: GosDeviceControlActivity.java
/**
 * 初始化控件.
 */
private void initViews() {
	tvColorText = (TextView) findViewById(R.id.tvColorText);
	llColor = (LinearLayout) findViewById(R.id.ll_color);
	swRed = (Switch) findViewById(R.id.sw_red);
	swInfrared = (Switch) findViewById(R.id.sw_infrared);
	tvRed = (TextView) findViewById(R.id.tv_red);
	tvGreen = (TextView) findViewById(R.id.tv_green);
	tvBlue = (TextView) findViewById(R.id.tv_blue);
	tvSpeed = (TextView) findViewById(R.id.tv_speed);
	tvTemplate = (TextView) findViewById(R.id.tv_template);
	tvHumidity = (TextView) findViewById(R.id.tv_humidity);
	sbRed = (SeekBar) findViewById(R.id.sb_red);
	sbGreen = (SeekBar) findViewById(R.id.sb_green);
	sbBlue = (SeekBar) findViewById(R.id.sb_blue);
	sbSpeed = (SeekBar) findViewById(R.id.sb_speed);

	redadd = (ImageView) findViewById(R.id.redadd);
	redsub = (ImageView) findViewById(R.id.redsub);
	greenadd = (ImageView) findViewById(R.id.greenadd);
	greensub = (ImageView) findViewById(R.id.greensub);
	blueadd = (ImageView) findViewById(R.id.blueadd);
	bluesub = (ImageView) findViewById(R.id.bluesub);
	speedadd = (ImageView) findViewById(R.id.speedadd);
	speedsub = (ImageView) findViewById(R.id.speedsub);

	String waitingText = (String) getText(R.string.waiting_device_ready);
	setProgressDialog(waitingText, true, false);
	progressDialog.setOnKeyListener(new OnKeyListener() {

		@Override
		public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {

			if (keyCode == KeyEvent.KEYCODE_BACK) {
				if (progressDialog.isShowing()) {
					GosDeviceControlActivity.this.finish();
					return true;
				}
			}

			return false;
		}
	});
}
 
/**
 * Sets the listener, which should be notified, when a key has been dispatched to the
 * preference's dialog.
 *
 * @param listener
 *         The listener, which should be set, as an instance of the type {@link OnKeyListener}
 *         or null, if no listener should be notified
 */
public final void setOnKeyListener(@Nullable final OnKeyListener listener) {
    onKeyListener = listener;
}
 
 类所在包
 同包方法