android.app.AlertDialog#show ( )源码实例Demo

下面列出了android.app.AlertDialog#show ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private void onEnterStartedState() {
    Log.d(TAG, "call onEnterStartedState");
    /* Connect camera */
    if (!connectCamera(getWidth(), getHeight())) {
        AlertDialog ad = new AlertDialog.Builder(getContext()).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL,  "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                ((Activity) getContext()).finish();
            }
        });
        ad.show();

    }
}
 
源代码2 项目: MOAAP   文件: CameraBridgeViewBase.java
private void onEnterStartedState() {
    Log.d(TAG, "call onEnterStartedState");
    /* Connect camera */
    if (!connectCamera(getWidth(), getHeight())) {
        AlertDialog ad = new AlertDialog.Builder(getContext()).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL,  "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                ((Activity) getContext()).finish();
            }
        });
        ad.show();

    }
}
 
源代码3 项目: mupdf-android   文件: MuPDFActivity.java
@Override
public void onBackPressed() {
	if (core != null && core.hasChanges()) {
		DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				if (which == AlertDialog.BUTTON_POSITIVE)
					core.save();

				finish();
			}
		};
		AlertDialog alert = mAlertBuilder.create();
		alert.setTitle("MuPDF");
		alert.setMessage(getString(R.string.document_has_changes_save_them_));
		alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.yes), listener);
		alert.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.no), listener);
		alert.show();
	} else {
		super.onBackPressed();
	}
}
 
源代码4 项目: PixaToon   文件: CameraBridgeViewBase.java
private void onEnterStartedState() {
    Log.d(TAG, "call onEnterStartedState");
    /* Connect camera */
    if (!connectCamera(getWidth(), getHeight())) {
        AlertDialog ad = new AlertDialog.Builder(getContext()).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL,  "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                ((Activity) getContext()).finish();
            }
        });
        ad.show();

    }
}
 
源代码5 项目: SimplePomodoro-android   文件: TaskListFragment.java
private void showXiaoMiAlertDialog(){
 	SettingUtility.setXiaoMiMode(true);
	AlertDialog d = new AlertDialog.Builder(getActivity())
       .setTitle(getActivity().getString(R.string.detect_is_miphone))
       .setMessage(getActivity().getString(R.string.miphone_message))
       .setPositiveButton(R.string.ok, new android.content.DialogInterface.OnClickListener() {
		
		@Override
		public void onClick(DialogInterface dialog, int which) {
			// TODO Auto-generated method stub
			
			
		}
	})
     	.create();
	d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
	d.show();
}
 
源代码6 项目: MOAAP   文件: CameraBridgeViewBase.java
private void onEnterStartedState() {
    Log.d(TAG, "call onEnterStartedState");
    /* Connect camera */
    if (!connectCamera(getWidth(), getHeight())) {
        AlertDialog ad = new AlertDialog.Builder(getContext()).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL,  "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                ((Activity) getContext()).finish();
            }
        });
        ad.show();

    }
}
 
源代码7 项目: RelaxFinger   文件: SettingActivity.java
public void questionsAnswer() {

        AlertDialog dialog = new AlertDialog.Builder(this).create();
        dialog.setTitle("帮助说明");
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setMessage("1.不能卸载软件:在设置界面关闭“开启锁屏”选项后,即可正常卸载。\r\n" +
                "2.屏幕截图没反应:部分手机在第一次屏幕截图时需要稍等片刻,弹出授权框后,点击允许即可。\r\n" +
                "3.截图保存在哪里:截图保存在系统存储卡根目录RelaxFinger文件夹里面。\r\n" +
                "4.避让软键盘无效:安卓7.0以下系统避让软键盘功能最好安装两个及以上输入法(包含系统自带输入法)。\r\n" +
                "5.不能开机自启动:首先确保设置界面“开机启动”选项已开启,如果仍然不能启动,到系统设置->" +
                "安全->应用程序许可中找到RelaxFinger,点击进去后打开自动运行开关即可。\r\n" +
                "6.自定义主题不好看:在系统存储卡根目录找到RelaxFinger目录,将里面的DIY.png换成喜欢的图片" +
                ",确保新图片名称依然是DIY.png即可。\r\n" +
                "7.若频繁需要重新激活,系统设置->安全->应用程序许可->RelaxFinger->启用自动运行," +
                "部分国产手机->电池管理->受保护应用->启用悬浮助手,任务管理器中的一键清除也会杀掉悬浮助手," +
                "可以在任务管理界面,给悬浮助手加上锁即可,手机不同加锁方法自行百度," +
                "华为是任务管理器界面按住悬浮助手往下拉,MIUI好像是就有个锁,点一下就好了。\r\n" +
                "8.临时移动模式:悬浮球会向上移动一段距离,可自由移动,点击退出临时移动模式。打开关闭输入法会自动"+
                "进入和退出临时移动模式。\r\n"+
                "9.显示消息通知:当接收到消息时,悬浮球会变成相应的APP图标,并晃动提示,点击打开消息,上滑忽略"+
                "当前消息,下滑忽略所有消息。\r\n"+
                "10.安卓6.0及以上系统出现叠加层解决方法:在系统设置->开发者选项->停用HW叠加层即可。");
        dialog.show();
    }
 
源代码8 项目: xDrip-plus   文件: ImportDatabaseActivity.java
private void showWarningAndInstructions() {
    LayoutInflater inflater= LayoutInflater.from(this);
    View view=inflater.inflate(R.layout.import_db_warning, null);
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
    alertDialog.setTitle("Import Instructions");
    alertDialog.setView(view);
    alertDialog.setCancelable(false);
    alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            generateDBGui();
        }
    });
    AlertDialog alert = alertDialog.create();
    alert.show();
}
 
源代码9 项目: NoiseCapture   文件: CalibrationActivityHost.java
public void onClickPinkNoise(View view) {
    calibrationService.setEmitNoise(true);
    AlertDialog alterDialog = new AlertDialog.Builder(this).setTitle(R.string.title_caution)
            .setMessage(R.string.calibration_host_warning)
            .setNeutralButton(R.string.text_OK, null)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .create();
    alterDialog.show();
}
 
源代码10 项目: product-emm   文件: PinCodeActivity.java
private void setPINCode(){
	evInput = new EditText(PinCodeActivity.this);
	alertDialog =
			CommonDialogUtils
					.getAlertDialogWithTwoButtonAndEditView(PinCodeActivity.this,
                       getResources()
                               .getString(
                                       R.string.title_head_confirm_pin),
                       getResources()
                               .getString(
                                       R.string.button_ok),
                       getResources()
                               .getString(
                                       R.string.button_cancel),
                       dialogClickListener,
                       dialogClickListener,
                       evInput);

	final AlertDialog dialog = alertDialog.create();
	dialog.show();
	// Overriding default positive button behavior to keep the
	// dialog open, if PINS don't match.
	dialog.getButton(AlertDialog.BUTTON_POSITIVE)
	      .setOnClickListener(new View.OnClickListener() {
		      @Override
		      public void onClick(View v) {
			      if (evPin.getText().toString()
			               .equals(evInput.getText().toString())) {
				      savePin();
				      dialog.dismiss();
			      } else {
				      evInput.setError(getResources().getString(
						      R.string.validation_pin_confirm));
			      }
		      }
	      });
	evInput.setInputType(InputType.TYPE_CLASS_NUMBER);
	evInput.setTransformationMethod(new PasswordTransformationMethod());
}
 
源代码11 项目: apigee-android-sdk   文件: AddAccount.java
private void showAddAccountClientError(String error) {
	String message = "Error: " + error;
	AlertDialog.Builder builder = new AlertDialog.Builder(this);
	builder.setMessage(message)
	.setCancelable(false)
	.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
		public void onClick(DialogInterface dialog, int id) {
			dialog.dismiss();
		}
	});
	AlertDialog alert = builder.create();
	alert.show();
}
 
源代码12 项目: wechatsdk-xamarin   文件: MMAlert.java
public static AlertDialog showAlert(final Context context, final String title, final View view, final DialogInterface.OnClickListener lOk) {
	if (context instanceof Activity && ((Activity) context).isFinishing()) {
		return null;
	}

	final Builder builder = new AlertDialog.Builder(context);
	builder.setTitle(title);
	builder.setView(view);
	builder.setPositiveButton(R.string.app_ok, lOk);
	// builder.setCancelable(true);
	final AlertDialog alert = builder.create();
	alert.show();
	return alert;
}
 
源代码13 项目: Kernel-Tuner   文件: Utility.java
/**
 * General Purpose AlertDialog
 */
public static AlertDialog showMessageAlertDialog(Context context, String message,
                                                 String title, DialogInterface.OnClickListener listener)
{
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(title != null ? Html.fromHtml(title) : null);
    builder.setMessage(message != null ? Html.fromHtml(message) : null);
    builder.setPositiveButton(android.R.string.ok, listener);
    AlertDialog dialog = builder.create();
    dialog.show();
    return dialog;
}
 
源代码14 项目: apigee-android-sdk   文件: AddAccount.java
private void showAddAccountPasswordLengthError() {
	AlertDialog.Builder builder = new AlertDialog.Builder(this);
	builder.setMessage(
			"Password must be five characters or more. Please try again.")
			.setCancelable(false)
			.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int id) {
					dialog.dismiss();
				}
			});
	AlertDialog alert = builder.create();
	alert.show();
}
 
源代码15 项目: talkback   文件: SetupWizardActivity.java
private void displayNextScreenOrWarning() {
  /*
   * If we are currently on a switch configuration screen, display a dialog asking if the user
   * wishes to continue if they attempt to proceed to the next screen without assigning any
   * switches. This combats human error in completing the setup wizard.
   */
  if (currentScreenFragment instanceof SetupWizardConfigureSwitchFragment
      && !((SetupWizardConfigureSwitchFragment) currentScreenFragment).hasSwitchesAdded()) {
    AlertDialog.Builder noKeysBuilder =
        new AlertDialog.Builder(
            new ContextThemeWrapper(this, R.style.SetupGuideAlertDialogStyle));
    noKeysBuilder.setTitle(getString(R.string.setup_switch_assignment_nothing_assigned_title));
    noKeysBuilder.setMessage(
        getString(R.string.setup_switch_assignment_nothing_assigned_message));

    noKeysBuilder.setPositiveButton(
        android.R.string.ok,
        (dialogInterface, viewId) -> {
          displayNextScreen();
          dialogInterface.cancel();
        });

    noKeysBuilder.setNegativeButton(android.R.string.cancel, (dialog, viewId) -> dialog.cancel());

    AlertDialog noKeysDialog = noKeysBuilder.create();
    noKeysDialog.show();
  } else {
    displayNextScreen();
  }
}
 
源代码16 项目: logmein-android   文件: ManagerUserServices.java
/**
 * Displays dialog box and manages updation of information
 * @param un username whose information is to be updated
 * @param inflater to instantiate layout
 * @return object of Dialog created
 */
public Dialog update(String un,LayoutInflater inflater){
    this.mUsername = un;
    initialize(inflater);
    mTextboxUsername.setText(un);
    final UserStructure us = mDatabaseEngine.getUsernamePassword(un);
    mTextboxPassword.setHint("(unchanged)");


    AlertDialog.Builder builder = new AlertDialog.Builder(this.mContext);
    builder.setView(mView)
           .setTitle("Update user")
           .setPositiveButton("UPDATE",null)
    .setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
        }
    });

    final AlertDialog dialog = builder.create();
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();

    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            flagAddUpdate = false;
            String tb_username = mTextboxUsername.getText().toString();
            String tb_password = mTextboxPassword.getText().toString();
            if(tb_password.isEmpty()){
                if(tb_username != us.getUsername()){
                    if(add_update(tb_username, us.getPassword())){
                        //Save new username to preference for service
                        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext);
                        SharedPreferences.Editor editor = preferences.edit();
                        editor.putString(SettingsActivity.KEY_CURRENT_USERNAME, tb_username);
                        //XXX: Should we save current position for recovery
                        editor.apply();
                        dialog.dismiss();
                    }
                }else{
                    dialog.dismiss();
                }
            }else if(add_update(mTextboxUsername.getText().toString(), mTextboxPassword.getText().toString())){
                dialog.dismiss();
            }
        }
    });
    return dialog;
}
 
源代码17 项目: osmdroid   文件: SampleCacheDownloaderCustomUI.java
private void showCacheManagerDialog() {

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                getActivity());


        // set title
        alertDialogBuilder.setTitle(R.string.cache_manager);
        //.setMessage(R.string.cache_manager_description);

        // set dialog message
        alertDialogBuilder.setItems(new CharSequence[]{
                        getResources().getString(R.string.cache_current_size),
                        getResources().getString(R.string.cache_download),
                        getResources().getString(R.string.cancelall),
                        getResources().getString(R.string.showpendingjobs),
                        getResources().getString(R.string.close)
                }, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        switch (which) {
                            case 0:
                                showCurrentCacheInfo();
                                break;
                            case 1:
                                downloadJobAlert();
                                break;
                            case 2:
                                mgr.cancelAllJobs();
                                Toast.makeText(getActivity(), "Jobs Canceled", Toast.LENGTH_LONG).show();
                                break;
                            case 3:
                                Toast.makeText(getActivity(), "Pending Jobs: " + mgr.getPendingJobs(), Toast.LENGTH_LONG).show();
                                break;
                        }
                        dialog.dismiss();
                    }
                }
        );


        // create alert dialog
        AlertDialog alertDialog = alertDialogBuilder.create();

        // show it
        alertDialog.show();


        //mgr.possibleTilesInArea(mMapView.getBoundingBox(), 0, 18);
        // mgr.
    }
 
源代码18 项目: TowerCollector   文件: MainActivity.java
private void displayNotCompatibleDialog() {
    // check if displayed in this app run
    if (showNotCompatibleDialog) {
        // check if not disabled in preferences
        boolean showCompatibilityWarningEnabled = MyApplication.getPreferencesProvider().getShowCompatibilityWarning();
        if (showCompatibilityWarningEnabled) {
            TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            // check if device contains telephony hardware (some tablets doesn't report even if have)
            // NOTE: in the future this may need to be expanded when new specific features appear
            PackageManager packageManager = getPackageManager();
            boolean noRadioDetected = !(packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) && (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_GSM) || packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA)));
            // show dialog if something is not supported
            if (noRadioDetected) {
                Timber.d("displayNotCompatibleDialog(): Not compatible because of radio: %s, phone type: %s", noRadioDetected, telephonyManager.getPhoneType());
                //use custom layout to show "don't show this again" checkbox
                AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
                LayoutInflater inflater = LayoutInflater.from(this);
                View dialogLayout = inflater.inflate(R.layout.dont_show_again_dialog, null);
                final CheckBox dontShowAgainCheckbox = (CheckBox) dialogLayout.findViewById(R.id.dont_show_again_dialog_checkbox);
                dialogBuilder.setView(dialogLayout);
                AlertDialog alertDialog = dialogBuilder.create();
                alertDialog.setCanceledOnTouchOutside(true);
                alertDialog.setCancelable(true);
                alertDialog.setTitle(R.string.main_dialog_not_compatible_title);
                StringBuilder stringBuilder = new StringBuilder(getString(R.string.main_dialog_not_compatible_begin));
                if (noRadioDetected) {
                    stringBuilder.append(getString(R.string.main_dialog_no_compatible_mobile_radio_message));
                }
                // text set this way to prevent checkbox from disappearing when text is too long
                TextView messageTextView = (TextView) dialogLayout.findViewById(R.id.dont_show_again_dialog_textview);
                messageTextView.setText(stringBuilder.toString());
                alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        boolean dontShowAgainCheckboxChecked = dontShowAgainCheckbox.isChecked();
                        Timber.d("displayNotCompatibleDialog(): Don't show again checkbox checked = %s", dontShowAgainCheckboxChecked);
                        if (dontShowAgainCheckboxChecked) {
                            MyApplication.getPreferencesProvider().setShowCompatibilityWarning(false);
                        }
                    }
                });
                alertDialog.show();
            }
        }
        showNotCompatibleDialog = false;
    }
}
 
源代码19 项目: NetworkMapper   文件: MainActivity.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    switch (id) {
        case R.id.action_settings:
            Intent i = new Intent(getApplicationContext(), SettingsActivity.class);
            startActivityForResult(i, 1);
            break;

        case R.id.action_download:
            downloadAll();
            break;

        case R.id.action_clear:
            outputView.setText("");
            break;

        case R.id.action_share:
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, outputView.getText());
            sendIntent.setType("text/plain");
            startActivity(Intent.createChooser(sendIntent, getText(R.string.share_to)));
            break;

        case R.id.action_copy2clipboard:
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText(getString(R.string.clipboard_title), outputView.getText());
            clipboard.setPrimaryClip(clip);
            Toast.makeText(getApplicationContext(),getString(R.string.toast_copy2cliboard), Toast.LENGTH_SHORT).show();
            break;

        case R.id.action_displayip:
            outputView.append(NetUtil.getIPs());
            break;

        case R.id.action_about:
            AlertDialog.Builder aboutbuilder = new AlertDialog.Builder(this);
            AlertDialog aboutdlg = aboutbuilder.setTitle(getString(R.string.aboutdlg_title)).
                setMessage(getString(R.string.aboutdlg_text)).create();
            aboutdlg.show();
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
源代码20 项目: citra_android   文件: EmulationActivity.java
private void toggleControls()
{
  final SharedPreferences.Editor editor = mPreferences.edit();
  boolean[] enabledButtons = new boolean[14];
  AlertDialog.Builder builder = new AlertDialog.Builder(this);
  builder.setTitle(R.string.emulation_toggle_controls);

  // TODO : remove this...
/*if (sIsGameCubeGame || mPreferences.getInt("wiiController", 3) == 0) {
	for (int i = 0; i < enabledButtons.length; i++) {
		enabledButtons[i] = mPreferences.getBoolean("buttonToggleGc" + i, true);
	}
	builder.setMultiChoiceItems(R.array.gcpadButtons, enabledButtons,
			(dialog, indexSelected, isChecked) -> editor.putBoolean("buttonToggleGc" + indexSelected, isChecked));
} else if (mPreferences.getInt("wiiController", 3) == 4) {
	for (int i = 0; i < enabledButtons.length; i++) {
		enabledButtons[i] = mPreferences.getBoolean("buttonToggleClassic" + i, true);
	}
	builder.setMultiChoiceItems(R.array.classicButtons, enabledButtons,
			(dialog, indexSelected, isChecked) -> editor.putBoolean("buttonToggleClassic" + indexSelected, isChecked));
} else {
	for (int i = 0; i < enabledButtons.length; i++) {
		enabledButtons[i] = mPreferences.getBoolean("buttonToggleWii" + i, true);
	}
	if (mPreferences.getInt("wiiController", 3) == 3) {
		builder.setMultiChoiceItems(R.array.nunchukButtons, enabledButtons,
				(dialog, indexSelected, isChecked) -> editor.putBoolean("buttonToggleWii" + indexSelected, isChecked));
	} else {
		builder.setMultiChoiceItems(R.array.wiimoteButtons, enabledButtons,
				(dialog, indexSelected, isChecked) -> editor.putBoolean("buttonToggleWii" + indexSelected, isChecked));
	}
}*/

  for (int i = 0; i < enabledButtons.length; i++)
  {
    enabledButtons[i] = mPreferences.getBoolean("buttonToggle3ds" + i, true);
  }
  builder.setMultiChoiceItems(R.array.n3dsButtons, enabledButtons,
          (dialog, indexSelected, isChecked) -> editor
                  .putBoolean("buttonToggle3ds" + indexSelected, isChecked));


  builder.setNeutralButton(getString(R.string.emulation_toggle_all),
          (dialogInterface, i) -> mEmulationFragment.toggleInputOverlayVisibility());
  builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) ->
  {
    editor.apply();

    mEmulationFragment.refreshInputOverlay();
  });

  AlertDialog alertDialog = builder.create();
  alertDialog.show();
}