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.SMBSync2.SyncTaskUtility.java

public void scanRemoteNetworkDlg(final NotifyEvent p_ntfy, String port_number, boolean scan_start) {
    //??/*  w  w w .java 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);

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

    final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_title_view);
    final TextView title = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_title);
    title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
    title.setTextColor(mGp.themeColorList.text_color_dialog_title);

    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 = CommonUtilities.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 CheckedTextView ctv_use_port_number = (CheckedTextView) dialog
            .findViewById(R.id.scan_remote_ntwk_ctv_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);
        ctv_use_port_number.setChecked(false);
    } else {
        et_port_number.setEnabled(true);
        et_port_number.setText(port_number);
        ctv_use_port_number.setChecked(true);
    }
    ctv_use_port_number.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ctv_use_port_number.toggle();
            boolean isChecked = ctv_use_port_number.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();

    if (scan_start)
        btn_scan.performClick();
}

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

private void listDirFilterLocal(SyncTaskItem sti, String prof_master, final ArrayList<String> dir_filter,
        final AdapterFilterList fla, final NotifyEvent p_ntfy) {
    final String cdir = sti.getMasterDirectoryName();
    String localBaseDir_t = mGp.internalRootDirectory;
    if (sti.getMasterFolderType().equals(SyncTaskItem.SYNC_FOLDER_TYPE_SDCARD))
        localBaseDir_t = mGp.sdcardRootDirectory;
    final String localBaseDir = localBaseDir_t;

    //??//from  w w w  .ja v a2 s  .co m
    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.item_select_list_dlg);

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

    final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.item_select_list_dlg_title_view);
    final TextView title = (TextView) dialog.findViewById(R.id.item_select_list_dlg_title);
    final TextView subtitle = (TextView) dialog.findViewById(R.id.item_select_list_dlg_subtitle);
    title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
    title.setTextColor(mGp.themeColorList.text_color_dialog_title);
    subtitle.setTextColor(mGp.themeColorList.text_color_dialog_title);

    title.setText(mContext.getString(R.string.msgs_filter_list_dlg_add_dir_filter));
    subtitle.setText(mContext.getString(R.string.msgs_current_dir) + " " + localBaseDir + "/" + cdir);
    final TextView dlg_msg = (TextView) dialog.findViewById(R.id.item_select_list_dlg_msg);
    final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn);

    final LinearLayout ll_context = (LinearLayout) dialog.findViewById(R.id.context_view_file_select);
    ll_context.setVisibility(LinearLayout.VISIBLE);
    final ImageButton ib_select_all = (ImageButton) ll_context.findViewById(R.id.context_button_select_all);
    final ImageButton ib_unselect_all = (ImageButton) ll_context.findViewById(R.id.context_button_unselect_all);

    dlg_msg.setVisibility(TextView.VISIBLE);

    //        if (rows.size()<=2) 
    //           ((TextView)dialog.findViewById(R.id.item_select_list_dlg_spacer))
    //           .setVisibility(TextView.VISIBLE);

    CommonDialog.setDlgBoxSizeLimit(dialog, true);

    final ListView lv = (ListView) dialog.findViewById(android.R.id.list);
    final TreeFilelistAdapter tfa = new TreeFilelistAdapter(mContext, false, false);
    lv.setAdapter(tfa);
    ArrayList<TreeFilelistItem> tfl = createLocalFilelist(true, localBaseDir, "/" + cdir);
    if (tfl.size() < 1)
        tfl.add(new TreeFilelistItem(mContext.getString(R.string.msgs_dir_empty)));
    tfa.setDataList(tfl);
    lv.setScrollingCacheEnabled(false);
    lv.setScrollbarFadingEnabled(false);

    ib_select_all.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            for (int i = 0; i < tfa.getDataItemCount(); i++) {
                TreeFilelistItem tfli = tfa.getDataItem(i);
                if (!tfli.isHideListItem())
                    tfa.setDataItemIsSelected(i);
            }
            tfa.notifyDataSetChanged();
            btn_ok.setEnabled(true);
        }
    });

    ib_unselect_all.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            for (int i = 0; i < tfa.getDataItemCount(); i++) {
                tfa.setDataItemIsUnselected(i);
            }
            tfa.notifyDataSetChanged();
            btn_ok.setEnabled(false);
        }
    });

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
            final int pos = tfa.getItem(idx);
            final TreeFilelistItem tfi = tfa.getDataItem(pos);
            if (tfi.getName().startsWith("---"))
                return;
            expandHideLocalDirTree(true, localBaseDir, pos, tfi, tfa);
        }
    });
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
            final int t_pos = tfa.getItem(position);
            final TreeFilelistItem tfi = tfa.getDataItem(t_pos);
            if (tfi.getName().startsWith("---"))
                return true;
            if (!tfa.getDataItem(t_pos).isChecked()) {
                tfa.setDataItemIsSelected(t_pos);
            }
            return true;
        }
    });

    //OK?
    btn_ok.setEnabled(false);
    NotifyEvent ntfy = new NotifyEvent(mContext);
    //Listen setRemoteShare response 
    ntfy.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context arg0, Object[] arg1) {
            btn_ok.setEnabled(true);
        }

        @Override
        public void negativeResponse(Context arg0, Object[] arg1) {
            boolean checked = false;
            for (int i = 0; i < tfa.getDataItemCount(); i++) {
                if (tfa.getDataItem(i).isChecked()) {
                    checked = true;
                    break;
                }
            }
            if (checked)
                btn_ok.setEnabled(true);
            else
                btn_ok.setEnabled(false);
        }
    });
    tfa.setCbCheckListener(ntfy);

    btn_ok.setText(mContext.getString(R.string.msgs_filter_list_dlg_add));
    btn_ok.setVisibility(Button.VISIBLE);
    btn_ok.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (!addDirFilter(true, tfa, fla, "/" + cdir + "/", dlg_msg))
                return;
            addDirFilter(false, tfa, fla, "/" + cdir + "/", dlg_msg);
            dialog.dismiss();
            p_ntfy.notifyToListener(true, null);
        }
    });

    //CANCEL?
    final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn);
    btn_cancel.setText(mContext.getString(R.string.msgs_filter_list_dlg_close));
    btn_cancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            p_ntfy.notifyToListener(true, null);
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btn_cancel.performClick();
        }
    });
    //        dialog.setOnKeyListener(new DialogOnKeyListener(context));
    //        dialog.setCancelable(false);
    dialog.show();

    return;

}

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

public void selectLocalDirDlg(final String url, final String dir, String p_dir, final NotifyEvent p_ntfy) {

    //??//from   w  ww.j  a v  a2  s  .  c om
    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.item_select_list_dlg);

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

    final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.item_select_list_dlg_title_view);
    final TextView title = (TextView) dialog.findViewById(R.id.item_select_list_dlg_title);
    final TextView subtitle = (TextView) dialog.findViewById(R.id.item_select_list_dlg_subtitle);
    title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
    title.setTextColor(mGp.themeColorList.text_color_dialog_title);
    subtitle.setTextColor(mGp.themeColorList.text_color_dialog_title);

    title.setText(mContext.getString(R.string.msgs_select_local_dir));
    subtitle.setText(mContext.getString(R.string.msgs_current_dir) + url + dir);

    final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn);

    //        if (rows.size()<=2) 
    //           ((TextView)dialog.findViewById(R.id.item_select_list_dlg_spacer))
    //           .setVisibility(TextView.VISIBLE);

    CommonDialog.setDlgBoxSizeLimit(dialog, true);

    ListView lv = (ListView) dialog.findViewById(android.R.id.list);
    final TreeFilelistAdapter tfa = new TreeFilelistAdapter(mContext, true, false);
    lv.setAdapter(tfa);
    ArrayList<TreeFilelistItem> tfl = createLocalFilelist(true, url, dir);
    if (tfl.size() < 1)
        tfl.add(new TreeFilelistItem(mContext.getString(R.string.msgs_dir_empty)));
    tfa.setDataList(tfl);
    lv.setScrollingCacheEnabled(false);
    lv.setScrollbarFadingEnabled(false);
    lv.setFastScrollEnabled(true);

    if (p_dir.length() != 0)
        for (int i = 0; i < tfa.getDataItemCount(); i++) {
            if (tfa.getDataItem(i).getName().equals(p_dir))
                lv.setSelection(i);
        }
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
            final int pos = tfa.getItem(idx);
            final TreeFilelistItem tfi = tfa.getDataItem(pos);
            if (tfi.getName().startsWith("---"))
                return;
            expandHideLocalDirTree(true, url, pos, tfi, tfa);
        }
    });
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
            final int t_pos = tfa.getItem(position);
            if (tfa.getDataItem(t_pos).isChecked()) {
                ccMenu.addMenuItem(mContext.getString(R.string.msgs_file_select_select_this_entry) + " "
                        + tfa.getDataItem(t_pos).getPath() + tfa.getDataItem(t_pos).getName())
                        .setOnClickListener(new CustomContextMenuOnClickListener() {
                            @Override
                            public void onClick(CharSequence menuTitle) {
                                final TreeFilelistItem tfi = tfa.getDataItem(t_pos);
                                if (tfi.getName().startsWith("---"))
                                    return;
                                tfa.setDataItemIsUnselected(t_pos);
                                if (tfa.isDataItemIsSelected())
                                    btn_ok.setEnabled(true);
                                else
                                    btn_ok.setEnabled(false);
                            }
                        });
            } else {
                ccMenu.addMenuItem(mContext.getString(R.string.msgs_file_select_select_this_entry) + " "
                        + tfa.getDataItem(t_pos).getPath() + tfa.getDataItem(t_pos).getName())
                        .setOnClickListener(new CustomContextMenuOnClickListener() {
                            @Override
                            public void onClick(CharSequence menuTitle) {
                                final TreeFilelistItem tfi = tfa.getDataItem(t_pos);
                                if (tfi.getName().startsWith("---"))
                                    return;
                                tfa.setDataItemIsSelected(t_pos);
                                btn_ok.setEnabled(true);
                            }
                        });
            }
            ccMenu.createMenu();
            return false;
        }
    });
    NotifyEvent ctv_ntfy = new NotifyEvent(mContext);
    ctv_ntfy.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
            if (o != null) {
                int pos = (Integer) o[0];
                if (tfa.getDataItem(pos).isChecked())
                    btn_ok.setEnabled(true);
            }
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
            btn_ok.setEnabled(false);
            for (int i = 0; i < tfa.getDataItemCount(); i++) {
                if (tfa.getDataItem(i).isChecked()) {
                    btn_ok.setEnabled(true);
                    break;
                }
            }
        }
    });
    tfa.setCbCheckListener(ctv_ntfy);

    //OK?
    btn_ok.setEnabled(false);
    btn_ok.setVisibility(Button.VISIBLE);
    btn_ok.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String sel = "";
            for (int i = 0; i < tfa.getCount(); i++) {
                if (tfa.getDataItem(i).isChecked()
                        && !tfa.getDataItem(i).getName().equals(mContext.getString(R.string.msgs_dir_empty))) {
                    if (tfa.getDataItem(i).getPath().length() == 1)
                        sel = tfa.getDataItem(i).getName();
                    else
                        sel = tfa.getDataItem(i).getPath().substring(1, tfa.getDataItem(i).getPath().length())
                                + tfa.getDataItem(i).getName();
                    break;
                }
            }
            if (sel.equals("")) {

            }
            dialog.dismiss();
            p_ntfy.notifyToListener(true, new Object[] { sel });
        }
    });

    //CANCEL?
    final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn);
    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.setOnKeyListener(new DialogOnKeyListener(context));
    //        dialog.setCancelable(false);
    dialog.show();

    return;
}

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

public void editDirFilterDlg(final SyncTaskItem sti, final String prof_master,
        final ArrayList<String> dir_filter, final NotifyEvent p_ntfy) {
    ArrayList<FilterListItem> filterList = new ArrayList<FilterListItem>();
    final AdapterFilterList filterAdapter;

    // ??//from  w w  w  .  jav  a2  s. c  o m
    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.filter_list_dlg);

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

    final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.filter_select_edit_title_view);
    final TextView title = (TextView) dialog.findViewById(R.id.filter_select_edit_title);
    title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
    title.setTextColor(mGp.themeColorList.text_color_dialog_title);

    filterAdapter = new AdapterFilterList(mContext, R.layout.filter_list_item_view, filterList);
    final ListView lv = (ListView) dialog.findViewById(R.id.filter_select_edit_listview);

    for (int i = 0; i < dir_filter.size(); i++) {
        String inc = dir_filter.get(i).substring(0, 1);
        String filter = dir_filter.get(i).substring(1, dir_filter.get(i).length());
        boolean b_inc = false;
        if (inc.equals(SMBSYNC_PROF_FILTER_INCLUDE))
            b_inc = true;
        filterAdapter.add(new FilterListItem(filter, b_inc));
    }
    if (filterAdapter.getCount() == 0)
        filterAdapter.add(new FilterListItem(mContext.getString(R.string.msgs_filter_list_no_filter), false));
    lv.setAdapter(filterAdapter);
    lv.setScrollingCacheEnabled(false);
    lv.setScrollbarFadingEnabled(false);

    title.setText(mContext.getString(R.string.msgs_filter_list_dlg_dir_filter));
    final TextView dlg_msg = (TextView) dialog.findViewById(R.id.filter_select_edit_msg);
    final Button dirbtn = (Button) dialog.findViewById(R.id.filter_select_edit_dir_btn);

    CommonDialog.setDlgBoxSizeLimit(dialog, true);

    final EditText et_filter = (EditText) dialog.findViewById(R.id.filter_select_edit_new_filter);
    final Button addbtn = (Button) dialog.findViewById(R.id.filter_select_edit_add_btn);
    final Button btn_cancel = (Button) dialog.findViewById(R.id.filter_select_edit_cancel_btn);
    final Button btn_ok = (Button) dialog.findViewById(R.id.filter_select_edit_ok_btn);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
            FilterListItem fli = filterAdapter.getItem(idx);
            if (fli.getFilter().startsWith("---") || fli.isDeleted())
                return;
            // ????????
            editDirFilter(idx, filterAdapter, fli, fli.getFilter());
        }
    });

    // Add?
    et_filter.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() != 0) {
                if (isFilterExists(s.toString().trim(), filterAdapter)) {
                    String mtxt = mContext.getString(R.string.msgs_filter_list_duplicate_filter_specified);
                    dlg_msg.setText(String.format(mtxt, s.toString().trim()));
                    addbtn.setEnabled(false);
                    dirbtn.setEnabled(true);
                    btn_ok.setEnabled(true);
                } else {
                    dlg_msg.setText("");
                    addbtn.setEnabled(true);
                    dirbtn.setEnabled(false);
                    btn_ok.setEnabled(false);
                }
            } else {
                addbtn.setEnabled(false);
                dirbtn.setEnabled(true);
                btn_ok.setEnabled(true);
            }
            //            et_filter.setText(s);
        }

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
    addbtn.setEnabled(false);
    addbtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dlg_msg.setText("");
            String newfilter = et_filter.getText().toString();
            if (isFilterExists(newfilter, filterAdapter)) {
                String mtxt = mContext.getString(R.string.msgs_filter_list_duplicate_filter_specified);
                dlg_msg.setText(String.format(mtxt, newfilter));
                return;
            }
            dlg_msg.setText("");
            et_filter.setText("");
            if (filterAdapter.getItem(0).getFilter().startsWith("---"))
                filterAdapter.remove(filterAdapter.getItem(0));
            filterAdapter.add(new FilterListItem(newfilter, true));
            filterAdapter.setNotifyOnChange(true);
            filterAdapter.sort(new Comparator<FilterListItem>() {
                @Override
                public int compare(FilterListItem lhs, FilterListItem rhs) {
                    return lhs.getFilter().compareToIgnoreCase(rhs.getFilter());
                };
            });
            dirbtn.setEnabled(true);
            btn_ok.setEnabled(true);
        }
    });
    // Directory?
    //      if (getProfileType(prof_master,prof_dapter).equals("L")) {
    //         if (!mGp.externalStorageIsMounted) dirbtn.setEnabled(false);
    //      } else if (getProfileType(prof_master,prof_dapter).equals("R")) {
    //         if (util.isRemoteDisable()) dirbtn.setEnabled(false);
    //      } else dirbtn.setEnabled(false);
    dirbtn.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) {
                    dlg_msg.setText("");
                }

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

    // CANCEL?
    btn_cancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            //            glblParms.profileListView.setSelectionFromTop(currentViewPosX,currentViewPosY);
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btn_cancel.performClick();
        }
    });
    // OK?
    btn_ok.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            dir_filter.clear();
            if (filterAdapter.getCount() > 0) {
                for (int i = 0; i < filterAdapter.getCount(); i++) {
                    if (!filterAdapter.getItem(i).isDeleted()
                            && !filterAdapter.getItem(i).getFilter().startsWith("---")) {
                        String inc = SMBSYNC_PROF_FILTER_EXCLUDE;
                        if (filterAdapter.getItem(i).getInc())
                            inc = SMBSYNC_PROF_FILTER_INCLUDE;
                        dir_filter.add(inc + filterAdapter.getItem(i).getFilter());
                    }

                }
            }
            p_ntfy.notifyToListener(true, null);
        }
    });
    //      dialog.setOnKeyListener(new DialogOnKeyListener(context));
    //      dialog.setCancelable(false);
    dialog.show();

}

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

private void selectImportProfileItem(final AdapterSyncTask tfl, final NotifyEvent p_ntfy) {
    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.export_import_profile_dlg);
    dialog.setCanceledOnTouchOutside(false);

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

    ArrayList<ExportImportProfileListItem> eipl = new ArrayList<ExportImportProfileListItem>();

    for (int i = 0; i < tfl.getCount(); i++) {
        SyncTaskItem pl = tfl.getItem(i);
        ExportImportProfileListItem eipli = new ExportImportProfileListItem();
        eipli.isChecked = true;// ww w  .  j av  a2s .co  m
        eipli.item_name = pl.getSyncTaskName();
        eipl.add(eipli);
    }
    //      Collections.sort(eipl, new Comparator<ExportImportProfileListItem>(){
    //         @Override
    //         public int compare(ExportImportProfileListItem arg0,
    //               ExportImportProfileListItem arg1) {
    //            if (arg0.item_name.equals(arg1.item_name)) return arg0.item_type.compareToIgnoreCase(arg1.item_type);
    //            return arg0.item_name.compareToIgnoreCase(arg1.item_name);
    //         }
    //      });
    //      ExportImportProfileListItem eipli=new ExportImportProfileListItem();
    //      eipli.isChecked=true;
    //      eipli.item_type="*";
    //      eipli.item_name=mContext.getString(R.string.msgs_export_import_profile_setting_parms);
    //      eipl.add(eipli);
    final AdapterExportImportSyncTask imp_list_adapt = new AdapterExportImportSyncTask(mContext,
            R.layout.export_import_profile_list_item, eipl);

    ListView lv = (ListView) dialog.findViewById(R.id.export_import_profile_listview);
    lv.setAdapter(imp_list_adapt);

    CommonDialog.setDlgBoxSizeLimit(dialog, true);

    final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.export_import_profile_title_view);
    final TextView title = (TextView) dialog.findViewById(R.id.export_import_profile_title);
    title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
    title.setTextColor(mGp.themeColorList.text_color_dialog_title);
    title.setText(mContext.getString(R.string.msgs_export_import_profile_title));
    //      TextView tv_msgx=(TextView)dialog.findViewById(R.id.export_import_profile_msg);
    //      tv_msgx.setVisibility(LinearLayout.GONE);
    LinearLayout ll_filelist = (LinearLayout) dialog.findViewById(R.id.export_import_profile_file_list);
    ll_filelist.setVisibility(LinearLayout.GONE);
    final Button ok_btn = (Button) dialog.findViewById(R.id.export_import_profile_dlg_btn_ok);
    Button cancel_btn = (Button) dialog.findViewById(R.id.export_import_profile_dlg_btn_cancel);

    final Button rb_select_all = (Button) dialog.findViewById(R.id.export_import_profile_list_select_all);
    final Button rb_unselect_all = (Button) dialog.findViewById(R.id.export_import_profile_list_unselect_all);
    final CheckedTextView ctv_reset_profile = (CheckedTextView) dialog
            .findViewById(R.id.export_import_profile_list_ctv_reset_profile);
    final CheckedTextView ctv_import_settings = (CheckedTextView) dialog
            .findViewById(R.id.export_import_profile_list_ctv_import_settings);
    final CheckedTextView ctv_import_schedule = (CheckedTextView) dialog
            .findViewById(R.id.export_import_profile_list_ctv_import_schedule);

    ctv_reset_profile.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ((CheckedTextView) v).toggle();
            setImportOkBtnEnabled(ctv_reset_profile, ctv_import_settings, ctv_import_schedule, imp_list_adapt,
                    ok_btn);
        }
    });

    ctv_import_settings.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ((CheckedTextView) v).toggle();
            setImportOkBtnEnabled(ctv_reset_profile, ctv_import_settings, ctv_import_schedule, imp_list_adapt,
                    ok_btn);
        }
    });

    ctv_import_schedule.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ((CheckedTextView) v).toggle();
            setImportOkBtnEnabled(ctv_reset_profile, ctv_import_settings, ctv_import_schedule, imp_list_adapt,
                    ok_btn);
        }
    });

    ctv_import_settings.setChecked(true);
    ctv_import_schedule.setChecked(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
            //              imp_list_adapt.getItem(pos).isChecked=!imp_list_adapt.getItem(pos).isChecked;
            //              imp_list_adapt.notifyDataSetChanged();
            //              if (imp_list_adapt.isItemSelected()) {
            //                 ok_btn.setEnabled(true);
            //              } else {
            //                 ok_btn.setEnabled(false);
            //              }
            setImportOkBtnEnabled(ctv_reset_profile, ctv_import_settings, ctv_import_schedule, imp_list_adapt,
                    ok_btn);
        }
    });

    //      lv.setOnItemLongClickListener(new OnItemLongClickListener(){
    //         @Override
    //         public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
    //               int pos, long arg3) {
    //            ccMenu.addMenuItem(
    //                  mContext.getString(R.string.msgs_export_import_profile_select_all),R.drawable.blank)
    //              .setOnClickListener(new CustomContextMenuOnClickListener() {
    //              @Override
    //              final public void onClick(CharSequence menuTitle) {
    //                 for (int i=0;i<imp_list_adapt.getCount();i++)
    //                    imp_list_adapt.getItem(i).isChecked=true;
    //                 imp_list_adapt.notifyDataSetChanged();
    //                 ok_btn.setEnabled(true);
    //                 }
    //              });
    //            ccMenu.addMenuItem(
    //                  mContext.getString(R.string.msgs_export_import_profile_unselect_all),R.drawable.blank)
    //              .setOnClickListener(new CustomContextMenuOnClickListener() {
    //              @Override
    //              final public void onClick(CharSequence menuTitle) {
    //                 for (int i=0;i<imp_list_adapt.getCount();i++)
    //                    imp_list_adapt.getItem(i).isChecked=false;
    //                 imp_list_adapt.notifyDataSetChanged();
    //                 ok_btn.setEnabled(false);
    //                 }
    //              });
    //            ccMenu.createMenu();
    //            return false;
    //         }
    //      });

    rb_select_all.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            for (int i = 0; i < imp_list_adapt.getCount(); i++)
                imp_list_adapt.getItem(i).isChecked = true;
            ctv_import_settings.setChecked(true);
            ctv_import_schedule.setChecked(true);
            imp_list_adapt.notifyDataSetChanged();
            ok_btn.setEnabled(true);
        }
    });
    rb_unselect_all.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            for (int i = 0; i < imp_list_adapt.getCount(); i++)
                imp_list_adapt.getItem(i).isChecked = false;
            ctv_import_settings.setChecked(false);
            ctv_import_schedule.setChecked(false);
            imp_list_adapt.notifyDataSetChanged();
            ok_btn.setEnabled(false);
        }
    });

    NotifyEvent ntfy_ctv_listener = new NotifyEvent(mContext);
    ntfy_ctv_listener.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
            //              if (imp_list_adapt.isItemSelected()) {
            //                 ok_btn.setEnabled(true);
            //              } else {
            //                 if (ctv_import_settings.isChecked()) ok_btn.setEnabled(true);
            //                 else ok_btn.setEnabled(false);
            //              }
            setImportOkBtnEnabled(ctv_reset_profile, ctv_import_settings, ctv_import_schedule, imp_list_adapt,
                    ok_btn);
        }

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

    ok_btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            if (ctv_reset_profile.isChecked())
                mGp.syncTaskAdapter.clear();
            importSelectedSyncTaskItem(imp_list_adapt, tfl, ctv_import_settings.isChecked(),
                    ctv_import_schedule.isChecked(), p_ntfy);
            dialog.dismiss();
        }
    });
    cancel_btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            dialog.dismiss();
        }
    });

    dialog.show();

}

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

private void listDirFilterSMB(SyncTaskItem sti, String prof_master, final ArrayList<String> dir_filter,
        final AdapterFilterList fla, final NotifyEvent p_ntfy) {
    setSmbUserPass(sti.getMasterRemoteUserID(), sti.getMasterRemotePassword());
    String t_remurl = "";
    if (sti.getMasterRemoteHostname().equals(""))
        t_remurl = sti.getMasterRemoteAddr();
    else/* w ww.  j a  v  a  2  s .  c  o m*/
        t_remurl = sti.getMasterRemoteHostname();
    String h_port = "";
    if (!sti.getMasterRemotePassword().equals(""))
        h_port = ":" + sti.getMasterRemotePort();
    final String remurl = "smb://" + t_remurl + h_port + "/" + sti.getMasterRemoteSmbShareName();
    final String remdir = "/" + sti.getMasterDirectoryName() + "/";

    NotifyEvent ntfy = new NotifyEvent(mContext);
    // set thread response 
    ntfy.setListener(new NotifyEventListener() {
        @Override
        public void positiveResponse(Context c, Object[] o) {
            final ArrayList<TreeFilelistItem> rows = new ArrayList<TreeFilelistItem>();
            @SuppressWarnings("unchecked")
            ArrayList<TreeFilelistItem> rfl = (ArrayList<TreeFilelistItem>) o[0];

            for (int i = 0; i < rfl.size(); i++) {
                if (rfl.get(i).isDir() && rfl.get(i).canRead())
                    rows.add(rfl.get(i));
            }
            Collections.sort(rows);
            if (rows.size() < 1)
                rows.add(new TreeFilelistItem(mContext.getString(R.string.msgs_dir_empty)));
            //??
            final Dialog dialog = new Dialog(mContext);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCanceledOnTouchOutside(false);
            dialog.setContentView(R.layout.item_select_list_dlg);

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

            final LinearLayout title_view = (LinearLayout) dialog
                    .findViewById(R.id.item_select_list_dlg_title_view);
            final TextView title = (TextView) dialog.findViewById(R.id.item_select_list_dlg_title);
            final TextView subtitle = (TextView) dialog.findViewById(R.id.item_select_list_dlg_subtitle);
            title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
            title.setTextColor(mGp.themeColorList.text_color_dialog_title);
            subtitle.setTextColor(mGp.themeColorList.text_color_dialog_title);

            title.setText(mContext.getString(R.string.msgs_filter_list_dlg_add_dir_filter));
            subtitle.setText(mContext.getString(R.string.msgs_current_dir) + " " + remurl + remdir);
            final TextView dlg_msg = (TextView) dialog.findViewById(R.id.item_select_list_dlg_msg);
            final LinearLayout ll_context = (LinearLayout) dialog.findViewById(R.id.context_view_file_select);
            ll_context.setVisibility(LinearLayout.VISIBLE);
            final ImageButton ib_select_all = (ImageButton) ll_context
                    .findViewById(R.id.context_button_select_all);
            final ImageButton ib_unselect_all = (ImageButton) ll_context
                    .findViewById(R.id.context_button_unselect_all);
            final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn);
            dlg_msg.setVisibility(TextView.VISIBLE);

            //              if (rows.size()<=2) 
            //                 ((TextView)dialog.findViewById(R.id.item_select_list_dlg_spacer))
            //                 .setVisibility(TextView.VISIBLE);

            CommonDialog.setDlgBoxSizeLimit(dialog, true);

            final ListView lv = (ListView) dialog.findViewById(android.R.id.list);
            final TreeFilelistAdapter tfa = new TreeFilelistAdapter(mContext, false, false);
            tfa.setDataList(rows);
            lv.setAdapter(tfa);
            lv.setScrollingCacheEnabled(false);
            lv.setScrollbarFadingEnabled(false);
            //             lv.setFastScrollEnabled(true);

            ib_select_all.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    for (int i = 0; i < tfa.getDataItemCount(); i++) {
                        TreeFilelistItem tfli = tfa.getDataItem(i);
                        if (!tfli.isHideListItem())
                            tfa.setDataItemIsSelected(i);
                    }
                    tfa.notifyDataSetChanged();
                    btn_ok.setEnabled(true);
                }
            });

            ib_unselect_all.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    for (int i = 0; i < tfa.getDataItemCount(); i++) {
                        tfa.setDataItemIsUnselected(i);
                    }
                    tfa.notifyDataSetChanged();
                    btn_ok.setEnabled(false);
                }
            });

            lv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
                    // ????????
                    final int pos = tfa.getItem(idx);
                    final TreeFilelistItem tfi = tfa.getDataItem(pos);
                    if (tfi.getName().startsWith("---"))
                        return;
                    expandHideRemoteDirTree(remurl, pos, tfi, tfa);
                }
            });

            lv.setOnItemLongClickListener(new OnItemLongClickListener() {
                @Override
                public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
                    final int t_pos = tfa.getItem(position);
                    final TreeFilelistItem tfi = tfa.getDataItem(t_pos);
                    if (tfi.getName().startsWith("---"))
                        return true;
                    if (!tfa.getDataItem(t_pos).isChecked()) {
                        tfa.setDataItemIsSelected(t_pos);
                    }
                    return true;
                }
            });

            //OK?
            btn_ok.setEnabled(false);
            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    btn_ok.setEnabled(true);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    if (tfa.isDataItemIsSelected())
                        btn_ok.setEnabled(true);
                    else
                        btn_ok.setEnabled(false);
                }
            });
            tfa.setCbCheckListener(ntfy);

            btn_ok.setText(mContext.getString(R.string.msgs_filter_list_dlg_add));
            btn_ok.setVisibility(Button.VISIBLE);
            btn_ok.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    if (!addDirFilter(true, tfa, fla, remdir, dlg_msg))
                        return;
                    addDirFilter(false, tfa, fla, remdir, dlg_msg);
                    dialog.dismiss();
                    p_ntfy.notifyToListener(true, null);
                }
            });
            //CANCEL?
            final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn);
            btn_cancel.setText(mContext.getString(R.string.msgs_filter_list_dlg_close));
            btn_cancel.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    dialog.dismiss();
                    p_ntfy.notifyToListener(true, null);
                }
            });
            // Cancel?
            dialog.setOnCancelListener(new Dialog.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface arg0) {
                    btn_cancel.performClick();
                }
            });
            //            dialog.setOnKeyListener(new DialogOnKeyListener(context));
            //            dialog.setCancelable(false);
            dialog.show();
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
            p_ntfy.notifyToListener(false, o);
        }
    });
    createRemoteFileList(remurl, remdir, ntfy, true);
}

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

public void setRemoteDir(final String remurl, final String curdir, final String p_dir,
        final NotifyEvent p_ntfy) {
    final ArrayList<TreeFilelistItem> rows = new ArrayList<TreeFilelistItem>();

    NotifyEvent ntfy = new NotifyEvent(mContext);
    // set thread response 
    ntfy.setListener(new NotifyEventListener() {
        @Override//from   w  w  w  . j a va2  s.  co  m
        public void positiveResponse(Context c, Object[] o) {
            @SuppressWarnings("unchecked")
            ArrayList<TreeFilelistItem> rfl = (ArrayList<TreeFilelistItem>) o[0];
            for (int i = 0; i < rfl.size(); i++) {
                if (rfl.get(i).isDir() && rfl.get(i).canRead())
                    rows.add(rfl.get(i));
            }
            Collections.sort(rows);
            if (rows.size() < 1)
                rows.add(new TreeFilelistItem(mContext.getString(R.string.msgs_dir_empty)));
            //??
            final Dialog dialog = new Dialog(mContext);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCanceledOnTouchOutside(false);
            dialog.setContentView(R.layout.item_select_list_dlg);

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

            final LinearLayout title_view = (LinearLayout) dialog
                    .findViewById(R.id.item_select_list_dlg_title_view);
            final TextView title = (TextView) dialog.findViewById(R.id.item_select_list_dlg_title);
            final TextView subtitle = (TextView) dialog.findViewById(R.id.item_select_list_dlg_subtitle);
            title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
            title.setTextColor(mGp.themeColorList.text_color_dialog_title);
            subtitle.setTextColor(mGp.themeColorList.text_color_dialog_title);

            title.setText(mContext.getString(R.string.msgs_select_remote_dir));
            subtitle.setText(mContext.getString(R.string.msgs_current_dir) + "/" + remurl);
            //             if (rows.size()<1) {
            //                TextView dlg_msg=(TextView)dialog.findViewById(R.id.item_select_list_dlg_msg);
            //                dlg_msg.setText(msgs_dir_empty);
            //                dlg_msg.setVisibility(TextView.VISIBLE);
            //             }
            final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn);
            //              if (rows.size()<=2) 
            //                 ((TextView)dialog.findViewById(R.id.item_select_list_dlg_spacer))
            //                 .setVisibility(TextView.VISIBLE);

            CommonDialog.setDlgBoxSizeLimit(dialog, true);

            final ListView lv = (ListView) dialog.findViewById(android.R.id.list);
            final TreeFilelistAdapter tfa = new TreeFilelistAdapter(mContext, true, false);
            //            tfa.setNotifyOnChange(true);
            tfa.setDataList(rows);
            lv.setAdapter(tfa);
            lv.setScrollingCacheEnabled(false);
            lv.setScrollbarFadingEnabled(false);
            lv.setFastScrollEnabled(true);

            if (p_dir.length() != 0)
                for (int i = 0; i < tfa.getDataItemCount(); i++) {
                    if (tfa.getDataItem(i).getName().equals(p_dir))
                        lv.setSelection(i);
                }

            lv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
                    // ????????
                    final int pos = tfa.getItem(idx);
                    final TreeFilelistItem tfi = tfa.getDataItem(pos);
                    if (tfi.getName().startsWith("---"))
                        return;
                    expandHideRemoteDirTree(remurl, pos, tfi, tfa);
                }
            });
            lv.setOnItemLongClickListener(new OnItemLongClickListener() {
                @Override
                public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
                    final int t_pos = tfa.getItem(position);
                    if (tfa.getDataItem(t_pos).isChecked()) {
                        ccMenu.addMenuItem(mContext.getString(R.string.msgs_file_select_unselect_this_entry)
                                + " " + tfa.getDataItem(t_pos).getPath() + tfa.getDataItem(t_pos).getName())
                                .setOnClickListener(new CustomContextMenuOnClickListener() {
                                    @Override
                                    public void onClick(CharSequence menuTitle) {
                                        final TreeFilelistItem tfi = tfa.getDataItem(t_pos);
                                        if (tfi.getName().startsWith("---"))
                                            return;
                                        tfa.setDataItemIsUnselected(t_pos);
                                        btn_ok.setEnabled(false);
                                    }
                                });
                    } else {
                        ccMenu.addMenuItem(mContext.getString(R.string.msgs_file_select_select_this_entry) + " "
                                + tfa.getDataItem(t_pos).getPath() + tfa.getDataItem(t_pos).getName())
                                .setOnClickListener(new CustomContextMenuOnClickListener() {
                                    @Override
                                    public void onClick(CharSequence menuTitle) {
                                        final TreeFilelistItem tfi = tfa.getDataItem(t_pos);
                                        if (tfi.getName().startsWith("---"))
                                            return;
                                        tfa.setDataItemIsSelected(t_pos);
                                        btn_ok.setEnabled(true);
                                    }
                                });
                    }
                    ccMenu.createMenu();
                    return false;
                }
            });
            NotifyEvent ctv_ntfy = new NotifyEvent(mContext);
            // set file list thread response listener 
            ctv_ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context c, Object[] o) {
                    if (o != null) {
                        int pos = (Integer) o[0];
                        if (tfa.getDataItem(pos).isChecked())
                            btn_ok.setEnabled(true);
                    }
                }

                @Override
                public void negativeResponse(Context c, Object[] o) {
                    btn_ok.setEnabled(false);
                    for (int i = 0; i < tfa.getDataItemCount(); i++) {
                        if (tfa.getDataItem(i).isChecked()) {
                            btn_ok.setEnabled(true);
                            break;
                        }
                    }
                }
            });
            tfa.setCbCheckListener(ctv_ntfy);

            //OK?
            btn_ok.setEnabled(false);
            btn_ok.setVisibility(Button.VISIBLE);
            btn_ok.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    String sel = "";
                    for (int i = 0; i < tfa.getCount(); i++) {
                        if (tfa.getDataItem(i).isChecked() && !tfa.getDataItem(i).getName()
                                .equals(mContext.getString(R.string.msgs_dir_empty))) {
                            if (tfa.getDataItem(i).getPath().length() == 1)
                                sel = tfa.getDataItem(i).getName();
                            else
                                sel = tfa.getDataItem(i).getPath().substring(1,
                                        tfa.getDataItem(i).getPath().length()) + tfa.getDataItem(i).getName();
                            break;
                        }
                    }
                    dialog.dismiss();
                    p_ntfy.notifyToListener(true, new Object[] { sel });
                }
            });
            //CANCEL?
            final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn);
            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.setOnKeyListener(new DialogOnKeyListener(context));
            //             dialog.setCancelable(false);
            dialog.show();
        }

        @Override
        public void negativeResponse(Context c, Object[] o) {
            p_ntfy.notifyToListener(false, o);
        }
    });
    createRemoteFileList(remurl, curdir, ntfy, true);
    return;
}

From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.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 CheckedTextView ctv_use_port_number = (CheckedTextView) dialog
            .findViewById(R.id.scan_remote_ntwk_ctv_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_scan_progress_spin_dlg_addr_cancel);
    ll_addr.setVisibility(LinearLayout.GONE);
    ll_prog.setVisibility(LinearLayout.VISIBLE);
    btn_scan.setVisibility(Button.GONE);
    btn_cancel.setVisibility(Button.GONE);
    adap.setButtonEnabled(false);/*  w w w . j  a  va 2  s . c  om*/
    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);
            util.addDebugMsg(1, "W", "IP Address list creation was cancelled");
            tc.setDisabled();
        }
    });
    dialog.show();

    util.addDebugMsg(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 = 60;
            String scan_port = "";
            if (ctv_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();
}

From source file:Steps.StepsFragment.java

private void showNewSticker(final Sticker sticker_1, final Sticker sticker_2, final Sticker sticker_3) {
    // custom dialog

    final Dialog dialog = new Dialog(getActivity());

    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override//from w  ww .j  ava  2s  .c  o  m
        public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
        }
    });

    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    dialog.setContentView(R.layout.new_stickers_dialog);
    //get the correct image -1st sticker

    ImageView image = (ImageView) (dialog).findViewById(R.id.sticker1);
    image.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showStickerMoreInfo(sticker_1);
        }
    });
    String file = sticker_1.getImagesrc();
    file = file.substring(0, file.lastIndexOf(".")); //trim the extension
    Resources resources = getActivity().getResources();
    int resourceId = resources.getIdentifier(file, "drawable", getActivity().getPackageName());
    TextView number = (TextView) (dialog).findViewById(R.id.text_sticker1);
    number.setText("#" + Integer.toString(sticker_1.getId()));
    RelativeLayout image_layout = (RelativeLayout) (dialog).findViewById(R.id.sticker1_layout);
    ImageView imageCategory = (ImageView) (dialog).findViewById(R.id.category_image1);
    determineCategoty(imageCategory, sticker_1);
    determinePicture(sticker_1, image, resourceId);
    animate(image_layout, 3000);

    //get the correct image -2nd sticker
    ImageView image2 = (ImageView) (dialog).findViewById(R.id.sticker2);
    image2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showStickerMoreInfo(sticker_2);
        }
    });
    String file2 = sticker_2.getImagesrc();
    file2 = file2.substring(0, file2.lastIndexOf(".")); //trim the extension
    Resources resources2 = getActivity().getResources();
    int resourceId2 = resources2.getIdentifier(file2, "drawable", getActivity().getPackageName());
    TextView number2 = (TextView) (dialog).findViewById(R.id.text_sticker2);
    number2.setText("#" + Integer.toString(sticker_2.getId()));
    RelativeLayout image_layout2 = (RelativeLayout) (dialog).findViewById(R.id.sticker2_layout);
    ImageView imageCategory2 = (ImageView) (dialog).findViewById(R.id.category_image2);
    determineCategoty(imageCategory2, sticker_2);
    determinePicture(sticker_2, image2, resourceId2);
    animate(image_layout2, 3000);

    //get the correct image -3rd sticker
    ImageView image3 = (ImageView) (dialog).findViewById(R.id.sticker3);
    image3.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showStickerMoreInfo(sticker_3);
        }
    });
    String file3 = sticker_3.getImagesrc();
    file3 = file3.substring(0, file3.lastIndexOf(".")); //trim the extension
    Resources resources3 = getActivity().getResources();
    int resourceId3 = resources3.getIdentifier(file3, "drawable", getActivity().getPackageName());

    TextView number3 = (TextView) (dialog).findViewById(R.id.text_sticker3);
    number3.setText("#" + Integer.toString(sticker_3.getId()));
    RelativeLayout image_layout3 = (RelativeLayout) (dialog).findViewById(R.id.sticker3_layout);
    ImageView imageCategory3 = (ImageView) (dialog).findViewById(R.id.category_image3);
    determineCategoty(imageCategory3, sticker_3);
    determinePicture(sticker_3, image3, resourceId3);
    animate(image_layout3, 3000);

    Display display = getActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;

    //set the layout to have the same widh and height as the  windows screen
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = width;
    lp.height = height;
    dialog.getWindow().setAttributes(lp);
    RelativeLayout mainLayout = (RelativeLayout) dialog.findViewById(R.id.showStickerLayout);
    dialog.show();
    // if button is clicked, close the custom dialog
    Button doneButton = (Button) (dialog).findViewById(R.id.doneButton);
    doneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();

        }

    });
}

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

private boolean auditScanAddressRangeValue(Dialog dialog) {
    boolean result = false;
    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);
    final TextView tvmsg = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_msg);

    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();

    tvmsg.setText("");
    if (ba1.equals("")) {
        tvmsg.setText(mContext.getString(R.string.msgs_ip_address_range_dlg_begin_notspecified));
        baEt1.requestFocus();//  ww  w . j a  v  a 2s  .c  o  m
        return false;
    } else if (ba2.equals("")) {
        tvmsg.setText(mContext.getString(R.string.msgs_ip_address_range_dlg_begin_notspecified));
        baEt2.requestFocus();
        return false;
    } else if (ba3.equals("")) {
        tvmsg.setText(mContext.getString(R.string.msgs_ip_address_range_dlg_begin_notspecified));
        baEt3.requestFocus();
        return false;
    } else if (ba4.equals("")) {
        tvmsg.setText(mContext.getString(R.string.msgs_ip_address_range_dlg_begin_notspecified));
        baEt4.requestFocus();
        return false;
    } else if (ea4.equals("")) {
        tvmsg.setText(mContext.getString(R.string.msgs_ip_address_range_dlg_end_notspecified));
        eaEt4.requestFocus();
        return false;
    }
    int iba1 = Integer.parseInt(ba1);
    if (iba1 > 255) {
        tvmsg.setText(mContext.getString(R.string.msgs_ip_address_range_dlg_addr_range_error));
        baEt1.requestFocus();
        return false;
    }
    int iba2 = Integer.parseInt(ba2);
    if (iba2 > 255) {
        tvmsg.setText(mContext.getString(R.string.msgs_ip_address_range_dlg_addr_range_error));
        baEt2.requestFocus();
        return false;
    }
    int iba3 = Integer.parseInt(ba3);
    if (iba3 > 255) {
        tvmsg.setText(mContext.getString(R.string.msgs_ip_address_range_dlg_addr_range_error));
        baEt3.requestFocus();
        return false;
    }
    int iba4 = Integer.parseInt(ba4);
    int iea4 = Integer.parseInt(ea4);
    if (iba4 > 0 && iba4 < 255) {
        if (iea4 > 0 && iea4 < 255) {
            if (iba4 <= iea4) {
                result = true;
            } else {
                baEt4.requestFocus();
                tvmsg.setText(mContext.getString(R.string.msgs_ip_address_range_dlg_begin_addr_gt_end_addr));
            }
        } else {
            eaEt4.requestFocus();
            tvmsg.setText(mContext.getString(R.string.msgs_ip_address_range_dlg_end_range_error));
        }
    } else {
        baEt4.requestFocus();
        tvmsg.setText(mContext.getString(R.string.msgs_ip_address_range_dlg_begin_range_error));
    }

    //      if (iba1==192&&iba2==168) {
    //         //class c private
    //      } else {
    //         if (iba1==10) {
    //            //class a private
    //         } else {
    //            if (iba1==172 && (iba2>=16&&iba2<=31)) {
    //               //class b private
    //            } else {
    //               //not private
    //               result=false;
    //               tvmsg.setText(mContext.getString(R.string.msgs_ip_address_range_dlg_not_private));
    //            }
    //         }
    //      }

    return result;
}