Java Code Examples for android.app.AlertDialog#setOnShowListener()

The following examples show how to use android.app.AlertDialog#setOnShowListener() . 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: CustomizeLaunchersActivity.java    From LaunchTime with GNU General Public License v3.0 6 votes vote down vote up
Dialog createDialog() {
    mAdapter = new ArrayAdapter<>(CustomizeLaunchersActivity.this, R.layout.add_list_item);
    mAdapter.add(getString(R.string.custom_icon_select_picture));
    mAdapter.add(getString(R.string.custom_icon_icon_packs));
    if (SpecialIconStore.hasBitmap(CustomizeLaunchersActivity.this, mAppClicked.getComponentName(), SpecialIconStore.IconType.Custom)) {
        mAdapter.add(getString(R.string.custom_icon_clear_icon));
    }

    final AlertDialog.Builder builder = new AlertDialog.Builder(CustomizeLaunchersActivity.this);
    builder.setTitle(R.string.custom_icon_select_icon_type);
    builder.setAdapter(mAdapter, this);

    //builder.setInverseBackgroundForced(false);

    AlertDialog dialog = builder.create();
    dialog.setOnCancelListener(this);
    dialog.setOnDismissListener(this);
    dialog.setOnShowListener(this);
    return dialog;
}
 
Example 2
Source File: DialogUtils.java    From mytracks with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a confirmation dialog.
 * 
 * @param context the context
 * @param titleId the title
 * @param message the message
 * @param okListener the listener when OK is clicked
 */
public static Dialog createConfirmationDialog(
    final Context context, int titleId, String message, DialogInterface.OnClickListener okListener) {
  final AlertDialog alertDialog = new AlertDialog.Builder(context)
      .setCancelable(true)
      .setIcon(android.R.drawable.ic_dialog_alert)
      .setMessage(message)
      .setNegativeButton(R.string.generic_no, null)
      .setPositiveButton(R.string.generic_yes, okListener)
      .setTitle(titleId).create();
  alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {

      @Override
    public void onShow(DialogInterface dialog) {
      setDialogTitleDivider(context, alertDialog);
    }
  });
  return alertDialog;
}
 
Example 3
Source File: FactoryResetProtectionPolicyFragment.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
public void createAddAccountDialog() {
    View view = LayoutInflater.from(getActivity()).inflate(R.layout.simple_edittext, null);
    final EditText input = view.findViewById(R.id.input);

    final AlertDialog dialog = new AlertDialog.Builder(getActivity())
            .setTitle(R.string.add_account)
            .setView(view)
            .setPositiveButton(android.R.string.ok, null)
            .setNegativeButton(android.R.string.cancel, null)
            .create();
    dialog.setOnShowListener(
            dialogInterface -> dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(
                    okButtonView -> {
                        String item = input.getText().toString();
                        if (TextUtils.isEmpty(item)) {
                            showToast(R.string.fail_to_add_account);
                            return;
                        }
                        mAccountsAdapter.add(item);
                        dialog.dismiss();
                    }));
    dialog.show();
}
 
Example 4
Source File: BrowseFragment.java    From android-vlc-remote with GNU General Public License v3.0 5 votes vote down vote up
private void displayAddToNewLibraryDialog(final File file) {
    final Set<String> libraries = mPreferences.getLibraries();
    final EditText e = new EditText(getActivity());
    e.setHint(R.string.hint_library_add);
    final AlertDialog d = new AlertDialog.Builder(getActivity())
        .setView(e)
        .setPositiveButton(R.string.ok, null) // set later
        .setNegativeButton(R.string.cancel, null)
        .setTitle(R.string.title_dialog_add_library)
        .create();
    d.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(final DialogInterface dialog) {
            d.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(e.getText().toString().isEmpty()) {
                        Toast.makeText(getActivity(), "Library name cannot be empty", Toast.LENGTH_SHORT).show();
                    } else if(libraries.contains(e.getText().toString())) {
                        Toast.makeText(getActivity(), "Library name already exists", Toast.LENGTH_SHORT).show();
                    } else {
                        addDirectoryToLibrary(file, e.getText().toString());
                        dialog.dismiss();
                    }
                }
            });
        }
    });
    d.show();
}
 
Example 5
Source File: AccountsSettingsFragment.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceClick(final Preference preference) {
    final TwoStatePreference syncPreference = (TwoStatePreference) preference;
    if (syncPreference.isChecked()) {
        // Uncheck for now.
        syncPreference.setChecked(false);

        // Show opt-in.
        final AlertDialog optInDialog = new AlertDialog.Builder(getActivity())
                .setTitle(R.string.cloud_sync_title)
                .setMessage(R.string.cloud_sync_opt_in_text)
                .setPositiveButton(R.string.account_select_ok,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog,
                                                final int which) {
                                if (which == DialogInterface.BUTTON_POSITIVE) {
                                    final Context context = getActivity();
                                    final String[] accountsForLogin =
                                            LoginAccountUtils.getAccountsForLogin(context);
                                    createAccountPicker(accountsForLogin,
                                            getSignedInAccountName(),
                                            new AccountChangedListener(syncPreference))
                                            .show();
                                }
                            }
                })
                .setNegativeButton(R.string.cloud_sync_cancel, null)
                .create();
        optInDialog.setOnShowListener(this);
        optInDialog.show();
    }
    return true;
}
 
Example 6
Source File: AccentAlertDialog.java    From holoaccent with Apache License 2.0 5 votes vote down vote up
/**
      * Creates a {@link AlertDialog} with the arguments supplied to this builder. It does not
      * {@link Dialog#show()} the dialog. This allows the user to do any extra processing
      * before displaying the dialog. Use {@link #show()} if you don't have any other processing
      * to do and want this to be created and displayed.
      */
     public AlertDialog create() {
         final AlertDialog result = mBuilder.create();
         // set a listener to apply the divider paint when shown
         result.setOnShowListener(new OnShowListener() {
	@Override
	public void onShow(DialogInterface dialog) {
		mDividerPainter.paint(result.getWindow());
	}
});
         return result;
     }
 
Example 7
Source File: AccountsSettingsFragment.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceClick(final Preference preference) {
    final TwoStatePreference syncPreference = (TwoStatePreference) preference;
    if (syncPreference.isChecked()) {
        // Uncheck for now.
        syncPreference.setChecked(false);

        // Show opt-in.
        final AlertDialog optInDialog = new AlertDialog.Builder(getActivity())
                .setTitle(R.string.cloud_sync_title)
                .setMessage(R.string.cloud_sync_opt_in_text)
                .setPositiveButton(R.string.account_select_ok,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog,
                                                final int which) {
                                if (which == DialogInterface.BUTTON_POSITIVE) {
                                    final Context context = getActivity();
                                    final String[] accountsForLogin =
                                            LoginAccountUtils.getAccountsForLogin(context);
                                    createAccountPicker(accountsForLogin,
                                            getSignedInAccountName(),
                                            new AccountChangedListener(syncPreference))
                                            .show();
                                }
                            }
                })
                .setNegativeButton(R.string.cloud_sync_cancel, null)
                .create();
        optInDialog.setOnShowListener(this);
        optInDialog.show();
    }
    return true;
}
 
Example 8
Source File: ContentsFragment.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
	checkedItems = savedInstanceState != null ? savedInstanceState.getBooleanArray(EXTRA_CHECKED_ITEMS) : null;
	if (checkedItems == null) {
		checkedItems = new boolean[] {true, true, true, false};
	}
	String[] items = getResources().getStringArray(R.array.preference_clear_cache_choices);
	AlertDialog dialog = new AlertDialog.Builder(getActivity())
			.setTitle(getString(R.string.preference_clear_cache))
			.setMultiChoiceItems(items, checkedItems, this)
			.setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, this)
			.create();
	dialog.setOnShowListener(this);
	return dialog;
}
 
Example 9
Source File: ForegroundManager.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
@SuppressLint("InflateParams")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
	Activity activity = getActivity();
	Bundle args = getArguments();
	View container = LayoutInflater.from(activity).inflate(R.layout.dialog_captcha, null);
	TextView comment = container.findViewById(R.id.comment);
	int descriptionResId = args.getInt(EXTRA_DESCRIPTION_RES_ID);
	if (descriptionResId != 0) {
		comment.setText(descriptionResId);
	} else {
		comment.setVisibility(View.GONE);
	}
	ChanConfiguration.Captcha captcha = ChanConfiguration.get(args.getString(EXTRA_CHAN_NAME))
			.safe().obtainCaptcha(args.getString(EXTRA_CAPTCHA_TYPE));
	EditText captchaInputView = container.findViewById(R.id.captcha_input);
	captchaForm.setupViews(container, null, captchaInputView, true, captcha);
	AlertDialog alertDialog = new AlertDialog.Builder(activity).setTitle(R.string.text_confirmation)
			.setView(container).setPositiveButton(android.R.string.ok, (dialog, which) -> onConfirmCaptcha())
			.setNegativeButton(android.R.string.cancel, (dialog, which) -> cancelInternal()).create();
	alertDialog.setCanceledOnTouchOutside(false);
	alertDialog.setOnShowListener(dialog -> {
		positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
		updatePositiveButtonState();
	});
	return alertDialog;
}
 
Example 10
Source File: WifiEapTlsCreateDialogFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View rootView = inflater.inflate(R.layout.eap_tls_wifi_config_dialog, null);
    rootView.findViewById(R.id.import_ca_cert).setOnClickListener(
            new ImportButtonOnClickListener(REQUEST_CA_CERT, "application/x-x509-ca-cert"));
    rootView.findViewById(R.id.import_user_cert).setOnClickListener(
            new ImportButtonOnClickListener(REQUEST_USER_CERT, "application/x-pkcs12"));
    mCaCertTextView = (TextView) rootView.findViewById(R.id.selected_ca_cert);
    mUserCertTextView = (TextView) rootView.findViewById(R.id.selected_user_cert);
    mSsidEditText = (EditText) rootView.findViewById(R.id.ssid);
    mCertPasswordEditText = (EditText) rootView.findViewById(R.id.wifi_client_cert_password);
    mIdentityEditText = (EditText) rootView.findViewById(R.id.wifi_identity);
    populateUi();
    final AlertDialog dialog = new AlertDialog.Builder(getActivity())
            .setTitle(R.string.create_eap_tls_wifi_configuration)
            .setView(rootView)
            .setPositiveButton(R.string.wifi_save, null)
            .setNegativeButton(R.string.wifi_cancel, null)
            .create();
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialogInterface) {
            dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            // Only dismiss the dialog when we saved the config.
                            if (extractInputDataAndSave()) {
                                dialog.dismiss();
                            }
                        }
                    });
        }
    });
    return dialog;
}
 
Example 11
Source File: BaseStringItemsFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
@Override
public void onEditButtonClick(final String existingEntry) {
    View view = LayoutInflater.from(getActivity()).inflate(R.layout.simple_edittext, null);
    final EditText input = (EditText) view.findViewById(R.id.input);
    if (existingEntry != null) {
        input.setText(existingEntry);
    }

    final AlertDialog dialog = new AlertDialog.Builder(getActivity())
            .setTitle(mDialogTitleResId)
            .setView(view)
            .setPositiveButton(android.R.string.ok, null)
            .setNegativeButton(android.R.string.cancel, null)
            .create();
    dialog.setOnShowListener(
            dialogInterface -> dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(
                    okButtonView -> {
                        String item = input.getText().toString();
                        if (TextUtils.isEmpty(item)) {
                            showToast(mEmptyItemResId);
                            return;
                        }
                        if (existingEntry != null) {
                            mItemArrayAdapter.remove(existingEntry);
                        }
                        mItemArrayAdapter.add(item);
                        dialog.dismiss();
                    }));
    dialog.show();
}
 
Example 12
Source File: YZLoginActivity.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
@Override
protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(R.string.input_nickname);
    final EditText editView = (EditText) LayoutInflater.from(this).inflate(R.layout.dialog_nickname_edit, null);
    builder.setView(editView);
    builder.setPositiveButton(R.string.confirm, null);
    builder.setNegativeButton(R.string.cancel, null);
    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {

            Button b = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            b.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    if (editView.getText().length() < 1) {
                        ToastUtils.show(YZLoginActivity.this, R.string.input_nickname);
                        return;
                    }
                    if (mLoginParams != null) {
                        ClanHttp.setNickname(YZLoginActivity.this, mLoginParams, editView.getText().toString(), mNicknameCallback);
                    }
                }
            });
        }
    });
    return alertDialog;
}
 
Example 13
Source File: AccountsSettingsFragment.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceClick(final Preference preference) {
    final TwoStatePreference syncPreference = (TwoStatePreference) preference;
    if (syncPreference.isChecked()) {
        // Uncheck for now.
        syncPreference.setChecked(false);

        // Show opt-in.
        final AlertDialog optInDialog = new AlertDialog.Builder(getActivity())
                .setTitle(R.string.cloud_sync_title)
                .setMessage(R.string.cloud_sync_opt_in_text)
                .setPositiveButton(R.string.account_select_ok,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog,
                                                final int which) {
                                if (which == DialogInterface.BUTTON_POSITIVE) {
                                    final Context context = getActivity();
                                    final String[] accountsForLogin =
                                            LoginAccountUtils.getAccountsForLogin(context);
                                    createAccountPicker(accountsForLogin,
                                            getSignedInAccountName(),
                                            new AccountChangedListener(syncPreference))
                                            .show();
                                }
                            }
                })
                .setNegativeButton(R.string.cloud_sync_cancel, null)
                .create();
        optInDialog.setOnShowListener(this);
        optInDialog.show();
    }
    return true;
}
 
Example 14
Source File: DefaultDialogManager.java    From AndroidRate with MIT License 5 votes vote down vote up
/**
 * <p>Creates Rate Dialog.</p>
 *
 * @return created dialog
 */
@SuppressWarnings("unused")
@Nullable
@Override
public Dialog createDialog() {

    AlertDialog.Builder builder = getDialogBuilder(context, dialogOptions.getThemeResId());
    Context dialogContext;

    if (SDK_INT >= HONEYCOMB) {
        dialogContext = builder.getContext();
    } else {
        dialogContext = context;
    }

    final View view = dialogOptions.getView(dialogContext);

    if ((dialogOptions.getType() == CLASSIC) || (view == null)) {
        if (dialogOptions.getType() != CLASSIC) {
            builder = getDialogBuilder(context, 0);
            if (SDK_INT >= HONEYCOMB) {
                dialogContext = builder.getContext();
            }
        }
        supplyClassicDialogArguments(builder, dialogContext);
    } else {
        supplyNonClassicDialogArguments(view, dialogContext);
    }

    final AlertDialog alertDialog = builder
            .setCancelable(dialogOptions.getCancelable())
            .setView(view)
            .create();

    alertDialog.setOnShowListener(showListener);
    alertDialog.setOnDismissListener(dismissListener);

    return alertDialog;
}
 
Example 15
Source File: BaseFragment.java    From nano-wallet-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Show opt-in alert for analytics
 */
protected void showSeedReminderAlert(String seed) {
    AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder = new AlertDialog.Builder(getContext(), android.R.style.Theme_Material_Light_Dialog_Alert);
    } else {
        builder = new AlertDialog.Builder(getContext());
    }
    String address = NanoUtil.publicToAddress(NanoUtil.privateToPublic(NanoUtil.seedToPrivate(seed)));
    String newSeedDisplay = seed.replaceAll("(.{4})", "$1 ");
    AlertDialog reminderDialog = builder.setTitle(R.string.seed_reminder_alert_title)
            .setMessage(getString(R.string.seed_reminder_alert_message, newSeedDisplay, address))
            .setPositiveButton(R.string.seed_reminder_alert_confirm_cta, null)
            .setNegativeButton(R.string.seed_reminder_alert_neutral_cta, null)
            .create();

    reminderDialog.setOnShowListener(dialog1 -> {
        Button copy = ((AlertDialog) dialog1).getButton(AlertDialog.BUTTON_NEGATIVE);
        Button ok = ((AlertDialog) dialog1).getButton(AlertDialog.BUTTON_POSITIVE);

        copy.setOnClickListener(view -> {
            dialog1.dismiss();
        });

        ok.setOnClickListener(view2 -> {
            if (getActivity() instanceof WindowControl) {
                reminderDialog.dismiss();
                RxBus.get().post(new Logout());
            }
        });
    });
    reminderDialog.show();
}
 
Example 16
Source File: ViewBarcodeActivity.java    From EnhancedScreenshotNotification with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle(R.string.action_view_barcode);
    builder.setView(R.layout.dialog_layout_view_barcode);
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog dialog = builder.create();
    dialog.setOnShowListener(this::onShow);
    return dialog;
}
 
Example 17
Source File: VideoUnit.java    From Dashchan with Apache License 2.0 4 votes vote down vote up
public void viewTechnicalInfo() {
	if (initialized) {
		HashMap<String, String> technicalInfo = player.getTechnicalInfo();
		StringBlockBuilder builder = new StringBlockBuilder();
		String videoFormat = technicalInfo.get("video_format");
		String width = technicalInfo.get("width");
		String height = technicalInfo.get("height");
		String frameRate = technicalInfo.get("frame_rate");
		String pixelFormat = technicalInfo.get("pixel_format");
		String surfaceFormat = technicalInfo.get("surface_format");
		String useLibyuv = technicalInfo.get("use_libyuv");
		String audioFormat = technicalInfo.get("audio_format");
		String channels = technicalInfo.get("channels");
		String sampleRate = technicalInfo.get("sample_rate");
		String encoder = technicalInfo.get("encoder");
		String title = technicalInfo.get("title");
		if (videoFormat != null) {
			builder.appendLine("Video: " + videoFormat);
		}
		if (width != null && height != null) {
			builder.appendLine("Resolution: " + width + '×' + height);
		}
		if (frameRate != null) {
			builder.appendLine("Frame rate: " + frameRate);
		}
		if (pixelFormat != null) {
			builder.appendLine("Pixels: " + pixelFormat);
		}
		if (surfaceFormat != null) {
			builder.appendLine("Surface: " + surfaceFormat);
		}
		if ("1".equals(useLibyuv)) {
			builder.appendLine("Use libyuv: true");
		} else if ("0".equals(useLibyuv)) {
			builder.appendLine("Use libyuv: false");
		}
		builder.appendEmptyLine();
		if (audioFormat != null) {
			builder.appendLine("Audio: " + audioFormat);
		}
		if (channels != null) {
			builder.appendLine("Channels: " + channels);
		}
		if (sampleRate != null) {
			builder.appendLine("Sample rate: " + sampleRate + " Hz");
		}
		builder.appendEmptyLine();
		if (encoder != null) {
			builder.appendLine("Encoder: " + encoder);
		}
		if (!StringUtils.isEmptyOrWhitespace(title)) {
			builder.appendLine("Title: " + title);
		}
		String message = builder.toString();
		if (message.length() > 0) {
			AlertDialog dialog = new AlertDialog.Builder(instance.galleryInstance.context)
					.setTitle(R.string.action_technical_info).setMessage(message)
					.setPositiveButton(android.R.string.ok, null).create();
			dialog.setOnShowListener(ViewUtils.ALERT_DIALOG_MESSAGE_SELECTABLE);
			dialog.show();
		}
	}
}
 
Example 18
Source File: GrxEqualizerManager.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 4 votes vote down vote up
private void showProfileSelectionDialog(){

        mOldSelectedEqProfile=mSelectedEqProfile;
        mDismissControl=false;
        mDeleteProfileControl=false;

        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setTitle(R.string.arizona_eqprofile_tit);
        builder.setSingleChoiceItems(getProfileNamesArray(), mSelectedEqProfile, (dialogInterface, i) -> {
            mSelectedEqProfile=i;
            if(mSelectedEqProfile<mNumOfMoroProfiles)
                ((AlertDialog)dialogInterface).getButton(DialogInterface.BUTTON_NEUTRAL).setVisibility(INVISIBLE);
            else
                 ((AlertDialog)dialogInterface).getButton(DialogInterface.BUTTON_NEUTRAL).setVisibility(VISIBLE);
        });
        builder.setPositiveButton(android.R.string.ok, (dialog, which) -> mDismissControl=true);
        builder.setNeutralButton(R.string.eq_profile_delete, (dialogInterface, i) -> {
            mDeleteProfileControl=true;
            mDismissControl=true;
        });
        builder.setOnDismissListener(dialog -> {
            if(mDismissControl) {
                if(!mDeleteProfileControl) {
                    if(mSelectedEqProfile!=mOldSelectedEqProfile) {
                        checkSelectedProfile();
                        fireSelectedProfile();
                    }
                }
                else delteSelectedProfile();
            }
            else mSelectedEqProfile=mOldSelectedEqProfile;
        });
        AlertDialog alertDialog = builder.create();
        alertDialog.setOnShowListener(dialogInterface -> {
            if(mSelectedEqProfile<mNumOfMoroProfiles)
                ((AlertDialog)dialogInterface).getButton(DialogInterface.BUTTON_NEUTRAL).setVisibility(INVISIBLE);
            else
                ((AlertDialog)dialogInterface).getButton(DialogInterface.BUTTON_NEUTRAL).setVisibility(VISIBLE);
        });
        alertDialog.show();
    }
 
Example 19
Source File: SubscribeDialogFragment.java    From uservoice-android-sdk with MIT License 4 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.uv_subscribe_dialog_title);
    if (!Utils.isDarkTheme(getActivity())) {
        builder.setInverseBackgroundForced(true);
    }
    View view = getActivity().getLayoutInflater().inflate(R.layout.uv_subscribe_dialog, null);
    final EditText emailField = (EditText) view.findViewById(R.id.uv_email);
    emailField.setText(Session.getInstance().getEmail(getActivity()));
    builder.setView(view);
    builder.setNegativeButton(R.string.uv_nevermind, null);
    builder.setPositiveButton(R.string.uv_subscribe, null);

    final AlertDialog dialog = builder.create();
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface d) {
            // We override the dialog listener here instead of through the builder so that we can control when the dialog gets dismissed.
            // Otherwise, the dialog will always dismiss when the positive button is clicked.
            Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String email = emailField.getText().toString();
                    if (!SigninManager.isValidEmail(email)) {
                        Toast.makeText(getActivity(), R.string.uv_msg_bad_email_format, Toast.LENGTH_SHORT).show();
                    } else {
                        Session.getInstance().persistIdentity(getActivity(), Session.getInstance().getName(getActivity()), email);
                        SigninManager.signinForSubscribe(getActivity(), Session.getInstance().getEmail(getActivity()), new SigninCallback() {
                            @Override
                            public void onSuccess() {
                                suggestion.subscribe(getActivity(), new DefaultCallback<Suggestion>(getActivity()) {
                                    @Override
                                    public void onModel(Suggestion model) {
                                        if (getActivity() instanceof InstantAnswersActivity)
                                            Deflection.trackDeflection(getActivity(), "subscribed", deflectingType, model);
                                        suggestionDialog.suggestionSubscriptionUpdated(model);
                                        dialog.dismiss();
                                    }
                                });
                            }
                        });
                    }
                }
            });
        }
    });
    return dialog;
}
 
Example 20
Source File: BaseArrayAdapter.java    From lrkFM with MIT License 4 votes vote down vote up
/**
 * Utility method to create an AlertDialog.
 *
 * @param positiveBtnText  the text of the positive button
 * @param title            the title
 * @param icon             the icon
 * @param view             the content view
 * @param positiveCallBack the positive callback
 * @param negativeCallBack the negative callback
 * @return the dialog
 */
public AlertDialog getGenericFileOpDialog(
        @StringRes int positiveBtnText,
        @StringRes int title,
        @DrawableRes int icon,
        @LayoutRes int view,
        Handler<AlertDialog> positiveCallBack,
        Handler<AlertDialog> negativeCallBack) {

    AlertDialog dialog = new AlertDialog.Builder(activity)
            .setView(view)
            .setTitle(title)
            .setCancelable(true).create();

    dialog.setButton(DialogInterface.BUTTON_POSITIVE, activity.getString(positiveBtnText), (d, i) -> positiveCallBack.handle(dialog));
    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, activity.getString(R.string.cancel), (d, i) -> negativeCallBack.handle(dialog));
    dialog.setOnShowListener(dialog1 -> {

        ImageView dialogIcon = dialog.findViewById(R.id.dialogIcon);
        dialogIcon.setImageDrawable(getContext().getDrawable(icon));

        EditText inputField;
        if (view == R.layout.layout_name_prompt) {
            inputField = dialog.findViewById(R.id.destinationName);
            if (inputField != null) {
                String name = activity.getTitleFromPath(activity.getCurrentDirectory());
                inputField.setText(name);
                Log.d(TAG, "Destination set to: " + name);
            } else {
                Log.w(TAG, "Unable to preset current name, text field is null!");
            }
        } else if (view == R.layout.layout_path_prompt) {
            inputField = dialog.findViewById(R.id.destinationPath);
            if (inputField != null) {
                String directory = activity.getCurrentDirectory();
                inputField.setText(directory);
                Log.d(TAG, "Destination set to: " + directory);
            } else {
                Log.w(TAG, "Unable to preset current path, text field is null!");
            }
        }
    });
    return dialog;
}