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:org.projectbuendia.client.ui.dialogs.NewUserDialogFragment.java

@Override
public @NonNull Dialog onCreateDialog(Bundle savedInstanceState) {
    View fragment = mInflater.inflate(R.layout.new_user_dialog_fragment, null);
    ButterKnife.inject(this, fragment);

    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity()).setCancelable(false) // Disable auto-cancel.
            .setTitle(getResources().getString(R.string.title_new_user))
            .setPositiveButton(getResources().getString(R.string.ok), null)
            .setNegativeButton(getResources().getString(R.string.cancel), null).setView(fragment);

    final AlertDialog dialog = dialogBuilder.create();
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override// ww  w.j  ava2s. c o m
        public void onShow(DialogInterface dialogInterface) {
            dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    // Validate the user.
                    String givenName = mGivenName.getText() == null ? ""
                            : mGivenName.getText().toString().trim();
                    String familyName = mFamilyName.getText() == null ? ""
                            : mFamilyName.getText().toString().trim();
                    boolean valid = true;
                    if (givenName.isEmpty()) {
                        setError(mGivenName, R.string.given_name_cannot_be_null);
                        valid = false;
                    }
                    if (familyName.isEmpty()) {
                        setError(mFamilyName, R.string.family_name_cannot_be_null);
                        valid = false;
                    }
                    Utils.logUserAction("add_user_submitted", "valid", "" + valid, "given_name", givenName,
                            "family_name", familyName);
                    if (!valid)
                        return;

                    App.getUserManager().addUser(new JsonNewUser(givenName, familyName));
                    if (mActivityUi != null) {
                        mActivityUi.showSpinner(true);
                    }
                    dialog.dismiss();
                }
            });
        }
    });
    // Open the keyboard, ready to type into the given name field.
    dialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    return dialog;
}

From source file:com.android.launcher3.Utilities.java

public static void licenseAlertDialog(Context context) {
    AlertDialog builder = new AlertDialog.Builder(context, R.style.AlertDialogCustom)
            .setTitle(context.getResources().getString(R.string.app_name)).setCancelable(false)
            .setIcon(R.mipmap.ic_launcher_home).setMessage(R.string.license_dialog_message).setPositiveButton(
                    context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                        }// w w w  .  j  av a2 s.co m
                    })
            .create();
    builder.show();
    ((TextView) builder.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
    ((TextView) builder.findViewById(android.R.id.message)).setGravity(Gravity.CENTER_VERTICAL);
    builder.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT);
}

From source file:com.android.launcher3.Utilities.java

public static void aboutAlertDialog(Context context) {
    AlertDialog builder = new AlertDialog.Builder(context, R.style.AlertDialogCustom)
            .setTitle(context.getResources().getString(R.string.app_name)).setCancelable(false)
            .setIcon(R.mipmap.ic_launcher_home).setMessage(R.string.disclaimer_dialog_message)
            .setPositiveButton(context.getResources().getString(R.string.ok),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                        }//from   w  ww .j a  v a2s.c  om
                    })
            .create();
    builder.show();
    ((TextView) builder.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
    ((TextView) builder.findViewById(android.R.id.message)).setGravity(Gravity.CENTER_VERTICAL);
    builder.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT);
}

From source file:com.android.launcher3.Utilities.java

public static void upgradeToPROAlertDialog(Context context) {
    AlertDialog builder = new AlertDialog.Builder(context, R.style.AlertDialogCustom)
            .setTitle(context.getResources().getString(R.string.app_name)).setCancelable(false)
            .setIcon(R.mipmap.ic_launcher_home).setMessage(R.string.license_dialog_message_pro)
            .setPositiveButton(context.getResources().getString(R.string.ok),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                        }/*from   www. j av a  2  s.c o  m*/
                    })
            .create();
    builder.show();
    ((TextView) builder.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
    ((TextView) builder.findViewById(android.R.id.message)).setGravity(Gravity.CENTER_VERTICAL);
    builder.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT);
}

From source file:com.picogram.awesomeness.SettingsActivity.java

public boolean onPreferenceClick(final Preference preference) {
    if (preference.getKey().equals("statistics")) {
        //TODO/* w w w .ja va2 s  .  c om*/
        Crouton.makeText(this, "This is not yet implemented", Style.INFO).show();
        final AlertDialog dialog = new AlertDialog.Builder(this).create();
        final String[] scoresTitles = new String[] { "Games Played", "Games Won", "Taps", "Taps per Puzzle",
                "Tapes per Minute", "Times Played" };
        final int gamesPlayed = 0, gamesWon = 0, taps = 0, tapsPerPuzzle = 0, tapsPerMinute = 0, timePlayed = 0;
        final int[] scores = { gamesPlayed, gamesWon, taps, tapsPerPuzzle, tapsPerMinute, timePlayed };
        // TODO: Implement the preferences and what not.
        final LinearLayout ll = new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);
        for (int i = 0; i != scores.length; ++i) {
            final LinearLayout sub = new LinearLayout(this);
            sub.setLayoutParams(new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
            sub.setOrientation(LinearLayout.HORIZONTAL);
            TextView tv = new TextView(this);
            tv.setLayoutParams(new TableLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
            tv.setText(scoresTitles[i]);
            sub.addView(tv);
            tv = new TextView(this);
            tv.setLayoutParams(new TableLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
            tv.setText(scores[i] + "");
            sub.addView(tv);
            ll.addView(sub);
        }
        dialog.setView(ll);
        dialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(final DialogInterface dialog, final int which) {
                dialog.dismiss();
            }
        });
        dialog.getWindow().getAttributes().windowAnimations = R.style.DialogTheme;
        dialog.show();
        dialog.dismiss();

        return true;
    } else if (preference.getKey().equals("changelog")) {
        // Launch change log dialog
        final ChangeLogDialog _ChangelogDialog = new ChangeLogDialog(this);
        _ChangelogDialog.show();
    } else if (preference.getKey().equals("licenses")) {
        // Launch the licenses stuff.
        Dialog ld = new LicensesDialog(this, R.raw.licenses, false, false).create();
        ld.getWindow().getAttributes().windowAnimations = R.style.DialogTheme;
        ld.show();
    } else if (preference.getKey().equals("email")) {
        final String email = "warner.73+Picogram@wright.edu";
        final String subject = "Picogram - <SUBJECT>";
        final String message = "Picogram,\n\n<MESSAGE>";
        // Contact me.
        final Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { email });
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        emailIntent.putExtra(Intent.EXTRA_TEXT, message);
        emailIntent.setType("message/rfc822");
        this.startActivity(Intent.createChooser(emailIntent, "Send Mail Using :"));
        overridePendingTransition(R.anim.fadein, R.anim.exit_left);
    } else if (preference.getKey().equals("rateapp")) {
        // TODO fix this when we publish.
        this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=Picogram")));
        overridePendingTransition(R.anim.fadein, R.anim.exit_left);
        final Editor editor = this.prefs.edit();
        editor.putBoolean(RateMeMaybe.PREF.DONT_SHOW_AGAIN, true);
        editor.commit();
    } else if (preference.getKey().equals("logoutgoogle")) {
        //TODO
        Crouton.makeText(this, "This is not currently supported.", Style.INFO).show();
    } else if (preference.getKey().equals("logoutfacebook")) {
        //TODO
        Crouton.makeText(this, "This is not currently supported.", Style.INFO).show();
    } else if (preference.getKey().equals("resetusername")) {
        Util.getPreferences(this).edit().putString("username", "").commit();
        Util.getPreferences(this).edit().putBoolean("hasLoggedInUsername", false).commit();
    }
    return false;
}

From source file:dude.morrildl.weatherport.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // this gets a little hairy, but each class is too trivial to bother
    // moving to its own file; but together they add up to be a little
    // irritating. So it goes.

    // first we need to inflate the View for the Action Bar operations, and
    // then set click handlers on them. This one is is the add-new-airport
    // dialog,/*from   w ww.j  av  a2  s .c  om*/
    // which cascades a bit
    getMenuInflater().inflate(R.menu.main, menu);
    menu.findItem(R.id.action_add).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            // yo dawg, I hurd you like callbacks
            LayoutInflater inflater = MainActivity.this.getLayoutInflater();
            View v = inflater.inflate(R.layout.dialog, null);
            final EditText et = (EditText) v.findViewById(R.id.dialog_input);

            // this is the
            // "enter a new airport code to add to the list" dialog
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            final AlertDialog dialog = builder.setTitle(R.string.dialog_title).setIcon(R.drawable.ic_launcher)
                    .setView(v).setPositiveButton(R.string.dialog_pos, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String newAirport = et.getText().toString().toUpperCase();
                            SharedPreferences prefs = MainActivity.this.getSharedPreferences("prefs",
                                    Context.MODE_PRIVATE);
                            Set<String> currentList = prefs.getStringSet("airports", new HashSet<String>());
                            HashSet<String> newSet = new HashSet<String>();
                            newSet.addAll(currentList);
                            newSet.add(newAirport);
                            prefs.edit().putStringSet("airports", newSet).commit();
                            ArrayList<String> newList = new ArrayList<String>();
                            newList.addAll(newSet);
                            Collections.sort(newList);
                            adapter.clear();
                            adapter.addAll(newList);
                            // I N C E P T I O N
                        }
                    }).setNegativeButton(R.string.dialog_neg, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    }).create();
            et.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean focused) {
                    if (focused) {
                        dialog.getWindow()
                                .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                    }
                }
            });
            dialog.show();
            return true;
        }
    });

    // ...and this one launches our FOSS compliance screen.
    menu.findItem(R.id.action_settings).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent();
            intent.setClass(MainActivity.this, AboutActivity.class);
            MainActivity.this.startActivity(intent);
            return true;
        }
    });
    return true;
}

From source file:com.xuejian.client.lxp.module.toolbox.im.IMMainActivity.java

private void showActionDialog() {
    final Activity act = this;
    final AlertDialog dialog = new AlertDialog.Builder(act).create();
    View contentView = View.inflate(act, R.layout.dialog_city_detail_action, null);
    Button btn = (Button) contentView.findViewById(R.id.btn_go_plan);
    btn.setText("Talk");
    btn.setOnClickListener(new View.OnClickListener() {
        @Override//from w ww.j  a va2s.  com
        public void onClick(View view) {
            MobclickAgent.onEvent(mContext, "event_create_new_talk");
            startActivityForResult(new Intent(IMMainActivity.this, PickContactsWithCheckboxActivity.class)
                    .putExtra("request", NEW_CHAT_REQUEST_CODE), NEW_CHAT_REQUEST_CODE);
            dialog.dismiss();
        }
    });
    Button btn1 = (Button) contentView.findViewById(R.id.btn_go_share);
    btn1.setText("?");
    btn1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            MobclickAgent.onEvent(mContext, "event_add_new_friend");
            startActivity(new Intent(IMMainActivity.this, AddContactActivity.class));
            dialog.dismiss();
        }
    });
    contentView.findViewById(R.id.btn_cancle).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    dialog.show();
    WindowManager windowManager = act.getWindowManager();
    Window window = dialog.getWindow();
    window.setContentView(contentView);
    Display display = windowManager.getDefaultDisplay();
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.width = (int) (display.getWidth()); // 
    window.setAttributes(lp);
    window.setGravity(Gravity.BOTTOM); // ?dialog?
    window.setWindowAnimations(R.style.SelectPicDialog); // 
}

From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    if (chanSelectMode) {
        return listView.startSorting(2, chans.size(), position);
    }/*w w w  .jav  a2 s  .  co  m*/
    final ListItem listItem = getItem(position);
    if (listItem != null) {
        if (listItem.type == ListItem.ITEM_FAVORITE && listItem.threadNumber != null
                && FavoritesStorage.getInstance().canSortManually()) {
            long time = multipleFingersTime
                    + (multipleFingersCountingTime ? System.currentTimeMillis() - multipleFingersStartTime
                            : 0L);
            if (time >= ViewConfiguration.getLongPressTimeout() / 10) {
                int start = position;
                int end = position;
                for (int i = position - 1;; i--) {
                    ListItem checkingListItem = getItem(i);
                    if (checkingListItem == null) {
                        break;
                    }
                    if (checkingListItem.type != ListItem.ITEM_FAVORITE
                            || !listItem.chanName.equals(checkingListItem.chanName)) {
                        start = i + 1;
                        break;
                    }
                }
                for (int i = position + 1;; i++) {
                    ListItem checkingListItem = getItem(i);
                    if (checkingListItem == null) {
                        break;
                    }
                    if (checkingListItem.type != ListItem.ITEM_FAVORITE
                            || !listItem.chanName.equals(checkingListItem.chanName)) {
                        end = i - 1;
                        break;
                    }
                }
                listView.startSorting(start, end, position);
                return true;
            }
        }
        switch (listItem.type) {
        case ListItem.ITEM_PAGE:
        case ListItem.ITEM_FAVORITE: {
            DialogMenu dialogMenu = new DialogMenu(context, new DialogMenu.Callback() {
                @Override
                public void onItemClick(Context context, int id, Map<String, Object> extra) {
                    switch (id) {
                    case MENU_COPY_LINK:
                    case MENU_SHARE_LINK: {
                        ChanLocator locator = ChanLocator.get(listItem.chanName);
                        Uri uri = listItem.isThreadItem()
                                ? locator.safe(true).createThreadUri(listItem.boardName, listItem.threadNumber)
                                : locator.safe(true).createBoardUri(listItem.boardName, 0);
                        if (uri != null) {
                            switch (id) {
                            case MENU_COPY_LINK: {
                                StringUtils.copyToClipboard(context, uri.toString());
                                break;
                            }
                            case MENU_SHARE_LINK: {
                                String subject = listItem.title;
                                if (StringUtils.isEmptyOrWhitespace(subject)) {
                                    subject = uri.toString();
                                }
                                NavigationUtils.share(context, subject, null, uri);
                                break;
                            }
                            }
                        }
                        break;
                    }
                    case MENU_ADD_TO_FAVORITES: {
                        if (listItem.isThreadItem()) {
                            FavoritesStorage.getInstance().add(listItem.chanName, listItem.boardName,
                                    listItem.threadNumber, listItem.title, 0);
                        } else {
                            FavoritesStorage.getInstance().add(listItem.chanName, listItem.boardName);
                        }
                        break;
                    }
                    case MENU_REMOVE_FROM_FAVORITES: {
                        FavoritesStorage.getInstance().remove(listItem.chanName, listItem.boardName,
                                listItem.threadNumber);
                        break;
                    }
                    case MENU_RENAME: {
                        final EditText editText = new SafePasteEditText(context);
                        editText.setSingleLine(true);
                        editText.setText(listItem.title);
                        editText.setSelection(editText.length());
                        LinearLayout linearLayout = new LinearLayout(context);
                        linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                        linearLayout.addView(editText, LinearLayout.LayoutParams.MATCH_PARENT,
                                LinearLayout.LayoutParams.WRAP_CONTENT);
                        int padding = context.getResources().getDimensionPixelSize(R.dimen.dialog_padding_view);
                        linearLayout.setPadding(padding, padding, padding, padding);
                        AlertDialog dialog = new AlertDialog.Builder(context).setView(linearLayout)
                                .setTitle(R.string.action_rename)
                                .setNegativeButton(android.R.string.cancel, null)
                                .setPositiveButton(android.R.string.ok, (d, which) -> {
                                    String newTitle = editText.getText().toString();
                                    FavoritesStorage.getInstance().modifyTitle(listItem.chanName,
                                            listItem.boardName, listItem.threadNumber, newTitle, true);
                                }).create();
                        dialog.getWindow()
                                .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
                        dialog.show();
                        break;
                    }
                    }
                }
            });
            dialogMenu.addItem(MENU_COPY_LINK, R.string.action_copy_link);
            if (listItem.isThreadItem()) {
                dialogMenu.addItem(MENU_SHARE_LINK, R.string.action_share_link);
            }
            if (listItem.type != ListItem.ITEM_FAVORITE && !FavoritesStorage.getInstance()
                    .hasFavorite(listItem.chanName, listItem.boardName, listItem.threadNumber)) {
                dialogMenu.addItem(MENU_ADD_TO_FAVORITES, R.string.action_add_to_favorites);
            }
            if (listItem.type == ListItem.ITEM_FAVORITE) {
                dialogMenu.addItem(MENU_REMOVE_FROM_FAVORITES, R.string.action_remove_from_favorites);
                if (listItem.threadNumber != null) {
                    dialogMenu.addItem(MENU_RENAME, R.string.action_rename);
                }
            }
            dialogMenu.show();
            return true;
        }
        }
    }
    return false;
}

From source file:com.mobiletin.inputmethod.indic.LatinIME.java

private void showOptionDialog(final AlertDialog dialog) {
    final IBinder windowToken = mKeyboardSwitcher.getMainKeyboardView().getWindowToken();
    if (windowToken == null) {
        return;//  w  w w.j a v  a2  s  .  com
    }

    final Window window = dialog.getWindow();
    final WindowManager.LayoutParams lp = window.getAttributes();
    lp.token = windowToken;
    lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
    window.setAttributes(lp);
    window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

    mOptionsDialog = dialog;
    dialog.show();
}

From source file:org.mitre.svmp.activities.SvmpActivity.java

protected void passwordChangePrompt(final ConnectionInfo connectionInfo) {
    // if this connection uses password authentication, proceed
    if ((connectionInfo.getAuthType() & PasswordModule.AUTH_MODULE_ID) == PasswordModule.AUTH_MODULE_ID) {

        // the service is running for this connection, stop it so we can re-authenticate
        if (SessionService.isRunningForConn(connectionInfo.getConnectionID()))
            stopService(new Intent(SvmpActivity.this, SessionService.class));

        // create the input container
        final LinearLayout inputContainer = (LinearLayout) getLayoutInflater().inflate(R.layout.auth_prompt,
                null);//ww  w . j a va 2  s .com

        // set the message
        TextView message = (TextView) inputContainer.findViewById(R.id.authPrompt_textView_message);
        message.setText(connectionInfo.getUsername());

        final HashMap<IAuthModule, View> moduleViewMap = new HashMap<IAuthModule, View>();
        // populate module view map, add input views for each required auth module
        // (we know at least password input is required)
        addAuthModuleViews(connectionInfo, moduleViewMap, inputContainer);

        // loop through the Auth module(s) to find the View for the old password input (needed for validation)
        View oldPasswordView = null;
        for (Map.Entry<IAuthModule, View> entry : moduleViewMap.entrySet()) {
            if (entry.getKey().getID() == PasswordModule.AUTH_MODULE_ID) {
                oldPasswordView = entry.getValue();
                break;
            }
        }

        // add "new password" and "confirm new password" views
        final PasswordChangeModule module = new PasswordChangeModule(oldPasswordView);
        View moduleView = module.generateUI(this);
        moduleViewMap.put(module, moduleView);
        inputContainer.addView(moduleView);

        // create a dialog
        final AlertDialog dialog = new AlertDialog.Builder(SvmpActivity.this).setCancelable(false)
                .setTitle(R.string.authPrompt_title_passwordChange).setView(inputContainer)
                .setPositiveButton(R.string.authPrompt_button_positive_text, null).setNegativeButton(
                        R.string.authPrompt_button_negative_text, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                busy = false;
                            }
                        })
                .create();

        // override positive button
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface d) {
                Button positive = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
                if (positive != null) {
                    positive.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            // before continuing, validate the new password inputs
                            int resId = module.areInputsValid();
                            if (resId == 0) {
                                dialog.dismiss(); // inputs are valid, dismiss the dialog
                                startAppRTCWithAuth(connectionInfo, moduleViewMap);
                            } else {
                                // tell the user that the new password is not valid
                                toastShort(resId);
                            }
                        }
                    });
                }
            }
        });

        // show the dialog
        dialog.show();
        // request keyboard
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    }
}