Example usage for android.app AlertDialog.Builder setView

List of usage examples for android.app AlertDialog.Builder setView

Introduction

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

Prototype

public void setView(View view) 

Source Link

Document

Set the view to display in that dialog.

Usage

From source file:com.boostcamp.hyeon.wallpaper.setting.view.SettingFragment.java

@OnClick(R.id.layout_wallpaper_change_cycle)
public void showAlertDialogForWallpaperChangeCycle() {
    if (mWallpaperChangeCycleTextView.getText().equals(getString(R.string.label_not_using)))
        return;//from  w  w w .ja  v a2  s  .c om
    onPause();
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setView(R.layout.item_menu_done_alert);
    builder.setPositiveButton(" ", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            setWallpaperChangeCycle();
        }
    });
    builder.setNegativeButton(getString(R.string.label_cancel), null);
    AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            ((Dialog) dialog).findViewById(R.id.layout_change_screen).setVisibility(View.GONE);
            mChangeRepeatCycleRadioGroup = (RadioGroup) ((Dialog) dialog)
                    .findViewById(R.id.rb_change_repeat_cycle);
            mChangeRepeatCycleRadioGroup.setOnCheckedChangeListener(SettingFragment.this);
            mChangeRepeatCycleRadioGroup.check(mChangeRepeatCycleRadioGroup.getChildAt(0).getId());
            for (int i = 0; i < mChangeRepeatCycleRadioGroup.getChildCount(); ++i) {
                AppCompatRadioButton radioButton = (AppCompatRadioButton) mChangeRepeatCycleRadioGroup
                        .getChildAt(i);
                String radioButtonValue = radioButton.getText().toString();
                if (radioButtonValue.equals(mWallpaperChangeCycleTextView.getText().toString())) {
                    mChangeRepeatCycleRadioGroup.check(radioButton.getId());
                    break;
                }
            }
        }
    });
    alertDialog.show();
}

From source file:com.androzic.ui.FileListDialog.java

@SuppressLint("InflateParams")
@Override//from  ww w . java2s.co m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(title);
    dialogView = (ViewGroup) getActivity().getLayoutInflater()
            .inflate(R.layout.list_with_empty_view_and_progressbar, null);
    builder.setView(dialogView);

    listView = (ListView) dialogView.findViewById(android.R.id.list);
    progressBar = (ProgressBar) dialogView.findViewById(R.id.progressbar);

    listView.setOnItemClickListener(this);

    shortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);

    return builder.create();
}

From source file:de.gadc.moneybeam.MoneyBeamActivity.java

/**
 * This method presents the user the dialog that enables him to enter his
 * email address./*from   w  ww . j a va 2  s  .c  om*/
 */
private void showEmailDialog() {
    final EditText editText = new EditText(this);
    AlertDialog.Builder emailDialogBuilder = new Builder(this);
    emailDialogBuilder.setTitle(R.string.hint_email);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    editText.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
    emailDialogBuilder.setView(editText);
    emailDialogBuilder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String mail = editText.getText().toString();
            prefs.edit().putString(Configuration.PREF_MAIL, mail).commit();
        }
    });
    emailDialogBuilder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    emailDialogBuilder.show();
}

From source file:com.example.linhdq.test.documents.creation.visualisation.LayoutQuestionDialog.java

@NonNull
@Override//from  www . j a  v a2 s. co m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getContext();
    mLayout = null;
    Pair<String, String> language = PreferencesUtils.getOCRLanguage(context);

    final InstallStatus installStatus = OcrLanguageDataStore.isLanguageInstalled(language.first, context);

    if (!installStatus.isInstalled()) {
        final String defaultLanguage = context.getString(R.string.default_ocr_language);
        final String defaultLanguageDisplay = context.getString(R.string.default_ocr_display_language);
        language = Pair.create(defaultLanguage, defaultLanguageDisplay);
    }
    mLanguage = language.first;

    AlertDialog.Builder builder;

    builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);
    View layout = View.inflate(context, R.layout.dialog_layout_question, null);
    builder.setView(layout);

    final ViewFlipper titleViewFlipper = (ViewFlipper) layout.findViewById(R.id.layout_title);
    final ImageView columnLayout = (ImageView) layout.findViewById(R.id.column_layout);
    final ImageView pageLayout = (ImageView) layout.findViewById(R.id.page_layout);
    final ImageSwitcher fairy = (ImageSwitcher) layout.findViewById(R.id.fairy_layout);
    fairy.setFactory(new ViewSwitcher.ViewFactory() {
        public View makeView() {
            return new ImageView(context);
        }
    });
    fairy.setImageResource(R.drawable.fairy_looks_center);
    fairy.setInAnimation(context, android.R.anim.fade_in);
    fairy.setOutAnimation(context, android.R.anim.fade_out);

    final int color = context.getResources().getColor(R.color.progress_color);

    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.LIGHTEN);

    columnLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mLayout != LayoutKind.COMPLEX) {
                fairy.setImageResource(R.drawable.fairy_looks_left);
                titleViewFlipper.setDisplayedChild(2);
                columnLayout.setColorFilter(colorFilter);
                pageLayout.clearColorFilter();
                mLayout = LayoutKind.COMPLEX;
            }

        }
    });
    pageLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mLayout != LayoutKind.SIMPLE) {
                mLayout = LayoutKind.SIMPLE;
                titleViewFlipper.setDisplayedChild(1);
                fairy.setImageResource(R.drawable.fairy_looks_right);
                pageLayout.setColorFilter(colorFilter);
                columnLayout.clearColorFilter();
            }
        }
    });

    final Spinner langButton = (Spinner) layout.findViewById(R.id.button_language);
    List<OcrLanguage> installedLanguages = OcrLanguageDataStore.getInstalledOCRLanguages(context);

    // actual values uses by tesseract
    final ArrayAdapter<OcrLanguage> adapter = new ArrayAdapter<>(context, R.layout.item_spinner_language,
            installedLanguages);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    langButton.setAdapter(adapter);
    for (int i = 0; i < installedLanguages.size(); i++) {
        OcrLanguage lang = installedLanguages.get(i);
        if (lang.getValue().equals(language.first)) {
            langButton.setSelection(i, false);
            break;
        }
    }
    langButton.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            final OcrLanguage item = adapter.getItem(position);
            mLanguage = item.getValue();
            PreferencesUtils.saveOCRLanguage(context, item);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    builder.setPositiveButton(R.string.start_scan, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            if (mLayout == null) {
                mLayout = LayoutKind.SIMPLE;
            }
            LayoutChoseListener listener = (LayoutChoseListener) getActivity();
            listener.onLayoutChosen(mLayout, mLanguage);
            dialog.dismiss();
        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            getActivity().finish();
            dialog.dismiss();
        }
    });

    return builder.create();

}

From source file:com.aniruddhc.acemusic.player.Dialogs.ViewPlaylistInformationDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    parentActivity = getActivity();/*from  ww  w. ja  v  a2 s. com*/
    dialogFragment = this;

    rootView = (View) parentActivity.getLayoutInflater().inflate(R.layout.dialog_playlist_information, null);

    playlistName = getArguments().getString("PLAYLIST_NAME");
    playlistFilePath = getArguments().getString("PLAYLIST_FILE_PATH");

    //Header text declarations.
    playlistNameText = (TextView) rootView.findViewById(R.id.playlist_name_text);
    playlistNameText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    playlistNameText.setPaintFlags(playlistNameText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG
            | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);

    playlistFormatText = (TextView) rootView.findViewById(R.id.playlist_format_text);
    playlistFormatText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    playlistFormatText.setPaintFlags(playlistFormatText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG
            | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);

    playlistLocationText = (TextView) rootView.findViewById(R.id.playlist_location_text);
    playlistLocationText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    playlistLocationText.setPaintFlags(playlistLocationText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG
            | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);

    playlistNumberOfSongsText = (TextView) rootView.findViewById(R.id.playlist_number_of_songs_text);
    playlistNumberOfSongsText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    playlistNumberOfSongsText.setPaintFlags(playlistNumberOfSongsText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG
            | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);

    playlistLastModifiedText = (TextView) rootView.findViewById(R.id.playlist_last_modified_text);
    playlistLastModifiedText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    playlistLastModifiedText.setPaintFlags(playlistLastModifiedText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG
            | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);

    playlistAddedToLibraryText = (TextView) rootView.findViewById(R.id.playlist_added_to_library_text);
    playlistAddedToLibraryText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    playlistAddedToLibraryText.setPaintFlags(playlistAddedToLibraryText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG
            | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);

    playlistCreatedText = (TextView) rootView.findViewById(R.id.playlist_created_text);
    playlistCreatedText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    playlistCreatedText.setPaintFlags(playlistCreatedText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG
            | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);

    //Values declarations.
    playlistNameValue = (TextView) rootView.findViewById(R.id.playlist_name_value);
    playlistNameValue.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    playlistNameValue.setPaintFlags(
            playlistNameValue.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    playlistFormatValue = (TextView) rootView.findViewById(R.id.playlist_format_value);
    playlistFormatValue.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    playlistFormatValue.setPaintFlags(
            playlistFormatValue.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    playlistLocationValue = (TextView) rootView.findViewById(R.id.playlist_location_value);
    playlistLocationValue.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    playlistLocationValue.setPaintFlags(
            playlistLocationValue.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    playlistNumberOfSongsValue = (TextView) rootView.findViewById(R.id.playlist_number_of_songs_value);
    playlistNumberOfSongsValue.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    playlistNumberOfSongsValue.setPaintFlags(
            playlistNumberOfSongsValue.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    playlistLastModifiedValue = (TextView) rootView.findViewById(R.id.playlist_last_modified_value);
    playlistLastModifiedValue.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    playlistLastModifiedValue.setPaintFlags(
            playlistLastModifiedValue.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    playlistAddedToLibraryValue = (TextView) rootView.findViewById(R.id.playlist_added_to_library_value);
    playlistAddedToLibraryValue
            .setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    playlistAddedToLibraryValue.setPaintFlags(
            playlistAddedToLibraryValue.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    playlistCreatedValue = (TextView) rootView.findViewById(R.id.playlist_created_value);
    playlistCreatedValue.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    playlistCreatedValue.setPaintFlags(
            playlistCreatedValue.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    //Set the playlist name and the file format.
    playlistNameValue.setText(playlistName);

    int extensionDotIndex = playlistFilePath.lastIndexOf(".");

    String extension = "";
    if (!playlistFilePath.isEmpty()) {
        extension = playlistFilePath.substring(extensionDotIndex, playlistFilePath.length());
    } else {
        extension = "Unknown";
    }
    playlistFormatValue.setText(extension);

    /*//Retrieve the information that needs to tbe displayed in the dialog.
    DBAccessHelper dbHelper = new DBAccessHelper(parentActivity);
    Cursor cursor = dbHelper.getPlaylistByFilePath(playlistFilePath);
            
    if (cursor.getCount() > 0) {
       //Get the number of songs in the playlist.
       playlistNumberOfSongs = cursor.getCount() + "";
       playlistNumberOfSongsValue.setText(playlistNumberOfSongs);
               
       //Get the date that the playlist was added to the library.
       cursor.moveToFirst();
               
       //Note that addTime isn't the actual "Last modification" date. It's actually the date the playlist was added to the library.
       long addTime = cursor.getLong(cursor.getColumnIndex(DBAccessHelper.PLAYLIST_LAST_MODIFIED));
       Date addDate = new Date(addTime);
               
       SimpleDateFormat addDateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm aa", Locale.getDefault());
       addDateFormat.setTimeZone(TimeZone.getDefault());
       playlistAddedToLibrary = addDateFormat.format(addDate);
               
       playlistAddedToLibraryValue.setText(playlistAddedToLibrary);
               
    }
            
    //Get a File that points to the playlist file on the filesystem.
    File file = new File(playlistFilePath);
    long lastModifiedTime = file.lastModified();
            
    if (lastModifiedTime==0) {
       playlistLastModifiedValue.setText("Unknown");
    } else {
       Date lastModifiedDate = new Date(lastModifiedTime);
               
       SimpleDateFormat lastModifiedDateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm aa", Locale.getDefault());
       lastModifiedDateFormat.setTimeZone(TimeZone.getDefault());
               
       playlistLastModified = lastModifiedDateFormat.format(lastModifiedDate);
       playlistLastModifiedValue.setText(playlistLastModified);
       playlistCreatedValue.setText(playlistLastModified);
    }*/

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

    //Set the dialog title.
    builder.setTitle(playlistName);
    builder.setView(rootView);
    builder.setNegativeButton(R.string.done, new OnClickListener() {

        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            dialogFragment.dismiss();

        }

    });

    return builder.create();
}

From source file:com.coinprism.wallet.QRCodeDialog.java

@android.support.annotation.NonNull
@Override//  w  w w  .  ja v  a2 s . com
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    // Get the layout inflater
    final LayoutInflater inflater = getActivity().getLayoutInflater();

    final View view = inflater.inflate(R.layout.dialog_qr_code, null);
    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(view);

    builder.setNegativeButton(getString(R.string.tab_wallet_dialog_qr_close),
            new DialogInterface.OnClickListener() {
                // Close the dialog
                public void onClick(DialogInterface dialog, int id) {
                    QRCodeDialog.this.getDialog().cancel();
                }
            });

    builder.setNeutralButton(getString(R.string.tab_wallet_dialog_qr_copy_address),
            new DialogInterface.OnClickListener() {
                // Copy the address into the clipboard
                public void onClick(DialogInterface dialogInterface, int i) {
                    ClipboardManager clipboard = (ClipboardManager) getActivity()
                            .getSystemService(FragmentActivity.CLIPBOARD_SERVICE);
                    ClipData clip = ClipData.newPlainText("label", QRCodeDialog.this.address);
                    clipboard.setPrimaryClip(clip);
                }
            });

    final Dialog result = builder.create();
    result.setTitle(this.title);

    final ImageView qrCode = (ImageView) view.findViewById(R.id.qrCode);
    QRCodeEncoder.createQRCode(this.address, qrCode, 592, 592, 0, 0x00FFFFFF);

    return result;
}

From source file:com.fastbootmobile.encore.app.fragments.SettingsFragment.java

private void openLicenses() {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    String text = getString(R.string.licenses);
    text = "<pre>" + text + "</pre>";
    text = text.replaceAll("\n", "<br />");

    WebView view = new WebView(getActivity());
    view.loadData(text, "text/html", "UTF-8");

    builder.setView(view);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override//w  w  w. j a  v a2 s.  co m
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.show();
}

From source file:com.duy.pascal.ui.file.FileExplorerAction.java

public void showDialogCreateFile(@Nullable final FileActionListener callback) {
    if (mDialog != null && mDialog.isShowing()) {
        mDialog.dismiss();/*from w ww . j a  va2 s . co m*/
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    builder.setView(R.layout.dialog_new_file);

    mDialog = builder.create();
    mDialog.show();

    final EditText editText = mDialog.findViewById(R.id.edit_input);
    View btnOK = mDialog.findViewById(R.id.btn_ok);
    View btnCancel = mDialog.findViewById(R.id.btn_cancel);

    btnCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mDialog.cancel();
        }
    });
    btnOK.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //get string path of in edit text
            String fileName = editText.getText().toString().trim();
            if (!FileManager.acceptPasFile(fileName)) {
                editText.setError(mContext.getString(R.string.invalid_file_name));
                return;
            }

            RadioButton isProgram = mDialog.findViewById(R.id.rad_program);
            RadioButton isUnit = mDialog.findViewById(R.id.rad_unit);
            RadioButton isInput = mDialog.findViewById(R.id.rad_inp);

            String template = "";
            if (isInput.isChecked()) {
                fileName += ".inp";
            } else if (isUnit.isChecked()) {
                template = CodeTemplate.createUnitTemplate(fileName);
                fileName += ".pas";
            } else if (isProgram.isChecked()) {
                template = CodeTemplate.createProgramTemplate(fileName);
                fileName += ".pas";
            }

            File file = new File(mExplorerContext.getCurrentDirectory(), fileName);
            FileManager fileManager = new FileManager(mContext);
            boolean result = fileManager.createNewFile(file.getPath()) != null;
            if (!result) {
                editText.setError(mContext.getString(R.string.can_not_create_file));
                return;
            } else {
                fileManager.saveFile(file, template);
            }
            if (callback != null) {
                callback.onFileSelected(new File(file.getPath()));
            }
            mView.refresh();
            destroyActionMode();
            mDialog.cancel();
        }
    });
}

From source file:com.farmerbb.notepad.fragment.dialog.AboutDialogFragment.java

@NonNull
@Override// w  w  w  . jav a2 s .c om
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    // Get the layout inflater
    final LayoutInflater inflater = getActivity().getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    final View view = inflater.inflate(R.layout.fragment_dialogs, null);

    builder.setView(view).setTitle(R.string.dialog_about_title).setPositiveButton(R.string.action_close, null);

    SignatureUtils.ReleaseType releaseType = SignatureUtils.getReleaseType(getActivity());
    if (!releaseType.equals(SignatureUtils.ReleaseType.UNKNOWN)) {
        builder.setNegativeButton(R.string.check_for_updates,
                (dialogInterface, i) -> checkForUpdates(releaseType));
    }

    textView = view.findViewById(R.id.dialogMessage);
    textView.setText(R.string.dialog_about_message);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

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

From source file:fi.mikuz.boarder.gui.internet.Login.java

private void showLoggedOutView() {
    setContentView(R.layout.internet_login_logged_out);

    mLogin = (Button) findViewById(R.id.submit);
    mUsername = (EditText) findViewById(R.id.userName);
    mPassword = (EditText) findViewById(R.id.userPassword);

    boolean usernameInDb = false;
    String dbPassword = null;//from   w ww . j  a va2s .  c o m

    try {
        Cursor loginCursor = mDbHelper.fetchLogin(InternetMenu.USERNAME_KEY);
        startManagingCursor(loginCursor);
        mUsername.setText(loginCursor.getString(loginCursor.getColumnIndexOrThrow(LoginDbAdapter.KEY_DATA)));
        usernameInDb = true;
    } catch (SQLException e) {
        Log.d(TAG, "Couldn't get database login info", e);
    } catch (CursorIndexOutOfBoundsException e) {
        Log.d(TAG, "Couldn't get database login info", e);
    }

    dbPassword = getDbPassword();

    final CheckBox rememberPassword = (CheckBox) findViewById(R.id.rememberPassword);

    if (dbPassword == null) {
        rememberPassword.setChecked(false);
    } else {
        rememberPassword.setChecked(true);
        mPassword.setText(dbPassword);
    }

    final CheckBox rememberUsername = (CheckBox) findViewById(R.id.rememberUsername);
    rememberUsername.setChecked(usernameInDb);

    mLogin.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mWaitDialog = new TimeoutProgressDialog(Login.this, "Waiting for response", TAG, false);

            String username = mUsername.getText().toString();
            String password = mPassword.getText().toString();
            Boolean entrancePassword = true;
            String dbPassword = getDbPassword();

            // Password in the Android database is always the same as in the server database
            // Being an entrance password means that the password is not the same as in the server database
            if (dbPassword != null) {
                if (dbPassword.equals(password)) {
                    entrancePassword = false;
                }
            }

            // If the password is now an entrance password then it's plain text and wants to be hashed
            if (entrancePassword) {
                try {
                    password = Security.passwordHash(password);
                } catch (NoSuchAlgorithmException e) {
                    String msg = "Couldn't make a password hash";
                    Toast.makeText(Login.this, msg, Toast.LENGTH_LONG).show();
                    Log.e(TAG, msg, e);
                }
            }

            if (rememberUsername.isChecked()) {
                mDbHelper.putLogin(InternetMenu.USERNAME_KEY, username);
            } else if (!rememberUsername.isChecked()) {
                mDbHelper.deleteLogin(InternetMenu.USERNAME_KEY);
            }

            if (rememberPassword.isChecked()) {
                if (!entrancePassword) {
                    mPasswordOperation = PASSWORD_OPERATION_NONE;
                    mDbHelper.putLogin(InternetMenu.PASSWORD_KEY, password);
                } else {
                    mPasswordOperation = PASSWORD_OPERATION_SAVE;
                }
            } else if (!rememberPassword.isChecked()) {
                mDbHelper.deleteLogin(InternetMenu.PASSWORD_KEY);
            }

            mDbHelper.deleteLogin(InternetMenu.USER_ID_KEY);
            mDbHelper.deleteLogin(InternetMenu.SESSION_TOKEN_KEY);
            CheckBox rememberSession = (CheckBox) findViewById(R.id.rememberSession);
            if (rememberSession.isChecked()) {
                mRememberSession = true;
            }

            HashMap<String, String> sendList = new HashMap<String, String>();
            sendList.put(InternetMenu.USERNAME_KEY, username);
            sendList.put(InternetMenu.PASSWORD_KEY, password);
            sendList.put(InternetMenu.ENTRANCE_PASSWORD_KEY, entrancePassword ? "1" : "0");
            new ConnectionManager(Login.this, InternetMenu.mLoginURL, sendList);
        }
    });

    Button recoverPassword = (Button) findViewById(R.id.recoverPassword);
    recoverPassword.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            LayoutInflater inflater = (LayoutInflater) Login.this.getSystemService(LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.internet_login_alert_recover_password,
                    (ViewGroup) findViewById(R.id.alert_settings_root));

            final EditText input = (EditText) layout.findViewById(R.id.input);
            Button submitButton = (Button) layout.findViewById(R.id.submitButton);

            AlertDialog.Builder builder = new AlertDialog.Builder(Login.this);
            builder.setView(layout);
            builder.setTitle("Password recovery");

            submitButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    mWaitDialog = new TimeoutProgressDialog(Login.this, "Waiting for response", TAG, false);
                    String inputText = input.getText().toString();

                    HashMap<String, String> sendList = new HashMap<String, String>();
                    sendList.put(InternetMenu.EMAIL_KEY, inputText);
                    new ConnectionManager(Login.this, InternetMenu.mRecoverPasswordURL, sendList);
                }
            });

            builder.show();
        }
    });

}