Example usage for android.app Dialog setContentView

List of usage examples for android.app Dialog setContentView

Introduction

In this page you can find the example usage for android.app Dialog setContentView.

Prototype

public void setContentView(@NonNull View view) 

Source Link

Document

Set the screen content to an explicit view.

Usage

From source file:com.trukr.shipper.fragment.RequestStatus.java

public void cancelAlertDialog(Context mContext, String Title, String Content, final int Status) {
    final Dialog dialog = new Dialog(mContext, R.style.Dialog);
    dialog.setCancelable(false);/*from ww w. j  a  v a2s  .  c o  m*/
    dialog.setContentView(R.layout.custom_alertdialog);

    // set the custom dialog components - title and content
    TextView alertHead = (TextView) dialog.findViewById(R.id.custom_alertdialog_tv_alerthead);
    alertHead.setText(Title);
    TextView alertContent = (TextView) dialog.findViewById(R.id.custom_alertdialog_tv_alertcontent);
    alertContent.setText(Content);

    View line = (View) dialog.findViewById(R.id.centerLineDialog);
    Button btnDialogCancel = (Button) dialog.findViewById(R.id.custom_alertdialog_btn_cancel);
    line.setVisibility(View.GONE);
    btnDialogCancel.setVisibility(View.GONE);
    Button btnDialogOk = (Button) dialog.findViewById(R.id.custom_alertdialog_btn_ok);
    btnDialogOk.setBackgroundResource(R.drawable.dialogbtnbackground);

    // if button is clicked, close the custom dialog
    btnDialogOk.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (Status == 100) {
                dialog.dismiss();
            } else
                dialog.dismiss();
        }
    });
    dialog.show();
}

From source file:edu.berkeley.boinc.PrefsFragment.java

private void setupSliderDialog(PrefsListItemWrapper item, final Dialog dialog) {
    final PrefsListItemWrapperValue valueWrapper = (PrefsListItemWrapperValue) item;
    dialog.setContentView(R.layout.prefs_layout_dialog_pct);
    TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
    SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar);

    if (valueWrapper.ID == R.string.battery_charge_min_pct_header
            || valueWrapper.ID == R.string.prefs_disk_max_pct_header
            || valueWrapper.ID == R.string.prefs_cpu_time_max_header
            || valueWrapper.ID == R.string.prefs_cpu_other_load_suspension_header
            || valueWrapper.ID == R.string.prefs_memory_max_idle_header) {
        Double seekBarDefault = valueWrapper.status / 10;
        slider.setProgress(seekBarDefault.intValue());
        final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener;
        slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                final String progressString = NumberFormat.getPercentInstance().format(progress / 10.0);
                TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
                sliderProgress.setText(progressString);
            }//w  ww  . j a  v  a  2 s. co  m

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        onSeekBarChangeListener.onProgressChanged(slider, seekBarDefault.intValue(), false);
    } else if (valueWrapper.ID == R.string.prefs_cpu_number_cpus_header) {
        if (!getHostInfo()) {
            if (Logging.WARNING)
                Log.w(Logging.TAG, "onItemClick missing hostInfo");
            return;
        }
        slider.setMax(hostinfo.p_ncpus <= 1 ? 0 : hostinfo.p_ncpus - 1);
        final int statusValue;
        slider.setProgress((statusValue = valueWrapper.status.intValue()) <= 0 ? 0
                : statusValue - 1 > slider.getMax() ? slider.getMax() : statusValue - 1);
        Log.d(Logging.TAG, String.format("statusValue == %,d", statusValue));
        final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener;
        slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                final String progressString = NumberFormat.getIntegerInstance()
                        .format(progress <= 0 ? 1 : progress + 1); // do not allow 0 cpus
                TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
                sliderProgress.setText(progressString);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        onSeekBarChangeListener.onProgressChanged(slider, statusValue - 1, false);
    } else if (valueWrapper.ID == R.string.prefs_gui_log_level_header) {
        slider.setMax(5);
        slider.setProgress(valueWrapper.status.intValue());
        final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener;
        slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                String progressString = NumberFormat.getIntegerInstance().format(progress);
                TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
                sliderProgress.setText(progressString);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        onSeekBarChangeListener.onProgressChanged(slider, valueWrapper.status.intValue(), false);
    }

    setupDialogButtons(item, dialog);
}

From source file:com.trukr.shipper.fragment.RequestStatus.java

public void cancelalertdialog(Context mContext, String Title, String Content, final int Status) {
    final Dialog dialog = new Dialog(mContext, R.style.Dialog);
    dialog.setCancelable(false);/*from w ww.  j a  v a 2s .c o m*/
    dialog.setContentView(R.layout.custom_alertdialog);

    // set the custom dialog components - title and content
    TextView alertHead = (TextView) dialog.findViewById(R.id.custom_alertdialog_tv_alerthead);
    alertHead.setText(Title);
    TextView alertContent = (TextView) dialog.findViewById(R.id.custom_alertdialog_tv_alertcontent);
    alertContent.setText(Content);

    View line = (View) dialog.findViewById(R.id.centerLineDialog);
    Button btnDialogCancel = (Button) dialog.findViewById(R.id.custom_alertdialog_btn_cancel);
    /* line.setVisibility(View.GONE);
    btnDialogCancel.setVisibility(View.GONE);*/
    Button btnDialogOk = (Button) dialog.findViewById(R.id.custom_alertdialog_btn_ok);
    /* btnDialogOk.setBackgroundResource(R.drawable.dialogbtnbackground);*/

    // if button is clicked, close the custom dialog
    btnDialogOk.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            cancelJob();
        }
    });
    btnDialogCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.dismiss();
        }
    });
    dialog.show();
}

From source file:org.smilec.smile.ui.GeneralActivity.java

@SuppressWarnings("deprecation")
@Override/*w w  w  . j  a  va 2s.c  o  m*/
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.bt_restart:
        AlertDialog.Builder builderRestart = new AlertDialog.Builder(this);
        builderRestart.setMessage(R.string.restart_game).setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                        try {
                            //new SmilePlugServerManager().connect(ip, GeneralActivity.this);
                            new SmilePlugServerManager().resetGame(ip, GeneralActivity.this);
                            // QuestionsManager.resetListOfDeletedQuestions(GeneralActivity.this);
                            GeneralActivity.this.finish();
                        } catch (NetworkErrorException e) {
                            ActivityUtil.showLongToast(GeneralActivity.this,
                                    R.string.toast_down_or_unavailable);
                            Log.e(Constants.LOG_CATEGORY, "Error: ", e);
                        }
                    }

                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertRestart = builderRestart.create();
        alertRestart.show();
        break;
    case R.id.bt_retake:
        AlertDialog.Builder builderRetake = new AlertDialog.Builder(this);
        builderRetake.setMessage(R.string.retake_game).setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        try {
                            new SmilePlugServerManager().startRetakeQuestions(ip, GeneralActivity.this, board);
                            ActivityUtil.showLongToast(GeneralActivity.this, R.string.toast_retaking);

                            Intent intent = new Intent(GeneralActivity.this,
                                    org.smilec.smile.ui.UsePreparedQuestionsActivity.class);
                            intent.putExtra(GeneralActivity.PARAM_IP, ip);
                            status = CurrentMessageStatus.RE_TAKE.name();
                            intent.putExtra(GeneralActivity.PARAM_STATUS, status);
                            startActivity(intent);

                        } catch (NetworkErrorException e) {
                            Log.e(Constants.LOG_CATEGORY, "Error: ", e);
                        }
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertRetake = builderRetake.create();
        alertRetake.show();
        break;
    case R.id.bt_about:
        Dialog aboutDialog = new Dialog(this, R.style.Dialog);
        aboutDialog.setContentView(R.layout.about);
        Display displaySize = ActivityUtil.getDisplaySize(getApplicationContext());
        aboutDialog.getWindow().setLayout(displaySize.getWidth(), displaySize.getHeight());
        aboutDialog.show();
        break;
    case R.id.bt_exit:
        AlertDialog.Builder builderExit = new AlertDialog.Builder(this);
        builderExit.setMessage(R.string.exit).setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        Intent intent = new Intent(Intent.ACTION_MAIN);
                        intent.addCategory(Intent.CATEGORY_HOME);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);

                        try {
                            new SmilePlugServerManager().resetGame(ip, GeneralActivity.this);
                        } catch (NetworkErrorException e) {
                            Log.e(Constants.LOG_CATEGORY, "Error: ", e);
                        }

                        // QuestionsManager.resetListOfDeletedQuestions(GeneralActivity.this);
                        GeneralActivity.this.finish();
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertExit = builderExit.create();
        alertExit.show();
        break;
    }
    return true;
}

From source file:com.ijsbrandslob.appirater.Appirater.java

private Dialog buildRatingDialog() {
    final Dialog rateDialog = new Dialog(mContext);
    final Resources res = mContext.getResources();

    CharSequence appname = "unknown";
    try {/*from  w ww .  ja  v  a  2  s .co  m*/
        appname = mContext.getPackageManager().getApplicationLabel(
                mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), 0));
    } catch (NameNotFoundException ex) { /* Do nothing */
    }

    rateDialog.setTitle(String.format(res.getString(R.string.APPIRATER_MESSAGE_TITLE), appname));
    rateDialog.setContentView(R.layout.appirater);

    TextView messageArea = (TextView) rateDialog.findViewById(R.id.appirater_message_area);
    messageArea.setText(String.format(res.getString(R.string.APPIRATER_MESSAGE), appname));

    Button rateButton = (Button) rateDialog.findViewById(R.id.appirater_rate_button);
    Button remindLaterButton = (Button) rateDialog.findViewById(R.id.appirater_rate_later_button);
    Button cancelButton = (Button) rateDialog.findViewById(R.id.appirater_cancel_button);

    rateButton.setText(String.format(res.getString(R.string.APPIRATER_RATE_BUTTON), appname));

    rateButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            rateDialog.dismiss();

            mRatedCurrentVersion = true;
            saveSettings();
            launchPlayStore();
        }
    });

    remindLaterButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mReminderRequestDate = new Date();
            saveSettings();
            rateDialog.dismiss();
        }
    });

    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mDeclinedToRate = true;
            saveSettings();
            rateDialog.dismiss();
        }
    });
    return rateDialog;
}

From source file:com.eurotong.orderhelperandroid.OrderMenuActivity.java

@Override
public void onClick(View v) {
    if (v.getId() == R.id.btnGoHome) {
        GotoTableOrderView();/*w  w w.  j a  v  a 2 s  .c  o  m*/
        //finish();
    }
    if (v.getId() == R.id.btnPrint) {
        // custom dialog
        final Dialog dialog = new Dialog(context);

        dialog.setContentView(R.layout.print_command_selection);
        dialog.setTitle(R.string.msg_please_select_operation);

        // set the custom dialog components - text, image and button
        Button btnPrintBill = (Button) dialog.findViewById(R.id.btnPrintBill);
        Button btnPrintKitchen = (Button) dialog.findViewById(R.id.btnPrintKitchen);
        Button btnExit = (Button) dialog.findViewById(R.id.btnExit);
        Button btnPrintBar = (Button) dialog.findViewById(com.eurotong.orderhelperandroid.R.id.btnPrintBar);
        Button btnPrintPreview = (Button) dialog
                .findViewById(com.eurotong.orderhelperandroid.R.id.btnPrintPreview);
        if (!User.Current().HasRight(Define.UR_DEBUG_PRINT_LAYOUT)) {
            btnPrintPreview.setVisibility(View.GONE);
        }
        // if button is clicked, close the custom dialog
        btnPrintBill.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (User.Current().HasRight(Define.UR_PRINT)) {
                    DoPrintPos(_table, PrintLayout.Current(), Setting.Current().NumberOfPrints);
                    dialog.dismiss();
                }
            }
        });

        btnPrintKitchen.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (User.Current().HasRight(Define.UR_PRINT_KITCHEN)) {
                    DoPrintPos(_table, PrintLayout.KitchenLayout(), Setting.Current().NumberOfPrintsKitchen);
                    dialog.dismiss();
                }
            }
        });

        btnPrintBar.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (User.Current().HasRight(Define.UR_PRINT_BAR)) {
                    DoPrintPos(_table, PrintLayout.BarLayout(), Setting.Current().NumberOfPrintsBar);
                    dialog.dismiss();
                }
            }
        });
        btnPrintPreview.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(context, PrintPreview.class);
                i.putExtra(Define.TABLE_NR, _table.TableNr);
                startActivity(i);
                dialog.dismiss();
            }
        });
        btnExit.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }
    if (v.getId() == R.id.btnExtra) {
        // custom dialog
        final Dialog dialog = new Dialog(context);

        dialog.setContentView(R.layout.table_order_extra);
        dialog.setTitle(R.string.msg_please_select_operation);

        // set the custom dialog components - text, image and button
        Button btnViewTableDetail = (Button) dialog.findViewById(R.id.btnViewTableDetail);
        Button btnDeleteTable = (Button) dialog.findViewById(R.id.btnDeleteTable);
        Button btnExit = (Button) dialog.findViewById(com.eurotong.orderhelperandroid.R.id.btnExit);
        Button btnAddChildTable = (Button) dialog
                .findViewById(com.eurotong.orderhelperandroid.R.id.btnAddChildTable);

        // if button is clicked, close the custom dialog
        btnViewTableDetail.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(context, TableDetailActivity.class);
                i.putExtra(Define.TABLE_NR, _table.TableNr);
                startActivity(i);
                dialog.dismiss();
            }
        });

        btnAddChildTable.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Table table;
                if (_table.ParentTable != null) {
                    table = _table.ParentTable.CreateChildTable();
                } else {
                    table = _table.CreateChildTable();
                }
                TableHelper.TableList().add(table);
                TableHelper.SaveTablesToStorage();
                _table = table;
                InitVMMenuGroup();
                ShowCurrentOrders();
                dialog.dismiss();
            }
        });

        btnDeleteTable.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Builder confirmDeleteTableDialog = new AlertDialog.Builder(context);
                confirmDeleteTableDialog.setTitle(R.string.msg_are_you_sure_to_delete_this_order);
                confirmDeleteTableDialog.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        TableHelper.DeleteTableByNumber(_table.TableNr);
                        TableHelper.SaveTablesToStorage();
                        dialog.dismiss();
                        finish();
                        //MyApplication.GoToHome();
                        //finish();
                        //Intent i = new Intent(context, TablesOverviewActivity.class);                        
                        //startActivity(i);
                        //dialog.dismiss();
                    }
                });
                confirmDeleteTableDialog.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //
                    }
                });
                confirmDeleteTableDialog.show();
                dialog.dismiss();
            }
        });
        btnExit.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }
    //else if(v.getId()==R.id.btnSave)
    ///{
    //   SaveTableOrders();
    //   GotoTableOrderView();
    //finish(); //finish means close. want to refresh tableorder when close this view. so instead use gototableorderview()
    //}   
    //else if(v.getId()==R.id.btnAllMenu)
    //{
    //   BindingMenuList();
    //}
    else if (v.getId() == R.id.btnMenuGroup) {
        MakeMenuGroupButtons();
    }
    //else if(v.getId()==R.id.btnMenuBar)
    //{
    //   BingMenuBarList();
    //}
    if (v.getId() == R.id.btnCurrentOrders) {
        ShowCurrentOrders();
        //finish();
    } else if (v.getId() == R.id.btnCloseKeyboard) {
        //close soft keyboard
        //http://www.workingfromhere.com/blog/2011/04/27/close-hide-the-android-soft-keyboard/
        InputMethodManager imm = (InputMethodManager) getSystemService(
                MyApplication.getAppContext().INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(editTextInput.getWindowToken(), 0);
        View filling = menusContainer.findViewById(R.id.hint_fill);
        if (filling != null) {
            filling.setVisibility(View.GONE);
        }
        SetEditTextInputText("");
        ShowCurrentOrders();
    }
}

From source file:com.google.ytd.SubmitActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    final Dialog dialog = new Dialog(SubmitActivity.this);
    dialog.setTitle("Terms of Service");
    switch (id) {
    case DIALOG_LEGAL:
        dialog.setContentView(R.layout.legal);

        TextView legalText = (TextView) dialog.findViewById(R.id.legal);

        legalText.setText(Util.readFile(this, R.raw.legal).toString());

        dialog.findViewById(R.id.agree).setOnClickListener(new OnClickListener() {
            @Override//  w  w w .  j a  va 2 s .  co  m
            public void onClick(View v) {
                dialog.cancel();
                getAuthTokenWithPermission(youTubeName);
            }
        });
        dialog.findViewById(R.id.notagree).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.cancel();
            }
        });

        break;
    }

    return dialog;
}

From source file:nf.frex.android.FrexActivity.java

private Dialog createDecorationsDialog() {
    Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.decorations_dialog);
    dialog.setTitle(R.string.decorations);
    return dialog;
}

From source file:nf.frex.android.FrexActivity.java

private Dialog createPropertiesDialog() {
    Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.properties_dialog);
    dialog.setTitle(getString(R.string.properties));
    return dialog;
}

From source file:org.computeforcancer.android.PrefsFragment.java

private void setupSelectionListDialog(final PrefsListItemWrapper item, final Dialog dialog)
        throws RemoteException {
    dialog.setContentView(R.layout.prefs_layout_dialog_selection);

    if (item.ID == R.string.prefs_client_log_flags_header) {
        final ArrayList<SelectionDialogOption> options = new ArrayList<SelectionDialogOption>();
        String[] array = getResources().getStringArray(R.array.prefs_client_log_flags);
        for (String option : array)
            options.add(new SelectionDialogOption(option));
        ListView lv = (ListView) dialog.findViewById(R.id.selection);
        new PrefsSelectionDialogListAdapter(getActivity(), lv, R.id.selection, options);

        // setup confirm button action
        Button confirm = (Button) dialog.findViewById(R.id.confirm);
        confirm.setOnClickListener(new OnClickListener() {
            @Override/*from w  ww  . j a va2s . co m*/
            public void onClick(View v) {
                ArrayList<String> selectedOptions = new ArrayList<String>();
                for (SelectionDialogOption option : options)
                    if (option.selected)
                        selectedOptions.add(option.name);
                if (Logging.DEBUG)
                    Log.d(Logging.TAG, selectedOptions.size() + " log flags selected");
                new SetCcConfigAsync().execute(formatOptionsToCcConfig(selectedOptions));
                dialog.dismiss();
            }
        });
    } else if (item.ID == R.string.prefs_power_source_header) {
        final ArrayList<SelectionDialogOption> options = new ArrayList<SelectionDialogOption>();
        options.add(new SelectionDialogOption(getResources().getString(R.string.prefs_power_source_ac),
                BOINCActivity.monitor.getPowerSourceAc()));
        options.add(new SelectionDialogOption(getResources().getString(R.string.prefs_power_source_usb),
                BOINCActivity.monitor.getPowerSourceUsb()));
        options.add(new SelectionDialogOption(getResources().getString(R.string.prefs_power_source_wireless),
                BOINCActivity.monitor.getPowerSourceWireless()));
        options.add(new SelectionDialogOption(getResources().getString(R.string.prefs_power_source_battery),
                clientPrefs.run_on_batteries, true));
        ListView lv = (ListView) dialog.findViewById(R.id.selection);
        new PrefsSelectionDialogListAdapter(getActivity(), lv, R.id.selection, options);

        // setup confirm button action
        Button confirm = (Button) dialog.findViewById(R.id.confirm);
        confirm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    for (SelectionDialogOption option : options) {
                        if (option.name == getResources().getString(R.string.prefs_power_source_ac))
                            BOINCActivity.monitor.setPowerSourceAc(option.selected);
                        if (option.name == getResources().getString(R.string.prefs_power_source_usb))
                            BOINCActivity.monitor.setPowerSourceUsb(option.selected);
                        if (option.name == getResources().getString(R.string.prefs_power_source_wireless))
                            BOINCActivity.monitor.setPowerSourceWireless(option.selected);
                        if (option.name == getResources().getString(R.string.prefs_power_source_battery)) {
                            clientPrefs.run_on_batteries = option.selected;
                            new WriteClientPrefsAsync().execute(clientPrefs); //async task triggers layout update
                        }
                    }
                    dialog.dismiss();
                } catch (RemoteException e) {
                }
            }
        });
    }

    // generic cancel button
    Button cancel = (Button) dialog.findViewById(R.id.cancel);
    cancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
}