Java Code Examples for android.app.AlertDialog#Builder

The following examples show how to use android.app.AlertDialog#Builder . 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: BaseActivity.java    From Dashboard with MIT License 6 votes vote down vote up
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();
    }
 
Example 2
Source File: AddItemShoppingList.java    From ShoppingList with MIT License 6 votes vote down vote up
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();
	}
}
 
Example 3
Source File: DialerActivity.java    From emerald-dialer with GNU General Public License v3.0 6 votes vote down vote up
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();
}
 
Example 4
Source File: DashBoard.java    From AnLinux-Adfree with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 5
Source File: LogoDownloadBehaviourDialogFragment.java    From PodEmu with GNU General Public License v3.0 6 votes vote down vote up
@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();
}
 
Example 6
Source File: EUExWindow.java    From appcan-android with GNU Lesser General Public License v3.0 6 votes vote down vote up
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);
  }
 
Example 7
Source File: MiscTweaksActivity.java    From Kernel-Tuner with GNU General Public License v3.0 6 votes vote down vote up
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();
}
 
Example 8
Source File: BarcodeCaptureActivity.java    From samples-android with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 9
Source File: AddAccount.java    From apigee-android-sdk with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 10
Source File: OktaProgressDialog.java    From samples-android with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 11
Source File: GoUtil.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: NumericOptionItem.java    From msdkui-android with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 13
Source File: tarks_account_login.java    From Favorite-Android-Client with Apache License 2.0 5 votes vote down vote up
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();
		}

	}

}
 
Example 14
Source File: LaunchVPN.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
@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();
        }
    });
}
 
Example 15
Source File: BaseActivity.java    From YuanNewsForAndroid with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 16
Source File: MainActivity.java    From NYU-BusTracker-Android with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 17
Source File: OfflineChild.java    From TraceByAmap with MIT License 5 votes vote down vote up
/**
 * 长按弹出提示框 删除(取消)下载
 * 加入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();
}
 
Example 18
Source File: LoginButton.java    From facebook-api-android-maven with Apache License 2.0 4 votes vote down vote up
@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);
    }
}
 
Example 19
Source File: Tools.java    From Beats with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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());
}
 
Example 20
Source File: SortListsDialog.java    From privacy-friendly-shopping-list with Apache License 2.0 4 votes vote down vote up
@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();
}