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.wellsandwhistles.android.redditsp.common.DialogUtils.java

public static void showSearchDialog(Context context, int titleRes, final OnSearchListener listener) {
    final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
    final EditText editText = (EditText) LayoutInflater.from(context).inflate(R.layout.dialog_editbox, null);

    alertBuilder.setView(editText);/*from   w ww  . j  av a 2s .  c o  m*/
    alertBuilder.setTitle(titleRes);

    alertBuilder.setPositiveButton(R.string.action_search, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final String query = General.asciiLowercase(editText.getText().toString()).trim();
            if (StringUtils.isEmpty(query)) {
                listener.onSearch(null);
            } else {
                listener.onSearch(query);
            }
        }
    });

    alertBuilder.setNegativeButton(R.string.dialog_cancel, null);

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

From source file:Main.java

public static Dialog confirm(String title, View view, Context context,
        DialogInterface.OnClickListener onConfirmListener) {
    Builder dialogBuilder = confirmBuilder(title, context, onConfirmListener).setView(view);

    if (view instanceof TextView) {
        ScrollView scrollView = new ScrollView(context);
        scrollView.addView(view);/*from   ww w.j ava2  s .co m*/
        dialogBuilder.setView(scrollView);
    }

    AlertDialog dialog = dialogBuilder.create();

    if (view instanceof EditText) {
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
                | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }

    dialog.show();
    return dialog;
}

From source file:nya.miku.wishmaster.http.cloudflare.CloudflareUIHandler.java

/**
 *  ?-?  Cloudflare./* w  w  w.j  ava2  s  .co m*/
 *    
 * @param e ? {@link CloudflareException}
 * @param chan  
 * @param activity ?,    ?  ( ?  ? ),
 *   ?   ? WebView ? Anti DDOS  ? javascript.
 * ???  ?  UI  ({@link Activity#runOnUiThread(Runnable)})
 * @param cfTask ?? 
 * @param callback ? {@link Callback}
 */
static void handleCloudflare(final CloudflareException e, final HttpChanModule chan, final Activity activity,
        final CancellableTask cfTask, final InteractiveException.Callback callback) {
    if (cfTask.isCancelled())
        return;

    if (!e.isRecaptcha()) { // ? anti DDOS 
        if (!CloudflareChecker.getInstance().isAvaibleAntiDDOS()) {
            //?  ?   ??  ,   ?  ? ?
            // ?, ?      ChanModule,    
            //  ?  ?  () cloudflare  ? ?
            //  ?  ? ? ?   ? CloudflareChecker
            while (!CloudflareChecker.getInstance().isAvaibleAntiDDOS())
                Thread.yield();
            if (!cfTask.isCancelled())
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        callback.onSuccess();
                    }
                });
            return;
        }

        Cookie cfCookie = CloudflareChecker.getInstance().checkAntiDDOS(e, chan.getHttpClient(), cfTask,
                activity);
        if (cfCookie != null) {
            chan.saveCookie(cfCookie);
            if (!cfTask.isCancelled()) {
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        callback.onSuccess();
                    }
                });
            }
        } else if (!cfTask.isCancelled()) {
            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    callback.onError(activity.getString(R.string.error_cloudflare_antiddos));
                }
            });
        }
    } else { //  ? 
        final Recaptcha recaptcha;
        try {
            recaptcha = CloudflareChecker.getInstance().getRecaptcha(e, chan.getHttpClient(), cfTask);
        } catch (RecaptchaException recaptchaException) {
            if (!cfTask.isCancelled())
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        callback.onError(activity.getString(R.string.error_cloudflare_get_captcha));
                    }
                });
            return;
        }

        if (!cfTask.isCancelled())
            activity.runOnUiThread(new Runnable() {
                @SuppressLint("InflateParams")
                @Override
                public void run() {
                    Context dialogContext = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
                            ? new ContextThemeWrapper(activity, R.style.Neutron_Medium)
                            : activity;
                    View view = LayoutInflater.from(dialogContext).inflate(R.layout.dialog_cloudflare_captcha,
                            null);
                    ImageView captchaView = (ImageView) view.findViewById(R.id.dialog_captcha_view);
                    final EditText captchaField = (EditText) view.findViewById(R.id.dialog_captcha_field);
                    captchaView.setImageBitmap(recaptcha.bitmap);

                    DialogInterface.OnClickListener process = new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (cfTask.isCancelled())
                                return;
                            PriorityThreadFactory.LOW_PRIORITY_FACTORY.newThread(new Runnable() {
                                @Override
                                public void run() {
                                    String answer = captchaField.getText().toString();
                                    Cookie cfCookie = CloudflareChecker.getInstance().checkRecaptcha(e,
                                            (ExtendedHttpClient) chan.getHttpClient(), cfTask,
                                            recaptcha.challenge, answer);
                                    if (cfCookie != null) {
                                        chan.saveCookie(cfCookie);
                                        if (!cfTask.isCancelled()) {
                                            activity.runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    callback.onSuccess();
                                                }
                                            });
                                        }
                                    } else {
                                        //   (?,  ,    )
                                        handleCloudflare(e, chan, activity, cfTask, callback);
                                    }
                                }
                            }).start();
                        }
                    };

                    DialogInterface.OnCancelListener onCancel = new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialog) {
                            callback.onError(activity.getString(R.string.error_cloudflare_cancelled));
                        }
                    };

                    if (cfTask.isCancelled())
                        return;

                    final AlertDialog recaptchaDialog = new AlertDialog.Builder(dialogContext).setView(view)
                            .setPositiveButton(R.string.dialog_cloudflare_captcha_check, process)
                            .setOnCancelListener(onCancel).create();
                    recaptchaDialog.getWindow()
                            .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                    recaptchaDialog.setCanceledOnTouchOutside(false);
                    recaptchaDialog.show();

                    captchaView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            recaptchaDialog.dismiss();
                            if (cfTask.isCancelled())
                                return;
                            PriorityThreadFactory.LOW_PRIORITY_FACTORY.newThread(new Runnable() {
                                @Override
                                public void run() {
                                    handleCloudflare(e, chan, activity, cfTask, callback);
                                }
                            }).start();
                        }
                    });
                }
            });
    }
}

From source file:tr.com.turkcellteknoloji.turkcellupdater.UpdaterDialogManager.java

/**
 * Creates a dialog for given message.//from www . j av a  2 s. c o m
 *
 * @param activity
 *            Parent activity.
 * @param message
 *            Message contents
 * @param dismissListener
 *            Listener that will be called when dialog is closed or
 *            cancelled.
 * @return Created dialog.
 */
public static Dialog createMessageDialog(Activity activity, Message message,
        OnDismissListener dismissListener) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);

    final String title = message.description == null ? null
            : message.description.get(MessageDescription.KEY_TITLE);
    if (!Utilities.isNullOrEmpty(title)) {
        builder.setTitle(title);
    }

    final View dialogContentsView = createMessageDialogContentsView(activity, message.description);
    builder.setView(dialogContentsView);

    initializeMessageDialogButtons(activity, builder, message);
    builder.setCancelable(true);

    final AlertDialog dialog = builder.create();

    if (Utilities.isNullOrEmpty(title)) {
        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    }

    dialog.setOnDismissListener(dismissListener);
    return dialog;
}

From source file:org.brandroid.openmanager.fragments.DialogHandler.java

public static void showAboutDialog(final Context mContext) {
    LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = li.inflate(R.layout.about, null);

    String sVersionInfo = "";
    try {//w  w w  .  ja v  a  2  s.  c om
        PackageInfo pi = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
        sVersionInfo += pi.versionName;
        if (!pi.versionName.contains("" + pi.versionCode))
            sVersionInfo += " (" + pi.versionCode + ")";
        if (OpenExplorer.IS_DEBUG_BUILD)
            sVersionInfo += " *debug*";
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String sBuildTime = "";
    try {
        sBuildTime = SimpleDateFormat.getInstance()
                .format(new Date(new ZipFile(
                        mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), 0).sourceDir)
                                .getEntry("classes.dex").getTime()));
    } catch (Exception e) {
        Logger.LogError("Couldn't get Build Time.", e);
    }

    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(dm);
    Display d = wm.getDefaultDisplay();
    String sHardwareInfo = "Display:\n";
    sHardwareInfo += "Size: " + d.getWidth() + "x" + d.getHeight() + "\n";
    if (dm != null)
        sHardwareInfo += "Density: " + dm.density + "\n";
    sHardwareInfo += "Rotation: " + d.getRotation() + "\n\n";
    sHardwareInfo += getNetworkInfo(mContext);
    sHardwareInfo += getDeviceInfo();
    ((TextView) view.findViewById(R.id.about_hardware)).setText(sHardwareInfo);

    final String sSubject = "Feedback for OpenExplorer " + sVersionInfo;
    OnClickListener email = new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            //intent.addCategory(Intent.CATEGORY_APP_EMAIL);
            intent.putExtra(android.content.Intent.EXTRA_TEXT, "\n" + getDeviceInfo());
            intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "brandroid64@gmail.com" });
            intent.putExtra(android.content.Intent.EXTRA_SUBJECT, sSubject);
            mContext.startActivity(Intent.createChooser(intent, mContext.getString(R.string.s_chooser_email)));
        }
    };
    OnClickListener viewsite = new OnClickListener() {
        public void onClick(View v) {
            mContext.startActivity(
                    new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://brandroid.org/open/")));
        }
    };
    view.findViewById(R.id.about_email).setOnClickListener(email);
    view.findViewById(R.id.about_email_btn).setOnClickListener(email);
    view.findViewById(R.id.about_site).setOnClickListener(viewsite);
    view.findViewById(R.id.about_site_btn).setOnClickListener(viewsite);
    final View mRecentLabel = view.findViewById(R.id.about_recent_status_label);
    final WebView mRecent = (WebView) view.findViewById(R.id.about_recent);
    final OpenChromeClient occ = new OpenChromeClient();
    occ.mStatus = (TextView) view.findViewById(R.id.about_recent_status);
    mRecent.setWebChromeClient(occ);
    mRecent.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            occ.mStatus.setVisibility(View.GONE);
            mRecent.setVisibility(View.GONE);
            mRecentLabel.setVisibility(View.GONE);
        }
    });
    mRecent.setBackgroundColor(Color.TRANSPARENT);
    mRecent.loadUrl("http://brandroid.org/open/?show=recent");

    ((TextView) view.findViewById(R.id.about_version)).setText(sVersionInfo);
    if (sBuildTime != "")
        ((TextView) view.findViewById(R.id.about_buildtime)).setText(sBuildTime);
    else
        ((TableRow) view.findViewById(R.id.row_buildtime)).setVisibility(View.GONE);

    fillShortcutsTable((TableLayout) view.findViewById(R.id.shortcuts_table));

    final View tab1 = view.findViewById(R.id.tab1);
    final View tab2 = view.findViewById(R.id.tab2);
    final View tab3 = view.findViewById(R.id.tab3);
    ((Button) view.findViewById(R.id.btn_recent)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tab1.setVisibility(View.VISIBLE);
            tab2.setVisibility(View.GONE);
            tab3.setVisibility(View.GONE);
        }
    });
    ((Button) view.findViewById(R.id.btn_hardware)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tab1.setVisibility(View.GONE);
            tab2.setVisibility(View.VISIBLE);
            tab3.setVisibility(View.GONE);
        }
    });
    ((Button) view.findViewById(R.id.btn_shortcuts)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            tab1.setVisibility(View.GONE);
            tab2.setVisibility(View.GONE);
            tab3.setVisibility(View.VISIBLE);
        }
    });

    AlertDialog mDlgAbout = new AlertDialog.Builder(mContext).setTitle(R.string.app_name).setView(view)
            .create();

    mDlgAbout.getWindow().getAttributes().windowAnimations = R.style.SlideDialogAnimation;
    mDlgAbout.getWindow().getAttributes().alpha = 0.9f;

    mDlgAbout.show();
}

From source file:com.klick.plugins.listviewalert.ListViewAlert.java

public void loadList(final JSONArray thelist, final CallbackContext callbackContext) {
    final CordovaInterface cordova = this.cordova;
    Runnable runnable = new Runnable() {
        public void run() {
            List<String> list = new ArrayList<String>();
            // we start with index 1 because index 0 is the title
            for (int x = 1; x < thelist.length(); x++) {
                try {
                    list.add(thelist.getString(x));
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }//from   w  ww.  j  av  a2s. c  om
            }
            CharSequence[] items = list.toArray(new CharSequence[list.size()]);
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(cordova.getActivity(), android.R.style.Theme_Holo_Dialog));
            try {
                builder.setTitle(thelist.getString(0));
                // builder.setMessage( "This is a hardcoded message to try whether or not this is feasible!");
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } // index 0 contains the title
            builder.setItems(items, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    dialog.dismiss();
                    // we +1 to item because item starts from 0, but from
                    // thelist[0], that was the title...
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, item + 1));
                    //callbackContext.sendPluginResult(pluginResult)
                }
            });
            AlertDialog alert = builder.create();
            alert.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            alert.show();
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:org.runbuddy.tomahawk.dialogs.HatchetLoginDialog.java

/**
 * Called when this {@link DialogFragment} is being created
 *///from   w  ww.j  av a 2 s.c o m
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (getArguments() != null && getArguments().containsKey(TomahawkFragment.PREFERENCEID)) {
        String authenticatorId = getArguments().getString(TomahawkFragment.PREFERENCEID);
        mAuthenticatorUtils = AuthenticatorManager.get().getAuthenticatorUtils(authenticatorId);
    }

    TextView headerTextView = (TextView) addScrollingViewToFrame(R.layout.config_textview);
    headerTextView.setText(mAuthenticatorUtils.getDescription());
    mHatchetLoginRegisterView = (HatchetLoginRegisterView) addScrollingViewToFrame(
            R.layout.config_hatchetloginregister);
    mHatchetLoginRegisterView.setup(mAuthenticatorUtils, mProgressBar);

    setDialogTitle(mAuthenticatorUtils.getPrettyName());
    if (TomahawkApp.PLUGINNAME_HATCHET.equals(mAuthenticatorUtils.getId())) {
        onResolverStateUpdated(HatchetStubResolver.get());
    } else {
        onResolverStateUpdated(PipeLine.get().getResolver(mAuthenticatorUtils.getId()));
    }
    hideNegativeButton();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(getDialogView());
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
    alertDialog.getWindow().clearFlags(
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    return alertDialog;
}

From source file:org.apache.cordova.plugins.AlertListPlugin.java

public void loadList(final JSONArray thelist, final CallbackContext callbackContext) {

    final CordovaInterface cordova = this.cordova;

    Runnable runnable = new Runnable() {

        public void run() {

            List<String> list = new ArrayList<String>();

            // we start with index 1 because index 0 is the title
            for (int x = 1; x < thelist.length(); x++) {
                try {
                    list.add(thelist.getString(x));
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }/*  w  w  w.ja v  a  2 s  . com*/
            }

            CharSequence[] items = list.toArray(new CharSequence[list.size()]);

            AlertDialog.Builder builder = new AlertDialog.Builder(cordova.getActivity());
            try {
                builder.setTitle(thelist.getString(0));
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } // index 0 contains the title
            builder.setItems(items, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    dialog.dismiss();
                    // we +1 to item because item starts from 0, but from
                    // thelist[0], that was the title...
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, item + 1));
                    //callbackContext.sendPluginResult(pluginResult)

                }
            });
            AlertDialog alert = builder.create();
            alert.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            alert.show();
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:org.tomahawk.tomahawk_android.dialogs.LoginConfigDialog.java

/**
 * Called when this {@link DialogFragment} is being created
 *//*  w  ww. ja  va 2  s  .  co  m*/
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (getArguments() != null && getArguments().containsKey(TomahawkFragment.PREFERENCEID)) {
        String authenticatorId = getArguments().getString(TomahawkFragment.PREFERENCEID);
        mAuthenticatorUtils = AuthenticatorManager.get().getAuthenticatorUtils(authenticatorId);
    }

    TextView headerTextView = (TextView) addScrollingViewToFrame(R.layout.config_textview);
    headerTextView.setText(mAuthenticatorUtils.getDescription());
    mHatchetLoginRegisterView = (HatchetLoginRegisterView) addScrollingViewToFrame(
            R.layout.config_hatchetloginregister);
    mHatchetLoginRegisterView.setup(getActivity(), mAuthenticatorUtils, mProgressBar);

    setDialogTitle(mAuthenticatorUtils.getPrettyName());
    if (TomahawkApp.PLUGINNAME_HATCHET.equals(mAuthenticatorUtils.getId())) {
        setStatus(HatchetStubResolver.get());
    } else {
        setStatus(PipeLine.get().getResolver(mAuthenticatorUtils.getId()));
    }
    hideNegativeButton();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(getDialogView());
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
    alertDialog.getWindow().clearFlags(
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    return alertDialog;
}

From source file:com.drisoftie.frags.comp.BaseDiagResult.java

@Override
public Dialog onCreateDialog(@NonNull Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View v = inflater.inflate(getArguments().getInt(getString(R.string.bundl_diag_layout)), null);
    createDialogComponents(v);/*from ww w  .j a v  a2 s  .c o m*/
    builder.setView(v);
    if (getArguments().containsKey(getString(R.string.bundl_diag_title))) {
        Object arg = getArguments().get(getString(R.string.bundl_diag_title));
        if (arg instanceof String) {
            builder.setTitle(getArguments().getString(getString(R.string.bundl_diag_title)));
        } else if (arg instanceof Integer) {
            builder.setTitle(getArguments().getInt(getString(R.string.bundl_diag_title)));
        }
    }
    if (getArguments().containsKey(getString(R.string.bundl_diag_btn_positive))) {
        builder.setPositiveButton(getArguments().getInt(getString(R.string.bundl_diag_btn_positive)),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                    }
                });
    }
    if (getArguments().containsKey(getString(R.string.bundl_diag_btn_positive))) {
        builder.setNegativeButton(getArguments().getInt(getString(R.string.bundl_diag_btn_negative)),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                    }
                });
    }
    AlertDialog diag = builder.create();
    diag.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    return diag;
}