Example usage for android.app Dialog Dialog

List of usage examples for android.app Dialog Dialog

Introduction

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

Prototype

public Dialog(@NonNull Context context) 

Source Link

Document

Creates a dialog window that uses the default dialog theme.

Usage

From source file:com.iiordanov.bVNC.RemoteCanvasActivity.java

private void selectColorModel() {

    String[] choices = new String[COLORMODEL.values().length];
    int currentSelection = -1;
    for (int i = 0; i < choices.length; i++) {
        COLORMODEL cm = COLORMODEL.values()[i];
        choices[i] = cm.toString();/*from   w  w  w  .  j  a v  a  2 s  .  c  om*/
        if (canvas.isColorModel(cm))
            currentSelection = i;
    }

    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    ListView list = new ListView(this);
    list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, choices));
    list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    list.setItemChecked(currentSelection, true);
    list.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            dialog.dismiss();
            COLORMODEL cm = COLORMODEL.values()[arg2];
            canvas.setColorModel(cm);
            connection.setColorModel(cm.nameString());
            connection.save(database.getWritableDatabase());
            database.close();
            Toast.makeText(RemoteCanvasActivity.this,
                    getString(R.string.info_update_color_model_to) + cm.toString(), Toast.LENGTH_SHORT).show();
        }
    });
    dialog.setContentView(list);
    dialog.show();
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

private void optionLegend() {
    // Show help//  ww w.j a  va  2  s  .  com
    Dialog dialog = new Dialog(ActivityMain.this);
    dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
    dialog.setTitle(R.string.menu_legend);
    dialog.setContentView(R.layout.legend);
    dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, getThemed(R.attr.icon_launcher));

    ((ImageView) dialog.findViewById(R.id.imgHelpHalf)).setImageBitmap(getHalfCheckBox());
    ((ImageView) dialog.findViewById(R.id.imgHelpOnDemand)).setImageBitmap(getOnDemandCheckBox());

    for (View child : Util.getViewsByTag((ViewGroup) dialog.findViewById(android.R.id.content), "details"))
        child.setVisibility(View.GONE);

    ((LinearLayout) dialog.findViewById(R.id.llUnsafe))
            .setVisibility(PrivacyManager.cVersion3 ? View.VISIBLE : View.GONE);

    dialog.setCancelable(true);
    dialog.show();
}

From source file:com.example.search.car.pools.welcome.java

public void dialog(String name, final String[] arr, final TextView tv) {

    final Dialog dialog = new Dialog(welcome.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    dialog.setContentView(R.layout.dialog);
    final ListView list = (ListView) dialog.findViewById(R.id.list_cities);
    DialogAdapter adapter = new DialogAdapter(welcome.this, arr);
    list.setAdapter(adapter);//from  ww w . j  a  v a2s  .  c om
    final TextView t = (TextView) dialog.findViewById(R.id.tv_1_send_msg);
    t.setText("Select " + name);
    Typeface tf = Typeface.createFromAsset(welcome.this.getAssets(), "AvenirLTStd_Book.otf");
    t.setTypeface(tf);
    list.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            tv.setText(arr[position]);
            dialog.dismiss();
        }
    });
    final RelativeLayout l_close = (RelativeLayout) dialog.findViewById(R.id.l_close);
    l_close.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            dialog.dismiss();
        }
    });
    dialog.show();
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

private void optionTutorial() {
    ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE);
    ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE);
    int userId = Util.getUserId(Process.myUid());
    PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialMain, Boolean.FALSE.toString());

    Dialog dlgUsage = new Dialog(this);
    dlgUsage.requestWindowFeature(Window.FEATURE_LEFT_ICON);
    dlgUsage.setTitle(R.string.title_usage_header);
    dlgUsage.setContentView(R.layout.usage);
    dlgUsage.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, getThemed(R.attr.icon_launcher));
    dlgUsage.setCancelable(true);//from   w  ww  .j  a va 2  s .  c  om
    dlgUsage.show();
}

From source file:com.zen.androidhtmleditor.AHEActivity.java

public void uploadFile() {

    ndialog = new Dialog(AHEActivity.this);
    ndialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    ndialog.setContentView(R.layout.uploadfilediag);
    ndialog.setCancelable(true);//from www . j  a  v a 2  s  .  com

    Button lb = (Button) ndialog.findViewById(R.id.localBackButton);

    lstLocal = (ListView) ndialog.findViewById(R.id.list);
    // lstTest.setDividerHeight(10);
    lstLocal.setPadding(0, 5, 0, 5);

    File sdCardRoot = Environment.getExternalStorageDirectory();
    File yourDir = new File(sdCardRoot, localPath);
    localalrts = new ArrayList<String[]>();

    for (File f : yourDir.listFiles()) {
        if (f.isDirectory()) {
            String values[] = { f.getName(), "folder" };
            localalrts.add(values);
            //Log.i("localDirectory",f.getName());
        }

    }

    for (File f : yourDir.listFiles()) {
        if (f.isFile()) {
            //Log.i("localFile",f.getName());
            String values[] = { f.getName(), "file" };
            localalrts.add(values);
        }

    }

    //localPath = localPath+"/"+fn+"/";
    lb.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String[] localPathBits = localPath.split("/");
            localPath = "";
            for (int i = 0; i < localPathBits.length - 1; i++) {
                localPath += localPathBits[i] + "/";
            }
            TextView lp = (TextView) ndialog.findViewById(R.id.localPath);
            lp.setText(localPath);
            uploadFileList();
        }
    });

    arrayLocalAdapter = new FetchAdapter(AHEActivity.this, R.layout.listitems, localalrts);
    lstLocal.setAdapter(arrayLocalAdapter);

    lstLocal.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
            TextView type = (TextView) v.findViewById(R.id.typeId);
            String t = type.getText().toString();

            TextView fileFolder = (TextView) v.findViewById(R.id.fileFolderName);
            String fn = fileFolder.getText().toString();

            if (t.equals("folder")) {

                localPath = localPath + fn + "/";
                TextView lp = (TextView) ndialog.findViewById(R.id.localPath);
                lp.setText(localPath);
                Button lb = (Button) ndialog.findViewById(R.id.localBackButton);

                if (localPath.equals("/")) {
                    lb.setVisibility(View.GONE);
                } else {
                    lb.setVisibility(View.VISIBLE);

                }
                uploadFileList();
            }
            if (t.equals("file")) {

                SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
                String currentServers = settings.getString("Accounts", "");
                int connectedTo = settings.getInt("connectedTo", -1);

                if (connectedTo != -1) {
                    if (currentServers.equals("")) {
                    } else {
                        Gson gson = new Gson();
                        SearchResponse response = gson.fromJson(currentServers, SearchResponse.class);
                        List<Result> results = response.data;
                        Result s = results.get(connectedTo);
                        if (s.serverName != "" && s.userName != "") {
                            String local = localPath + fn;
                            String remote = folderPath + fn;
                            new LocalUploadTask(s.serverName, s.userName, s.passWord, local, remote, s.sftp,
                                    s.port, 0).execute();
                            ndialog.dismiss();

                        }
                    }
                }

            }
            //loadFileFolder(v);

        }
    });

    ndialog.show();

}

From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java

public void logonToRemoteDlg(final String host, final String addr, final String port, final String user,
        final String pass, final NotifyEvent p_ntfy) {
    final ThreadCtrl tc = new ThreadCtrl();
    tc.setEnabled();//from  w  ww  .java  2  s.c  o  m
    tc.setThreadResultSuccess();

    // ??
    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.progress_spin_dlg);

    LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.progress_spin_dlg_view);
    ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color);

    final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.progress_spin_dlg_title_view);
    final TextView title = (TextView) dialog.findViewById(R.id.progress_spin_dlg_title);
    title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
    title.setTextColor(mGp.themeColorList.text_color_dialog_title);
    title.setText(R.string.msgs_progress_spin_dlg_test_logon);

    final Button btn_cancel = (Button) dialog.findViewById(R.id.progress_spin_dlg_btn_cancel);
    btn_cancel.setText(R.string.msgs_progress_spin_dlg_test_logon_cancel);

    //      (dialog.context.findViewById(R.id.progress_spin_dlg)).setVisibility(TextView.GONE);
    //      (dialog.context.findViewById(R.id.progress_spin_dlg)).setEnabled(false);

    CommonDialog.setDlgBoxSizeCompact(dialog);
    // CANCEL?
    btn_cancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            tc.setDisabled();//disableAsyncTask();
            btn_cancel.setText(mContext.getString(R.string.msgs_progress_dlg_canceling));
            btn_cancel.setEnabled(false);
            util.addDebugMsg(1, "W", "Logon is cancelled.");
        }
    });
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btn_cancel.performClick();
        }
    });
    //      dialog.setOnKeyListener(new DialogOnKeyListener(context));
    //      dialog.setCancelable(false);
    //      dialog.show(); showDelayedProgDlg?

    Thread th = new Thread() {
        @Override
        public void run() {
            util.addDebugMsg(1, "I", "Test logon started, host=" + host + ", addr=" + addr + ", port=" + port
                    + ", user=" + user);
            NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, user, pass);

            NotifyEvent ntfy = new NotifyEvent(mContext);
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context c, Object[] o) {
                    dialog.dismiss();
                    String err_msg = (String) o[0];
                    if (tc.isEnabled()) {
                        if (err_msg != null) {
                            commonDlg.showCommonDialog(false, "E",
                                    mContext.getString(R.string.msgs_remote_profile_dlg_logon_error), err_msg,
                                    null);
                            if (p_ntfy != null)
                                p_ntfy.notifyToListener(false, null);
                        } else {
                            commonDlg.showCommonDialog(false, "I", "",
                                    mContext.getString(R.string.msgs_remote_profile_dlg_logon_success), null);
                            if (p_ntfy != null)
                                p_ntfy.notifyToListener(true, null);
                        }
                    } else {
                        commonDlg.showCommonDialog(false, "I", "",
                                mContext.getString(R.string.msgs_remote_profile_dlg_logon_cancel), null);
                        if (p_ntfy != null)
                            p_ntfy.notifyToListener(true, null);
                    }
                }

                @Override
                public void negativeResponse(Context c, Object[] o) {
                }
            });

            if (host.equals("")) {
                boolean reachable = false;
                if (port.equals("")) {
                    if (NetworkUtil.isIpAddressAndPortConnected(addr, 139, 3500)
                            || NetworkUtil.isIpAddressAndPortConnected(addr, 445, 3500)) {
                        reachable = true;
                    }
                } else {
                    reachable = NetworkUtil.isIpAddressAndPortConnected(addr, Integer.parseInt(port), 3500);
                }
                if (reachable) {
                    testAuth(auth, addr, port, ntfy);
                } else {
                    util.addDebugMsg(1, "I", "Test logon failed, remote server not connected");
                    String unreachble_msg = "";
                    if (port.equals("")) {
                        unreachble_msg = String
                                .format(mContext.getString(R.string.msgs_mirror_smb_addr_not_connected), addr);
                    } else {
                        unreachble_msg = String.format(
                                mContext.getString(R.string.msgs_mirror_smb_addr_not_connected_with_port), addr,
                                port);
                    }
                    ntfy.notifyToListener(true, new Object[] { unreachble_msg });
                }
            } else {
                if (NetworkUtil.getSmbHostIpAddressFromName(host) != null)
                    testAuth(auth, host, port, ntfy);
                else {
                    util.addDebugMsg(1, "I", "Test logon failed, remote server not connected");
                    String unreachble_msg = "";
                    unreachble_msg = mContext.getString(R.string.msgs_mirror_smb_name_not_found) + host;
                    ntfy.notifyToListener(true, new Object[] { unreachble_msg });
                }
            }
        }
    };
    th.start();
    dialog.show();
}

From source file:com.sentaroh.android.Utilities.Dialog.FileSelectDialogFragment.java

private void fileSelectEditDialogCreateBtn(final Activity activity, final Context context, final String c_dir,
        final String n_dir, final String mp, final TreeFilelistAdapter tfa, final NotifyEvent p_ntfy,
        final ListView lv) {
    // ??/*ww w.j a  v a 2  s  .co m*/
    mCreateDirDialog = new Dialog(activity);
    mCreateDirDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mCreateDirDialog.setContentView(R.layout.single_item_input_dlg);
    final TextView dlg_title = (TextView) mCreateDirDialog.findViewById(R.id.single_item_input_title);
    dlg_title.setText(context.getString(R.string.msgs_file_select_edit_dlg_create));
    final TextView dlg_msg = (TextView) mCreateDirDialog.findViewById(R.id.single_item_input_msg);
    final TextView dlg_cmp = (TextView) mCreateDirDialog.findViewById(R.id.single_item_input_name);
    final Button btnOk = (Button) mCreateDirDialog.findViewById(R.id.single_item_input_ok_btn);
    final Button btnCancel = (Button) mCreateDirDialog.findViewById(R.id.single_item_input_cancel_btn);
    final EditText etDir = (EditText) mCreateDirDialog.findViewById(R.id.single_item_input_dir);

    dlg_cmp.setText(context.getString(R.string.msgs_file_select_edit_parent_directory) + ":" + c_dir);
    CommonDialog.setDlgBoxSizeCompact(mCreateDirDialog);
    etDir.setText(n_dir.replaceAll(c_dir, ""));
    btnOk.setEnabled(false);
    etDir.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) {
            if (s.length() > 0) {
                File lf = new File(c_dir + "/" + s.toString());
                //               Log.v("","fp="+lf.getPath());
                if (lf.exists()) {
                    btnOk.setEnabled(false);
                    dlg_msg.setText(context.getString(R.string.msgs_single_item_input_dlg_duplicate_dir));
                } else {
                    btnOk.setEnabled(true);
                    dlg_msg.setText("");
                }
            }
        }

    });

    //OK button
    btnOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //            NotifyEvent 
            final String creat_dir = etDir.getText().toString();
            final String n_path = c_dir + "/" + creat_dir;
            NotifyEvent ntfy = new NotifyEvent(context);
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context c, Object[] o) {
                    File lf = new File(n_path);
                    boolean rc_create = false;
                    if (c_dir.startsWith(mSafFileMgr.getExternalSdcardPath())) {
                        SafFile sf = mSafFileMgr.getSafFileBySdcardPath(mSafFileMgr.getSdcardSafFile(), n_path,
                                true);
                        rc_create = sf.exists();
                    } else {
                        rc_create = lf.mkdirs();
                    }
                    if (!rc_create) {
                        dlg_msg.setText(String.format(
                                context.getString(R.string.msgs_file_select_edit_dlg_dir_not_created),
                                etDir.getText()));
                        return;
                    } else {
                        //                     String[] a_dir=creat_dir.startsWith("/")?creat_dir.substring(1).split("/"):creat_dir.split("/");
                        String t_path = n_path.replace(mp, "");
                        String[] a_dir = t_path.startsWith("/") ? t_path.substring(1).split("/")
                                : t_path.split("/");
                        String p_dir = "/", sep = "";
                        for (int i = 0; i < a_dir.length; i++) {
                            if (a_dir[i] != null && !a_dir[i].equals("")) {
                                //                           Log.v("","p_dir="+p_dir);
                                //                           updateTreeFileList(p_dir,a_dir[i],c_dir.replace(mp,"")+"/",tfa,lv);
                                updateTreeFileList(p_dir, a_dir[i], mp, tfa, lv);
                                p_dir += sep + a_dir[i];
                                sep = "/";
                            }
                        }
                        mCreateDirDialog.dismiss();
                        mCreateDirDialog = null;
                        p_ntfy.notifyToListener(true, new Object[] { etDir.getText().toString() });
                    }
                }

                @Override
                public void negativeResponse(Context c, Object[] o) {
                }
            });
            CommonDialog cd = new CommonDialog(context, getFragmentManager());
            cd.showCommonDialog(true, "W",
                    context.getString(R.string.msgs_file_select_edit_confirm_create_directory), n_path, ntfy);
        }
    });
    // CANCEL?
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mCreateDirDialog.dismiss();
            //            Log.v("","cancel create");
            mCreateDirDialog = null;
            p_ntfy.notifyToListener(false, null);
        }
    });
    mCreateDirDialog.show();
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@SuppressLint("DefaultLocale")
private void optionAbout() {
    // About//  ww  w  .j a  v a2 s  .  c o  m
    Dialog dlgAbout = new Dialog(this);
    dlgAbout.requestWindowFeature(Window.FEATURE_LEFT_ICON);
    dlgAbout.setTitle(R.string.menu_about);
    dlgAbout.setContentView(R.layout.about);
    dlgAbout.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, getThemed(R.attr.icon_launcher));

    // Show version
    try {
        int userId = Util.getUserId(Process.myUid());
        Version currentVersion = new Version(Util.getSelfVersionName(this));
        Version storedVersion = new Version(
                PrivacyManager.getSetting(userId, PrivacyManager.cSettingVersion, "0.0"));
        boolean migrated = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingMigrated, false);
        String versionName = currentVersion.toString();
        if (currentVersion.compareTo(storedVersion) != 0)
            versionName += "/" + storedVersion.toString();
        if (!migrated)
            versionName += "!";
        int versionCode = Util.getSelfVersionCode(this);
        TextView tvVersion = (TextView) dlgAbout.findViewById(R.id.tvVersion);
        tvVersion.setText(String.format(getString(R.string.app_version), versionName, versionCode));
    } catch (Throwable ex) {
        Util.bug(null, ex);
    }

    if (!PrivacyManager.cVersion3 || Hook.isAOSP(19))
        ((TextView) dlgAbout.findViewById(R.id.tvCompatibility)).setVisibility(View.GONE);

    // Show license
    String licensed = Util.hasProLicense(this);
    TextView tvLicensed1 = (TextView) dlgAbout.findViewById(R.id.tvLicensed);
    TextView tvLicensed2 = (TextView) dlgAbout.findViewById(R.id.tvLicensedAlt);
    if (licensed == null) {
        tvLicensed1.setText(Environment.getExternalStorageDirectory().getAbsolutePath());
        tvLicensed2.setText(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
                .getAbsolutePath());
    } else {
        tvLicensed1.setText(String.format(getString(R.string.app_licensed), licensed));
        tvLicensed2.setVisibility(View.GONE);
    }

    // Show some build properties
    String android = String.format("%s (%d)", Build.VERSION.RELEASE, Build.VERSION.SDK_INT);
    ((TextView) dlgAbout.findViewById(R.id.tvAndroid)).setText(android);
    ((TextView) dlgAbout.findViewById(R.id.build_brand)).setText(Build.BRAND);
    ((TextView) dlgAbout.findViewById(R.id.build_manufacturer)).setText(Build.MANUFACTURER);
    ((TextView) dlgAbout.findViewById(R.id.build_model)).setText(Build.MODEL);
    ((TextView) dlgAbout.findViewById(R.id.build_product)).setText(Build.PRODUCT);
    ((TextView) dlgAbout.findViewById(R.id.build_device)).setText(Build.DEVICE);
    ((TextView) dlgAbout.findViewById(R.id.build_host)).setText(Build.HOST);
    ((TextView) dlgAbout.findViewById(R.id.build_display)).setText(Build.DISPLAY);
    ((TextView) dlgAbout.findViewById(R.id.build_id)).setText(Build.ID);

    dlgAbout.setCancelable(true);

    final int userId = Util.getUserId(Process.myUid());
    if (PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFirstRun, true))
        dlgAbout.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                Dialog dlgUsage = new Dialog(ActivityMain.this);
                dlgUsage.requestWindowFeature(Window.FEATURE_LEFT_ICON);
                dlgUsage.setTitle(R.string.app_name);
                dlgUsage.setContentView(R.layout.usage);
                dlgUsage.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, getThemed(R.attr.icon_launcher));
                dlgUsage.setCancelable(true);
                dlgUsage.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        PrivacyManager.setSetting(userId, PrivacyManager.cSettingFirstRun,
                                Boolean.FALSE.toString());
                        optionLegend();
                    }
                });
                dlgUsage.show();
            }
        });

    dlgAbout.show();
}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Change the order of the favorite rows.
 * /*from   w w w. j a v  a  2  s.c o m*/
 * @param context
 */
public static void displayChangeRowOrder(final Launcher context) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.row_list);

    final ListView listView = (ListView) dialog.findViewById(R.id.rowList);
    ArrayList<RowInfo> persistedRows = RowsTable.getRows(context);
    final ArrayList<RowInfo> rows = new ArrayList<RowInfo>();
    // Add in reverse order to match favorite rows order
    for (RowInfo rowInfo : persistedRows) {
        rows.add(0, rowInfo);
    }
    final RowAdapter rowAdapter = new RowAdapter(context, rows);
    listView.setAdapter(rowAdapter);
    listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            RowInfo rowInfo = (RowInfo) parent.getAdapter().getItem(position);
            if (rowInfo.isSelected()) {
                rowInfo.setSelected(false);

                // Persist the new row order
                try {
                    int counter = 0;
                    for (int i = rowAdapter.getCount() - 1; i >= 0; i--) {
                        RowInfo currentRowInfo = (RowInfo) parent.getAdapter().getItem(i);
                        RowsTable.updateRow(context, currentRowInfo.getId(), currentRowInfo.getTitle(), counter,
                                currentRowInfo.getType());
                        counter++;
                    }
                } catch (Exception e) {
                    Log.e(LOG_TAG, "displayChangeRowOrder", e);
                }
                Analytics.logEvent(Analytics.CHANGE_ROW_ORDER);
            } else {
                rowInfo.setSelected(true);
            }
            rowAdapter.notifyDataSetChanged();
        }

    });
    listView.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // Swap the selected item in the list
            int selectedRowIndex = -1;
            for (int i = 0; i < rows.size(); i++) {
                RowInfo rowInfo = rows.get(i);
                if (rowInfo.isSelected()) {
                    selectedRowIndex = i;
                    break;
                }
            }
            if (selectedRowIndex != -1) {
                try {
                    Collections.swap(rows, position, selectedRowIndex);
                    rowAdapter.notifyDataSetChanged();
                } catch (Exception e) {
                    Log.e(LOG_TAG, "displayChangeRowOrder", e);
                }
            }
        }

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

    });
    listView.setDrawingCacheEnabled(true);
    listView.setOnKeyListener(onKeyListener);
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
            context.reloadAllGalleries();
        }

    });
    Button okButton = (Button) dialog.findViewById(R.id.okButton);
    okButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            context.showCover(false);
            dialog.dismiss();
            context.reloadAllGalleries();
        }

    });
    context.showCover(true);
    dialog.show();
    Analytics.logEvent(Analytics.DIALOG_CHANGE_ROW_ORDER);
}

From source file:com.updetector.MainActivity.java

/**
* Handle Performance Tuning Click// ww w. j ava2  s.  c o  m
*/
private void handleAdvancedSetting() {
    final Dialog dialog = new Dialog(this);
    dialog.setTitle(R.string.menu_item_advanced_settings);
    dialog.setContentView(R.layout.advanced_setting);

    final SharedPreferences mPrefs = getSharedPreferences(Constants.SHARED_PREFERENCES, Context.MODE_PRIVATE);
    final Editor editor = mPrefs.edit();

    final ToggleButton classifierForCIVOnButton = (ToggleButton) dialog.findViewById(R.id.civ_classifier_on);
    classifierForCIVOnButton.setChecked(mPrefs.getBoolean(Constants.PREFERENCE_KEY_CIV_CLASSIFIER_ON, false));

    final ToggleButton isOutdoorButton = (ToggleButton) dialog.findViewById(R.id.is_outdoor);
    isOutdoorButton.setChecked(mPrefs.getBoolean(Constants.PREFERENCE_KEY_IS_OUTDOOR, false));

    final EditText notificationTresholdText = (EditText) dialog.findViewById(R.id.notification_threshold);
    notificationTresholdText
            .setText(String.format("%.2f", mPrefs.getFloat(Constants.PREFERENCE_KEY_NOTIFICATION_THRESHOLD,
                    (float) Constants.DEFAULT_DETECTION_THRESHOLD)));

    //final EditText detectionIntervalText=(EditText)dialog.findViewById(R.id.detection_interval);
    //detectionIntervalText.setText(String.valueOf(mPrefs.getInt(Constants.PREFERENCE_KEY_DETECTION_INTERVAL, Constants.DETECTION_INTERVAL_DEFAULT_VALUE) ));

    final EditText googleActivityUpdateIntervalText = (EditText) dialog
            .findViewById(R.id.google_activity_update_interval);
    googleActivityUpdateIntervalText
            .setText(String.valueOf(mPrefs.getInt(Constants.PREFERENCE_KEY_GOOGLE_ACTIVITY_UPDATE_INTERVAL,
                    Constants.GOOGLE_ACTIVITY_UPDATE_INTERVAL_DEFAULT_VALUE)));

    //final ToggleButton useGoogleActivityInFusion=(ToggleButton)dialog.findViewById(R.id.use_google_for_motion_state_in_fusion);
    //useGoogleActivityInFusion.setChecked(mPrefs.getBoolean(Constants.PREFERENCE_KEY_USE_GOOGLE_ACTIVITY_IN_FUSION, false));

    final ToggleButton logAcclRawButton = (ToggleButton) dialog.findViewById(R.id.log_raw_switch);
    logAcclRawButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_ACCL_RAW_SWITCH, false));

    final ToggleButton logGoogleActUpdatesButton = (ToggleButton) dialog
            .findViewById(R.id.log_google_updates_switch);
    logGoogleActUpdatesButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_GOOGLE_ACTIVITY_UPDATE, false));

    final ToggleButton logDetectionButton = (ToggleButton) dialog.findViewById(R.id.log_report_switch);
    logDetectionButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_DETECTION_SWITCH, false));

    final ToggleButton logErrorButton = (ToggleButton) dialog.findViewById(R.id.log_error_switch);
    logErrorButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_ERROR_SWITCH, true));

    //final EditText deltaForConditionalProb=(EditText)dialog.findViewById(R.id.normal_dist_delta);
    //deltaForConditionalProb.setText(String.valueOf(mPrefs.getFloat(Constants.CIV_DELTA_CONDITIONAL_PROBABILITY, 2)) );      

    final Button applyButton = (Button) dialog.findViewById(R.id.performance_apply_button);
    final Button cancelButton = (Button) dialog.findViewById(R.id.peformance_cancel_button);
    applyButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (classifierForCIVOnButton.isChecked())
                editor.putBoolean(Constants.PREFERENCE_KEY_CIV_CLASSIFIER_ON, true);
            else
                editor.putBoolean(Constants.PREFERENCE_KEY_CIV_CLASSIFIER_ON, false);

            if (isOutdoorButton.isChecked())
                editor.putBoolean(Constants.PREFERENCE_KEY_IS_OUTDOOR, true);
            else
                editor.putBoolean(Constants.PREFERENCE_KEY_IS_OUTDOOR, false);

            if (logAcclRawButton.isChecked())
                editor.putBoolean(Constants.LOGGING_ACCL_RAW_SWITCH, true);
            else
                editor.putBoolean(Constants.LOGGING_ACCL_RAW_SWITCH, false);

            if (logGoogleActUpdatesButton.isChecked())
                editor.putBoolean(Constants.LOGGING_GOOGLE_ACTIVITY_UPDATE, true);
            else
                editor.putBoolean(Constants.LOGGING_GOOGLE_ACTIVITY_UPDATE, false);

            if (logDetectionButton.isChecked())
                editor.putBoolean(Constants.LOGGING_DETECTION_SWITCH, true);
            else
                editor.putBoolean(Constants.LOGGING_DETECTION_SWITCH, false);

            if (logErrorButton.isChecked())
                editor.putBoolean(Constants.LOGGING_ERROR_SWITCH, true);
            else
                editor.putBoolean(Constants.LOGGING_ERROR_SWITCH, false);

            float notificationTreshold;
            try {
                notificationTreshold = Float.parseFloat(notificationTresholdText.getText().toString());
            } catch (Exception ex) {
                notificationTreshold = (float) Constants.DEFAULT_DETECTION_THRESHOLD;
            }
            editor.putFloat(Constants.PREFERENCE_KEY_NOTIFICATION_THRESHOLD, notificationTreshold);

            /*int detectionInterval;
            try{
               detectionInterval=Integer.parseInt(
             detectionIntervalText.getText().toString());
            }catch(Exception ex){
               detectionInterval=Constants.DETECTION_INTERVAL_DEFAULT_VALUE;
            }
            editor.putInt(Constants.PREFERENCE_KEY_DETECTION_INTERVAL, detectionInterval);*/

            /*if (useGoogleActivityInFusion.isChecked())
               editor.putBoolean(Constants.PREFERENCE_KEY_USE_GOOGLE_ACTIVITY_IN_FUSION, true);
            else
               editor.putBoolean(Constants.PREFERENCE_KEY_USE_GOOGLE_ACTIVITY_IN_FUSION, false);*/

            int googleActivityUpdateInterval;
            try {
                googleActivityUpdateInterval = Integer
                        .parseInt(googleActivityUpdateIntervalText.getText().toString());
            } catch (Exception ex) {
                googleActivityUpdateInterval = Constants.GOOGLE_ACTIVITY_UPDATE_INTERVAL_DEFAULT_VALUE;
            }
            editor.putInt(Constants.PREFERENCE_KEY_GOOGLE_ACTIVITY_UPDATE_INTERVAL,
                    googleActivityUpdateInterval);

            /*try{
               Float delta=Float.parseFloat(deltaForConditionalProb.getText().toString());
               editor.putFloat(Constants.CIV_DELTA_CONDITIONAL_PROBABILITY, delta);
            }catch(Exception ex){
               Toast.makeText(getApplicationContext(), "Input must be a float number", Toast.LENGTH_SHORT).show();
            }*/

            editor.commit();
            dialog.cancel();
        }
    });

    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            dialog.cancel();
        }
    });
    dialog.show();
}