Java Code Examples for android.app.AlertDialog.Builder

The following are Jave code examples for showing how to use Builder of the android.app.AlertDialog class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: natumassas-app   File: DBConnection.java   View Source Code Vote up 6 votes
/**
 * Para debug.
 * @param activity
 * @param context
 */
public void createConnection(Activity activity, Context context){
    try{
        dataOpenHelper = new DataOpenHelper(activity);

        connection = dataOpenHelper.getWritableDatabase();

        Toast.makeText(context, "Conexão com o banco bem sucedida", Toast.LENGTH_SHORT).show();
    }
    catch (SQLException e) {
        AlertDialog.Builder alert = new AlertDialog.Builder(activity);
        alert.setTitle(R.string.title_erro);
        alert.setMessage(e.getMessage());
        alert.setNeutralButton("Que Merda!", null);
        alert.show();
    }
}
 
Example 2
Project: MVVMFrames   File: BaseDialogFragment.java   View Source Code Vote up 6 votes
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (isBuilder() && getLayoutId() != 0) {
        view = getActivity().getLayoutInflater().inflate(getLayoutId(), null);
    }

    // 绑定ButterKnife
    unbinder = ButterKnife.bind(this, view);

    // 创建AlertDialog
    AlertDialog.Builder dialog = builder();
    if (isBuilder() && getLayoutId() != 0) {
        dialog.setView(view);
    }

    // 拆分系统onCreateDialog方法,提供一个create方法,基本初始化代码放到onCreateDialog执行,对于子类的初始化放到create方法执行
    this.create(savedInstanceState, view);

    return dialog.create();
}
 
Example 3
Project: Thesis_Farmers_Helper   File: Read_Me_Dialog.java   View Source Code Vote up 6 votes
public void ActivateReadMeDialog(Activity activity , Context context,int Language){
    AlertDialog.Builder mReadMeBuilder = new AlertDialog.Builder(activity);
    final AlertDialog mReadMeDialog =  mReadMeBuilder.create();
    mReadMeDialog.show();
    mReadMeDialog.setContentView(R.layout.read_me_layout);
    mBackButton = (Button)mReadMeDialog.findViewById(R.id.back_buttonOnReadMe);
    TextView mReadMeTextView = (TextView)mReadMeDialog.findViewById(R.id.ReadMeTextView);
    if(Language==0){mReadMeTextView.setText(activity.getResources().getString(R.string.ReadMeGrDialog));}
    else{mReadMeTextView.setText(activity.getResources().getString(R.string.ReadMeEngDialog));}
    mBackButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mReadMeDialog.cancel();
        }
    });

}
 
Example 4
Project: sflauncher   File: MainActivity.java   View Source Code Vote up 6 votes
private void promptForMusicAccess() {
    if (alreadyPrompted) return;
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (!prefs.getString("headerStyle2", "Search Bar").equals("Music Controls") &&
            !prefs.getString("city", "San Francisco").equals("Music:music-theme")) {
        return;
    }
    alreadyPrompted = true;
    AlertDialog.Builder d = new AlertDialog.Builder(MainActivity.this);
    d.setTitle("Notification Access Required");
    d.setMessage("SF Launcher requires access to notifications in order to display music info and album art. Please enable it on the next page.");
    d.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
        }
    });
    d.show();
}
 
Example 5
Project: FCM-for-Mojo   File: HttpUriPreferenceDialogFragment.java   View Source Code Vote up 6 votes
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity();

    final AlertDialog.Builder builder = new AlertDialog.Builder(context)
            .setTitle(getPreference().getDialogTitle())
            .setIcon(getPreference().getDialogIcon())
            .setPositiveButton(getPreference().getPositiveButtonText(), this)
            .setNegativeButton(getPreference().getNegativeButtonText(), this);

    View contentView = onCreateDialogView(context);
    if (contentView != null) {
        onBindDialogView(contentView);
        builder.setView(contentView);
    } else {
        builder.setMessage(getPreference().getDialogMessage());
    }

    this.dialog = builder.create();

    return dialog;
}
 
Example 6
Project: AIMSICDL   File: CellTowerMarker.java   View Source Code Vote up 6 votes
@Override
public boolean onMarkerClick(Marker marker, MapView mapView) {
    CellTowerMarker cellTowerMarker = (CellTowerMarker) marker;
    AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
    dialog.setTitle(cellTowerMarker.getTitle());
    dialog.setView(getInfoContents(cellTowerMarker.getMarkerData()));
    dialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    });
    dialog.show();

    return true;
}
 
Example 7
Project: airgram   File: ChannelCreateActivity.java   View Source Code Vote up 6 votes
private void showErrorAlert(String error) {
    if (getParentActivity() == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    switch (error) {
        case "USERNAME_INVALID":
            builder.setMessage(LocaleController.getString("LinkInvalid", R.string.LinkInvalid));
            break;
        case "USERNAME_OCCUPIED":
            builder.setMessage(LocaleController.getString("LinkInUse", R.string.LinkInUse));
            break;
        case "USERNAMES_UNAVAILABLE":
            builder.setMessage(LocaleController.getString("FeatureUnavailable", R.string.FeatureUnavailable));
            break;
        default:
            builder.setMessage(LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred));
            break;
    }
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    showDialog(builder.create());
}
 
Example 8
Project: AcopioMX   File: ActivityAgregar.java   View Source Code Vote up 5 votes
private void showAvisoDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this, R.style.DialogTheme);
    alert.setTitle("Aviso");
    alert.setMessage("Estás a punto de agregar un producto que este centro de acopio" +
            " necesita, por favor introduce solamente información verídica y confirmada");
    alert.setPositiveButton("Aceptar", null);
    alert.show();
}
 
Example 9
Project: financisto1-holo   File: CCardStatementClosingDayActivity.java   View Source Code Vote up 5 votes
/**
 * 
 * @return
 */
private boolean isNewDayValid() {
	// check if the value in form is valid
	String text = newClosingDay.getText().toString();
	String alertMsg = "";
	
	if (text!=null && text.length()>0) {
		// Max day of reference month
		Calendar periodCal = new GregorianCalendar(year, month, 1);
		int maxDay = periodCal.getActualMaximum(Calendar.DAY_OF_MONTH);
		
		int newCD = Integer.parseInt(text);
		
		if (newCD<1 || newCD>maxDay) {
			alertMsg = getString(R.string.alert_invalid_closing_day)+" [1-"+maxDay+"].";
		} else if (newCD==regularClosingDay) {
			alertMsg = getString(R.string.alert_regular_closing_day);
		}
		
	} else {
		// text null - alert user
		alertMsg = getString(R.string.alert_null_closing_day);
	}
	if (alertMsg.length()>0) {
		// Alert message
		Log.w("Alert", alertMsg);
		AlertDialog.Builder dlgAlert  = new AlertDialog.Builder(this);
        dlgAlert.setMessage(alertMsg);
        dlgAlert.setTitle(R.string.closing_day);
        dlgAlert.setPositiveButton(R.string.ok, null);
        dlgAlert.setCancelable(true);
        dlgAlert.create().show();
        return false;
	} else {
		return true;
	}
}
 
Example 10
Project: CustomListView   File: GoUtil.java   View Source Code Vote up 5 votes
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 11
Project: GCSApp   File: OrderInfoFinishAdapter.java   View Source Code Vote up 5 votes
public void showDialogFinish(final OrderDetail orderDetail){
    final AlertDialog dialog_finish;
    AlertDialog.Builder builder = new AlertDialog.Builder(context,R.style.DialogTransBackGround);
    dialog_finish = builder.create();
    dialog_finish.setCancelable(true);
    dialog_finish.show();
    View view_dialog = LayoutInflater.from(context).inflate(R.layout.item_dialog_confirm, null);
    dialog_finish.setContentView(view_dialog);
    TextView tv_title = (TextView) view_dialog.findViewById(R.id.tv_dialog_title);
    TextView tv_content = (TextView) view_dialog.findViewById(R.id.tv_dialog_content);
    Button bt_yes = (Button) view_dialog.findViewById(R.id.bt_dialog_yes);

    tv_title.setText("提示");
    tv_content.setText("确定要申请退货吗?");
    bt_yes.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog_finish.dismiss();

            if (orderDetail.state == 4) {
                if (orderDetail.orderDetailId == 0) {
                    Toast.makeText(context, "orderDetailId为空!", Toast.LENGTH_SHORT).show();
                } else {
                    orderDetail.state = 5;
                    orderDetail.refundStatus = 1;
                    notifyDataSetChanged();
                    MyOrderActivity.instance.refundOrder(orderId, orderDetail.orderDetailId);
                }
            }
        }
    });
}
 
Example 12
Project: dhbw-timetable-android   File: ListDialog.java   View Source Code Vote up 5 votes
/**
 * Applies the args
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.DialogStyle);

    // Apply args
    builder.setTitle(title).setSingleChoiceItems(choices, active, onC).setPositiveButton("OK", onC);

    Dialog d = builder.create();
    d.setCanceledOnTouchOutside(false);

    // Create the AlertDialog object and return it
    return d;
}
 
Example 13
Project: divertsy-client   File: BLEScanner.java   View Source Code Vote up 5 votes
/**
 * Attempts to create the scanner.
 *
 * @param context
 * @return true if successful
 */
public boolean init(final Activity context) {
    // New Android M+ permission check requirement.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (context.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
                != PackageManager.PERMISSION_GRANTED) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle("This app needs coarse location access");
            builder.setMessage("Please grant coarse location access so this app can scan for beacons");
            builder.setPositiveButton(android.R.string.ok, null);
            builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    ActivityCompat.requestPermissions(context, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
                            PERMISSION_REQUEST_COARSE_LOCATION);
                }
            });
            builder.show();
        }
    }
    BluetoothManager manager = (BluetoothManager) context.getApplicationContext()
            .getSystemService(Context.BLUETOOTH_SERVICE);
    BluetoothAdapter btAdapter = manager.getAdapter();
    if (btAdapter == null) {
        return false;
    } else if (!btAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        context.startActivityForResult(enableBtIntent, mRequestEnableBluetooth);
        return false;
    } else {
        scanner = btAdapter.getBluetoothLeScanner();
    }
    return true;
}
 
Example 14
Project: emerald   File: Apps.java   View Source Code Vote up 5 votes
void menu() {
	//Log.v(APP_TAG, "Trying to open menu");
	if (lock) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		//builder.setTitle("");
		builder.setMessage(getResources().getString(R.string.type_password));
		final EditText inputBox = new EditText(this);
		inputBox.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
		builder.setView(inputBox);
		builder.setPositiveButton(android.R.string.yes, 
			new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				if (inputBox.getText().toString().equals(options.getString(Keys.PASSWORD, ""))) {
					openOptionsMenu();
				} else {
					Toast.makeText(getApplicationContext(), getResources().getString(R.string.wrong_password), Toast.LENGTH_LONG).show();
				}
		} });
		builder.setCancelable(true);
		if (!isFinishing()) {
			builder.show();
		}
	} else {
		openOptionsMenu();
	}
}
 
Example 15
Project: youkes_browser   File: BrowserActivity.java   View Source Code Vote up 5 votes
private void onImageLongClickExtraUrl(final String newUrl) {
	DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
               switch (which) {
                   case DialogInterface.BUTTON_POSITIVE:
                       newTab(newUrl, true);
                       break;

                   case DialogInterface.BUTTON_NEGATIVE:
                       getCurrentWebView().loadUrl(newUrl);
                       break;

                   case DialogInterface.BUTTON_NEUTRAL:
                       if (API > 8) {
                           Utils.downloadFile(mActivity, newUrl,
								getCurrentWebView().getUserAgent(), "attachment", false);
                       }
                       break;
               }
           }
       };

	AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); // dialog
	builder.setTitle(newUrl.replace(Constants.HTTP, ""))
               .setMessage(getResources().getString(R.string.dialog_image))
               .setPositiveButton(getResources().getString(R.string.action_new_tab),
					dialogClickListener)
               .setNegativeButton(getResources().getString(R.string.action_open),
					dialogClickListener)
               .setNeutralButton(getResources().getString(R.string.action_download),
					dialogClickListener).show();
}
 
Example 16
Project: PimPam   File: Functions.java   View Source Code Vote up 5 votes
public static AlertDialog.Builder getModalLogOut( final Context context) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);

    builder.setMessage(context.getString(R.string.logout_confirm));
    builder.setNegativeButton(context.getString(R.string.cancel), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();

        }
    });

    return builder;
}
 
Example 17
Project: editor-sql   File: PermissionUtils.java   View Source Code Vote up 5 votes
public static void accountPermissonDesc(final Activity context) {
    AlertDialog.Builder alertDialogBuider = new AlertDialog.Builder(context);
    alertDialogBuider.setTitle(R.string.account_permission);
    alertDialogBuider.setMessage(R.string.account_permission_desc);
    alertDialogBuider.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ActivityCompat.requestPermissions(context, PermissionUtils.GET_ACCOUNTS,
                    PermissionUtils.GET_ACCOUNTS_REQUEST);
        }
    });
    alertDialogBuider.setNegativeButton(R.string.no, null);
    alertDialogBuider.create().show();
}
 
Example 18
Project: TitanCompanion   File: AdventureCreation.java   View Source Code Vote up 5 votes
public void showAlert(String message) {
	AlertDialog.Builder builder = new AlertDialog.Builder(this);
	builder.setTitle(R.string.result).setMessage(message).setCancelable(false)
			.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int id) {
					dialog.cancel();
				}
			});
	AlertDialog alert = builder.create();
	alert.show();
}
 
Example 19
Project: FastReading   File: BookEditDialog.java   View Source Code Vote up 5 votes
private void showCancelDialog(Activity activity, DialogInterface editingDialogInterface) {
    AlertDialog.Builder cancelBuilder = new AlertDialog.Builder(activity);
    cancelBuilder.setMessage(R.string.editing_cancel_text)
            .setPositiveButton(R.string.yes, (dialog, which) -> editingDialogInterface.dismiss())
            .setNegativeButton(R.string.no, (dialog, which) -> {
            })
            .create()
            .show();
}
 
Example 20
Project: PlusGram   File: AndroidUtilities.java   View Source Code Vote up 4 votes
public static AlertDialog.Builder buildTTLAlert(final Context context, final TLRPC.EncryptedChat encryptedChat) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(LocaleController.getString("MessageLifetime", R.string.MessageLifetime));
    final NumberPicker numberPicker = new NumberPicker(context);
    numberPicker.setMinValue(0);
    numberPicker.setMaxValue(20);
    if (encryptedChat.ttl > 0 && encryptedChat.ttl < 16) {
        numberPicker.setValue(encryptedChat.ttl);
    } else if (encryptedChat.ttl == 30) {
        numberPicker.setValue(16);
    } else if (encryptedChat.ttl == 60) {
        numberPicker.setValue(17);
    } else if (encryptedChat.ttl == 60 * 60) {
        numberPicker.setValue(18);
    } else if (encryptedChat.ttl == 60 * 60 * 24) {
        numberPicker.setValue(19);
    } else if (encryptedChat.ttl == 60 * 60 * 24 * 7) {
        numberPicker.setValue(20);
    } else if (encryptedChat.ttl == 0) {
        numberPicker.setValue(0);
    }
    numberPicker.setFormatter(new NumberPicker.Formatter() {
        @Override
        public String format(int value) {
            if (value == 0) {
                return LocaleController.getString("ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever);
            } else if (value >= 1 && value < 16) {
                return AndroidUtilities.formatTTLString(value);
            } else if (value == 16) {
                return AndroidUtilities.formatTTLString(30);
            } else if (value == 17) {
                return AndroidUtilities.formatTTLString(60);
            } else if (value == 18) {
                return AndroidUtilities.formatTTLString(60 * 60);
            } else if (value == 19) {
                return AndroidUtilities.formatTTLString(60 * 60 * 24);
            } else if (value == 20) {
                return AndroidUtilities.formatTTLString(60 * 60 * 24 * 7);
            }
            return "";
        }
    });
    builder.setView(numberPicker);
    builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            int oldValue = encryptedChat.ttl;
            which = numberPicker.getValue();
            if (which >= 0 && which < 16) {
                encryptedChat.ttl = which;
            } else if (which == 16) {
                encryptedChat.ttl = 30;
            } else if (which == 17) {
                encryptedChat.ttl = 60;
            } else if (which == 18) {
                encryptedChat.ttl = 60 * 60;
            } else if (which == 19) {
                encryptedChat.ttl = 60 * 60 * 24;
            } else if (which == 20) {
                encryptedChat.ttl = 60 * 60 * 24 * 7;
            }
            if (oldValue != encryptedChat.ttl) {
                SecretChatHelper.getInstance().sendTTLMessage(encryptedChat, null);
                MessagesStorage.getInstance().updateEncryptedChatTTL(encryptedChat);
            }
        }
    });
    return builder;
}