List of usage examples for android.app Dialog setOnCancelListener
public void setOnCancelListener(@Nullable OnCancelListener listener)
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 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.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
public void selectLocalDirDlg(final String url, final String dir, String p_dir, final NotifyEvent p_ntfy) { //??//from ww w .j a va 2 s . c o 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_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.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) { // ??//from ww w . j a va 2 s. 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) { //??/*from www . jav 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.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 ww w . j a va2 s . com 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.TaskAutomation.Config.ProfileMaintenanceActionProfile.java
final static private void editActivityExtraDataItem(final GlobalParameters mGlblParms, final int sel_pos) { // ??/* ww w. j av a 2 s.c o m*/ final Dialog dialog = new Dialog(mGlblParms.context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // dialog.getWindow().setSoftInputMode( // WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); dialog.setContentView(R.layout.edit_activity_extra_data_item_dlg); final TextView dlg_msg = (TextView) dialog.findViewById(R.id.edit_activity_extra_data_item_msg); // final TextView dlg_title = (TextView) dialog.findViewById(R.id.edit_activity_extra_data_item_title); // CommonDialog.setDlgBoxSizeLimit(dialog,true); final Button btn_cancel = (Button) dialog.findViewById(R.id.edit_activity_extra_data_item_cancel_btn); final Button btn_ok = (Button) dialog.findViewById(R.id.edit_activity_extra_data_item_ok_btn); final EditText et_key = (EditText) dialog.findViewById(R.id.edit_activity_extra_data_item_key); final EditText et_string = (EditText) dialog.findViewById(R.id.edit_activity_extra_data_item_data_string); final EditText et_int = (EditText) dialog.findViewById(R.id.edit_activity_extra_data_item_data_int); final CheckBox cb_array = (CheckBox) dialog.findViewById(R.id.edit_activity_extra_data_item_array); final Button btn_add_array = (Button) dialog.findViewById(R.id.edit_activity_extra_data_item_add_array); final ListView lv_array = (ListView) dialog.findViewById(R.id.edit_activity_extra_data_item_array_listview); final TextView lv_spacer = (TextView) dialog.findViewById(R.id.edit_activity_extra_data_item_array_spacer); final Spinner spinnerExtraDataType = (Spinner) dialog .findViewById(R.id.edit_activity_extra_data_item_data_type); final CustomSpinnerAdapter adapterExtraDataType = new CustomSpinnerAdapter(mGlblParms.context, R.layout.custom_simple_spinner_item); adapterExtraDataType.setTextColor(Color.BLACK); setSpinnerExtraDataType(mGlblParms, dialog, spinnerExtraDataType, adapterExtraDataType, PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING); final Spinner spinnerExtraDataBoolean = (Spinner) dialog .findViewById(R.id.edit_activity_extra_data_item_data_boolean); final CustomSpinnerAdapter adapterExtraDataBoolean = new CustomSpinnerAdapter(mGlblParms.context, R.layout.custom_simple_spinner_item); adapterExtraDataBoolean.setTextColor(Color.BLACK); setSpinnerExtraDataBoolean(mGlblParms, dialog, spinnerExtraDataBoolean, adapterExtraDataBoolean, "false"); final Button update_apply = (Button) dialog .findViewById(R.id.edit_activity_extra_data_item_data_update_apply); final Button update_cancel = (Button) dialog .findViewById(R.id.edit_activity_extra_data_item_data_update_cancel); update_apply.setVisibility(Button.GONE); update_cancel.setVisibility(Button.GONE); spinnerExtraDataBoolean.setVisibility(Spinner.GONE); et_string.setVisibility(EditText.GONE); et_int.setVisibility(EditText.GONE); btn_add_array.setVisibility(Button.GONE); lv_array.setVisibility(ListView.GONE); lv_spacer.setVisibility(TextView.VISIBLE); final ArrayList<DataArrayEditListItem> aed_array_list = new ArrayList<DataArrayEditListItem>(); final AdapterDataArrayEditList aed_array_adapter = new AdapterDataArrayEditList(mGlblParms.context, R.layout.data_array_edit_list_item, aed_array_list); lv_array.setAdapter(aed_array_adapter); setActivityExtraDataEditItemViewVisibility(mGlblParms, dialog, aed_array_adapter, spinnerExtraDataType); cb_array.setChecked(false); if (sel_pos != -1) { et_key.setEnabled(false); et_key.setTextColor(Color.WHITE); et_key.selectAll(); et_key.setText(mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).key_value); if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { et_string.setText(mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_value); spinnerExtraDataType.setSelection(0); } else if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) { et_int.setText(mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_value); spinnerExtraDataType.setSelection(1); } else if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) { spinnerExtraDataType.setSelection(2); if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_value.equals("false")) spinnerExtraDataBoolean.setSelection(0); else spinnerExtraDataBoolean.setSelection(1); } mGlblParms.currentSelectedExtraDataType = spinnerExtraDataType.getSelectedItem().toString(); if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_value_array .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_ARRAY_YES)) { cb_array.setChecked(true); et_string.setText(""); et_int.setText(""); createActivityExtraDataArrayList(aed_array_adapter, mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos)); aed_array_adapter.notifyDataSetChanged(); update_apply.setVisibility(Button.GONE); update_cancel.setVisibility(Button.GONE); spinnerExtraDataBoolean.setVisibility(Spinner.GONE); et_string.setVisibility(EditText.GONE); et_int.setVisibility(EditText.GONE); btn_add_array.setVisibility(Button.VISIBLE); lv_array.setVisibility(ListView.VISIBLE); lv_spacer.setVisibility(TextView.GONE); } else { cb_array.setChecked(false); update_apply.setVisibility(Button.GONE); update_cancel.setVisibility(Button.GONE); spinnerExtraDataBoolean.setVisibility(Spinner.GONE); et_string.setVisibility(EditText.GONE); et_int.setVisibility(EditText.GONE); btn_add_array.setVisibility(Button.GONE); lv_array.setVisibility(ListView.GONE); lv_spacer.setVisibility(TextView.VISIBLE); if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { et_string.setVisibility(EditText.VISIBLE); } else if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) { et_int.setVisibility(EditText.VISIBLE); } else if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) { spinnerExtraDataBoolean.setVisibility(Spinner.VISIBLE); } } } btn_add_array.setOnClickListener(new OnClickListener() { @Override final public void onClick(View arg0) { String n_data = ""; if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { n_data = ""; } else if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) { n_data = "0"; } else if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) { n_data = "false"; } DataArrayEditListItem aeda_item = new DataArrayEditListItem(); aeda_item.data_value = n_data; aed_array_adapter.add(aeda_item); aed_array_adapter.notifyDataSetChanged(); } }); NotifyEvent ntfy = new NotifyEvent(mGlblParms.context); ntfy.setListener(new NotifyEventListener() { @Override final public void positiveResponse(Context c, Object[] o) { spinnerExtraDataType.setEnabled(false); String c_data = (String) o[0]; if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { et_string.setText(c_data); spinnerExtraDataBoolean.setVisibility(Spinner.GONE); et_string.setVisibility(EditText.VISIBLE); et_int.setVisibility(EditText.GONE); et_string.requestFocus(); } else if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) { et_int.setText(c_data); spinnerExtraDataBoolean.setVisibility(Spinner.GONE); et_string.setVisibility(EditText.GONE); et_int.setVisibility(EditText.VISIBLE); et_int.requestFocus(); } else if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) { if (c_data.equals("false")) spinnerExtraDataBoolean.setSelection(0); else spinnerExtraDataBoolean.setSelection(1); spinnerExtraDataBoolean.setVisibility(Spinner.VISIBLE); et_string.setVisibility(EditText.GONE); et_int.setVisibility(EditText.GONE); } update_apply.setVisibility(Button.VISIBLE); update_cancel.setVisibility(Button.VISIBLE); btn_ok.setEnabled(false); btn_cancel.setEnabled(false); cb_array.setEnabled(false); btn_add_array.setEnabled(false); } @Override final public void negativeResponse(Context c, Object[] o) { } }); aed_array_adapter.setEditBtnNotifyListener(ntfy); update_apply.setVisibility(Button.GONE); update_cancel.setVisibility(Button.GONE); update_apply.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { boolean no_err = auditActivityExtraData(mGlblParms, dialog, spinnerExtraDataType, spinnerExtraDataBoolean); if (!no_err) return; int pos = -1; for (int i = 0; i < aed_array_list.size(); i++) { if (aed_array_list.get(i).while_edit) { pos = i; break; } } if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { aed_array_list.get(pos).data_value = et_string.getText().toString(); aed_array_list.get(pos).while_edit = false; } else if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) { aed_array_list.get(pos).data_value = et_int.getText().toString(); aed_array_list.get(pos).while_edit = false; } else if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) { String n_boolean = "true"; if (spinnerExtraDataBoolean.getSelectedItem().toString().equals("false")) n_boolean = "false"; aed_array_list.get(pos).data_value = n_boolean; aed_array_list.get(pos).while_edit = false; } et_string.setText(""); et_int.setText(""); et_string.setVisibility(EditText.GONE); et_int.setVisibility(EditText.GONE); spinnerExtraDataBoolean.setVisibility(Spinner.GONE); aed_array_adapter.notifyDataSetChanged(); update_apply.setVisibility(Button.GONE); update_cancel.setVisibility(Button.GONE); spinnerExtraDataType.setEnabled(true); btn_ok.setEnabled(true); btn_cancel.setEnabled(true); cb_array.setEnabled(true); btn_add_array.setEnabled(true); } }); update_cancel.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { for (int i = 0; i < aed_array_list.size(); i++) { aed_array_list.get(i).while_edit = false; } et_string.setText(""); et_int.setText(""); et_string.setVisibility(EditText.GONE); et_int.setVisibility(EditText.GONE); spinnerExtraDataBoolean.setVisibility(Spinner.GONE); aed_array_adapter.notifyDataSetChanged(); update_apply.setVisibility(Button.GONE); update_cancel.setVisibility(Button.GONE); spinnerExtraDataType.setEnabled(true); btn_ok.setEnabled(true); btn_cancel.setEnabled(true); cb_array.setEnabled(true); btn_add_array.setEnabled(true); } }); // CANCEL? btn_cancel.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { dialog.dismiss(); } }); // OK? btn_ok.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { ActivityExtraDataItem aedi = null; if (sel_pos == -1) {//Add item if (et_key.getText().toString().equals("")) { dlg_msg.setText(mGlblParms.context .getString(R.string.msgs_edit_profile_action_activity_extra_data_key_name_missing)); return; } aedi = new ActivityExtraDataItem(); } else {//Edit item aedi = mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos); } aedi.key_value = et_key.getText().toString(); if (cb_array.isChecked()) { if (aed_array_list.size() == 0) { dlg_msg.setText(mGlblParms.context.getString( R.string.msgs_edit_profile_action_activity_extra_data_array_data_missing)); return; } aedi.data_value_array = PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_ARRAY_YES; aedi.data_type = spinnerExtraDataType.getSelectedItem().toString(); aedi.data_value = ""; // Log.v("","array size="+aed_array_list.size()); for (int i = 0; i < aed_array_list.size(); i++) { if (aedi.data_type.equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { // aedi.data_value+="\u00a0"+aed_array_list.get(i).array_data_value+"\u0003"; aedi.data_value += aed_array_list.get(i).data_value + "\u0003"; // GeneralUtilities.hexString("String",aed_array_list.get(i).array_data_value.getBytes(),0,aed_array_list.get(i).array_data_value.getBytes().length); } else { aedi.data_value += aed_array_list.get(i).data_value + "\u0003"; // GeneralUtilities.hexString("int",aed_array_list.get(i).data_value.getBytes(),0,aed_array_list.get(i).data_value.getBytes().length); } } // GeneralUtilities.hexString("test",aedi.data_value.getBytes(),0,aedi.data_value.getBytes().length); // Log.v("","dv="+aedi.data_value.replaceAll("\u0003", ";")); } else { boolean no_err = auditActivityExtraData(mGlblParms, dialog, spinnerExtraDataType, spinnerExtraDataBoolean); if (!no_err) return; else { aedi.data_value_array = PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_ARRAY_NO; aedi.data_type = spinnerExtraDataType.getSelectedItem().toString(); if (spinnerExtraDataType.getSelectedItem().toString() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { aedi.data_value = et_string.getText().toString(); } else if (spinnerExtraDataType.getSelectedItem().toString() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) { aedi.data_value = et_int.getText().toString(); } else if (spinnerExtraDataType.getSelectedItem().toString() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) { if (spinnerExtraDataBoolean.getSelectedItem().toString().equals("false")) aedi.data_value = "false"; else aedi.data_value = "true"; } } } if (sel_pos == -1) mGlblParms.activityExtraDataEditListAdapter.add(aedi); if (mGlblParms.activityExtraDataEditListAdapter.getItem(0).key_value.equals("")) mGlblParms.activityExtraDataEditListAdapter.remove(0); mGlblParms.activityExtraDataEditListAdapter.notifyDataSetChanged(); dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btn_cancel.performClick(); } }); // dialog.setCancelable(false); dialog.show(); }