Example usage for android.app Dialog findViewById

List of usage examples for android.app Dialog findViewById

Introduction

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

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID or null if the ID is invalid (< 0), there is no matching view in the hierarchy, or the dialog has not yet been fully created (for example, via #show() or #create() ).

Usage

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void closeScanRemoteNetworkProgressDlg(final Dialog dialog, final NotifyEvent p_ntfy,
        final ListView lv_ipaddr, final AdapterScanAddressResultList adap, final TextView tvmsg) {
    final LinearLayout ll_addr = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_scan_address);
    final LinearLayout ll_prog = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_progress);
    final Button btn_scan = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_ok);
    final Button btn_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_cancel);
    ll_addr.setVisibility(LinearLayout.VISIBLE);
    ll_prog.setVisibility(LinearLayout.GONE);
    btn_scan.setEnabled(true);//from   w w w  .  ja v a 2  s . co m
    btn_cancel.setEnabled(true);
    adap.setButtonEnabled(true);
    dialog.setOnKeyListener(null);
    dialog.setCancelable(true);
    if (p_ntfy != null)
        p_ntfy.notifyToListener(true, null);

}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    switch (id) {
    case DIALOG_CREATE_SHORTCUT:
        break;/*from  www . j a  v  a  2 s  . c  o m*/
    case DIALOG_RENAME_FOLDER:
        if (mFolderInfo != null) {
            EditText input = (EditText) dialog.findViewById(R.id.folder_name);
            final CharSequence text = mFolderInfo.title;
            input.setText(text);
            input.setSelection(0, text.length());
        }
        break;
    }
}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void setRemoteShare(final String prof_user, final String prof_pass, final String prof_addr,
        final NotifyEvent p_ntfy) {
    final ArrayList<String> rows = new ArrayList<String>();

    NotifyEvent ntfy = new NotifyEvent(mContext);
    ntfy.setListener(new NotifyEventListener() {
        @Override/*from w  ww.  j  a  va2s.  c o m*/
        public void positiveResponse(Context c, Object[] o) {
            FileListAdapter tfl = (FileListAdapter) o[0];

            for (int i = 0; i < tfl.getCount(); i++) {
                FileListItem item = tfl.getItem(i);
                if (item.isDir() && item.canRead() && !item.getName().startsWith("IPC$")) {
                    String tmp = item.getName();
                    rows.add(tmp);
                }
            }
            if (rows.size() < 1)
                rows.add(getString(R.string.msgs_no_shared_resource));

            //??
            final Dialog dialog = new Dialog(c);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCanceledOnTouchOutside(false);
            dialog.setContentView(R.layout.item_select_list_dlg);
            ((TextView) dialog.findViewById(R.id.item_select_list_dlg_title)).setText("Select remote share");
            ((TextView) dialog.findViewById(R.id.item_select_list_dlg_subtitle)).setText("");

            CommonDialog.setDlgBoxSizeLimit(dialog, false);

            ListView lv = (ListView) dialog.findViewById(android.R.id.list);
            lv.setAdapter(new ArrayAdapter<String>(c, R.layout.simple_list_item_1m, rows));
            lv.setScrollingCacheEnabled(false);
            lv.setScrollbarFadingEnabled(false);

            lv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
                    if (rows.get(idx).startsWith("---"))
                        return;
                    dialog.dismiss();
                    // ????????
                    p_ntfy.notifyToListener(true, new Object[] { rows.get(idx).toString() });
                }
            });
            //CANCEL?
            final Button btnCancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn);
            btnCancel.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    dialog.dismiss();
                    p_ntfy.notifyToListener(true, new Object[] { "" });
                }
            });
            // Cancel?
            dialog.setOnCancelListener(new Dialog.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface arg0) {
                    btnCancel.performClick();
                }
            });
            //              dialog.setOnKeyListener(new DialogOnKeyListener(currentContext));
            //              dialog.setCancelable(false);
            dialog.show();
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
            p_ntfy.notifyToListener(false, new Object[] { "Remote file list creation error" });
        }
    });
    createRemoteFileList("smb://" + prof_addr + "/", ntfy);
    return;
}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void createItem(final FileListAdapter fla, final String item_optyp, final String base_dir) {
    sendDebugLogMsg(1, "I", "createItem entered.");

    // ??/* w  w w.j  a  v a  2 s. c  o m*/
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.file_rename_create_dlg);
    final EditText newName = (EditText) dialog.findViewById(R.id.file_rename_create_dlg_newname);
    final Button btnOk = (Button) dialog.findViewById(R.id.file_rename_create_dlg_ok_btn);
    final Button btnCancel = (Button) dialog.findViewById(R.id.file_rename_create_dlg_cancel_btn);

    CommonDialog.setDlgBoxSizeCompact(dialog);

    ((TextView) dialog.findViewById(R.id.file_rename_create_dlg_title)).setText("Create directory");
    ((TextView) dialog.findViewById(R.id.file_rename_create_dlg_subtitle)).setText("Enter new name");

    // newName.setText(item_name);

    btnOk.setEnabled(false);
    // btnCancel.setEnabled(false);
    newName.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            if (s.toString().length() < 1)
                btnOk.setEnabled(false);
            else
                btnOk.setEnabled(true);
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

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

    // OK?
    btnOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            if (!checkDuplicateDir(fla, newName.getText().toString())) {
                commonDlg.showCommonDialog(false, "E", "Create", "Duplicate directory name specified", null);
            } else {
                int cmd = 0;
                if (currentTabName.equals(SMBEXPLORER_TAB_LOCAL)) {
                    fileioLinkParm = buildFileioLinkParm(fileioLinkParm, base_dir, "",
                            newName.getText().toString(), "", smbUser, smbPass, true);
                    cmd = FILEIO_PARM_LOCAL_CREATE;
                } else {
                    cmd = FILEIO_PARM_REMOTE_CREATE;
                    fileioLinkParm = buildFileioLinkParm(fileioLinkParm, base_dir, "",
                            newName.getText().toString(), "", smbUser, smbPass, true);
                }
                sendDebugLogMsg(1, "I", "createItem FILEIO task invoked.");
                startFileioTask(fla, cmd, fileioLinkParm, newName.getText().toString(), null, null);
            }
        }
    });
    // CANCEL?
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            sendDebugLogMsg(1, "W", "createItem cancelled.");
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnCancel.performClick();
        }
    });
    //      dialog.setOnKeyListener(new DialogOnKeyListener(currentContext));
    //      setFixedOrientation(true);
    //      dialog.setCancelable(false);
    dialog.show();
}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void editRemoteProfile(String prof_act, String prof_name, String prof_user, String prof_pass,
        String prof_addr, final String prof_port, String prof_share, String msg_text, final int item_num) {

    // ??//from   w  w w . j  a  va2  s  .  co  m
    final Dialog dialog = new Dialog(this);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.edit_remote_profile);
    final TextView dlg_msg = (TextView) dialog.findViewById(R.id.remote_profile_dlg_msg);

    if (msg_text.length() != 0) {
        dlg_msg.setText(msg_text);
    }

    dialog.setTitle("Edit remote profile");

    CommonDialog.setDlgBoxSizeLimit(dialog, false);

    final EditText editname = (EditText) dialog.findViewById(R.id.remote_profile_name);
    editname.setText(prof_name);
    final EditText editaddr = (EditText) dialog.findViewById(R.id.remote_profile_addr);
    editaddr.setText(prof_addr);
    final EditText edituser = (EditText) dialog.findViewById(R.id.remote_profile_user);
    edituser.setText(prof_user);
    final EditText editpass = (EditText) dialog.findViewById(R.id.remote_profile_pass);
    editpass.setText(prof_pass);
    final EditText editshare = (EditText) dialog.findViewById(R.id.remote_profile_share);
    editshare.setText(prof_share);
    final EditText editport = (EditText) dialog.findViewById(R.id.remote_profile_port_number);
    editport.setText(prof_port);

    final CheckBox tg = (CheckBox) dialog.findViewById(R.id.remote_profile_active);
    if (prof_act.equals("A"))
        tg.setChecked(true);
    else
        tg.setChecked(false);

    // address?
    Button btnAddr = (Button) dialog.findViewById(R.id.remote_profile_addrbtn);
    btnAddr.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    editaddr.setText((String) arg1[1]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    if (arg1 != null)
                        dlg_msg.setText((String) arg1[0]);
                    else
                        dlg_msg.setText("");
                }

            });
            scanRemoteNetworkDlg(ntfy, editport.getText().toString());
        }
    });

    Button btnGet1 = (Button) dialog.findViewById(R.id.remote_profile_get_btn1);
    btnGet1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String prof_addr, prof_user, prof_pass;
            editaddr.selectAll();
            prof_addr = editaddr.getText().toString();
            edituser.selectAll();
            prof_user = edituser.getText().toString();
            editpass.selectAll();
            prof_pass = editpass.getText().toString();

            setJcifsProperties(prof_user, prof_pass);

            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    if (!((String) arg1[0]).equals(""))
                        editshare.setText((String) arg1[0]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    dlg_msg.setText((String) arg1[0]);
                }

            });
            setRemoteShare(prof_user, prof_pass, prof_addr, ntfy);
        }
    });

    // CANCEL?
    final Button btnCancel = (Button) dialog.findViewById(R.id.remote_profile_cancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            //            setFixedOrientation(false);
        }
    });
    // OK?
    Button btnOK = (Button) dialog.findViewById(R.id.remote_profile_ok);
    btnOK.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String new_user, new_pass, new_addr, new_share, new_act, new_name;

            dialog.dismiss();
            //            setFixedOrientation(false);

            new_addr = editaddr.getText().toString();
            new_user = edituser.getText().toString();
            new_pass = editpass.getText().toString();
            new_share = editshare.getText().toString();
            new_name = editname.getText().toString();
            String new_port = editport.getText().toString();

            if (tg.isChecked())
                new_act = "A";
            else
                new_act = "I";

            int pos = profileListView.getFirstVisiblePosition();
            int topPos = 0;
            if (profileListView.getChildAt(0) != null)
                profileListView.getChildAt(0).getTop();
            ProfileListItem item = profileAdapter.getItem(item_num);

            profileAdapter.remove(item);
            profileAdapter.insert(new ProfileListItem("R", new_name, new_act, new_user, new_pass, new_addr,
                    new_port, new_share, false), item_num);

            saveProfile(false, "", "");
            //            appendProfile();
            //            profileAdapter = 
            //                  createProfileList(false); // create profile list
            profileListView.setSelectionFromTop(pos, topPos);
            profileAdapter.setNotifyOnChange(true);
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnCancel.performClick();
        }
    });
    //      dialog.setOnKeyListener(new DialogOnKeyListener(currentContext));
    //      setFixedOrientation(true);
    //      dialog.setCancelable(false);
    dialog.show();

}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void renameItem(final FileListAdapter fla, final String item_optyp, final String item_name,
        final boolean item_isdir, final int item_num) {

    sendDebugLogMsg(1, "I", "renameItem entered.");
    // ??/*w w w  . j ava 2  s  .c o m*/
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.file_rename_create_dlg);
    final EditText newName = (EditText) dialog.findViewById(R.id.file_rename_create_dlg_newname);
    final Button btnOk = (Button) dialog.findViewById(R.id.file_rename_create_dlg_ok_btn);
    final Button btnCancel = (Button) dialog.findViewById(R.id.file_rename_create_dlg_cancel_btn);

    CommonDialog.setDlgBoxSizeCompact(dialog);

    ((TextView) dialog.findViewById(R.id.file_rename_create_dlg_title)).setText("Rename");
    ((TextView) dialog.findViewById(R.id.file_rename_create_dlg_subtitle)).setText("Enter new name");

    newName.setText(item_name);

    btnOk.setEnabled(false);
    newName.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            if (s.toString().length() < 1 || item_name.equals(s.toString()))
                btnOk.setEnabled(false);
            else
                btnOk.setEnabled(true);
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

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

    // OK?
    btnOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            //            setFixedOrientation(false);
            if (item_name.equals(newName.getText().toString())) {
                commonDlg.showCommonDialog(false, "E", "Rename", "Duplicate file name specified", null);
            } else {
                int cmd = 0;
                if (currentTabName.equals(SMBEXPLORER_TAB_LOCAL)) {
                    fileioLinkParm = buildFileioLinkParm(fileioLinkParm, fla.getItem(item_num).getPath(),
                            fla.getItem(item_num).getPath(), item_name, newName.getText().toString(), "", "",
                            true);
                    cmd = FILEIO_PARM_LOCAL_RENAME;
                } else {
                    cmd = FILEIO_PARM_REMOTE_RENAME;
                    if (item_isdir)
                        fileioLinkParm = buildFileioLinkParm(fileioLinkParm, fla.getItem(item_num).getPath(),
                                fla.getItem(item_num).getPath(), item_name, newName.getText().toString(),
                                smbUser, smbPass, true);
                    else
                        fileioLinkParm = buildFileioLinkParm(fileioLinkParm, fla.getItem(item_num).getPath(),
                                fla.getItem(item_num).getPath(), item_name, newName.getText().toString(),
                                smbUser, smbPass, true);
                }
                sendDebugLogMsg(1, "I", "renameItem FILEIO task invoked.");
                startFileioTask(fla, cmd, fileioLinkParm, item_name, null, null);
            }
        }
    });
    // CANCEL?
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            //            setFixedOrientation(false);
            sendDebugLogMsg(1, "W", "renameItem cancelled.");
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnCancel.performClick();
        }
    });
    //      dialog.setOnKeyListener(new DialogOnKeyListener(currentContext));
    //      setFixedOrientation(true);
    //      dialog.setCancelable(false);
    dialog.show();
}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void addRemoteProfile(final String prof_act, final String prof_name, final String prof_user,
        final String prof_pass, final String prof_addr, final String prof_port, final String prof_share,
        final String msg_text) {

    // ??// ww  w  .  jav  a2s  .com
    final Dialog dialog = new Dialog(this);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.edit_remote_profile);
    final TextView dlg_msg = (TextView) dialog.findViewById(R.id.remote_profile_dlg_msg);
    if (msg_text.length() != 0) {
        dlg_msg.setText(msg_text);
    }

    dialog.setTitle("Add remote profile");

    final EditText editname = (EditText) dialog.findViewById(R.id.remote_profile_name);
    editname.setText(prof_name);
    final EditText editaddr = (EditText) dialog.findViewById(R.id.remote_profile_addr);
    editaddr.setText(prof_addr);
    final EditText edituser = (EditText) dialog.findViewById(R.id.remote_profile_user);
    edituser.setText(prof_user);
    final EditText editpass = (EditText) dialog.findViewById(R.id.remote_profile_pass);
    editpass.setText(prof_pass);
    final EditText editshare = (EditText) dialog.findViewById(R.id.remote_profile_share);
    editshare.setText(prof_share);
    final EditText editport = (EditText) dialog.findViewById(R.id.remote_profile_port_number);
    editport.setText(prof_port);

    CommonDialog.setDlgBoxSizeCompact(dialog);

    final CheckBox tg = (CheckBox) dialog.findViewById(R.id.remote_profile_active);
    if (prof_act.equals("A"))
        tg.setChecked(true);
    else
        tg.setChecked(false);

    // address?
    Button btnAddr = (Button) dialog.findViewById(R.id.remote_profile_addrbtn);
    btnAddr.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    editaddr.setText((String) arg1[1]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    dlg_msg.setText("");
                }

            });
            scanRemoteNetworkDlg(ntfy, editport.getText().toString());
        }
    });

    final Button btnGet1 = (Button) dialog.findViewById(R.id.remote_profile_get_btn1);
    btnGet1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            btnGet1.setEnabled(false);
            String prof_addr, prof_user, prof_pass;
            editaddr.selectAll();
            prof_addr = editaddr.getText().toString();
            edituser.selectAll();
            prof_user = edituser.getText().toString();
            editpass.selectAll();
            prof_pass = editpass.getText().toString();

            setJcifsProperties(prof_user, prof_pass);

            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    if (!((String) arg1[0]).equals(""))
                        editshare.setText((String) arg1[0]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    dlg_msg.setText((String) arg1[0]);
                }

            });
            setRemoteShare(prof_user, prof_pass, prof_addr, ntfy);
        }
    });

    // CANCEL?
    final Button btnCancel = (Button) dialog.findViewById(R.id.remote_profile_cancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            //            setFixedOrientation(false);
        }
    });
    // OK?
    Button btnOK = (Button) dialog.findViewById(R.id.remote_profile_ok);
    btnOK.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String new_act, new_name;
            editaddr.selectAll();
            edituser.selectAll();
            editpass.selectAll();
            editshare.selectAll();
            editname.selectAll();
            new_name = editname.getText().toString();

            if (tg.isChecked())
                new_act = "A";
            else
                new_act = "A";

            if (isProfileDuplicated("R", new_name)) {
                dlg_msg.setText(getString(R.string.msgs_add_remote_profile_duplicate));
            } else {
                dialog.dismiss();
                //               setFixedOrientation(false);
                int pos = profileListView.getFirstVisiblePosition();
                int topPos = 0;
                if (profileListView.getChildAt(0) != null)
                    profileListView.getChildAt(0).getTop();
                String prof_user = edituser.getText().toString();
                String prof_pass = editpass.getText().toString();
                String prof_addr = editaddr.getText().toString();
                String prof_share = editshare.getText().toString();
                String prof_port = editport.getText().toString();
                profileAdapter.add(new ProfileListItem("R", new_name, new_act, prof_user, prof_pass, prof_addr,
                        prof_port, prof_share, false));
                saveProfile(false, "", "");
                profileAdapter = createProfileList(false, ""); // create profile list

                profileListView.setSelectionFromTop(pos, topPos);
                profileAdapter.setNotifyOnChange(true);

                setRemoteDirBtnListener();
            }
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnCancel.performClick();
        }
    });
    //      dialog.setOnKeyListener(new DialogOnKeyListener(currentContext));
    //      setFixedOrientation(true);
    //      dialog.setCancelable(false);
    dialog.show();
}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

public void scanRemoteNetworkDlg(final NotifyEvent p_ntfy, String port_number) {
    //??/*  ww w . j av  a  2  s  . c  o  m*/
    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.scan_remote_ntwk_dlg);
    final Button btn_scan = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_ok);
    final Button btn_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_cancel);
    final TextView tvmsg = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_msg);
    final TextView tv_result = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_scan_result_title);
    tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_press_scan_btn));
    tv_result.setVisibility(TextView.GONE);

    final String from = getLocalIpAddress();
    String subnet = from.substring(0, from.lastIndexOf("."));
    String subnet_o1, subnet_o2, subnet_o3;
    subnet_o1 = subnet.substring(0, subnet.indexOf("."));
    subnet_o2 = subnet.substring(subnet.indexOf(".") + 1, subnet.lastIndexOf("."));
    subnet_o3 = subnet.substring(subnet.lastIndexOf(".") + 1, subnet.length());
    final EditText baEt1 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o1);
    final EditText baEt2 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o2);
    final EditText baEt3 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o3);
    final EditText baEt4 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o4);
    final EditText eaEt4 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_end_address_o4);
    baEt1.setText(subnet_o1);
    baEt2.setText(subnet_o2);
    baEt3.setText(subnet_o3);
    baEt4.setText("1");
    baEt4.setSelection(1);
    eaEt4.setText("254");
    baEt4.requestFocus();

    final CheckBox cb_use_port_number = (CheckBox) dialog.findViewById(R.id.scan_remote_ntwk_use_port);
    final EditText et_port_number = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_port_number);

    CommonDialog.setDlgBoxSizeLimit(dialog, true);

    if (port_number.equals("")) {
        et_port_number.setEnabled(false);
        cb_use_port_number.setChecked(false);
    } else {
        et_port_number.setEnabled(true);
        et_port_number.setText(port_number);
        cb_use_port_number.setChecked(true);
    }
    cb_use_port_number.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            et_port_number.setEnabled(isChecked);
        }
    });

    final NotifyEvent ntfy_lv_click = new NotifyEvent(mContext);
    ntfy_lv_click.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
            dialog.dismiss();
            p_ntfy.notifyToListener(true, o);
        }

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

    final ArrayList<ScanAddressResultListItem> ipAddressList = new ArrayList<ScanAddressResultListItem>();
    //      ScanAddressResultListItem li=new ScanAddressResultListItem();
    //      li.server_name=mContext.getString(R.string.msgs_ip_address_no_address);
    //      ipAddressList.add(li);
    final ListView lv = (ListView) dialog.findViewById(R.id.scan_remote_ntwk_scan_result_list);
    final AdapterScanAddressResultList adap = new AdapterScanAddressResultList(mContext,
            R.layout.scan_address_result_list_item, ipAddressList, ntfy_lv_click);
    lv.setAdapter(adap);
    lv.setScrollingCacheEnabled(false);
    lv.setScrollbarFadingEnabled(false);

    //SCAN?
    btn_scan.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            ipAddressList.clear();
            NotifyEvent ntfy = new NotifyEvent(mContext);
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context c, Object[] o) {
                    if (ipAddressList.size() < 1) {
                        tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_not_detected));
                        tv_result.setVisibility(TextView.GONE);
                    } else {
                        tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_select_detected_host));
                        tv_result.setVisibility(TextView.VISIBLE);
                    }
                    //                   adap.clear();
                    //                   for (int i=0;i<ipAddressList.size();i++) 
                    //                      adap.add(ipAddressList.get(i));
                }

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

            });
            if (auditScanAddressRangeValue(dialog)) {
                tv_result.setVisibility(TextView.GONE);
                String ba1 = baEt1.getText().toString();
                String ba2 = baEt2.getText().toString();
                String ba3 = baEt3.getText().toString();
                String ba4 = baEt4.getText().toString();
                String ea4 = eaEt4.getText().toString();
                String subnet = ba1 + "." + ba2 + "." + ba3;
                int begin_addr = Integer.parseInt(ba4);
                int end_addr = Integer.parseInt(ea4);
                scanRemoteNetwork(dialog, lv, adap, ipAddressList, subnet, begin_addr, end_addr, ntfy);
            } else {
                //error
            }
        }
    });

    //CANCEL?
    btn_cancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            p_ntfy.notifyToListener(false, null);
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btn_cancel.performClick();
        }
    });
    dialog.show();

}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void showFileListCache(final ArrayList<FileListCacheItem> fcl, final FileListAdapter fla,
        final ListView flv, final Spinner spinner) {
    // ??/*  w  w w . j a v a  2s  .  c o  m*/
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.select_file_cache_dlg);
    //      final Button btnOk = 
    //            (Button) dialog.findViewById(R.id.select_file_cache_dlg_ok);
    final Button btnCancel = (Button) dialog.findViewById(R.id.select_file_cache_dlg_cancel);

    CommonDialog.setDlgBoxSizeCompact(dialog);

    ((TextView) dialog.findViewById(R.id.select_file_cache_dlg_title)).setText("Select file cache");

    ListView lv = (ListView) dialog.findViewById(R.id.select_file_cache_dlg_listview);

    final ArrayList<String> list = new ArrayList<String>();
    for (int i = 0; i < fcl.size(); i++) {
        list.add(fcl.get(i).directory);
    }
    Collections.sort(list, new Comparator<String>() {
        @Override
        public int compare(String lhs, String rhs) {
            return lhs.compareToIgnoreCase(rhs);
        }
    });
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, R.layout.simple_list_item_1o, list);
    lv.setAdapter(adapter);

    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String t_dir = list.get(position);
            FileListCacheItem dhi = getFileListCache(t_dir, fcl);
            if (dhi != null) {
                mIgnoreSpinnerSelection = true;
                int s_no = -1;
                for (int i = 0; i < spinner.getCount(); i++) {
                    if (spinner.getItemAtPosition(i).toString().equals(dhi.profile_name)) {
                        s_no = i;
                        break;
                    }
                }
                fla.setDataList(dhi.file_list);
                fla.notifyDataSetChanged();
                if (currentTabName.equals(SMBEXPLORER_TAB_LOCAL)) {
                    localBase = dhi.base;
                    if (dhi.base.equals(dhi.directory))
                        localDir = "";
                    else
                        localDir = dhi.directory.replace(localBase + "/", "");
                    replaceDirHist(localDirHist, dhi.directory_history);
                    setFilelistCurrDir(localFileListDirSpinner, localBase, localDir);
                    setFileListPathName(localFileListPathBtn, localFileListCache, localBase, localDir);
                    setEmptyFolderView();
                    localCurrFLI = dhi;
                    flv.setSelection(0);
                    for (int j = 0; j < localFileListView.getChildCount(); j++)
                        localFileListView.getChildAt(j).setBackgroundColor(Color.TRANSPARENT);
                    localFileListReloadBtn.performClick();
                } else if (currentTabName.equals(SMBEXPLORER_TAB_REMOTE)) {
                    remoteBase = dhi.base;
                    if (dhi.base.equals(dhi.directory))
                        remoteDir = "";
                    else
                        remoteDir = dhi.directory.replace(remoteBase + "/", "");
                    replaceDirHist(remoteDirHist, dhi.directory_history);
                    setFilelistCurrDir(remoteFileListDirSpinner, remoteBase, remoteDir);
                    setFileListPathName(remoteFileListPathBtn, remoteFileListCache, remoteBase, remoteDir);
                    setEmptyFolderView();
                    remoteCurrFLI = dhi;
                    flv.setSelection(0);

                    //                  Log.v("","base="+remoteBase+", dir="+remoteDir+", histsz="+remoteDirHist.size());
                    for (int j = 0; j < remoteFileListView.getChildCount(); j++)
                        remoteFileListView.getChildAt(j).setBackgroundColor(Color.TRANSPARENT);
                    if (remoteDir.equals("")) {
                        remoteFileListTopBtn.setEnabled(false);
                        remoteFileListUpBtn.setEnabled(false);
                    } else {
                        remoteFileListTopBtn.setEnabled(true);
                        remoteFileListUpBtn.setEnabled(true);
                    }
                }

                if (s_no != -1)
                    spinner.setSelection(s_no);
                Handler hndl = new Handler();
                hndl.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mIgnoreSpinnerSelection = false;
                    }
                }, 100);
                dialog.dismiss();
            }
        }
    });

    btnCancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    dialog.show();

}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void scanRemoteNetwork(final Dialog dialog, final ListView lv_ipaddr,
        final AdapterScanAddressResultList adap, final ArrayList<ScanAddressResultListItem> ipAddressList,
        final String subnet, final int begin_addr, final int end_addr, final NotifyEvent p_ntfy) {
    final Handler handler = new Handler();
    final ThreadCtrl tc = new ThreadCtrl();
    final LinearLayout ll_addr = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_scan_address);
    final LinearLayout ll_prog = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_progress);
    final TextView tvmsg = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_progress_msg);
    final Button btn_scan = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_ok);
    final Button btn_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_cancel);
    final Button scan_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_progress_cancel);

    final CheckBox cb_use_port_number = (CheckBox) dialog.findViewById(R.id.scan_remote_ntwk_use_port);
    final EditText et_port_number = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_port_number);

    tvmsg.setText("");
    scan_cancel.setText(R.string.msgs_progress_spin_dlg_addr_cancel);
    ll_addr.setVisibility(LinearLayout.GONE);
    ll_prog.setVisibility(LinearLayout.VISIBLE);
    btn_scan.setEnabled(false);//from  ww  w.jav  a2  s  . c o  m
    btn_cancel.setEnabled(false);
    adap.setButtonEnabled(false);
    scan_cancel.setEnabled(true);
    dialog.setOnKeyListener(new DialogBackKeyListener(mContext));
    dialog.setCancelable(false);
    // CANCEL?
    scan_cancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            scan_cancel.setText(mContext.getString(R.string.msgs_progress_dlg_canceling));
            scan_cancel.setEnabled(false);
            sendDebugLogMsg(1, "W", "IP Address list creation was cancelled");
            tc.setDisabled();
        }
    });
    dialog.show();

    sendDebugLogMsg(1, "I", "Scan IP address ransge is " + subnet + "." + begin_addr + " - " + end_addr);

    final String scan_prog = mContext.getString(R.string.msgs_ip_address_scan_progress);
    String p_txt = String.format(scan_prog, 0);
    tvmsg.setText(p_txt);

    new Thread(new Runnable() {
        @Override
        public void run() {//non UI thread
            mScanCompleteCount = 0;
            mScanAddrCount = end_addr - begin_addr + 1;
            int scan_thread = 50;
            String scan_port = "";
            if (cb_use_port_number.isChecked())
                scan_port = et_port_number.getText().toString();
            for (int i = begin_addr; i <= end_addr; i += scan_thread) {
                if (!tc.isEnabled())
                    break;
                boolean scan_end = false;
                for (int j = i; j < (i + scan_thread); j++) {
                    if (j <= end_addr) {
                        startRemoteNetworkScanThread(handler, tc, dialog, p_ntfy, lv_ipaddr, adap, tvmsg,
                                subnet + "." + j, ipAddressList, scan_port);
                    } else {
                        scan_end = true;
                    }
                }
                if (!scan_end) {
                    for (int wc = 0; wc < 210; wc++) {
                        if (!tc.isEnabled())
                            break;
                        SystemClock.sleep(30);
                    }
                }
            }
            if (!tc.isEnabled()) {
                handler.post(new Runnable() {// UI thread
                    @Override
                    public void run() {
                        closeScanRemoteNetworkProgressDlg(dialog, p_ntfy, lv_ipaddr, adap, tvmsg);
                    }
                });
            } else {
                handler.postDelayed(new Runnable() {// UI thread
                    @Override
                    public void run() {
                        closeScanRemoteNetworkProgressDlg(dialog, p_ntfy, lv_ipaddr, adap, tvmsg);
                    }
                }, 10000);
            }
        }
    }).start();
}