Example usage for android.app AlertDialog getWindow

List of usage examples for android.app AlertDialog getWindow

Introduction

In this page you can find the example usage for android.app AlertDialog getWindow.

Prototype

public @Nullable Window getWindow() 

Source Link

Document

Retrieve the current Window for the activity.

Usage

From source file:com.craftingmobile.alertdialogusage.LoginDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    Log.i(TAG, "onCreateDialog");
    LayoutInflater lf = LayoutInflater.from(getActivity());

    /** //from  w  ww .j a v  a 2 s.c  om
     *  Inflate our custom view for this dialog, it contains
     *  two TextViews and two EditTexts, one set for the username
     *  and a second set for the password
     */
    View v = lf.inflate(R.layout.login_dialog, null);

    username = (TextView) v.findViewById(R.id.login_username);
    password = (TextView) v.findViewById(R.id.login_password);

    /**
     * Register our listener for the 'Done' key on the soft keyboard
     */
    password.setOnEditorActionListener(this);
    username.requestFocus();

    final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setView(v).setTitle(R.string.log_in)
            .setPositiveButton(R.string.log_in, null).setNegativeButton(R.string.cancel, null).create();

    /**
     * We have to override setOnShowListener here (min API level 8)
     * in order to validate the inputs before closing the dialog.
     * Just overriding setPositiveButton closes the dialog
     * automatically when the button is pressed
     */
    dialog.setOnShowListener(this);

    /**
     * Show the soft keyboard automatically
     */
    dialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);

    /**
     * These TextWatchers are used to clear the error icons
     * automatically once the user has remedied an error
     */
    username.addTextChangedListener(this);
    password.addTextChangedListener(this);
    return dialog;
}

From source file:com.wordpress.ebc81.rtl_ais_android.tools.DialogManager.java

/**
 * Add new dialogs here!/* www. ja  v a2s.c o m*/
 * @param id
 * @param args
 * @return
 */
private Dialog createDialog(final dialogs id, final String[] args) {
    switch (id) {
    case DIAG_LIST_USB:
        return genUSBDeviceDialog();
    case DIAG_ABOUT:
        final AlertDialog addd = new AlertDialog.Builder(getActivity()).setTitle(R.string.help)
                .setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).setMessage(Html.fromHtml(getString(R.string.help_info))).create();
        try {
            addd.setOnShowListener(new DialogInterface.OnShowListener() {

                @Override
                public void onShow(DialogInterface paramDialogInterface) {
                    try {
                        final TextView tv = (TextView) addd.getWindow().findViewById(android.R.id.message);
                        if (tv != null)
                            tv.setMovementMethod(LinkMovementMethod.getInstance());

                    } catch (Exception e) {
                    }
                }
            });
        } catch (Exception e) {
        }

        return addd;
    case DIAG_LICENSE:
        return new AlertDialog.Builder(getActivity()).setTitle("COPYING")
                .setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).setMessage(readWholeStream("COPYING")).create();
    }
    return null;
}

From source file:com.hctrom.romcontrol.MainViewActivity.java

private void showThemeChooserDialog() {
    AlertDialog.Builder b = new AlertDialog.Builder(this);
    Adapter adapter = new ArrayAdapter<>(this, R.layout.simple_list_item_single_choice,
            getResources().getStringArray(R.array.theme_items));
    b.setIcon(R.drawable.ic_htc_personalize).setTitle(getString(R.string.theme_chooser_dialog_title))
            .setSingleChoiceItems((ListAdapter) adapter,
                    PreferenceManager.getDefaultSharedPreferences(this).getInt("theme_prefs", 0),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            //Invokes method initTheme(int) - next method based on chosen theme
                            initTheme(which);
                        }/*from ww w. j av a 2 s .c  om*/
                    });
    AlertDialog d = b.create();
    d.show();
    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = this.getTheme();
    theme.resolveAttribute(R.attr.colorAccent, typedValue, true);

    Button cancel = d.getButton(AlertDialog.BUTTON_NEGATIVE);
    cancel.setTextColor(typedValue.data);
    Button ok = d.getButton(AlertDialog.BUTTON_POSITIVE);
    ok.setTextColor(typedValue.data);
    d.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg);
    ListView lv = d.getListView();
    int paddingTop = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_top_padding));
    int paddingBottom = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_bottom_padding));
    lv.setPadding(0, paddingTop, 0, paddingBottom);
}

From source file:com.hctrom.romcontrol.MainViewActivity.java

private void getAvisoBackupDialog() {
    View checkBoxView = View.inflate(this, R.layout.aviso_backup_text, null);
    final CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkBoxAvisoBackup);
    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override/*ww  w  . j a v  a 2s. c o  m*/
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (checkBox.isChecked()) {
                PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit()
                        .putInt("aviso_backup", 1).commit();
            } else {
                PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit()
                        .putInt("aviso_backup", 0).commit();
            }
        }
    });
    AlertDialog.Builder b = new AlertDialog.Builder(this);
    b.setView(checkBoxView).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    AlertDialog d = b.create();
    d.show();
    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = this.getTheme();
    theme.resolveAttribute(R.attr.colorAccent, typedValue, true);

    Button cancel = d.getButton(AlertDialog.BUTTON_NEGATIVE);
    cancel.setTextColor(typedValue.data);
    Button ok = d.getButton(AlertDialog.BUTTON_POSITIVE);
    ok.setTextColor(typedValue.data);
    d.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg);
}

From source file:com.android.screenspeak.contextmenu.ListMenuManager.java

private void showDialogMenu(String title, CharSequence[] items, final ContextMenu menu) {
    if (items == null || items.length == 0) {
        return;/*from   w  w w.jav  a  2s  .  c om*/
    }

    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            final ContextMenuItem menuItem = menu.getItem(item);
            if (menuItem.hasSubMenu()) {
                menuItem.onClickPerformed();
            } else {
                mDeferredAction = getDeferredAction(menuItem);
            }
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(mService);
    builder.setTitle(title);
    builder.setItems(items, listener);
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    AlertDialog alert = builder.create();
    alert.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            mMenuShown--;
            if (mMenuShown == 0) {
                long delay = 0;
                if (mDeferredAction != null) {
                    mService.addEventListener(ListMenuManager.this);

                    if (needFocusDelay(mDeferredAction.actionId)) {
                        delay = RESET_FOCUS_DELAY;
                    }
                }

                mService.resetFocusedNode(delay);
                mCurrentDialog = null;
            }
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        alert.getWindow().setType(WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY);
    } else {
        alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
    }

    alert.show();
    mCurrentDialog = alert;
    mMenuShown++;
}

From source file:com.geotrackin.gpslogger.GpsMainActivity.java

/**
 * Annotates GPX and KML files, TXT files are ignored.
 * <p/>//from   w  w w.  j ava2s. co  m
 * The annotation is done like this:
 * <wpt lat="##.##" lon="##.##">
 * <name>user input</name>
 * </wpt>
 * <p/>
 * The user is prompted for the content of the <name> tag. If a valid
 * description is given, the logging service starts in single point mode.
 */
private void Annotate() {

    if (!AppSettings.shouldLogToGpx() && !AppSettings.shouldLogToKml() && !AppSettings.shouldLogToCustomUrl()) {
        tracer.debug("GPX, KML, URL disabled; annotation shouldn't work");
        Toast.makeText(getApplicationContext(), getString(R.string.annotation_requires_logging),
                Toast.LENGTH_SHORT).show();
        return;
    }

    AlertDialog.Builder alert = new AlertDialog.Builder(GpsMainActivity.this);
    alert.setTitle(R.string.add_description);
    alert.setMessage(R.string.letters_numbers);

    // Set an EditText view to get user input
    final EditText input = new EditText(getApplicationContext());
    input.setTextColor(getResources().getColor(android.R.color.black));
    input.setBackgroundColor(getResources().getColor(android.R.color.white));
    input.setText(Session.getDescription());
    alert.setView(input);

    /* ok */
    alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            final String desc = Utilities.CleanDescription(input.getText().toString());
            if (desc.length() == 0) {
                tracer.debug("Clearing annotation");
                Session.clearDescription();
                OnClearAnnotation();
            } else {
                tracer.debug("Setting annotation: " + desc);
                Session.setDescription(desc);
                OnSetAnnotation();
                // logOnce will start single point mode.
                if (!Session.isStarted()) {
                    tracer.debug("Will start log-single-point");
                    LogSinglePoint();
                }
            }
        }

    });

    alert.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // Cancelled.
        }
    });

    AlertDialog alertDialog = alert.create();
    alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    alertDialog.show();
}

From source file:org.catnut.fragment.TweetFragment.java

@Override
public boolean onMenuItemClick(MenuItem item) {
    // first check emotions
    if (item.getItemId() == R.id.action_emotions) {
        GridView emotions = (GridView) LayoutInflater.from(getActivity()).inflate(R.layout.emotions, null);
        emotions.setAdapter(new EmotionsAdapter(getActivity()));
        emotions.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override//from w w  w . j a v  a 2 s.  c o m
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                int cursor = mSendText.getSelectionStart();
                mSendText.getText().insert(cursor,
                        CatnutUtils.text2Emotion(getActivity(), TweetImageSpan.EMOTION_KEYS[position],
                                getResources().getInteger(R.integer.icon_bound_px)));
                mSendText.requestFocus();
            }
        });
        AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setView(emotions).create();
        alertDialog.show();
        alertDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
                getResources().getDimensionPixelSize(R.dimen.emotion_window_height));
        return true;
    }
    switch (item.getItemId()) {
    case R.id.action_reply_none:
        mRetweetOption = 0;
        break;
    case R.id.action_reply_current:
        mRetweetOption = 1;
        break;
    case R.id.action_reply_original:
        mRetweetOption = 2;
        break;
    case R.id.action_reply_both:
        mRetweetOption = 3;
        break;
    default:
        break;
    }
    if (!item.isChecked()) {
        item.setChecked(true);
    }
    return true;
}

From source file:it.imwatch.nfclottery.dialogs.InsertContactDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the Builder class for convenient dialog construction
    final Activity activity = getActivity();
    if (activity == null) {
        Log.e(TAG, "Not attached to Activity: cannot build dialog");
        return null;
    }//from w w  w  . j  a va 2  s  . c  o m

    AlertDialog.Builder builder = new AlertDialog.Builder(activity);

    // Get the layout inflater
    LayoutInflater inflater = LayoutInflater.from(activity);
    final View rootView = inflater.inflate(R.layout.dialog_insert, null);
    if (rootView == null) {
        Log.e(TAG, "Cannot inflate the dialog layout!");
        return null;
    }

    mErrorAnimTranslateY = getResources().getDimensionPixelSize(R.dimen.error_anim_translate_y);

    mEmailErrorTextView = (TextView) rootView.findViewById(R.id.lbl_email_error);
    mNameErrorTextView = (TextView) rootView.findViewById(R.id.lbl_name_error);

    // Restore instance state (if any)
    if (savedInstanceState != null) {
        mNameErrorState = savedInstanceState.getInt(EXTRA_NAME_ERROR, 0);
        mEmailErrorState = savedInstanceState.getInt(EXTRA_EMAIL_ERROR, 0);

        if (mNameErrorState == 1)
            showNameError();
        if (mEmailErrorState == 1) {
            showEmailError(activity.getString(R.string.error_emailinput_invalid), 1);
        } else if (mEmailErrorState == 2) {
            showEmailError(activity.getString(R.string.error_emailinput_duplicate), 2);
        }
    }

    mEmailEditText = (EditText) rootView.findViewById(R.id.txt_edit_email);
    mNameEditText = (EditText) rootView.findViewById(R.id.txt_edit_name);
    mOrganizationEditText = (EditText) rootView.findViewById(R.id.txt_edit_organization);
    mTitleEditText = (EditText) rootView.findViewById(R.id.txt_edit_title);

    // Add the check for a valid email address and names
    mEmailEditText.setOnFocusChangeListener(mFocusWatcher);
    mNameEditText.setOnFocusChangeListener(mFocusWatcher);

    // Add the check for a valid email during typing
    mEmailEditText.addTextChangedListener(mEmailTypingWatcher);

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(rootView).setPositiveButton(android.R.string.ok, null)
            .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    final Dialog thisDialog = InsertContactDialog.this.getDialog();
                    if (thisDialog != null) {
                        thisDialog.cancel();
                    } else {
                        Log.w(TAG, "Can't get the Dialog instance.");
                    }
                }
            });

    // Create the AlertDialog object and return it
    AlertDialog alertDialog = builder.create();

    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            final AlertDialog alertDialog = (AlertDialog) dialog;

            // Disable the positive button. It will be enabled only when there is a valid email
            final Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            if (button != null) {
                button.setEnabled(false);
                button.setOnClickListener(new DontAutoCloseDialogListener(alertDialog));
            } else {
                Log.w(TAG, "Can't get the dialog positive button.");
            }

            alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        }
    });

    return alertDialog;
}

From source file:com.github.howeyc.slideshow.activities.SettingsActivity.java

private void showNotConnectedDialog(final Dialog dialog) {
    AlertDialog notConnectedAlert = new AlertDialog.Builder(SettingsActivity.this)
            .setMessage(R.string.sett_dialog_notConnected_message)
            .setPositiveButton(R.string.sett_yes, new DialogInterface.OnClickListener() {
                @Override//from   w ww  .ja va  2 s . com
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialog.dismiss();
                    dialogInterface.dismiss();
                }
            }).setNegativeButton(R.string.sett_no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                    dialog.show();
                }
            }).create();
    notConnectedAlert.getWindow().setGravity(Gravity.CENTER);
    notConnectedAlert.setCancelable(false);
    notConnectedAlert.show();
}

From source file:com.github.nutomic.pegasus.activities.ProfileList.java

/**
 * Show an AlertDialog to edit the name of a profile.
 * /*from w  w  w.  j a v a 2s .  co  m*/
 * @param profile ID of the profile to rename.
 */
private void renameProfile(final long profile, String name) {
    final EditText input = new EditText(this);
    input.setText(name);
    input.setSingleLine();
    AlertDialog alert = new AlertDialog.Builder(this).setTitle(R.string.profilelist_rename).setView(input)
            .setPositiveButton(android.R.string.ok, new OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    new UpdateTask() {

                        @Override
                        protected Long doInBackground(Void... params) {
                            ContentValues cv = new ContentValues();
                            cv.put(ProfileColumns.NAME, input.getText().toString());
                            Database.getInstance(ProfileList.this).getWritableDatabase().update(
                                    ProfileColumns.TABLE_NAME, cv, ProfileColumns._ID + " = ?",
                                    new String[] { Long.toString(profile) });
                            return null;
                        }
                    }.execute((Void) null);
                }
            }).setNegativeButton(android.R.string.cancel, null).create();
    alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    alert.show();
    input.selectAll();
}