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:fr.cph.chicago.core.listener.TrainOnClickListener.java

@Override
public void onClick(final View view) {
    if (!Util.isNetworkAvailable(view.getContext())) {
        Util.showNetworkErrorMessage(view);
    } else {//from  w w w  . j  a va  2 s. com
        final List<String> values = new ArrayList<>();
        final List<Integer> colors = new ArrayList<>();
        values.add(view.getContext().getString(R.string.message_open_details));
        for (final TrainLine line : trainLines) {
            values.add(line.toString() + " line - See trains");
            if (line != TrainLine.YELLOW) {
                colors.add(line.getColor());
            } else {
                colors.add(ContextCompat.getColor(view.getContext(), R.color.yellowLine));
            }
        }
        final PopupTrainAdapter ada = new PopupTrainAdapter(view.getContext(), values, colors);

        final List<TrainLine> lines = new ArrayList<>();
        lines.addAll(trainLines);

        final AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setAdapter(ada, (dialog, position) -> {
            final Bundle extras = new Bundle();
            if (position == 0) {
                // Start station activity
                final Intent intent = new Intent(view.getContext(), StationActivity.class);
                extras.putInt(view.getContext().getString(R.string.bundle_train_stationId), stationId);
                intent.putExtras(extras);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                view.getContext().startActivity(intent);
            } else {
                // Follow all trains from given line on google map view
                final Intent intent = new Intent(view.getContext(), TrainMapActivity.class);
                extras.putString(view.getContext().getString(R.string.bundle_train_line),
                        lines.get(position - 1).toTextString());
                intent.putExtras(extras);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                view.getContext().startActivity(intent);
            }
        });

        final int[] screenSize = Util.getScreenSize(view.getContext().getApplicationContext());
        final AlertDialog dialog = builder.create();
        dialog.show();
        dialog.getWindow().setLayout((int) (screenSize[0] * 0.7), LayoutParams.WRAP_CONTENT);
    }
}

From source file:net.naonedbus.fragment.impl.GroupesFragment.java

private void menuAdd() {
    final View alertDialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_input, null);
    final EditText input = (EditText) alertDialogView.findViewById(R.id.text);
    input.selectAll();//from   www .  ja  v a2  s .  co  m

    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(alertDialogView);
    builder.setTitle(R.string.action_groupes_add);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            final Groupe groupe = new Groupe();
            groupe.setNom(input.getText().toString().trim());
            groupe.setOrdre(mCursor.getCount());
            mGroupeManager.add(getActivity().getContentResolver(), groupe);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);

    final AlertDialog alert = builder.create();
    alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    alert.show();
}

From source file:net.naonedbus.fragment.impl.GroupesFragment.java

private void editCheckedItem() {
    final int checkedItem = getFirstSelectedItemPosition();
    final CursorWrapper wrapper = (CursorWrapper) mListView.getItemAtPosition(checkedItem);
    final Groupe groupe = mGroupeManager.getSingleFromCursor(wrapper);

    final View alertDialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_input, null);
    final EditText input = (EditText) alertDialogView.findViewById(R.id.text);
    input.setText(groupe.getNom());//from   w  w  w  . j  av a 2 s . c  om
    input.selectAll();

    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(alertDialogView);
    builder.setTitle(R.string.action_rename);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            final String nom = input.getText().toString().trim();
            groupe.setNom((nom.length() == 0) ? null : nom);

            mGroupeManager.update(getActivity().getContentResolver(), groupe);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);

    final AlertDialog alert = builder.create();
    alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    alert.show();
}

From source file:com.irccloud.android.fragment.BanListFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context ctx = getActivity();/* ww w. ja  v  a2s  .c  o  m*/
    if (ctx == null)
        return null;

    LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.ignorelist, null);
    listView = (ListView) v.findViewById(android.R.id.list);
    TextView empty = (TextView) v.findViewById(android.R.id.empty);
    empty.setText(
            "No bans in effect.\n\nYou can ban someone by tapping their nickname in the user list, long-pressing a message, or by using /ban.");
    listView.setEmptyView(empty);
    if (savedInstanceState != null && savedInstanceState.containsKey("cid")) {
        cid = savedInstanceState.getInt("cid");
        bid = savedInstanceState.getInt("bid");
        event = new IRCCloudJSONObject(savedInstanceState.getString("event"));
        bans = event.getJsonNode("bans");
        adapter = new BansAdapter(this);
        listView.setAdapter(adapter);
    }
    AlertDialog.Builder b = new AlertDialog.Builder(ctx)
            .setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
            .setTitle("Ban list for " + event.getString("channel")).setView(v)
            .setNegativeButton("Close", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    try {
        ServersDataSource.Server server = ServersDataSource.getInstance().getServer(cid);
        UsersDataSource.User self_user = UsersDataSource.getInstance().getUser(bid,
                ServersDataSource.getInstance().getServer(cid).nick);
        if (self_user != null && (self_user.mode.contains(server != null ? server.MODE_OWNER : "q")
                || self_user.mode.contains(server != null ? server.MODE_ADMIN : "a")
                || self_user.mode.contains(server != null ? server.MODE_OP : "o"))) {
            b.setPositiveButton("Add Ban Mask", new AddClickListener());
        }
    } catch (Exception e) {

    }

    AlertDialog d = b.create();
    d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    return d;
}

From source file:org.sufficientlysecure.ical.ui.UrlDialog.java

@Override
@NonNull/*from   ww  w.j a  v  a 2  s  .  c  om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {

    mActivity = (MainActivity) getActivity();

    ViewGroup nullViewGroup = null; // Avoid bad lint warning in inflate()
    View view = mActivity.getLayoutInflater().inflate(R.layout.urldialog, nullViewGroup);

    mCheckboxLoginRequired = (CheckBox) view.findViewById(R.id.CheckboxLoginRequired);
    CompoundButton.OnCheckedChangeListener loginRequiredTask;
    loginRequiredTask = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton button, boolean isChecked) {
            mTextUsername.setEnabled(isChecked);
            mTextPassword.setEnabled(isChecked);
        }
    };
    mCheckboxLoginRequired.setOnCheckedChangeListener(loginRequiredTask);

    mTextCalendarUrl = (EditText) view.findViewById(R.id.TextCalendarUrl);
    mTextUsername = (EditText) view.findViewById(R.id.TextUsername);
    mTextPassword = (EditText) view.findViewById(R.id.TextPassword);

    Settings settings = mActivity.getSettings();
    mTextCalendarUrl.setText(settings.getString(Settings.PREF_LASTURL));
    mTextUsername.setText(settings.getString(Settings.PREF_LASTURLUSERNAME));
    mTextPassword.setText(settings.getString(Settings.PREF_LASTURLPASSWORD));

    mCheckboxLoginRequired.setChecked(mTextUsername.getText().length() != 0);
    mTextCalendarUrl.selectAll();

    DialogInterface.OnClickListener okTask;
    okTask = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface iface, int id) {
            // We override this in onStart()
        }
    };

    DialogInterface.OnClickListener cancelTask;
    cancelTask = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface iface, int id) {
            iface.cancel();
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    AlertDialog dlg = builder.setIcon(R.mipmap.ic_launcher).setTitle(R.string.enter_source_url).setView(view)
            .setPositiveButton(android.R.string.ok, okTask)
            .setNegativeButton(android.R.string.cancel, cancelTask).create();
    dlg.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    return dlg;
}

From source file:com.vk.sdk.VKCaptchaDialog.java

/**
 * Prepare, create and show dialog for displaying captcha
 *///  w  ww .j a v  a 2 s. c  o m
public void show() {
    Context context = VKUIHelper.getTopActivity();
    View innerView = LayoutInflater.from(context).inflate(R.layout.dialog_vkcaptcha, null);
    assert innerView != null;
    mCaptchaAnswer = (EditText) innerView.findViewById(R.id.captchaAnswer);
    mCaptchaImage = (ImageView) innerView.findViewById(R.id.imageView);
    mProgressBar = (ProgressBar) innerView.findViewById(R.id.progressBar);

    mDensity = context.getResources().getDisplayMetrics().density;
    final AlertDialog dialog = new AlertDialog.Builder(context).setView(innerView).create();
    mCaptchaAnswer.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });
    mCaptchaAnswer.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                sendAnswer();
                return true;
            }
            return false;
        }
    });

    dialog.setButton(AlertDialog.BUTTON_NEGATIVE, context.getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    sendAnswer();
                }
            });
    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialogInterface) {
            mCaptchaError.request.cancel();
        }
    });
    loadImage();
    dialog.show();
}

From source file:com.android.talkback.labeling.LabelDialogManager.java

private void showDialog(AlertDialog dialog) {
    if (mAccessibilityOverlay) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY);
        } else {//from w ww  .  j a v a 2  s.  c  om
            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
        }

        // Only need to register overlay dialogs (since they'll cover the lock screen).
        TalkBackService service = TalkBackService.getInstance();
        if (service != null) {
            service.getRingerModeAndScreenMonitor().registerDialog(dialog);
        }
    }
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    dialog.show();
}

From source file:com.tencent.wetest.fragment.HomePageFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View mView = inflater.inflate(R.layout.home, container, false);

    app_select_layout = (LinearLayout) mView.findViewById(R.id.app_select_layout);
    app_select_layout.setOnClickListener(new View.OnClickListener() {
        @Override/* w  ww. j a va  2s  .  co m*/
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), AppListActivity.class);
            getActivity().startActivity(intent);

        }
    });

    root_alert_layout = (LinearLayout) mView.findViewById(R.id.root_alert_layout);
    root_alert_layout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (!((WTApplication) WTApplication.getContext()).isRoot()) {
                AlertDialog.Builder root_b = new AlertDialog.Builder(getActivity());
                root_b.setTitle(getResources().getString(R.string.explain));
                root_b.setMessage(getResources().getString(R.string.explain_content));
                root_b.setPositiveButton(getResources().getString(R.string.i_know), null);

                AlertDialog root_d = root_b.create();
                root_d.getWindow().setType(WindowManager.LayoutParams.LAST_SUB_WINDOW);

                if (((MainActivity) getActivity()).isRunning())
                    root_d.show();
            }

        }
    });

    appName = (TextView) mView.findViewById(R.id.appName);

    btnstart = (Button) mView.findViewById(R.id.btn_test_start);
    btnstart.setOnClickListener(onStartClick);

    isRoot = (TextView) mView.findViewById(R.id.isRoot);
    isRoot.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (!((WTApplication) WTApplication.getContext()).isRoot()) {
                AlertDialog.Builder root_b = new AlertDialog.Builder(getActivity());
                root_b.setTitle(getResources().getString(R.string.explain));
                root_b.setMessage(getResources().getString(R.string.explain_content));
                root_b.setPositiveButton(getResources().getString(R.string.i_know), null);

                AlertDialog root_d = root_b.create();
                root_d.getWindow().setType(WindowManager.LayoutParams.LAST_SUB_WINDOW);

                if (((MainActivity) getActivity()).isRunning())
                    root_d.show();
            }
        }
    });

    avail_para = (TextView) mView.findViewById(R.id.avail_para);

    ImageView img_alert = (ImageView) mView.findViewById(R.id.img_alert);

    if (((WTApplication) WTApplication.getContext()).isRoot()) {
        avail_para.setText(getResources().getString(R.string.home_bottom_title) + " FPS");
        img_alert.setVisibility(View.GONE);
    } else {

        avail_para.setText(getResources().getString(R.string.home_bottom_title));
        img_alert.setVisibility(View.VISIBLE);
    }

    //      avail_para.setOnClickListener(new View.OnClickListener() {
    //         @Override
    //         public void onClick(View v) {
    //
    //            if(!((WTApplication)WTApplication.getContext()).isRoot()) {
    //               AlertDialog.Builder root_b = new AlertDialog.Builder(getActivity());
    //               root_b.setTitle(getResources().getString(R.string.explain));
    //               root_b.setMessage(getResources().getString(R.string.explain_content));
    //               root_b.setPositiveButton(getResources().getString(R.string.i_know), null);
    //
    //               AlertDialog root_d = root_b.create();
    //               root_d.getWindow().setType(WindowManager.LayoutParams.LAST_SUB_WINDOW);
    //
    //               if(((MainActivity)getActivity()).isRunning())
    //                  root_d.show();
    //            }
    //         }
    //      });

    if (((WTApplication) WTApplication.getContext()).isRoot()) {
        Logger.info("Homepage is root");
        isRoot.setText(getResources().getString(R.string.phone_is_root));

    }

    mSetting = ((WTApplication) WTApplication.getContext()).getmSetting();
    if (!((WTApplication) WTApplication.getContext()).isRoot() && mSetting.getBoolean("isFirstSetup", true)) {
        mSetting.edit().putBoolean("isFirstSetup", false).apply();
        isRoot.performClick();
    }
    return mView;
}

From source file:com.linkbubble.util.YouTubeEmbedHelper.java

private AlertDialog getMultipleEmbedsDialog() {
    if (embedInfoMatchesIds()) {
        return getEmbedResultsDialog();
    } else {/* ww w .j a  v a 2s  .c  o  m*/
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);

        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.view_loading, null);

        TextView textView = (TextView) view.findViewById(R.id.loading_text);
        textView.setText(R.string.loading_youtube_embed_info);

        builder.setView(view);
        builder.setIcon(0);

        AlertDialog alertDialog = builder.create();
        alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

        if (mCurrentDownloadTask != null) {
            synchronized (mCurrentDownloadTask) {
                if (mCurrentDownloadTask != null) {
                    mCurrentDownloadTask.cancel(true);
                }
                mCurrentDownloadTask = new DownloadYouTubeEmbedInfoTask(true, alertDialog);
                mCurrentDownloadTask.execute(null, null, null);
            }
        } else {
            mCurrentDownloadTask = new DownloadYouTubeEmbedInfoTask(true, alertDialog);
            mCurrentDownloadTask.execute(null, null, null);
        }

        return alertDialog;
    }
}

From source file:com.chaitu.lmscalendar.ui.UrlDialog.java

@Override
@NonNull/*from ww w. j  av a2 s .c o m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {

    mActivity = (MainActivity) getActivity();

    ViewGroup nullViewGroup = null; // Avoid bad lint warning in inflate()
    View view = mActivity.getLayoutInflater().inflate(R.layout.urldialog, nullViewGroup);

    mTextCalendarUrl = (EditText) view.findViewById(R.id.TextCalendarUrl);
    mTextUsername = (EditText) view.findViewById(R.id.TextUsername);
    mTextPassword = (EditText) view.findViewById(R.id.TextPassword);

    Settings settings = mActivity.getSettings();
    mTextCalendarUrl.setText(settings.getString(Settings.PREF_LASTURL));
    mTextUsername.setText(settings.getString(Settings.PREF_LASTURLUSERNAME));
    mTextPassword.setText(settings.getString(Settings.PREF_LASTURLPASSWORD));

    mTextCalendarUrl.selectAll();

    //sync intervals
    mSpinnerSyncInterval = (Spinner) view.findViewById(R.id.sync_interval);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mActivity.getApplicationContext(),
            R.array.sync_intervals, android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    mSpinnerSyncInterval.setAdapter(adapter);

    mSpinnerCalendar = (Spinner) view.findViewById(R.id.calendar);
    //calendar
    List<CalendarModel> calendars = EventUtil.readCalendars(mActivity.getApplicationContext(),
            mActivity.getApplicationContext().getContentResolver());

    ArrayAdapter<CalendarModel> adapter1 = new ArrayAdapter<CalendarModel>(mActivity.getApplicationContext(),
            android.R.layout.simple_spinner_dropdown_item, calendars);
    mSpinnerCalendar.setAdapter(adapter1);

    String name = settings.getString(Settings.PREF_LASTCALENDARNAME);
    int id = settings.getInt(Settings.PREF_LASTCALENDARID);
    if (id > 0 && name != null && !name.isEmpty()) {
        CalendarModel cal = new CalendarModel(id, name);
        mSpinnerCalendar.setSelection(adapter1.getPosition(cal));
    }

    DialogInterface.OnClickListener okTask;
    okTask = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface iface, int id) {
            // We override this in onStart()
        }
    };

    DialogInterface.OnClickListener cancelTask;
    cancelTask = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface iface, int id) {
            iface.cancel();
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    AlertDialog dlg = builder.setIcon(R.mipmap.ic_launcher).setTitle(R.string.enter_source_url).setView(view)
            .setPositiveButton(android.R.string.ok, okTask)
            .setNegativeButton(android.R.string.cancel, cancelTask).create();
    dlg.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    return dlg;
}