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

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

源代码1 项目: Kernel-Tuner   文件: MiscTweaksActivity.java
private void showSelectSchedulerDialog()
{
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.select_scheduler));
    builder.setNegativeButton(R.string.cancel, null);

    final String[] items = IOHelper.schedulersAsArray();
    builder.setItems(items, new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialogInterface, int i)
        {
            RCommand.setScheduler(items[i], MiscTweaksActivity.this);
        }
    });

    builder.show();
}
 
源代码2 项目: appcan-android   文件: EUExWindow.java
private void showPermissionDialog(final String windName) {
      EBrowserActivity activity = (EBrowserActivity) mContext;
      /*if (!activity.isVisable()) {
	return;
}*/
      Runnable ui = new Runnable() {
          @Override
          public void run() {
              AlertDialog.Builder dia = new AlertDialog.Builder(mContext);
              dia.setTitle(EUExUtil.getString("warning"));
              dia.setMessage(String.format(EUExUtil.getString("no_permission_to_open_window"), windName));
              dia.setCancelable(false);
              dia.setPositiveButton(EUExUtil.getString("confirm"), null);
              dia.show();
          }
      };
      activity.runOnUiThread(ui);
  }
 
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
    //PackageManager pm = super.getPackageManager();
    Vector<String> appNames = new Vector<String>();
    for (Integer i : logoDownloadBehaviourList)
    {
        appNames.add(SettingsActivity.getLogoBehaviourOptionString(i, getContext()));
    }

    // converting Vector appNames to String[] appNamesStr
    String [] appNamesStr=appNames.toArray(new String[appNames.size()]);

    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Select logo download behaviour")
            .setItems(appNamesStr, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // The 'which' argument contains the index position
                    // of the selected item
                    mListener.onLogoDownloadBehaviourSelected(dialog, which);
                }
            });
    // Create the AlertDialog object and return it
    return builder.create();
}
 
源代码4 项目: Dashboard   文件: BaseActivity.java
public void getzooper(View view)

    {
        final AlertDialog.Builder menuAleart = new AlertDialog.Builder(this);
        final String[] menuList = {"AMAZON APP STORE", "GOOGLE PLAY STORE"};
        menuAleart.setItems(menuList, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                switch (item) {
                    case 0:
                        boolean installed = appInstalledOrNot("com.amazon.venezia");
                        if (installed) {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("amzn://apps/android?p=org.zooper.zwpro")));
                        } else {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.amazon.com/gp/mas/dl/android?p=org.zooper.zwpro")));
                        }
                        break;
                    case 1:
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=org.zooper.zwpro")));
                        break;
                }
            }
        });
        AlertDialog menuDrop = menuAleart.create();
        menuDrop.show();
    }
 
源代码5 项目: AnLinux-Adfree   文件: DashBoard.java
public void notifyUserForNethunter(){
    final ViewGroup nullParent = null;
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
    LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
    View view = layoutInflater.inflate(R.layout.notify1, nullParent);
    TextView textView = view.findViewById(R.id.textView);

    alertDialog.setView(view);
    alertDialog.setCancelable(false);
    alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putBoolean("IsNethunterNotified", true);
            editor.apply();
            isNethunterNotified = sharedPreferences.getBoolean("IsNethunterNotified", false);
            dialog.dismiss();
        }
    });
    alertDialog.show();
    textView.setText(R.string.nethunter_warning_content);
}
 
源代码6 项目: emerald-dialer   文件: DialerActivity.java
private void showDeviceId() {
	AlertDialog.Builder builder = new AlertDialog.Builder(this);
	String deviceId;
	
	if (Build.VERSION.SDK_INT < 26) {
		deviceId = telephonyManager.getDeviceId();
	} else {
		switch (telephonyManager.getPhoneType()) {
		case TelephonyManager.PHONE_TYPE_GSM:
			deviceId = telephonyManager.getImei();
			break;
		case TelephonyManager.PHONE_TYPE_CDMA:
			deviceId = telephonyManager.getMeid();
			break;
		default:
			deviceId = "null";
		}
	}
	builder.setMessage(deviceId);
	builder.create().show();
}
 
源代码7 项目: ShoppingList   文件: AddItemShoppingList.java
private void deleteAll(final boolean onlyCheckeds) {
	if (adapter.getCount() > 0) {
		AlertDialog.Builder adb = new AlertDialog.Builder(this);
		adb.setTitle(R.string.delete_question);
		adb.setMessage(getString(onlyCheckeds ? R.string.want_delete_all_selected_itens : R.string.want_delete_all_items));
		adb.setNegativeButton(R.string.no, null);
		adb.setPositiveButton(R.string.yes, new AlertDialog.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				try {
					ItemShoppingListDAO.deleteAllLista(AddItemShoppingList.this, shoppingList.getId(), onlyCheckeds);
					cancelEditing();
				} catch (VansException e) {
					e.printStackTrace();
					Toast.makeText(AddItemShoppingList.this, e.getMessage(), Toast.LENGTH_LONG).show();
				}
			}
		});

		adb.show();
	}
}
 
源代码8 项目: AndroidBase   文件: GoUtil.java
public static AlertDialog.Builder dialogBuilder(Context context, String title, String msg) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    if (msg != null) {
        builder.setMessage(msg);
    }
    if (title != null) {
        builder.setTitle(title);
    }
    return builder;
}
 
public void handleMessage(Message msg) {
	//Stop progressbar
	setSupportProgressBarIndeterminateVisibility(false);
	
	if (msg.what == -1) {
		ConnectionError();
		
	}

	if (msg.what == 1) {
		myResult = msg.obj.toString();
		if (myResult.matches("")) {
			// Error Login
			AlertDialog.Builder builder1 = new AlertDialog.Builder(
					tarks_account_login.this);
			builder1.setMessage(getString(R.string.error_login))
					.setPositiveButton(getString(R.string.yes), null)
					.setTitle(getString(R.string.error));
			builder1.show();
		} else {
			// Save auth key to temp

			// Intent 생성
			Intent intent = new Intent();
			// 생성한 Intent에 데이터 입력
			intent.putExtra("id", edit1.getText().toString());
			intent.putExtra("auth_code", myResult);
			// 결과값 설정(결과 코드, 인텐트)
			tarks_account_login.this.setResult(RESULT_OK, intent);
			// 본 Activity 종료
			finish();
		}

	}

}
 
源代码10 项目: samples-android   文件: OktaProgressDialog.java
private AlertDialog createAlertDialog(String message) {
    if(mContext.get() != null) {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext.get());
        builder.setCancelable(false); // if you want user to wait for some process to finish,
        LayoutInflater mInflater = (LayoutInflater) mContext.get().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = mInflater.inflate(R.layout.layout_progress_dialog, null, false);
        String textViewMessage = (message == null) ? mContext.get().getString(R.string.progress_dialog_message) : message;
        ((TextView)view.findViewById(R.id.message_textview)).setText(textViewMessage);
        builder.setView(view);
        return builder.create();
    }
    return null;
}
 
源代码11 项目: apigee-android-sdk   文件: AddAccount.java
private void showAddAccountEmailFormatError() {
	AlertDialog.Builder builder = new AlertDialog.Builder(this);
	builder.setMessage(
			"Email format error. eg. [email protected]")
			.setCancelable(false)
			.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int id) {
					dialog.dismiss();
				}
			});
	AlertDialog alert = builder.create();
	alert.show();
}
 
源代码12 项目: samples-android   文件: BarcodeCaptureActivity.java
/**
 * Callback for the result from requesting permissions. This method
 * is invoked for every call on {@link #requestPermissions(String[], int)}.
 * <p>
 * <strong>Note:</strong> It is possible that the permissions request interaction
 * with the user is interrupted. In this case you will receive empty permissions
 * and results arrays which should be treated as a cancellation.
 * </p>
 *
 * @param requestCode  The request code passed in {@link #requestPermissions(String[], int)}.
 * @param permissions  The requested permissions. Never null.
 * @param grantResults The grant results for the corresponding permissions
 *                     which is either {@link PackageManager#PERMISSION_GRANTED}
 *                     or {@link PackageManager#PERMISSION_DENIED}. Never null.
 * @see #requestPermissions(String[], int)
 */
@Override
public void onRequestPermissionsResult(int requestCode,
                                       @NonNull String[] permissions,
                                       @NonNull int[] grantResults) {
    if (requestCode != RC_HANDLE_CAMERA_PERM) {
        Log.d(TAG, "Got unexpected permission result: " + requestCode);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        return;
    }

    if (grantResults.length != 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        Log.d(TAG, "Camera permission granted - initialize the camera source");
        // we have permission, so create the camerasource
        boolean autoFocus = getIntent().getBooleanExtra(AutoFocus,false);
        boolean useFlash = getIntent().getBooleanExtra(UseFlash, false);
        createCameraSource(autoFocus, useFlash);
        return;
    }

    Log.e(TAG, "Permission not granted: results len = " + grantResults.length +
            " Result code = " + (grantResults.length > 0 ? grantResults[0] : "(empty)"));

    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            finish();
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Multitracker sample")
            .setMessage(R.string.no_camera_permission)
            .setPositiveButton(R.string.ok, listener)
            .show();
}
 
源代码13 项目: msdkui-android   文件: NumericOptionItem.java
/**
 * Shows an alert dialog to confirm the value that was set.
 */
protected void showDialog() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle(getLabel());
    final View editTextView = LayoutInflater.from(getContext()).inflate(R.layout.numeric_option_item_edittext, this, false);
    builder.setView(editTextView);
    final EditText inputText = (EditText) editTextView.findViewById(R.id.numeric_item_value_text);
    inputText.setInputType(mInputType);
    builder.setPositiveButton(getContext().getText(R.string.msdkui_ok), new PositiveDialogOnClickListener(inputText));
    builder.setNegativeButton(getContext().getText(R.string.msdkui_cancel), new NegativeDialogOnClickListener());
    builder.show();
}
 
源代码14 项目: bitmask_android   文件: LaunchVPN.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void setOnDismissListener(AlertDialog.Builder d) {
    d.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            finish();
        }
    });
}
 
源代码15 项目: YuanNewsForAndroid   文件: BaseActivity.java
private void showChoiceDialog(){
    floatDialogClickListener=new FloatDialogClickListener();
    AlertDialog.Builder builder=new AlertDialog.Builder(this);
    View view = View.inflate(this, R.layout.base_main_float_dialog, null);
    builder.setView(view);
    builder.setTitle("排序规则");
    dialog = builder.create();
    dialog.show();
    view.findViewById(R.id.float_tuijian).setOnClickListener(floatDialogClickListener);
    view.findViewById(R.id.float_comment).setOnClickListener(floatDialogClickListener);
    view.findViewById(R.id.float_quxiao).setOnClickListener(floatDialogClickListener);
    view.findViewById(R.id.float_rnum).setOnClickListener(floatDialogClickListener);
    view.findViewById(R.id.float_zan).setOnClickListener(floatDialogClickListener);
}
 
源代码16 项目: NYU-BusTracker-Android   文件: MainActivity.java
@SuppressWarnings("UnusedParameters")
public void createInfoDialog(View view) {
    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    LinearLayout linearLayout = (LinearLayout) getLayoutInflater()
            .inflate(
                    R.layout.information_layout,
                    (ViewGroup) ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0),
                    false
            );
    builder.setView(linearLayout);
    Dialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(true);
    dialog.show();
}
 
源代码17 项目: TraceByAmap   文件: OfflineChild.java
/**
 * 长按弹出提示框 删除(取消)下载
 * 加入synchronized 避免在dialog还没有关闭的时候再次,请求弹出的bug
 */
public synchronized void showDeleteDialog(final String name) {
	AlertDialog.Builder builder = new Builder(mContext);

	builder.setTitle(name);
	builder.setSingleChoiceItems(new String[] { "删除" }, -1,
			new DialogInterface.OnClickListener() {

				@Override
				public void onClick(DialogInterface arg0, int arg1) {
					dialog.dismiss();
					if (amapManager == null) {
						return;
					}
					switch (arg1) {
					case 0:
						amapManager.remove(name);
						break;

					default:
						break;
					}

					// amapManager.log();

				}
			});
	builder.setNegativeButton("取消", null);
	dialog = builder.create();
	dialog.show();
}
 
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{

    LayoutInflater i = getActivity().getLayoutInflater();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.DialogColourful);
    View rootView = i.inflate(R.layout.sort_lists_dialog, null);

    SortListsDialogCache cache = new SortListsDialogCache(rootView);
    setupPreviosOptions(cache);

    builder.setView(rootView);
    builder.setTitle(getActivity().getString(R.string.sort_options));
    builder.setNegativeButton(getActivity().getString(R.string.cancel), null);
    builder.setPositiveButton(getActivity().getString(R.string.okay), new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int which)
        {
            MainActivity host = (MainActivity) activity;
            AbstractInstanceFactory instanceFactory = new InstanceFactory(host.getApplicationContext());
            ShoppingListService shoppingListService = (ShoppingListService) instanceFactory.createInstance(ShoppingListService.class);

            String criteria = PFAComparators.SORT_BY_NAME;
            if ( cache.getPriority().isChecked() )
            {
                criteria = PFAComparators.SORT_BY_PRIORITY;
            }
            final String finalCriteria = criteria;
            boolean ascending = cache.getAscending().isChecked();

            List<ListItem> listItems = new ArrayList<>();

            shoppingListService.getAllListItems()
                    .doOnNext(item -> listItems.add(item))
                    .doOnCompleted(() ->
                    {
                        shoppingListService.sortList(listItems, finalCriteria, ascending);
                        host.reorderListView(listItems);
                    })
                    .doOnError(Throwable::printStackTrace)
                    .subscribe();

            // save sort options
            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(activity);
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putString(SettingsKeys.LIST_SORT_BY, criteria);
            editor.putBoolean(SettingsKeys.LIST_SORT_ASCENDING, ascending);
            editor.commit();
        }
    });

    return builder.create();
}
 
源代码19 项目: facebook-api-android-maven   文件: LoginButton.java
@Override
public void onClick(View v) {
    Context context = getContext();
    final Session openSession = sessionTracker.getOpenSession();

    if (openSession != null) {
        // If the Session is currently open, it must mean we need to log out
        if (confirmLogout) {
            // Create a confirmation dialog
            String logout = getResources().getString(R.string.com_facebook_loginview_log_out_action);
            String cancel = getResources().getString(R.string.com_facebook_loginview_cancel_action);
            String message;
            if (user != null && user.getName() != null) {
                message = String.format(getResources().getString(R.string.com_facebook_loginview_logged_in_as), user.getName());
            } else {
                message = getResources().getString(R.string.com_facebook_loginview_logged_in_using_facebook);
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setMessage(message)
                   .setCancelable(true)
                   .setPositiveButton(logout, new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int which) {
                           openSession.closeAndClearTokenInformation();
                       }
                   })
                   .setNegativeButton(cancel, null);
            builder.create().show();
        } else {
            openSession.closeAndClearTokenInformation();
        }
    } else {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
            sessionTracker.setSession(null);
            Session session = new Session.Builder(context).setApplicationId(applicationId).build();
            Session.setActiveSession(session);
            currentSession = session;
        }
        if (!currentSession.isOpened()) {
            Session.OpenRequest openRequest = null;
            if (parentFragment != null) {
                openRequest = new Session.OpenRequest(parentFragment);
            } else if (context instanceof Activity) {
                openRequest = new Session.OpenRequest((Activity)context);
            }

            if (openRequest != null) {
                openRequest.setDefaultAudience(properties.defaultAudience);
                openRequest.setPermissions(properties.permissions);
                openRequest.setLoginBehavior(properties.loginBehavior);

                if (SessionAuthorizationType.PUBLISH.equals(properties.authorizationType)) {
                    currentSession.openForPublish(openRequest);
                } else {
                    currentSession.openForRead(openRequest);
                }
            }
        }
    }

    AppEventsLogger logger = AppEventsLogger.newLogger(getContext());

    Bundle parameters = new Bundle();
    parameters.putInt("logging_in", (openSession != null) ? 0 : 1);

    logger.logSdkEvent(loginLogoutEventName, null, parameters);

    if (listenerCallback != null) {
        listenerCallback.onClick(v);
    }
}
 
源代码20 项目: Beats   文件: Tools.java
private static void alert_dialog(
		String title, int icon, CharSequence msg,
		String yes_msg, OnClickListener yes_action,
		String no_msg, OnClickListener no_action,
		final int ignoreSetting, boolean checked,
		boolean cancelable
	) {
	if (c == null) return;
	
	AlertDialog.Builder alertBuilder = new AlertDialog.Builder(c);
	alertBuilder.setCancelable(cancelable);
	alertBuilder.setTitle(title);
	alertBuilder.setIcon(icon);
	
	if (ignoreSetting != -1) {
		View notes = LayoutInflater.from(c).inflate(R.layout.notes, null);
		TextView notes_text = (TextView)notes.findViewById(R.id.notes_text);
		notes_text.setText(msg);
		notes_text.setTextColor(Color.WHITE);
		if (msg.length() < 300) notes_text.setTextSize(16); // Normal size?
		
		CheckBox checkbox = (CheckBox)notes.findViewById(R.id.checkbox);
		View.OnClickListener ignoreCheck = new View.OnClickListener() {
			public void onClick(View v) {
				if (((CheckBox) v).isChecked()) {
					Tools.putSetting(ignoreSetting, "1");
				} else {
					Tools.putSetting(ignoreSetting, "0");
				}
			}
		};
		if (checked) {
			checkbox.setChecked(true);
			Tools.putSetting(ignoreSetting, "1");
		}
		checkbox.setOnClickListener(ignoreCheck);
		alertBuilder.setView(notes);
	} else {
		alertBuilder.setMessage(msg);
	}
	
	if (no_action == null) {
		alertBuilder.setPositiveButton(yes_msg, yes_action);
	} else {
		alertBuilder.setPositiveButton(yes_msg, yes_action);
		alertBuilder.setNegativeButton(no_msg, no_action);
	}
	alertBuilder.show().setOwnerActivity(c);
	
	debugLogCat(msg.toString());
}