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.offsec.nethunter.AppNavHomeActivity.java

public void showLicense() {
    // @binkybear here goes the changelog etc... \n\n%s
    String readmeData = String.format("%s\n\n%s", getResources().getString(R.string.licenseInfo),
            getResources().getString(R.string.nhwarning));

    AlertDialog.Builder adb = new AlertDialog.Builder(this);
    adb.setTitle("README INFO").setMessage(readmeData).setNegativeButton("Close",
            new DialogInterface.OnClickListener() {
                @Override//from  w w w  .j av  a2 s .  c o  m
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            }); //nhwarning
    AlertDialog ad = adb.create();
    ad.setCancelable(false);
    ad.getWindow().getAttributes().windowAnimations = R.style.DialogStyle;
    ad.show();
}

From source file:ch.ethz.coss.nervousnet.hub.ui.SensorDisplayActivity.java

public void showInfo(View view) {
    String title = "Sensor Frequency:";

    // Includes the updates as well so users know what changed.
    String message = "\n\n- Settings to control the frequency of Sensors."
            + "\nClick on the options to switch off or change the frequency."
            + "\n- Various levels of frequency can be selected" + "\n          - HIGH, MEDIUM, LOW or OFF"
            + "\n Please note if the Nervousnet Service is Paused, this control is disabled.";

    AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(title).setMessage(message)
            .setPositiveButton("OK", new Dialog.OnClickListener() {

                @Override/*  www.j  a  v  a2s  . c o  m*/
                public void onClick(DialogInterface dialogInterface, int i) {

                    dialogInterface.dismiss();

                }
            });
    builder.setCancelable(false);

    AlertDialog alert = builder.create();
    alert.show();

    alert.getWindow().getAttributes();

    TextView textView = (TextView) alert.findViewById(android.R.id.message);
    textView.setTextSize(12);
}

From source file:com.cleanwiz.applock.ui.activity.SplashActivity.java

public void showUpdateDialog(String intro) {
    final AlertDialog updateDialogDlg = new AlertDialog.Builder(this).create();
    updateDialogDlg.show();/*from   w w  w . j  a va  2  s. c  o m*/
    Window win = updateDialogDlg.getWindow();
    win.setContentView(R.layout.dialog_update);
    TextView tvMsg = (TextView) win.findViewById(R.id.tvMsg);
    tvMsg.setText(intro);
    Button btOk = (Button) win.findViewById(R.id.btOk);
    ImageView closeImageView = (ImageView) win.findViewById(R.id.updateclose);
    closeImageView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            updateDialogDlg.dismiss();
            SplashHandler handler = new SplashHandler();
            Message msg = new Message();
            msg.what = CHECKVERSION_CANCEL;
            handler.sendMessage(msg);
        }
    });

    btOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            SplashHandler handler = new SplashHandler();
            Message msg = new Message();
            msg.what = CHECKVERSION_DOWN;
            handler.sendMessage(msg);
        }
    });

    updateDialogDlg.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            // TODO Auto-generated method stub
            List<UpdateVersionManafer> updateVersionManafers = updateVersionManagerService.getVersionManafers();
            for (UpdateVersionManafer updateVersionManafer : updateVersionManafers) {
                updateVersionManafer.setLasttipdate(new Date().getTime());
                updateVersionManagerService.modifyTipsDate(updateVersionManafer);
                break;
            }
            SplashHandler handler = new SplashHandler();
            Message msg = new Message();
            msg.what = CHECKVERSION_CANCEL;
            handler.sendMessage(msg);
        }
    });
}

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

AlertDialog getEmbedResultsDialog() {
    if (mEmbedInfo.size() > 0) {
        ListView listView = new ListView(mContext);
        listView.setAdapter(new EmbedItemAdapter());

        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setView(listView);//from w  w w  . ja  va  2 s. c o  m
        builder.setIcon(mYouTubeResolveInfo.loadIcon(mContext.getPackageManager()));
        builder.setTitle(R.string.title_youtube_embed_to_load);

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

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                EmbedInfo embedInfo = (EmbedInfo) view.getTag();
                if (embedInfo != null) {
                    loadYouTubeVideo(embedInfo.mId);
                }
                alertDialog.dismiss();
            }
        });

        return alertDialog;
    } else {
        final AlertDialog alertDialog = new AlertDialog.Builder(mContext).create();
        alertDialog.setTitle(R.string.youtube_embed_error_title);
        alertDialog.setMessage(mContext.getString(R.string.youtube_embed_error_summary));
        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE,
                mContext.getResources().getString(R.string.action_ok), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        alertDialog.dismiss();
                    }

                });
        alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        return alertDialog;
    }
}

From source file:org.catrobat.catroid.ui.dialogs.LoginRegisterDialog.java

@Override
public Dialog onCreateDialog(Bundle bundle) {
    View rootView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_login_register, null);

    usernameEditText = (EditText) rootView.findViewById(R.id.username);
    passwordEditText = (EditText) rootView.findViewById(R.id.password);
    termsOfUseLinkTextView = (TextView) rootView.findViewById(R.id.register_terms_link);

    String termsOfUseUrl = getString(R.string.about_link_template, Constants.CATROBAT_TERMS_OF_USE_URL,
            getString(R.string.register_pocketcode_terms_of_use_text));
    termsOfUseLinkTextView.setMovementMethod(LinkMovementMethod.getInstance());
    termsOfUseLinkTextView.setText(Html.fromHtml(termsOfUseUrl));

    usernameEditText.setText("");
    passwordEditText.setText("");

    final AlertDialog loginRegisterDialog = new AlertDialog.Builder(getActivity()).setView(rootView)
            .setTitle(R.string.login_register_dialog_title).setPositiveButton(R.string.login_or_register, null)
            .setNeutralButton(R.string.password_forgotten, null).create();
    loginRegisterDialog.setCanceledOnTouchOutside(true);
    loginRegisterDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    loginRegisterDialog.setOnShowListener(new OnShowListener() {
        @Override/*from   w ww.  j av a  2s  . c  om*/
        public void onShow(DialogInterface dialog) {
            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(usernameEditText, InputMethodManager.SHOW_IMPLICIT);

            Button loginRegisterButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            loginRegisterButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    handleLoginRegisterButtonClick();
                }
            });

            Button passwordForgottenButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
            passwordForgottenButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    handlePasswordForgottenButtonClick();
                }
            });
        }
    });

    return loginRegisterDialog;
}

From source file:info.snowhow.plugin.RecorderService.java

private void showNoGPSAlert() {
    Log.i(LOG_TAG, "No GPS available --- show Dialog");
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setMessage("GPS is disabled on your device. Would you like to enable it?")
            .setCancelable(false).setPositiveButton("GPS Settings", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    Intent callGPSSettingIntent = new Intent(
                            android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    callGPSSettingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(callGPSSettingIntent);
                }/* w  w w.j ava 2s.c o  m*/
            });
    alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            stopRecording();
            dialog.cancel();
        }
    });
    AlertDialog alert = alertDialogBuilder.create();
    alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    alert.show();
}

From source file:de.jadehs.jadehsnavigator.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /***** DATABSE SANITY CHECK ****/
    try {//from w w w  .ja va2 s  . c  o m
        DBHelper dbHelper = new DBHelper(getApplicationContext());
        dbHelper.getWritableDatabase();
    } catch (Exception ex) {
        Log.wtf(TAG, "Err", ex);
    }

    /**** START GCM INIT ****/
    //@todo: Wird vorerst nicht implementiert, da nicht essentiell und kein Server bereitsteht..
    /*
    registrationBroadcastReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        Preferences preferences = new Preferences(getApplicationContext());
        Toast.makeText(getApplicationContext(), "DEBUG: Broadcast erhalten", Toast.LENGTH_LONG).show();
    }
    };
    */
    /*** END GCM INIT ***/

    mTitle = mDrawerTitle = getTitle();

    navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);

    navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.list_slidermenu);

    navDrawerItems = new ArrayList<NavDrawerItem>();

    //navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1))); //home
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1))); //neuigkeiten
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1))); //infosys
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1))); //vorlesungsplan
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1))); //mensaplan
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1))); //lageplan
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1))); //about
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[6], navMenuIcons.getResourceId(6, -1))); //settings

    navMenuIcons.recycle();

    mDrawerList.setOnItemClickListener(new SlideMenuClickListener());

    adapter = new NavDrawerListAdapter(getApplicationContext(), navDrawerItems);
    mDrawerList.setAdapter(adapter);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.navigation_drawer_open,
            R.string.navigation_drawer_close) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu();
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    Preferences preferences = new Preferences(this);
    if (savedInstanceState == null) {
        //displayView(1);
        int index = Integer.parseInt(preferences.get("IndexPreference_list", "1"));
        displayView(index);
    }

    /*
    * @todo: Gehrt zu Google Cloud Messages. Vorerst ausgeschaltet.
    if (checkPlayServices()){
       // Starte Registration..
       Intent intent = new Intent(this, RegistrationIntentService.class);
       startService(intent);
    }
    */
    /***** START FIRST TIME SETUP ****/

    if (!preferences.getBoolean("setupDone", false)) {
        Log.wtf(TAG, "Setup is not yet done");
        // show the user that there is a drawer menu
        mDrawerLayout.openDrawer(Gravity.LEFT);
        // don't show this dialog again and set the flag to remind of feedback
        preferences.save("setupDone", true);
        preferences.save("feedbackReminderSeen", false);

        final AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
        builder.setMessage(getApplicationContext().getString(R.string.alert_firsttimesetup)).setCancelable(true)
                .setPositiveButton(getApplicationContext().getString(R.string.positive),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                try {
                                    Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
                                    startActivity(intent);
                                } catch (Exception ex) {
                                    Log.wtf(TAG, "Preference Activity failed", ex);
                                }
                            }
                        })
                .setNegativeButton(getApplicationContext().getString(R.string.negative),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });
        final AlertDialog alert = builder.create();
        alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        alert.show();
    } else if (preferences.getBoolean("setupDone", false)
            && !preferences.getBoolean("feedbackReminderSeen", false)) {
        // remind to leave feedback
        preferences.save("feedbackReminderSeen", true);
        final AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
        builder.setMessage(getApplicationContext().getString(R.string.alert_feedbackreminder))
                .setCancelable(true).setPositiveButton(getApplicationContext().getString(R.string.positive),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                try {
                                    startActivity(new Intent(Intent.ACTION_VIEW,
                                            Uri.parse("market://details?id=" + getPackageName())));
                                } catch (Exception ex) {
                                    Log.wtf(TAG, "Store Activity failed", ex);
                                }
                            }
                        })
                .setNegativeButton(getApplicationContext().getString(R.string.negative),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });
        final AlertDialog alert = builder.create();
        alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        alert.show();
    } else {
        // we already showed the reminder
        Log.wtf(TAG, "Setup is already done. Business as usual");
    }
    /**** END FIRST TIME SETUP ****/

}

From source file:jp.seesaa.android.datetimepicker.date.DatePickerDialog.java

@NonNull
@Override//from w  w w .  j av a 2s.  c  om
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.dtp_alertdialog);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            tryVibrate();
            if (mCallBack != null) {
                mCallBack.onDateSet(DatePickerDialog.this, mCalendar.get(Calendar.YEAR),
                        mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));
            }
            dismiss();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);

    View view = createView(LayoutInflater.from(getActivity()), savedInstanceState);
    builder.setView(view);

    AlertDialog alertDialog = builder.create();
    alertDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    WindowManager.LayoutParams lp = alertDialog.getWindow().getAttributes();
    lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
    alertDialog.getWindow().setAttributes(lp);

    return alertDialog;
}

From source file:hku.fyp14017.blencode.ui.dialogs.LoginRegisterDialog.java

@Override
public Dialog onCreateDialog(Bundle bundle) {
    View rootView = LayoutInflater.from(getActivity())
            .inflate(hku.fyp14017.blencode.R.layout.dialog_login_register, null);

    usernameEditText = (EditText) rootView.findViewById(hku.fyp14017.blencode.R.id.username);
    passwordEditText = (EditText) rootView.findViewById(hku.fyp14017.blencode.R.id.password);
    termsOfUseLinkTextView = (TextView) rootView.findViewById(hku.fyp14017.blencode.R.id.register_terms_link);

    String termsOfUseUrl = getString(hku.fyp14017.blencode.R.string.about_link_template,
            Constants.CATROBAT_TERMS_OF_USE_URL,
            getString(hku.fyp14017.blencode.R.string.register_pocketcode_terms_of_use_text));
    termsOfUseLinkTextView.setMovementMethod(LinkMovementMethod.getInstance());
    termsOfUseLinkTextView.setText(Html.fromHtml(termsOfUseUrl));

    usernameEditText.setText("");
    passwordEditText.setText("");

    final AlertDialog loginRegisterDialog = new AlertDialog.Builder(getActivity()).setView(rootView)
            .setTitle(hku.fyp14017.blencode.R.string.login_register_dialog_title)
            .setPositiveButton(hku.fyp14017.blencode.R.string.login_or_register, null)
            .setNeutralButton(hku.fyp14017.blencode.R.string.password_forgotten, null).create();
    loginRegisterDialog.setCanceledOnTouchOutside(true);
    loginRegisterDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    loginRegisterDialog.setOnShowListener(new OnShowListener() {
        @Override//from ww w  . ja va 2  s .  c o m
        public void onShow(DialogInterface dialog) {
            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(usernameEditText, InputMethodManager.SHOW_IMPLICIT);

            Button loginRegisterButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            loginRegisterButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    handleLoginRegisterButtonClick();
                }
            });

            Button passwordFhkuottenButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
            passwordFhkuottenButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    handlePasswordForgottenButtonClick();
                }
            });
        }
    });

    return loginRegisterDialog;
}

From source file:fr.forexperts.ui.PortfolioFragment.java

public void showAddDialog() {
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View alertView = inflater.inflate(R.layout.alertdialog_add_value, null);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(alertView);//from  www .  j a  v  a2s  . c om
    final AlertDialog dialog = builder.create();
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

    WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
    wmlp.gravity = Gravity.TOP | Gravity.CENTER;
    wmlp.x = 10;
    wmlp.y = 10;

    final EditText mStockName = (EditText) alertView.findViewById(R.id.stockName);
    mListViewStock = (ListView) alertView.findViewById(R.id.listViewStock);
    mListViewStock.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String text = (String) parent.getItemAtPosition(position);
            String[] result = text.split(" ");

            AddTickerTask task = new AddTickerTask();
            task.execute(result[0]);

            dialog.dismiss();
        }
    });

    mStockName.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            SuggestStockTask task = new SuggestStockTask();
            task.execute(mStockName.getText().toString());
        }
    });

    // TODO: Change hard coded width
    mStockName.setWidth(10000);

    dialog.show();
}