Java tutorial
package com.sentaroh.android.SMBSync2; /* The MIT License (MIT) Copyright (c) 2011-2013 Sentaroh Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import static com.sentaroh.android.SMBSync2.Constants.*; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.lang.Thread.UncaughtExceptionHandler; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import jcifs.smb.NtlmPasswordAuthentication; import jcifs.smb.SmbException; import jcifs.smb.SmbFile; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Handler; import android.os.SystemClock; import android.preference.PreferenceManager; import android.support.v4.app.FragmentManager; import android.text.Editable; import android.text.TextWatcher; import android.util.SparseBooleanArray; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckedTextView; import android.widget.EditText; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import com.sentaroh.android.SMBSync2.R; import com.sentaroh.android.Utilities.Base64Compat; import com.sentaroh.android.Utilities.EncryptUtil; import com.sentaroh.android.Utilities.EncryptUtil.CipherParms; import com.sentaroh.android.Utilities.NetworkUtil; import com.sentaroh.android.Utilities.NotifyEvent; import com.sentaroh.android.Utilities.NotifyEvent.NotifyEventListener; import com.sentaroh.android.Utilities.SafUtil; import com.sentaroh.android.Utilities.SafCommonArea; import com.sentaroh.android.Utilities.ThreadCtrl; import com.sentaroh.android.Utilities.ContextMenu.CustomContextMenu; import com.sentaroh.android.Utilities.ContextMenu.CustomContextMenuItem.CustomContextMenuOnClickListener; import com.sentaroh.android.Utilities.Dialog.CommonDialog; import com.sentaroh.android.Utilities.Dialog.DialogBackKeyListener; import com.sentaroh.android.Utilities.TreeFilelist.TreeFilelistAdapter; import com.sentaroh.android.Utilities.TreeFilelist.TreeFilelistItem; public class SyncTaskUtility { private CustomContextMenu ccMenu = null; private String smbUser, smbPass; private Context mContext; private CommonUtilities util; private ArrayList<PreferenceParmListIItem> importedSettingParmList = new ArrayList<PreferenceParmListIItem>(); private CommonDialog commonDlg = null; private GlobalParameters mGp = null; private FragmentManager mFragMgr = null; private SafCommonArea mSafCA = new SafCommonArea(); SyncTaskUtility(CommonUtilities mu, Context c, CommonDialog cd, CustomContextMenu ccm, GlobalParameters gp, FragmentManager fm) { mContext = c; mGp = gp; util = mu; commonDlg = cd; ccMenu = ccm; mFragMgr = fm; SafUtil.initWorkArea(mContext, mSafCA, mGp.settingDebugLevel > 0); }; public void importSyncTaskListDlg(final String lurl, final String ldir, String file_name, final NotifyEvent p_ntfy) { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { final String fpath = (String) o[0]; NotifyEvent ntfy_pswd = new NotifyEvent(mContext); ntfy_pswd.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { mGp.profilePassword = (String) o[0]; final AdapterSyncTask tfl = new AdapterSyncTask(mContext, R.layout.sync_task_item_view, createSyncTaskList(mContext, mGp, util, true, fpath, importedSettingParmList)); selectImportProfileItem(tfl, p_ntfy); } @Override public void negativeResponse(Context c, Object[] o) { } }); if (isSyncTaskListFileEncrypted(fpath)) { promptPasswordForImport(fpath, ntfy_pswd); } else ntfy_pswd.notifyToListener(true, new Object[] { "" }); } @Override public void negativeResponse(Context c, Object[] o) { } }); commonDlg.fileOnlySelectWithoutCreateHideMP(lurl, ldir, file_name, mContext.getString(R.string.msgs_select_import_file), ntfy); }; static private boolean isSyncTaskListFileEncrypted(String fpath) { boolean result = false; File lf = new File(fpath); if (lf.exists() && lf.canRead()) { try { BufferedReader br; br = new BufferedReader(new FileReader(fpath), 8192); String pl = br.readLine(); if (pl != null) { if (pl.startsWith(SMBSYNC_PROF_VER1)) { if (pl.startsWith(SMBSYNC_PROF_VER1 + SMBSYNC_PROF_ENC)) result = true; } } br.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return result; }; public void promptPasswordForImport(final String fpath, final NotifyEvent ntfy_pswd) { // ?? final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(false); dialog.setContentView(R.layout.password_input_dlg); LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.password_input_dlg_view); ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.password_input_title_view); final TextView title = (TextView) dialog.findViewById(R.id.password_input_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); final TextView dlg_msg = (TextView) dialog.findViewById(R.id.password_input_msg); final CheckedTextView ctv_protect = (CheckedTextView) dialog.findViewById(R.id.password_input_ctv_protect); final Button btn_ok = (Button) dialog.findViewById(R.id.password_input_ok_btn); final Button btn_cancel = (Button) dialog.findViewById(R.id.password_input_cancel_btn); final EditText et_password = (EditText) dialog.findViewById(R.id.password_input_password); final EditText et_confirm = (EditText) dialog.findViewById(R.id.password_input_password_confirm); et_confirm.setVisibility(EditText.GONE); btn_ok.setText(mContext.getString(R.string.msgs_export_import_pswd_btn_ok)); ctv_protect.setVisibility(CheckedTextView.GONE); dlg_msg.setText(mContext.getString(R.string.msgs_export_import_pswd_password_required)); CommonDialog.setDlgBoxSizeCompact(dialog); btn_ok.setEnabled(false); et_password.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { if (arg0.length() > 0) btn_ok.setEnabled(true); else btn_ok.setEnabled(false); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } }); //OK button btn_ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String passwd = et_password.getText().toString(); BufferedReader br; String pl; boolean pswd_invalid = true; try { br = new BufferedReader(new FileReader(fpath), 8192); pl = br.readLine(); if (pl != null) { String enc_str = ""; if (pl.startsWith(SMBSYNC_PROF_VER1 + SMBSYNC_PROF_ENC)) { enc_str = pl.replace(SMBSYNC_PROF_VER1 + SMBSYNC_PROF_ENC, ""); } if (!enc_str.equals("")) { CipherParms cp = EncryptUtil.initDecryptEnv(mGp.profileKeyPrefix + passwd); byte[] enc_array = Base64Compat.decode(enc_str, Base64Compat.NO_WRAP); String dec_str = EncryptUtil.decrypt(enc_array, cp); if (!SMBSYNC_PROF_ENC.equals(dec_str)) { dlg_msg.setText( mContext.getString(R.string.msgs_export_import_pswd_invalid_password)); } else { pswd_invalid = false; } } } br.close(); } catch (IOException e) { e.printStackTrace(); } if (!pswd_invalid) { dialog.dismiss(); ntfy_pswd.notifyToListener(true, new Object[] { passwd }); } } }); // CANCEL? btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); ntfy_pswd.notifyToListener(false, null); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btn_cancel.performClick(); } }); // dialog.setCancelable(false); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); dialog.show(); }; public void promptPasswordForExport(final String fpath, final NotifyEvent ntfy_pswd) { // ?? final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(false); dialog.setContentView(R.layout.password_input_dlg); LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.password_input_dlg_view); ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.password_input_title_view); final TextView title = (TextView) dialog.findViewById(R.id.password_input_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); final TextView dlg_msg = (TextView) dialog.findViewById(R.id.password_input_msg); final CheckedTextView ctv_protect = (CheckedTextView) dialog.findViewById(R.id.password_input_ctv_protect); final Button btn_ok = (Button) dialog.findViewById(R.id.password_input_ok_btn); final Button btn_cancel = (Button) dialog.findViewById(R.id.password_input_cancel_btn); final EditText et_password = (EditText) dialog.findViewById(R.id.password_input_password); final EditText et_confirm = (EditText) dialog.findViewById(R.id.password_input_password_confirm); dlg_msg.setText(mContext.getString(R.string.msgs_export_import_pswd_specify_password)); CommonDialog.setDlgBoxSizeCompact(dialog); ctv_protect.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ctv_protect.toggle(); boolean isChecked = ctv_protect.isChecked(); setPasswordFieldVisibility(isChecked, et_password, et_confirm, btn_ok, dlg_msg); } }); ctv_protect.setChecked(mGp.settingExportedProfileEncryptRequired); setPasswordFieldVisibility(mGp.settingExportedProfileEncryptRequired, et_password, et_confirm, btn_ok, dlg_msg); et_password.setEnabled(true); et_confirm.setEnabled(false); et_password.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { btn_ok.setEnabled(false); setPasswordPromptOkButton(et_password, et_confirm, btn_ok, dlg_msg); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } }); et_confirm.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { btn_ok.setEnabled(false); setPasswordPromptOkButton(et_password, et_confirm, btn_ok, dlg_msg); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } }); //OK button btn_ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String passwd = et_password.getText().toString(); if ((ctv_protect.isChecked() && !mGp.settingExportedProfileEncryptRequired) || (!ctv_protect.isChecked() && mGp.settingExportedProfileEncryptRequired)) { mGp.settingExportedProfileEncryptRequired = ctv_protect.isChecked(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); prefs.edit().putBoolean(mContext.getString(R.string.settings_exported_profile_encryption), ctv_protect.isChecked()).commit(); } if (!ctv_protect.isChecked()) { dialog.dismiss(); ntfy_pswd.notifyToListener(true, new Object[] { "" }); } else { if (!passwd.equals(et_confirm.getText().toString())) { //Unmatch dlg_msg.setText( mContext.getString(R.string.msgs_export_import_pswd_unmatched_confirm_pswd)); } else { dialog.dismiss(); ntfy_pswd.notifyToListener(true, new Object[] { passwd }); } } } }); // CANCEL? btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); ntfy_pswd.notifyToListener(false, null); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btn_cancel.performClick(); } }); // dialog.setCancelable(false); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); dialog.show(); }; private void setPasswordFieldVisibility(boolean isChecked, EditText et_password, EditText et_confirm, Button btn_ok, TextView dlg_msg) { if (isChecked) { et_password.setVisibility(EditText.VISIBLE); et_confirm.setVisibility(EditText.VISIBLE); setPasswordPromptOkButton(et_password, et_confirm, btn_ok, dlg_msg); } else { dlg_msg.setText(""); et_password.setVisibility(EditText.GONE); et_confirm.setVisibility(EditText.GONE); btn_ok.setEnabled(true); } }; private void setPasswordPromptOkButton(EditText et_passwd, EditText et_confirm, Button btn_ok, TextView dlg_msg) { String password = et_passwd.getText().toString(); String confirm = et_confirm.getText().toString(); if (password.length() > 0 && et_confirm.getText().length() == 0) { dlg_msg.setText(mContext.getString(R.string.msgs_export_import_pswd_unmatched_confirm_pswd)); et_confirm.setEnabled(true); } else if (password.length() > 0 && et_confirm.getText().length() > 0) { et_confirm.setEnabled(true); if (!password.equals(confirm)) { btn_ok.setEnabled(false); dlg_msg.setText(mContext.getString(R.string.msgs_export_import_pswd_unmatched_confirm_pswd)); } else { btn_ok.setEnabled(true); dlg_msg.setText(""); } } else if (password.length() == 0 && confirm.length() == 0) { btn_ok.setEnabled(false); dlg_msg.setText(mContext.getString(R.string.msgs_export_import_pswd_specify_password)); et_passwd.setEnabled(true); et_confirm.setEnabled(false); } else if (password.length() == 0 && confirm.length() > 0) { dlg_msg.setText(mContext.getString(R.string.msgs_export_import_pswd_unmatched_confirm_pswd)); } }; 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; 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(); }; private void setImportOkBtnEnabled(final CheckedTextView ctv_reset_profile, final CheckedTextView ctv_import_settings, final CheckedTextView ctv_import_schedule, final AdapterExportImportSyncTask imp_list_adapt, final Button ok_btn) { if (ctv_import_settings.isChecked() || ctv_import_schedule.isChecked() || imp_list_adapt.isItemSelected()) ok_btn.setEnabled(true); else ok_btn.setEnabled(false); }; private void importSelectedSyncTaskItem(final AdapterExportImportSyncTask imp_list_adapt, final AdapterSyncTask tfl, final boolean import_settings, final boolean import_schedule, final NotifyEvent p_ntfy) { String repl_list = ""; for (int i = 0; i < imp_list_adapt.getCount(); i++) { ExportImportProfileListItem eipli = imp_list_adapt.getItem(i); if (eipli.isChecked && getSyncTaskByName(mGp.syncTaskAdapter, eipli.item_name) != null) { repl_list += eipli.item_name + "\n"; } } NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { String imp_list = ""; for (int i = 0; i < tfl.getCount(); i++) { SyncTaskItem ipfli = tfl.getItem(i); ExportImportProfileListItem eipli = imp_list_adapt.getItem(i); if (eipli.isChecked) { imp_list += ipfli.getSyncTaskName() + "\n"; // Log.v("","name1="+ipfli.getName()+ // ", result="+getProfile(ipfli.getName(), mGp.syncTaskListAdapter)); SyncTaskItem mpfli = getSyncTaskByName(mGp.syncTaskAdapter, ipfli.getSyncTaskName()); if (mpfli != null) { mGp.syncTaskAdapter.remove(mpfli); ipfli.setSyncTaskPosition(mpfli.getSyncTaskPosition()); mGp.syncTaskAdapter.add(ipfli); } else { ipfli.setSyncTaskPosition(mGp.syncTaskAdapter.getCount()); mGp.syncTaskAdapter.add(ipfli); } } } restoreImportedSystemOption(); if (import_settings) { restoreImportedSettingParms(); imp_list += mContext.getString(R.string.msgs_export_import_profile_setting_parms) + "\n"; } if (import_schedule) { restoreImportedScheduleParms(); imp_list += mContext.getString(R.string.msgs_export_import_profile_schedule_parms) + "\n"; } if (imp_list.length() > 0) imp_list += " "; mGp.syncTaskAdapter.sort(); mGp.syncTaskListView.setSelection(0); saveSyncTaskListToFile(mGp, mContext, util, false, "", "", mGp.syncTaskAdapter.getArrayList(), false); commonDlg.showCommonDialog(false, "I", mContext.getString(R.string.msgs_export_import_profile_import_success), imp_list, null); if (import_settings || import_schedule) { boolean[] parm = new boolean[] { import_settings, import_schedule }; p_ntfy.notifyToListener(true, new Object[] { parm }); } } @Override public void negativeResponse(Context c, Object[] o) { } }); if (!repl_list.equals("")) { //Confirm commonDlg.showCommonDialog(true, "W", mContext.getString(R.string.msgs_export_import_profile_confirm_override), repl_list, ntfy); } else { ntfy.notifyToListener(true, null); } }; private void restoreImportedSystemOption() { final ArrayList<PreferenceParmListIItem> spl = importedSettingParmList; if (spl.size() == 0) { util.addDebugMsg(2, "I", "Import setting parms can not be not found."); return; } final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); final Editor pe = prefs.edit(); if (spl.size() >= 0) { for (int i = 0; i < spl.size(); i++) { if (spl.get(i).parms_key.startsWith("system_rest")) { restorePreferenceParms(pe, spl.get(i)); } } pe.commit(); // applySettingParms(); } }; private void restorePreferenceParms(Editor pe, PreferenceParmListIItem pa) { if (pa.parms_type.equals(SMBSYNC_UNLOAD_SETTINGS_TYPE_STRING)) { pe.putString(pa.parms_key, pa.parms_value); util.addDebugMsg(2, "I", "Restored parms=" + pa.parms_key + "=" + pa.parms_value); } else if (pa.parms_type.equals(SMBSYNC_UNLOAD_SETTINGS_TYPE_BOOLEAN)) { boolean b_val = false; if (pa.parms_value.equals("false")) b_val = false; else b_val = true; pe.putBoolean(pa.parms_key, b_val); util.addDebugMsg(2, "I", "Restored parms=" + pa.parms_key + "=" + pa.parms_value); } else if (pa.parms_type.equals(SMBSYNC_UNLOAD_SETTINGS_TYPE_INT)) { int i_val = 0; i_val = Integer.parseInt(pa.parms_value); ; pe.putInt(pa.parms_key, i_val); util.addDebugMsg(2, "I", "Restored parms=" + pa.parms_key + "=" + pa.parms_value); } else if (pa.parms_type.equals(SMBSYNC_UNLOAD_SETTINGS_TYPE_LONG)) { long i_val = 0; i_val = Long.parseLong(pa.parms_value); ; pe.putLong(pa.parms_key, i_val); util.addDebugMsg(2, "I", "Restored parms=" + pa.parms_key + "=" + pa.parms_value); } }; private void restoreImportedScheduleParms() { final ArrayList<PreferenceParmListIItem> spl = importedSettingParmList; if (spl.size() == 0) { util.addDebugMsg(2, "I", "Import setting parms can not be not found."); return; } final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); final Editor pe = prefs.edit(); if (spl.size() >= 0) { for (int i = 0; i < spl.size(); i++) { if (spl.get(i).parms_key.startsWith("schedule")) { restorePreferenceParms(pe, spl.get(i)); } } pe.commit(); // applySettingParms(); } }; private void restoreImportedSettingParms() { final ArrayList<PreferenceParmListIItem> spl = importedSettingParmList; if (spl.size() == 0) { util.addDebugMsg(2, "I", "Import setting parms can not be not found."); return; } final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); final Editor pe = prefs.edit(); if (spl.size() >= 0) { for (int i = 0; i < spl.size(); i++) { if (spl.get(i).parms_key.startsWith("settings")) { restorePreferenceParms(pe, spl.get(i)); } } pe.commit(); // applySettingParms(); } }; public void exportSyncTaskListDlg(final String lurl, final String ldir, final String ifn) { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { final String fpath = (String) o[0]; NotifyEvent ntfy_pswd = new NotifyEvent(mContext); ntfy_pswd.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { mGp.profilePassword = (String) o[0]; boolean encrypt_required = false; if (!mGp.profilePassword.equals("")) encrypt_required = true; String fd = fpath.substring(0, fpath.lastIndexOf("/")); String fn = fpath.replace(fd + "/", ""); exportSyncTaskListToFile(fd, fn, encrypt_required); } @Override public void negativeResponse(Context c, Object[] o) { } }); promptPasswordForExport(fpath, ntfy_pswd); } @Override public void negativeResponse(Context c, Object[] o) { } }); commonDlg.fileOnlySelectWithCreateHideMP(lurl, ldir, ifn, mContext.getString(R.string.msgs_select_export_file), ntfy); }; public void exportSyncTaskListToFile(final String profile_dir, final String profile_filename, final boolean encrypt_required) { File lf = new File(profile_dir + "/" + profile_filename); if (lf.exists()) { NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { String fp = profile_dir + "/" + profile_filename; String fd = profile_dir; if (saveSyncTaskListToFile(mGp, mContext, util, true, fd, fp, mGp.syncTaskAdapter.getArrayList(), encrypt_required)) { commonDlg.showCommonDialog(false, "I", mContext.getString(R.string.msgs_export_prof_success), "File=" + fp, null); util.addDebugMsg(1, "I", "Profile was exported. fn=" + fp); } else { commonDlg.showCommonDialog(false, "E", mContext.getString(R.string.msgs_export_prof_fail), "File=" + fp, null); } } @Override public void negativeResponse(Context c, Object[] o) { } }); commonDlg.showCommonDialog(true, "W", mContext.getString(R.string.msgs_export_prof_title), profile_dir + "/" + profile_filename + " " + mContext.getString(R.string.msgs_override), ntfy); } else { String fp = profile_dir + "/" + profile_filename; String fd = profile_dir; if (saveSyncTaskListToFile(mGp, mContext, util, true, fd, fp, mGp.syncTaskAdapter.getArrayList(), encrypt_required)) { commonDlg.showCommonDialog(false, "I", mContext.getString(R.string.msgs_export_prof_success), "File=" + fp, null); util.addDebugMsg(1, "I", "Profile was exported. fn=" + fp); } else { commonDlg.showCommonDialog(false, "E", mContext.getString(R.string.msgs_export_prof_fail), "File=" + fp, null); } } }; static public void setAllSyncTaskToUnchecked(boolean hideCheckBox, AdapterSyncTask pa) { pa.setAllItemChecked(false); if (hideCheckBox) pa.setShowCheckBox(false); pa.notifyDataSetChanged(); }; static public void setSyncTaskToChecked(boolean chk, AdapterSyncTask pa, int no) { SyncTaskItem item = pa.getItem(no); item.setChecked(chk); }; public void setProfileToActive(GlobalParameters gp) { SyncTaskItem item; // int pos=gp.profileListView.getFirstVisiblePosition(); // int posTop=gp.profileListView.getChildAt(0).getTop(); for (int i = 0; i < gp.syncTaskAdapter.getCount(); i++) { item = gp.syncTaskAdapter.getItem(i); if (item.isChecked()) { item.setSyncTaskAuto(true); } } saveSyncTaskListToFile(mGp, mContext, util, false, "", "", gp.syncTaskAdapter.getArrayList(), false); mGp.syncTaskAdapter.notifyDataSetChanged(); gp.syncTaskAdapter.setNotifyOnChange(true); // gp.profileListView.setSelectionFromTop(pos,posTop); }; public void setProfileToInactive() { SyncTaskItem item; int pos = mGp.syncTaskListView.getFirstVisiblePosition(); int posTop = mGp.syncTaskListView.getChildAt(0).getTop(); for (int i = 0; i < mGp.syncTaskAdapter.getCount(); i++) { item = mGp.syncTaskAdapter.getItem(i); if (item.isChecked()) { item.setSyncTaskAuto(false); // item.setChecked(false); } } saveSyncTaskListToFile(mGp, mContext, util, false, "", "", mGp.syncTaskAdapter.getArrayList(), false); mGp.syncTaskAdapter.notifyDataSetChanged(); mGp.syncTaskAdapter.setNotifyOnChange(true); mGp.syncTaskListView.setSelectionFromTop(pos, posTop); }; public void deleteSyncTask(final NotifyEvent p_ntfy) { final int[] dpnum = new int[mGp.syncTaskAdapter.getCount()]; String dpmsg = ""; for (int i = 0; i < mGp.syncTaskAdapter.getCount(); i++) { if (mGp.syncTaskAdapter.getItem(i).isChecked()) { dpmsg = dpmsg + mGp.syncTaskAdapter.getItem(i).getSyncTaskName() + "\n"; dpnum[i] = i; } else dpnum[i] = -1; } NotifyEvent ntfy = new NotifyEvent(mContext); // set commonDlg.showCommonDialog response ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { ArrayList<SyncTaskItem> dpItemList = new ArrayList<SyncTaskItem>(); int pos = mGp.syncTaskListView.getFirstVisiblePosition(); for (int i = 0; i < dpnum.length; i++) { if (dpnum[i] != -1) dpItemList.add(mGp.syncTaskAdapter.getItem(dpnum[i])); } for (int i = 0; i < dpItemList.size(); i++) mGp.syncTaskAdapter.remove(dpItemList.get(i)); saveSyncTaskListToFile(mGp, mContext, util, false, "", "", mGp.syncTaskAdapter.getArrayList(), false); mGp.syncTaskAdapter.setNotifyOnChange(true); mGp.syncTaskListView.setSelection(pos); if (mGp.syncTaskAdapter.isEmptyAdapter()) { mGp.syncTaskAdapter.setShowCheckBox(false); } SyncTaskUtility.setAllSyncTaskToUnchecked(true, mGp.syncTaskAdapter); p_ntfy.notifyToListener(true, null); } @Override public void negativeResponse(Context c, Object[] o) { p_ntfy.notifyToListener(false, null); } }); commonDlg.showCommonDialog(true, "W", mContext.getString(R.string.msgs_delete_following_profile), dpmsg, ntfy); }; public void showSelectSdcardMsg(final NotifyEvent ntfy, String msg) { final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.show_select_sdcard_dlg); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.show_select_sdcard_dlg_title_view); final TextView title = (TextView) dialog.findViewById(R.id.show_select_sdcard_dlg_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); final TextView dlg_msg = (TextView) dialog.findViewById(R.id.show_select_sdcard_dlg_msg); dlg_msg.setText(msg); ; final ImageView func_view = (ImageView) dialog.findViewById(R.id.show_select_sdcard_dlg_image); try { InputStream is = mContext.getResources().getAssets() .open(mContext.getString(R.string.msgs_main_external_sdcard_select_required_select_msg_file)); Bitmap bm = BitmapFactory.decodeStream(is); func_view.setImageBitmap(bm); } catch (IOException e) { /* ? */ } final Button btnOk = (Button) dialog.findViewById(R.id.show_select_sdcard_dlg_btn_ok); final Button btnCancel = (Button) dialog.findViewById(R.id.show_select_sdcard_dlg_btn_cancel); CommonDialog.setDlgBoxSizeLimit(dialog, true); // OK? btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); ntfy.notifyToListener(true, null); } }); // Cancel? btnCancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); ntfy.notifyToListener(false, null); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnCancel.performClick(); } }); dialog.show(); } public boolean isExternalSdcardUsedByOutput() { boolean result = false; for (SyncTaskItem pli : mGp.syncTaskAdapter.getArrayList()) { // Log.v("","name="+pli.getProfileName()+", type="+pli.getProfileType()+", act="+pli.isProfileActive()); if (pli.getTargetFolderType().equals(SyncTaskItem.SYNC_FOLDER_TYPE_SDCARD)) { result = true; break; } } return result; }; public void logonToRemoteDlg(final String host, final String addr, final String port, final String user, final String pass, final NotifyEvent p_ntfy) { final ThreadCtrl tc = new ThreadCtrl(); tc.setEnabled(); tc.setThreadResultSuccess(); // ?? final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(false); dialog.setContentView(R.layout.progress_spin_dlg); LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.progress_spin_dlg_view); ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.progress_spin_dlg_title_view); final TextView title = (TextView) dialog.findViewById(R.id.progress_spin_dlg_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); title.setText(R.string.msgs_progress_spin_dlg_test_logon); final Button btn_cancel = (Button) dialog.findViewById(R.id.progress_spin_dlg_btn_cancel); btn_cancel.setText(R.string.msgs_progress_spin_dlg_test_logon_cancel); // (dialog.context.findViewById(R.id.progress_spin_dlg)).setVisibility(TextView.GONE); // (dialog.context.findViewById(R.id.progress_spin_dlg)).setEnabled(false); CommonDialog.setDlgBoxSizeCompact(dialog); // CANCEL? btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { tc.setDisabled();//disableAsyncTask(); btn_cancel.setText(mContext.getString(R.string.msgs_progress_dlg_canceling)); btn_cancel.setEnabled(false); util.addDebugMsg(1, "W", "Logon is cancelled."); } }); dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btn_cancel.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); // dialog.show(); showDelayedProgDlg? Thread th = new Thread() { @Override public void run() { util.addDebugMsg(1, "I", "Test logon started, host=" + host + ", addr=" + addr + ", port=" + port + ", user=" + user); NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, user, pass); NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { dialog.dismiss(); String err_msg = (String) o[0]; if (tc.isEnabled()) { if (err_msg != null) { commonDlg.showCommonDialog(false, "E", mContext.getString(R.string.msgs_remote_profile_dlg_logon_error), err_msg, null); if (p_ntfy != null) p_ntfy.notifyToListener(false, null); } else { commonDlg.showCommonDialog(false, "I", "", mContext.getString(R.string.msgs_remote_profile_dlg_logon_success), null); if (p_ntfy != null) p_ntfy.notifyToListener(true, null); } } else { commonDlg.showCommonDialog(false, "I", "", mContext.getString(R.string.msgs_remote_profile_dlg_logon_cancel), null); if (p_ntfy != null) p_ntfy.notifyToListener(true, null); } } @Override public void negativeResponse(Context c, Object[] o) { } }); if (host.equals("")) { boolean reachable = false; if (port.equals("")) { if (NetworkUtil.isIpAddressAndPortConnected(addr, 139, 3500) || NetworkUtil.isIpAddressAndPortConnected(addr, 445, 3500)) { reachable = true; } } else { reachable = NetworkUtil.isIpAddressAndPortConnected(addr, Integer.parseInt(port), 3500); } if (reachable) { testAuth(auth, addr, port, ntfy); } else { util.addDebugMsg(1, "I", "Test logon failed, remote server not connected"); String unreachble_msg = ""; if (port.equals("")) { unreachble_msg = String .format(mContext.getString(R.string.msgs_mirror_smb_addr_not_connected), addr); } else { unreachble_msg = String.format( mContext.getString(R.string.msgs_mirror_smb_addr_not_connected_with_port), addr, port); } ntfy.notifyToListener(true, new Object[] { unreachble_msg }); } } else { if (NetworkUtil.getSmbHostIpAddressFromName(host) != null) testAuth(auth, host, port, ntfy); else { util.addDebugMsg(1, "I", "Test logon failed, remote server not connected"); String unreachble_msg = ""; unreachble_msg = mContext.getString(R.string.msgs_mirror_smb_name_not_found) + host; ntfy.notifyToListener(true, new Object[] { unreachble_msg }); } } } }; th.start(); dialog.show(); }; @SuppressWarnings("unused") private void testAuth(final NtlmPasswordAuthentication auth, final String host, String port, final NotifyEvent ntfy) { final UncaughtExceptionHandler defaultUEH = Thread.currentThread().getUncaughtExceptionHandler(); Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable ex) { Thread.currentThread().setUncaughtExceptionHandler(defaultUEH); ex.printStackTrace(); StackTraceElement[] st = ex.getStackTrace(); String st_msg = ""; for (int i = 0; i < st.length; i++) { st_msg += "\n at " + st[i].getClassName() + "." + st[i].getMethodName() + "(" + st[i].getFileName() + ":" + st[i].getLineNumber() + ")"; } String end_msg = ex.toString() + st_msg; ntfy.notifyToListener(true, new Object[] { end_msg }); // re-throw critical exception further to the os (important) // defaultUEH.uncaughtException(thread, ex); } }); String err_msg = null; SmbFile sf = null; SmbFile[] lf = null; String url = ""; if (port.equals("")) { url = "smb://" + host + "/IPC$/"; } else { url = "smb://" + host + ":" + port + "/IPC$/"; } // Log.v("","url="+url); try { sf = new SmbFile(url, auth); sf.connect(); util.addDebugMsg(1, "I", "Test logon completed, host=" + host + ", port=" + port + ", user=" + auth.getUsername()); } catch (SmbException e) { String[] e_msg = NetworkUtil.analyzeNtStatusCode(e, mContext, url, auth.getUsername()); err_msg = e_msg[0]; util.addDebugMsg(1, "I", "Test logon failed." + "\n" + err_msg); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Thread.currentThread().setUncaughtExceptionHandler(defaultUEH); ntfy.notifyToListener(true, new Object[] { err_msg }); }; public void copySyncTask(SyncTaskItem pli, NotifyEvent p_ntfy) { SyncTaskItem npfli = pli.copySyncTaskItem(); SyncTaskEditor pmsp = SyncTaskEditor.newInstance(); pmsp.showDialog(mFragMgr, pmsp, "COPY", npfli, this, util, commonDlg, p_ntfy); }; public void renameProfile(final SyncTaskItem pli, final NotifyEvent p_ntfy) { // ?? final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(false); dialog.setContentView(R.layout.single_item_input_dlg); LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.single_item_input_dlg_view); ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.single_item_input_title_view); final TextView title = (TextView) dialog.findViewById(R.id.single_item_input_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); // final TextView dlg_msg = (TextView) dialog.findViewById(R.id.single_item_input_msg); final TextView dlg_cmp = (TextView) dialog.findViewById(R.id.single_item_input_name); final Button btn_ok = (Button) dialog.findViewById(R.id.single_item_input_ok_btn); final Button btn_cancel = (Button) dialog.findViewById(R.id.single_item_input_cancel_btn); final EditText etInput = (EditText) dialog.findViewById(R.id.single_item_input_dir); title.setText(mContext.getString(R.string.msgs_rename_profile)); dlg_cmp.setVisibility(TextView.GONE); CommonDialog.setDlgBoxSizeCompact(dialog); etInput.setText(pli.getSyncTaskName()); btn_ok.setEnabled(false); etInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { if (!arg0.toString().equals(pli.getSyncTaskName())) btn_ok.setEnabled(true); else btn_ok.setEnabled(false); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } }); //OK button btn_ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); String new_name = etInput.getText().toString(); pli.setSyncTaskName(new_name); mGp.syncTaskAdapter.sort(); mGp.syncTaskAdapter.notifyDataSetChanged(); saveSyncTaskListToFile(mGp, mContext, util, false, "", "", mGp.syncTaskAdapter.getArrayList(), false); SyncTaskUtility.setAllSyncTaskToUnchecked(true, mGp.syncTaskAdapter); p_ntfy.notifyToListener(true, null); } }); // CANCEL? btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btn_cancel.performClick(); } }); // dialog.setCancelable(false); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); dialog.show(); }; public void ipAddressScanButtonDlg(Dialog dialog) { final TextView dlg_msg = (TextView) dialog.findViewById(R.id.edit_sync_folder_dlg_msg); final EditText edithost = (EditText) dialog.findViewById(R.id.edit_sync_folder_dlg_remote_server); final CheckedTextView ctv_use_port_number = (CheckedTextView) dialog .findViewById(R.id.edit_sync_folder_dlg_ctv_use_remote_port_number); final EditText editport = (EditText) dialog.findViewById(R.id.edit_sync_folder_dlg_remote_port); NotifyEvent ntfy = new NotifyEvent(mContext); //Listen setRemoteShare response ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context arg0, Object[] arg1) { edithost.setText((String) arg1[1]); } @Override public void negativeResponse(Context arg0, Object[] arg1) { dlg_msg.setText(""); } }); String port_num = ""; if (ctv_use_port_number.isChecked()) port_num = editport.getText().toString(); scanRemoteNetworkDlg(ntfy, port_num, false); }; public void invokeSelectRemoteShareDlg(Dialog dialog) { final TextView dlg_msg = (TextView) dialog.findViewById(R.id.edit_sync_folder_dlg_msg); final EditText edituser = (EditText) dialog.findViewById(R.id.edit_sync_folder_dlg_remote_user); final EditText editpass = (EditText) dialog.findViewById(R.id.edit_sync_folder_dlg_remote_pass); final EditText editshare = (EditText) dialog.findViewById(R.id.edit_sync_folder_dlg_share_name); final EditText edithost = (EditText) dialog.findViewById(R.id.edit_sync_folder_dlg_remote_server); final CheckedTextView ctv_use_userpass = (CheckedTextView) dialog .findViewById(R.id.edit_sync_folder_dlg_ctv_use_user_pass); final EditText editport = (EditText) dialog.findViewById(R.id.edit_sync_folder_dlg_remote_port); final CheckedTextView ctv_use_port_number = (CheckedTextView) dialog .findViewById(R.id.edit_sync_folder_dlg_ctv_use_remote_port_number); String remote_addr, remote_user = "", remote_pass = "", remote_host; if (ctv_use_userpass.isChecked()) { remote_user = edituser.getText().toString(); remote_pass = editpass.getText().toString(); } if (edithost.getText().toString().length() < 1) { dlg_msg.setText(mContext.getString(R.string.msgs_audit_hostname_not_spec)); return; } if (hasInvalidChar(remote_pass, new String[] { "\t" })) { remote_pass = removeInvalidChar(remote_pass); dlg_msg.setText( String.format(mContext.getString(R.string.msgs_audit_msgs_password1), detectedInvalidCharMsg)); editpass.setText(remote_pass); editpass.requestFocus(); return; } if (hasInvalidChar(remote_user, new String[] { "\t" })) { remote_user = removeInvalidChar(remote_user); dlg_msg.setText( String.format(mContext.getString(R.string.msgs_audit_msgs_username1), detectedInvalidCharMsg)); edituser.setText(remote_user); edituser.requestFocus(); return; } setSmbUserPass(remote_user, remote_pass); String t_url = ""; if (NetworkUtil.isValidIpAddress(edithost.getText().toString())) { remote_addr = edithost.getText().toString(); t_url = remote_addr; } else { remote_host = edithost.getText().toString(); t_url = remote_host; } String h_port = ""; if (ctv_use_port_number.isChecked()) { if (editport.getText().length() > 0) h_port = ":" + editport.getText().toString(); else { dlg_msg.setText(mContext.getString(R.string.msgs_audit_hostport_not_spec)); return; } } String remurl = "smb://" + t_url + h_port + "/"; NotifyEvent ntfy = new NotifyEvent(mContext); //Listen setRemoteShare response ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context arg0, Object[] arg1) { editshare.setText((String) arg1[0]); } @Override public void negativeResponse(Context arg0, Object[] arg1) { if (arg1 != null) dlg_msg.setText((String) arg1[0]); else dlg_msg.setText(""); } }); selectRemoteShareDlg(remurl, "", ntfy); }; public void setSmbUserPass(String user, String pass) { smbUser = user; smbPass = pass; }; public void selectRemoteDirectory(Dialog dialog) { final TextView dlg_msg = (TextView) dialog.findViewById(R.id.edit_sync_folder_dlg_msg); final EditText edithost = (EditText) dialog.findViewById(R.id.edit_sync_folder_dlg_remote_server); final EditText edituser = (EditText) dialog.findViewById(R.id.edit_sync_folder_dlg_remote_user); final EditText editpass = (EditText) dialog.findViewById(R.id.edit_sync_folder_dlg_remote_pass); final EditText editshare = (EditText) dialog.findViewById(R.id.edit_sync_folder_dlg_share_name); final EditText editdir = (EditText) dialog.findViewById(R.id.edit_sync_folder_dlg_directory_name); final CheckedTextView ctv_use_userpass = (CheckedTextView) dialog .findViewById(R.id.edit_sync_folder_dlg_ctv_use_user_pass); final EditText editport = (EditText) dialog.findViewById(R.id.edit_sync_folder_dlg_remote_port); final CheckedTextView ctv_use_port_number = (CheckedTextView) dialog .findViewById(R.id.edit_sync_folder_dlg_ctv_use_remote_port_number); String remote_addr, remote_user = "", remote_pass = "", remote_share, remote_host; if (ctv_use_userpass.isChecked()) { remote_user = edituser.getText().toString(); remote_pass = editpass.getText().toString(); } remote_share = editshare.getText().toString(); if (edithost.getText().toString().length() < 1) { dlg_msg.setText(mContext.getString(R.string.msgs_audit_hostname_not_spec)); return; } if (remote_share.length() < 1) { dlg_msg.setText(mContext.getString(R.string.msgs_audit_share_not_spec)); return; } if (hasInvalidChar(remote_pass, new String[] { "\t" })) { remote_pass = removeInvalidChar(remote_pass); dlg_msg.setText( String.format(mContext.getString(R.string.msgs_audit_msgs_password1), detectedInvalidCharMsg)); editpass.setText(remote_pass); editpass.requestFocus(); return; } if (hasInvalidChar(remote_user, new String[] { "\t" })) { remote_user = removeInvalidChar(remote_user); dlg_msg.setText( String.format(mContext.getString(R.string.msgs_audit_msgs_username1), detectedInvalidCharMsg)); edituser.setText(remote_user); edituser.requestFocus(); return; } String p_dir = editdir.getText().toString(); setSmbUserPass(remote_user, remote_pass); String t_url = ""; if (NetworkUtil.isValidIpAddress(edithost.getText().toString())) { remote_addr = edithost.getText().toString(); t_url = remote_addr; } else { remote_host = edithost.getText().toString(); t_url = remote_host; } String h_port = ""; if (ctv_use_port_number.isChecked()) { if (editport.getText().length() > 0) h_port = ":" + editport.getText().toString(); else { dlg_msg.setText(mContext.getString(R.string.msgs_audit_hostport_not_spec)); return; } } String remurl = "smb://" + t_url + h_port + "/" + remote_share + "/"; NotifyEvent ntfy = new NotifyEvent(mContext); //Listen setRemoteShare response ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context arg0, Object[] arg1) { editdir.setText((String) arg1[0]); } @Override public void negativeResponse(Context arg0, Object[] arg1) { if (arg1 != null) dlg_msg.setText((String) arg1[0]); else dlg_msg.setText(""); } }); setRemoteDir(remurl, "", p_dir, ntfy); }; // static public SyncTaskItem getProfile(GlobalParameters gp, String name) { // SyncTaskItem pli=null; // for (int i=0;i<gp.syncTaskAdapter.getCount();i++) { // if (gp.syncTaskAdapter.getItem(i).getSyncTaskName().equals(name)) { // pli=gp.syncTaskAdapter.getItem(i); // break; // } // } // return pli; // }; static public SyncTaskItem getExternalSdcardUsedSyncProfile(GlobalParameters gp) { SyncTaskItem pli = null; for (int i = 0; i < gp.syncTaskAdapter.getCount(); i++) { if (gp.syncTaskAdapter.getItem(i).getTargetFolderType().equals(SyncTaskItem.SYNC_FOLDER_TYPE_SDCARD)) { pli = gp.syncTaskAdapter.getItem(i); break; } } return pli; }; public void invokeEditDirFilterDlg(Dialog dialog, SyncTaskItem sti, String task_name, final ArrayList<String> n_dir_filter) { // final CheckedTextView cbmpd = (CheckedTextView)dialog.findViewById(R.id.sync_profile_master_dir_cb); // final TextView dlg_dir_filter=(TextView) dialog.findViewById(R.id.sync_filter_summary_dir_filter); final Button dlg_dir_filter = (Button) dialog.findViewById(R.id.sync_filter_edit_dir_filter_btn); // final TextView dlg_msg=(TextView) dialog.findViewById(R.id.edit_sync_task_msg); NotifyEvent ntfy = new NotifyEvent(mContext); //Listen setRemoteShare response ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context arg0, Object[] arg1) { String d_fl = ""; if (n_dir_filter != null) { String cn = ""; for (int i = 0; i < n_dir_filter.size(); i++) { d_fl += cn + n_dir_filter.get(i).substring(1, n_dir_filter.get(i).length()); cn = ","; } } if (d_fl.length() == 0) d_fl = mContext.getString(R.string.msgs_filter_list_dlg_not_specified); dlg_dir_filter.setText(d_fl); } @Override public void negativeResponse(Context arg0, Object[] arg1) { } }); editDirFilterDlg(sti, task_name, n_dir_filter, ntfy); }; public void editFileFilterDlg(final ArrayList<String> file_filter, final NotifyEvent p_ntfy) { ArrayList<FilterListItem> filterList = new ArrayList<FilterListItem>(); final AdapterFilterList filterAdapter; // ?? 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); Button dirbtn = (Button) dialog.findViewById(R.id.filter_select_edit_dir_btn); dirbtn.setVisibility(Button.GONE); filterAdapter = new AdapterFilterList(mContext, R.layout.filter_list_item_view, filterList); ListView lv = (ListView) dialog.findViewById(R.id.filter_select_edit_listview); for (int i = 0; i < file_filter.size(); i++) { String inc = file_filter.get(i).substring(0, 1); String filter = file_filter.get(i).substring(1, file_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); // filterAdapter.getFileFilter().filter("D"); // lv.setTextFilterEnabled(false); // lv.setDivider(new ColorDrawable(Color.WHITE)); title.setText(mContext.getString(R.string.msgs_filter_list_dlg_file_filter)); final TextView dlg_msg = (TextView) dialog.findViewById(R.id.filter_select_edit_msg); CommonDialog.setDlgBoxSizeLimit(dialog, true); // CommonDialog.setDlgBoxSizeCompact(dialog); 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? addBtn.setEnabled(false); 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); btn_ok.setEnabled(true); } else { dlg_msg.setText(""); addBtn.setEnabled(true); btn_ok.setEnabled(false); } } else { addBtn.setEnabled(false); 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.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dlg_msg.setText(""); String newfilter = et_filter.getText().toString().trim(); 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()); }; }); btn_ok.setEnabled(true); } }); // 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(); file_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; file_filter.add(inc + filterAdapter.getItem(i).getFilter()); } } } p_ntfy.notifyToListener(true, null); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); dialog.show(); }; 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; // ?? 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(); }; private void editDirFilter(final int edit_idx, final AdapterFilterList fa, final FilterListItem fli, final String filter) { // ?? final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(false); dialog.setContentView(R.layout.filter_edit_dlg); LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.filter_edit_dlg_view); ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.filter_edit_dlg_title_view); final TextView title = (TextView) dialog.findViewById(R.id.filter_edit_dlg_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); CommonDialog.setDlgBoxSizeCompact(dialog); final EditText et_filter = (EditText) dialog.findViewById(R.id.filter_edit_dlg_filter); et_filter.setText(filter); // CANCEL? final Button btn_cancel = (Button) dialog.findViewById(R.id.filter_edit_dlg_cancel_btn); 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? Button btn_ok = (Button) dialog.findViewById(R.id.filter_edit_dlg_ok_btn); btn_ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { TextView dlg_msg = (TextView) dialog.findViewById(R.id.filter_edit_dlg_msg); String newfilter = et_filter.getText().toString(); if (!filter.equals(newfilter)) { if (isFilterExists(newfilter, fa)) { String mtxt = mContext.getString(R.string.msgs_filter_list_duplicate_filter_specified); dlg_msg.setText(String.format(mtxt, newfilter)); return; } } dialog.dismiss(); fa.remove(fli); fa.insert(fli, edit_idx); fli.setFilter(newfilter); et_filter.setText(""); fa.setNotifyOnChange(true); fa.sort(new Comparator<FilterListItem>() { @Override public int compare(FilterListItem lhs, FilterListItem rhs) { return lhs.getFilter().compareToIgnoreCase(rhs.getFilter()); }; }); // p_ntfy.notifyToListener(true, null); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); dialog.show(); }; private boolean isFilterExists(String nf, AdapterFilterList fa) { if (fa.getCount() == 0) return false; for (int i = 0; i < fa.getCount(); i++) { if (!fa.getItem(i).isDeleted()) if (fa.getItem(i).getFilter().equals(nf)) return true; } return false; }; static public SyncTaskItem getSyncTaskByName(ArrayList<SyncTaskItem> t_prof, String task_name) { SyncTaskItem stli = null; for (SyncTaskItem li : t_prof) { if (li.getSyncTaskName().equals(task_name)) { stli = li; break; } } return stli; }; static public SyncTaskItem getSyncTaskByName(AdapterSyncTask t_prof, String task_name) { return getSyncTaskByName(t_prof.getArrayList(), task_name); }; private void listDirFilter(SyncTaskItem sti, String prof_master, final ArrayList<String> dir_filter, AdapterFilterList fla, final NotifyEvent p_ntfy) { if (sti.getMasterFolderType().equals(SyncTaskItem.SYNC_FOLDER_TYPE_INTERNAL)) { listDirFilterLocal(sti, prof_master, dir_filter, fla, p_ntfy); } else if (sti.getMasterFolderType().equals(SyncTaskItem.SYNC_FOLDER_TYPE_USB_SAF)) { listDirFilterLocal(sti, prof_master, dir_filter, fla, p_ntfy); } else if (sti.getMasterFolderType().equals(SyncTaskItem.SYNC_FOLDER_TYPE_SDCARD)) { listDirFilterLocal(sti, prof_master, dir_filter, fla, p_ntfy); } else if (sti.getMasterFolderType().equals(SyncTaskItem.SYNC_FOLDER_TYPE_SMB)) { listDirFilterSMB(sti, prof_master, dir_filter, fla, p_ntfy); } }; 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; //?? 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; }; 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 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); }; private boolean addDirFilter(boolean check_only, TreeFilelistAdapter tfa, AdapterFilterList fla, String cdir, TextView dlg_msg) { String sel = "", add_msg = ""; //check duplicate entry for (int i = 0; i < tfa.getCount(); i++) { if (tfa.getDataItem(i).isChecked()) { if (tfa.getDataItem(i).getPath().length() == 1) sel = tfa.getDataItem(i).getName(); else sel = tfa.getDataItem(i).getPath() + tfa.getDataItem(i).getName(); sel = sel.replaceFirst(cdir, ""); if (isFilterExists(sel, fla)) { String mtxt = mContext.getString(R.string.msgs_filter_list_duplicate_filter_specified); dlg_msg.setText(String.format(mtxt, sel)); return false; } if (!check_only) { fla.add(new FilterListItem(sel, true)); if (add_msg.length() == 0) add_msg = sel; else add_msg = add_msg + "," + sel; } } } if (!check_only) { fla.setNotifyOnChange(true); fla.sort(new Comparator<FilterListItem>() { @Override public int compare(FilterListItem lhs, FilterListItem rhs) { return lhs.getFilter().compareToIgnoreCase(rhs.getFilter()); }; }); dlg_msg.setText(String.format(mContext.getString(R.string.msgs_filter_list_dlg_filter_added), add_msg)); } return true; }; private String detectedInvalidChar = "", detectedInvalidCharMsg = ""; public boolean hasInvalidChar(String in_text, String[] invchar) { for (int i = 0; i < invchar.length; i++) { if (in_text.indexOf(invchar[i]) >= 0) { if (invchar[i].equals("\t")) { detectedInvalidCharMsg = "TAB"; detectedInvalidChar = "\t"; } else { detectedInvalidCharMsg = detectedInvalidChar = invchar[i]; } return true; } } return false; }; public String getInvalidCharMsg() { return detectedInvalidCharMsg; }; public String removeInvalidChar(String in) { if (detectedInvalidChar == null || detectedInvalidChar.length() == 0) return in; String out = ""; for (int i = 0; i < in.length(); i++) { if (in.substring(i, i + 1).equals(detectedInvalidChar)) { //ignore } else { out = out + in.substring(i, i + 1); } } return out; } public boolean isSyncTaskExists(String prof_name) { return isSyncTaskExists(prof_name, mGp.syncTaskAdapter.getArrayList()); }; static public boolean isSyncTaskExists(String prof_name, ArrayList<SyncTaskItem> pfl) { boolean dup = false; for (int i = 0; i <= pfl.size() - 1; i++) { SyncTaskItem item = pfl.get(i); String prof_chk = item.getSyncTaskName(); if (prof_chk.equals(prof_name)) { dup = true; break; } } return dup; }; static public boolean isSyncTaskAuto(GlobalParameters gp, String prof_name) { boolean active = false; for (int i = 0; i <= gp.syncTaskAdapter.getCount() - 1; i++) { String item_key = gp.syncTaskAdapter.getItem(i).getSyncTaskName(); if (item_key.equals(prof_name)) { active = gp.syncTaskAdapter.getItem(i).isSyncTaskAuto(); } } return active; }; static public boolean isSyncTaskSelected(AdapterSyncTask pa) { boolean result = false; for (int i = 0; i < pa.getCount(); i++) { if (pa.getItem(i).isChecked()) { result = true; break; } } return result; }; static public int getSyncTaskSelectedItemCount(AdapterSyncTask pa) { int result = 0; for (int i = 0; i < pa.getCount(); i++) { if (pa.getItem(i).isChecked()) { result++; } } return result; }; public void scanRemoteNetworkDlg(final NotifyEvent p_ntfy, String port_number, boolean scan_start) { //?? 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(); }; private int mScanCompleteCount = 0, mScanAddrCount = 0; private String mLockScanCompleteCount = ""; 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); 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(); }; private void closeScanRemoteNetworkProgressDlg(final Dialog dialog, final NotifyEvent p_ntfy, final ListView lv_ipaddr, final AdapterScanAddressResultList adap, final TextView tvmsg) { final LinearLayout ll_addr = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_scan_address); final LinearLayout ll_prog = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_progress); final Button btn_scan = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_ok); final Button btn_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_cancel); ll_addr.setVisibility(LinearLayout.VISIBLE); ll_prog.setVisibility(LinearLayout.GONE); btn_scan.setVisibility(Button.VISIBLE); btn_cancel.setVisibility(Button.VISIBLE); adap.setButtonEnabled(true); dialog.setOnKeyListener(null); dialog.setCancelable(true); if (p_ntfy != null) p_ntfy.notifyToListener(true, null); }; private void startRemoteNetworkScanThread(final Handler handler, final ThreadCtrl tc, final Dialog dialog, final NotifyEvent p_ntfy, final ListView lv_ipaddr, final AdapterScanAddressResultList adap, final TextView tvmsg, final String addr, final ArrayList<ScanAddressResultListItem> ipAddressList, final String scan_port) { final String scan_prog = mContext.getString(R.string.msgs_ip_address_scan_progress); Thread th = new Thread(new Runnable() { @Override public void run() { if (isIpAddrSmbHost(addr, scan_port)) { final String srv_name = getSmbHostName(addr); handler.post(new Runnable() {// UI thread @Override public void run() { synchronized (mLockScanCompleteCount) { mScanCompleteCount++; ScanAddressResultListItem li = new ScanAddressResultListItem(); li.server_address = addr; li.server_name = srv_name; ipAddressList.add(li); Collections.sort(ipAddressList, new Comparator<ScanAddressResultListItem>() { @Override public int compare(ScanAddressResultListItem lhs, ScanAddressResultListItem rhs) { return lhs.server_address.compareTo(rhs.server_address); } }); } } }); } else { synchronized (mLockScanCompleteCount) { mScanCompleteCount++; } } handler.post(new Runnable() {// UI thread @Override public void run() { synchronized (mLockScanCompleteCount) { lv_ipaddr.setSelection(lv_ipaddr.getCount()); adap.notifyDataSetChanged(); String p_txt = String.format(scan_prog, (mScanCompleteCount * 100) / mScanAddrCount); tvmsg.setText(p_txt); if (mScanCompleteCount >= mScanAddrCount) { closeScanRemoteNetworkProgressDlg(dialog, p_ntfy, lv_ipaddr, adap, tvmsg); } } } }); } }); th.start(); }; private boolean isIpAddrSmbHost(String address, String scan_port) { boolean smbhost = false; // boolean reachable=NetworkUtil.ping(address); // if (reachable) { // } if (scan_port.equals("")) { if (!NetworkUtil.isIpAddressAndPortConnected(address, 139, 3000)) { smbhost = NetworkUtil.isIpAddressAndPortConnected(address, 445, 3000); } else smbhost = true; } else { smbhost = NetworkUtil.isIpAddressAndPortConnected(address, Integer.parseInt(scan_port), 3000); } util.addDebugMsg(2, "I", "isIpAddrSmbHost Address=" + address + ", port=" + scan_port + ", smbhost=" + smbhost); return smbhost; }; private String getSmbHostName(String address) { String srv_name = NetworkUtil.getSmbHostNameFromAddress(address); util.addDebugMsg(1, "I", "getSmbHostName Address=" + address + ", name=" + srv_name); return srv_name; }; 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(); 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; }; private ArrayList<TreeFilelistItem> createLocalFilelist(boolean dironly, String url, String dir) { ArrayList<TreeFilelistItem> tfl = new ArrayList<TreeFilelistItem>(); ; String tdir, fp; if (dir.equals("")) fp = tdir = "/"; else { tdir = dir; fp = dir + "/"; } File lf = new File(url + tdir); final File[] ff = lf.listFiles(); TreeFilelistItem tfi = null; if (ff != null) { for (int i = 0; i < ff.length; i++) { // Log.v("","name="+ff[i].getName()+", d="+ff[i].isDirectory()+", r="+ff[i].canRead()); if (ff[i].canRead()) { int dirct = 0; if (ff[i].isDirectory()) { File tlf = new File(url + tdir + "/" + ff[i].getName()); File[] lfl = tlf.listFiles(); if (lfl != null) { for (int j = 0; j < lfl.length; j++) { if (dironly) { if (lfl[j].isDirectory()) dirct++; } else dirct++; } } } tfi = new TreeFilelistItem(ff[i].getName(), "" + ", ", ff[i].isDirectory(), 0, 0, false, ff[i].canRead(), ff[i].canWrite(), ff[i].isHidden(), fp, 0); tfi.setSubDirItemCount(dirct); if (dironly) { if (ff[i].isDirectory()) tfl.add(tfi); } else tfl.add(tfi); } } Collections.sort(tfl); } return tfl; }; public void selectLocalDirDlg(final String url, final String dir, String p_dir, final NotifyEvent p_ntfy) { //?? 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; }; private void createRemoteFileList(String remurl, String remdir, final NotifyEvent p_event, boolean readSubDirCnt) { final ArrayList<TreeFilelistItem> remoteFileList = new ArrayList<TreeFilelistItem>(); final ThreadCtrl tc = new ThreadCtrl(); tc.setEnabled(); tc.setThreadResultSuccess(); // ?? final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(false); dialog.setContentView(R.layout.progress_spin_dlg); LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.progress_spin_dlg_view); ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.progress_spin_dlg_title_view); final TextView title = (TextView) dialog.findViewById(R.id.progress_spin_dlg_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); title.setText(R.string.msgs_progress_spin_dlg_filelist_getting); final Button btn_cancel = (Button) dialog.findViewById(R.id.progress_spin_dlg_btn_cancel); btn_cancel.setText(R.string.msgs_progress_spin_dlg_filelist_cancel); // (dialog.context.findViewById(R.id.progress_spin_dlg)).setVisibility(TextView.GONE); // (dialog.context.findViewById(R.id.progress_spin_dlg)).setEnabled(false); CommonDialog.setDlgBoxSizeCompact(dialog); // CANCEL? btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { tc.setDisabled();//disableAsyncTask(); btn_cancel.setText(mContext.getString(R.string.msgs_progress_dlg_canceling)); btn_cancel.setEnabled(false); util.addDebugMsg(1, "W", "Sharelist is cancelled."); } }); dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btn_cancel.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); // dialog.show(); showDelayedProgDlg? final Handler hndl = new Handler(); NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { hndl.post(new Runnable() { @Override public void run() { dialog.dismiss(); String err; util.addDebugMsg(1, "I", "FileListThread result=" + tc.getThreadResult() + "," + "msg=" + tc.getThreadMessage() + ", enable=" + tc.isEnabled()); if (tc.isThreadResultSuccess()) { p_event.notifyToListener(true, new Object[] { remoteFileList }); } else { if (tc.isThreadResultCancelled()) err = mContext.getString(R.string.msgs_filelist_cancel); else err = mContext.getString(R.string.msgs_filelist_error) + "\n" + tc.getThreadMessage(); p_event.notifyToListener(false, new Object[] { err }); } } }); } @Override public void negativeResponse(Context c, Object[] o) { } }); Thread tf = new Thread(new ReadSmbFilelist(mContext, tc, remurl, remdir, remoteFileList, smbUser, smbPass, ntfy, true, readSubDirCnt, mGp)); tf.start(); // showDelayedProgDlg(200,dialog, tc); dialog.show(); }; // private void showDelayedProgDlg(final int wt, final Dialog dialog, final ThreadCtrl tc) { // final Handler handler=new Handler(); // // new Thread(new Runnable() { // @Override // public void run() {//Non UI thread // try { // Thread.sleep(wt); // } catch (InterruptedException e) // {e.printStackTrace();} // // handler.post(new Runnable() { // @Override // public void run() {// UI thread // if (tc.isEnabled()) if (dialog!=null) dialog.show(); // } // }); // } // }) // .start(); // } public void selectRemoteShareDlg(final String remurl, String remdir, final NotifyEvent p_ntfy) { NotifyEvent ntfy = new NotifyEvent(mContext); // set thread response ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { final ArrayList<String> rows = new ArrayList<String>(); @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() && !rfl.get(i).getName().endsWith("$")) // !rfl.get(i).getName().startsWith("IPC$")) rows.add(rfl.get(i).getName().replaceAll("/", "")); } boolean wk_list_empty = false; if (rows.size() < 1) { wk_list_empty = true; rows.add(mContext.getString(R.string.msgs_dir_empty)); } final boolean list_empty = wk_list_empty; Collections.sort(rows, String.CASE_INSENSITIVE_ORDER); //?? 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_share)); subtitle.setVisibility(TextView.GONE); // if (rows.size()<=2) // ((TextView)dialog.findViewById(R.id.item_select_list_dlg_spacer)) // .setVisibility(TextView.VISIBLE); final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn); final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn); btn_ok.setEnabled(false); CommonDialog.setDlgBoxSizeLimit(dialog, false); final ListView lv = (ListView) dialog.findViewById(android.R.id.list); if (!list_empty) { lv.setAdapter( new ArrayAdapter<String>(mContext, R.layout.custom_simple_list_item_checked, rows)); // android.R.layout.simple_list_item_checked,rows)); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); } else { lv.setAdapter(new ArrayAdapter<String>(mContext, R.layout.simple_list_item_1o, rows)); } lv.setScrollingCacheEnabled(false); lv.setScrollbarFadingEnabled(false); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> items, View view, int idx, long id) { if (rows.get(idx).startsWith("---")) return; if (!list_empty) btn_ok.setEnabled(true); } }); //CANCEL? btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); p_ntfy.notifyToListener(false, null); } }); //OK? btn_ok.setVisibility(Button.VISIBLE); btn_ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); SparseBooleanArray checked = lv.getCheckedItemPositions(); for (int i = 0; i <= rows.size(); i++) { if (checked.get(i) == true) { p_ntfy.notifyToListener(true, new Object[] { rows.get(i) }); break; } } } }); // 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, false); }; 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 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; }; private void expandHideRemoteDirTree(String remurl, final int pos, final TreeFilelistItem tfi, final TreeFilelistAdapter tfa) { if (tfi.getSubDirItemCount() == 0) return; if (tfi.isChildListExpanded()) { tfa.hideChildItem(tfi, pos); } else { if (tfi.isSubDirLoaded()) tfa.reshowChildItem(tfi, pos); else { if (tfi.isSubDirLoaded()) tfa.reshowChildItem(tfi, pos); else { NotifyEvent ne = new NotifyEvent(mContext); ne.setListener(new NotifyEventListener() { @SuppressWarnings("unchecked") @Override public void positiveResponse(Context c, Object[] o) { tfa.addChildItem(tfi, (ArrayList<TreeFilelistItem>) o[0], pos); } @Override public void negativeResponse(Context c, Object[] o) { } }); createRemoteFileList(remurl, tfi.getPath() + tfi.getName() + "/", ne, true); } } } }; private void expandHideLocalDirTree(boolean dironly, String lclurl, final int pos, final TreeFilelistItem tfi, final TreeFilelistAdapter tfa) { if (tfi.getSubDirItemCount() == 0) return; if (tfi.isChildListExpanded()) { tfa.hideChildItem(tfi, pos); } else { if (tfi.isSubDirLoaded()) tfa.reshowChildItem(tfi, pos); else { if (tfi.isSubDirLoaded()) tfa.reshowChildItem(tfi, pos); else { ArrayList<TreeFilelistItem> ntfl = createLocalFilelist(dironly, lclurl, tfi.getPath() + tfi.getName()); tfa.addChildItem(tfi, ntfl, pos); } } } }; public static ArrayList<SyncTaskItem> createSyncTaskList(Context context, GlobalParameters gp, CommonUtilities util, boolean sdcard, String fp, ArrayList<PreferenceParmListIItem> ispl) { ArrayList<SyncTaskItem> sync = new ArrayList<SyncTaskItem>(); if (ispl != null) ispl.clear(); if (sdcard) { File sf = new File(fp); if (sf.exists()) { CipherParms cp = null; boolean prof_encrypted = isSyncTaskListFileEncrypted(fp); if (prof_encrypted) { cp = EncryptUtil.initDecryptEnv(gp.profileKeyPrefix + gp.profilePassword); } try { BufferedReader br; br = new BufferedReader(new FileReader(fp), 8192); String pl; while ((pl = br.readLine()) != null) { String prof_pre = ""; prof_pre = SMBSYNC_PROF_VER1; if (!pl.startsWith(prof_pre + SMBSYNC_PROF_ENC) && !pl.startsWith(prof_pre + SMBSYNC_PROF_DEC)) { if (prof_encrypted) { String enc_str = pl.replace(prof_pre, ""); byte[] enc_array = Base64Compat.decode(enc_str, Base64Compat.NO_WRAP); String dec_str = EncryptUtil.decrypt(enc_array, cp); addSyncTaskList(prof_pre + dec_str, sync, ispl); } else { addSyncTaskList(pl, sync, ispl); } } } br.close(); } catch (IOException e) { e.printStackTrace(); } } else { util.addLogMsg("E", String.format(context.getString(R.string.msgs_create_profile_not_found), fp)); } } else { BufferedReader br; String pf = SMBSYNC_PROFILE_FILE_NAME_V1; try { File lf = new File(gp.applicationRootDirectory + "/" + pf); if (lf.exists()) { br = new BufferedReader(new FileReader(gp.applicationRootDirectory + "/" + pf), 8192); String pl; while ((pl = br.readLine()) != null) { // Log.v("","read pl="+pl); addSyncTaskList(pl, sync, ispl); } br.close(); } else { util.addDebugMsg(1, "W", "profile not found, empty profile list created. fn=" + gp.applicationRootDirectory + "/" + pf); } } catch (IOException e) { e.printStackTrace(); } if (sync.size() == 0) { if (BUILD_FOR_AMAZON) { //????? } else { if (gp.sampleProfileCreateRequired) { createSampleSyncTask(sync); saveSyncTaskListToFile(gp, context, util, false, "", "", sync, false); gp.sampleProfileCreateRequired = false; } } } } sortSyncTaskList(sync); return sync; }; private static void createSampleSyncTask(ArrayList<SyncTaskItem> pfl) { SyncTaskItem stli = null; stli = new SyncTaskItem("DOWNLOAD-MY-PICTURE", true, false); stli.setMasterFolderType(SyncTaskItem.SYNC_FOLDER_TYPE_SMB); stli.setMasterRemoteAddr("192.168.0.2"); stli.setMasterSmbUser("TESTUSER"); stli.setMasterSmbPassword("PSWD"); stli.setMasterSmbShareName("SHARE"); stli.setSyncTestMode(false); stli.setMasterDirectoryName("Android/Pictures"); stli.setTargetFolderType(SyncTaskItem.SYNC_FOLDER_TYPE_INTERNAL); stli.setTargetDirectoryName("Pictures"); stli.setSyncTaskPosition(0); pfl.add(stli); stli = new SyncTaskItem("BACKUP-MY-PICTURE", true, false); stli.setMasterFolderType(SyncTaskItem.SYNC_FOLDER_TYPE_INTERNAL); stli.setMasterDirectoryName("DCIM"); stli.setTargetFolderType(SyncTaskItem.SYNC_FOLDER_TYPE_SMB); stli.setTargetRemoteAddr("192.168.0.2"); stli.setTargetSmbUser("TESTUSER"); stli.setTargetSmbPassword("PSWD"); stli.setTargetSmbShareName("SHARE"); stli.setSyncTestMode(false); stli.setTargetDirectoryName("Android/DCIM"); stli.setSyncTaskPosition(1); pfl.add(stli); stli = new SyncTaskItem("BACKUP-TO-SDCARD", true, false); stli.setMasterFolderType(SyncTaskItem.SYNC_FOLDER_TYPE_INTERNAL); stli.setMasterDirectoryName("Pictures"); stli.setTargetFolderType(SyncTaskItem.SYNC_FOLDER_TYPE_SDCARD); stli.setTargetDirectoryName("Pictures"); stli.setSyncTestMode(false); stli.setSyncTaskPosition(2); pfl.add(stli); Collections.sort(pfl); }; static public void sortSyncTaskList(ArrayList<SyncTaskItem> items) { Collections.sort(items, new Comparator<SyncTaskItem>() { @Override public int compare(SyncTaskItem l_item, SyncTaskItem r_item) { if (l_item.getSyncTaskPosition() == r_item.getSyncTaskPosition()) return l_item.getSyncTaskName().compareToIgnoreCase(r_item.getSyncTaskName()); else { String l_key = String.format("%3d", l_item.getSyncTaskPosition()) + l_item.getSyncTaskName(); String r_key = String.format("%3d", r_item.getSyncTaskPosition()) + r_item.getSyncTaskName(); return l_key.compareToIgnoreCase(r_key); } } }); for (int i = 0; i < items.size(); i++) items.get(i).setSyncTaskPosition(i); }; private static void addSyncTaskList(String pl, ArrayList<SyncTaskItem> sync, ArrayList<PreferenceParmListIItem> ispl) { if (pl.startsWith(SMBSYNC_PROF_VER1)) { if (pl.length() > 10) { addSyncTaskListVer1(pl.replace(SMBSYNC_PROF_VER1, ""), sync); if (ispl != null) addImportSettingsParm(pl, ispl); } } }; private static void addSyncTaskListVer1(String pl, ArrayList<SyncTaskItem> sync) { //Extract ArrayList<String> field String list1 = "", list2 = "", list3 = "", npl = ""; if (pl.indexOf("[") >= 0) { // found first List list1 = pl.substring(pl.indexOf("[") + 1, pl.indexOf("]")); npl = pl.replace("[" + list1 + "]\t", ""); if (npl.indexOf("[") >= 0) { // found second List list2 = npl.substring(npl.indexOf("[") + 1, npl.indexOf("]")); npl = npl.replace("[" + list2 + "]\t", ""); } if (npl.indexOf("[") >= 0) { // found third List list3 = npl.substring(npl.indexOf("[") + 1, npl.indexOf("]")); npl = npl.replace("[" + list3 + "]\t", ""); } } else npl = pl; // Log.v("","pl="+pl); // Log.v("","npl="+npl); String[] tmp_pl = npl.split("\t");// {"type","name","active",options...}; String[] parm = new String[100]; for (int i = 0; i < 100; i++) parm[i] = ""; for (int i = 0; i < tmp_pl.length; i++) { if (tmp_pl[i] == null) parm[i] = ""; else { if (tmp_pl[i] == null) parm[i] = ""; else parm[i] = convertToSpecChar(tmp_pl[i].trim()); } // Log.v("","i="+i+", "+parm[i]); } if (parm[0].equals(SMBSYNC_PROF_TYPE_SETTINGS)) return; //ignore settings entry if (parm[0].equals(SMBSYNC_PROF_TYPE_SYNC)) {//Sync ArrayList<String> ff = new ArrayList<String>(); ArrayList<String> df = new ArrayList<String>(); ArrayList<String> wifi_wl = new ArrayList<String>(); if (list1.length() != 0) { String[] fp = list1.split("\t"); for (int i = 0; i < fp.length; i++) ff.add(convertToSpecChar(fp[i])); } else ff.clear(); if (list2.length() != 0) { String[] dp = list2.split("\t"); for (int i = 0; i < dp.length; i++) df.add(convertToSpecChar(dp[i])); } else df.clear(); if (list3.length() != 0) { String[] wl = list3.split("\t"); for (int i = 0; i < wl.length; i++) wifi_wl.add(convertToSpecChar(wl[i])); } else wifi_wl.clear(); SyncTaskItem stli = new SyncTaskItem(parm[1], parm[2].equals("0") ? false : true, false); stli.setSyncTaskType(parm[3]); stli.setMasterFolderType(parm[4]); stli.setMasterSmbUser(parm[5]); stli.setMasterSmbPassword(parm[6]); stli.setMasterSmbShareName(parm[7]); stli.setMasterDirectoryName(parm[8]); stli.setMasterRemoteAddr(parm[9]); stli.setMasterRemotePort(parm[10]); stli.setMasterRemoteHostname(parm[11]); stli.setMasterRemoteDomain(parm[12]); stli.setTargetFolderType(parm[13]); stli.setTargetSmbUser(parm[14]); stli.setTargetSmbPassword(parm[15]); stli.setTargetSmbShareName(parm[16]); stli.setTargetDirectoryName(parm[17]); stli.setTargetRemoteAddr(parm[18]); stli.setTargetRemotePort(parm[19]); stli.setTargetRemoteHostname(parm[20]); stli.setTargetRemoteDomain(parm[21]); stli.setFileFilter(ff); stli.setDirFilter(df); stli.setSyncWifiConnectionWhiteList(wifi_wl); stli.setSyncProcessRootDirFile(parm[22].equals("1") ? true : false); stli.setSyncProcessOverrideOrDelete(parm[23].equals("1") ? true : false); stli.setSyncConfirmOverrideOrDelete(parm[24].equals("1") ? true : false); stli.setSyncDetectLastModBySmbsync(parm[25].equals("1") ? true : false); stli.setSyncDoNotResetLastModSmbFile(parm[26].equals("1") ? true : false); stli.setSyncRetryCount(parm[27]); stli.setSyncEmptyDirectory(parm[28].equals("1") ? true : false); stli.setSyncHiddenFile(parm[29].equals("1") ? true : false); stli.setSyncHiddenDirectory(parm[30].equals("1") ? true : false); stli.setSyncSubDirectory(parm[31].equals("1") ? true : false); stli.setSyncUseSmallIoBuffer(parm[32].equals("1") ? true : false); stli.setSyncTestMode(parm[33].equals("1") ? true : false); stli.setSyncDifferentFileAllowableTime(Integer.parseInt(parm[34])); stli.setSyncDifferentFileByModTime(parm[35].equals("1") ? true : false); stli.setSyncUseFileCopyByTempName(parm[36].equals("1") ? true : false); stli.setSyncWifiStatusOption(parm[37]); stli.setLastSyncTime(parm[38]); stli.setLastSyncResult(Integer.parseInt(parm[39])); if (!parm[40].equals("") && !parm[40].equals("end")) stli.setSyncTaskPosition(Integer.parseInt(parm[40])); if (!parm[41].equals("") && !parm[41].equals("end")) stli.setMasterFolderUseInternalUsbFolder(parm[41].equals("1") ? true : false); if (!parm[41].equals("") && !parm[42].equals("end")) stli.setTargetFolderUseInternalUsbFolder(parm[42].equals("1") ? true : false); sync.add(stli); } }; private static String convertToSpecChar(String in) { if (in == null || in.length() == 0) return ""; boolean cont = true; String out = in; while (cont) { if (out.indexOf("\u0001") >= 0) out = out.replace("\u0001", "["); else cont = false; } cont = true; while (cont) { if (out.indexOf("\u0002") >= 0) out = out.replace("\u0002", "]"); else cont = false; } return out; }; private static String convertToCodeChar(String in) { if (in == null || in.length() == 0) return ""; boolean cont = true; String out = in; while (cont) { if (out.indexOf("[") >= 0) out = out.replace("[", "\u0001"); else cont = false; } cont = true; while (cont) { if (out.indexOf("]") >= 0) out = out.replace("]", "\u0002"); else cont = false; } return out; }; // public static SyncTaskItem getProfile(String pfn, AdapterSyncTask pa) { // return getProfile(pfn, pa.getArrayList()); // }; // // public static SyncTaskItem getProfile(String pfn, ArrayList<SyncTaskItem> pfl) { // for (int i=0;i<pfl.size();i++) // if (pfl.get(i).getSyncTaskName().equals(pfn)) // return pfl.get(i); // return null; // }; // public static boolean saveSyncTaskListToFile(GlobalParameters mGp, Context c, CommonUtilities util, boolean sdcard, String fd, String fp, ArrayList<SyncTaskItem> pfl, boolean encrypt_required) { boolean result = true; String ofp = ""; PrintWriter pw; BufferedWriter bw = null; try { CipherParms cp = null; if (sdcard) { if (encrypt_required) { cp = EncryptUtil.initEncryptEnv(mGp.profileKeyPrefix + mGp.profilePassword); } File lf = new File(fd); if (!lf.exists()) lf.mkdir(); bw = new BufferedWriter(new FileWriter(fp), 8192); pw = new PrintWriter(bw); ofp = fp; if (encrypt_required) { byte[] enc_array = EncryptUtil.encrypt(SMBSYNC_PROF_ENC, cp); String enc_str = Base64Compat.encodeToString(enc_array, Base64Compat.NO_WRAP); // MiscUtil.hexString("", enc_array, 0, enc_array.length); pw.println(CURRENT_SMBSYNC_PROFILE_VERSION + SMBSYNC_PROF_ENC + enc_str); } else pw.println(CURRENT_SMBSYNC_PROFILE_VERSION + SMBSYNC_PROF_DEC); } else { // OutputStream out = context.openFileOutput(SMBSYNC_PROFILE_FILE_NAME, // Context.MODE_PRIVATE); // pw = new PrintWriter(new OutputStreamWriter(out, "UTF-8")); // ofp=SMBSYNC_PROFILE_FILE_NAME; ofp = mGp.applicationRootDirectory + "/" + CURRENT_SMBSYNC_PROFILE_FILE_NAME; File lf = new File(mGp.applicationRootDirectory); if (!lf.exists()) lf.mkdir(); bw = new BufferedWriter(new FileWriter(ofp), 8192); pw = new PrintWriter(bw); } if (pfl.size() > 0) { String pl; for (int i = 0; i < pfl.size(); i++) { SyncTaskItem item = pfl.get(i); String pl_name = convertToCodeChar(item.getSyncTaskName()); String pl_active = item.isSyncTaskAuto() ? "1" : "0"; String pl_master_folder_type = convertToCodeChar(item.getMasterFolderType()); String pl_master_remote_user_id = convertToCodeChar(item.getMasterRemoteUserID()); String pl_master_remote_password = convertToCodeChar(item.getMasterRemotePassword()); String pl_master_remoteSmbShare = convertToCodeChar(item.getMasterRemoteSmbShareName()); String pl_master_directory_name = convertToCodeChar(item.getMasterDirectoryName()); String pl_master_remote_addr = item.getMasterRemoteAddr(); String pl_master_remote_port = item.getMasterRemotePort(); String pl_master_remote_hostname = item.getMasterRemoteHostname(); String pl_master_use_usb_folder = item.isMasterFolderUseInternalUsbFolder() ? "1" : "0"; String pl_target_folder_type = convertToCodeChar(item.getTargetFolderType()); String pl_target_remote_user_id = convertToCodeChar(item.getTargetRemoteUserID()); String pl_target_remote_password = convertToCodeChar(item.getTargetRemotePassword()); String pl_target_remoteSmbShare = convertToCodeChar(item.getTargetRemoteSmbShareName()); String pl_target_directory_name = convertToCodeChar(item.getTargetDirectoryName()); String pl_target_remote_addr = item.getTargetRemoteAddr(); String pl_target_remote_port = item.getTargetRemotePort(); String pl_target_remote_hostname = item.getTargetRemoteHostname(); String pl_target_use_usb_folder = item.isTargetFolderUseInternalUsbFolder() ? "1" : "0"; String pl_synctype = item.getSyncTaskType(); pl = ""; String fl = "", dl = "", wifi_wl = ""; for (int j = 0; j < item.getFileFilter().size(); j++) { if (fl.length() != 0) fl += "\t"; if (!item.getFileFilter().get(j).equals("")) fl += item.getFileFilter().get(j); } fl = convertToCodeChar(fl); fl = "[" + fl + "]"; for (int j = 0; j < item.getDirFilter().size(); j++) { if (dl.length() != 0) dl += "\t"; if (!item.getDirFilter().get(j).equals("")) dl += item.getDirFilter().get(j); } dl = convertToCodeChar(dl); dl = "[" + dl + "]"; for (int j = 0; j < item.getSyncWifiConnectionWhiteList().size(); j++) { if (wifi_wl.length() != 0) wifi_wl += "\t"; if (!item.getSyncWifiConnectionWhiteList().get(j).equals("")) wifi_wl += item.getSyncWifiConnectionWhiteList().get(j); } wifi_wl = convertToCodeChar(wifi_wl); wifi_wl = "[" + wifi_wl + "]"; String sync_root_dir_file_tobe_processed = item.isSyncProcessRootDirFile() ? "1" : "0"; String sync_process_override_delete = item.isSyncProcessOverrideOrDelete() ? "1" : "0"; String sync_confirm_override_delete = item.isSyncConfirmOverrideOrDelete() ? "1" : "0"; String sync_force_last_mod_use_smbsync = item.isSyncDetectLastModBySmbsync() ? "1" : "0"; String sync_not_used_last_mod_for_remote = item.isSyncDoNotResetLastModSmbFile() ? "1" : "0"; String sync_retry_count = item.getSyncRetryCount(); String sync_sync_empty_dir = item.isSyncEmptyDirectory() ? "1" : "0"; String sync_sync_hidden_file = item.isSyncHiddenFile() ? "1" : "0"; String sync_sync_hidden_dir = item.isSyncHiddenDirectory() ? "1" : "0"; String sync_sync_sub_dir = item.isSyncSubDirectory() ? "1" : "0"; String sync_use_small_io_buf = item.isSyncUseSmallIoBuffer() ? "1" : "0"; String sync_sync_test_mode = item.isSyncTestMode() ? "1" : "0"; String sync_file_copy_by_diff_file = String.valueOf(item.getSyncDifferentFileAllowableTime()); String sync_sync_diff_file_by_last_mod = item.isSyncDifferentFileBySize() ? "1" : "0"; String sync_sync_use_file_copy_by_temp_name = item.isSyncUseFileCopyByTempName() ? "1" : "0"; String sync_sync_wifi_status_option = item.getSyncWifiStatusOption(); String sync_result_last_time = item.getLastSyncTime(); String sync_result_last_status = String.valueOf(item.getLastSyncResult()); String sync_pos = String.valueOf(item.getSyncTaskPosition()); pl = SMBSYNC_PROF_TYPE_SYNC + "\t" + pl_name + "\t" + //1 pl_active + "\t" + //2 pl_synctype + "\t" + //3 pl_master_folder_type + "\t" + //4 pl_master_remote_user_id + "\t" + //5 pl_master_remote_password + "\t" + //6 pl_master_remoteSmbShare + "\t" + //7 pl_master_directory_name + "\t" + //8 pl_master_remote_addr + "\t" + //9 pl_master_remote_port + "\t" + //10 pl_master_remote_hostname + "\t" + //11 item.getMasterRemoteDomain() + "\t" + //12 pl_target_folder_type + "\t" + //13 pl_target_remote_user_id + "\t" + //14 pl_target_remote_password + "\t" + //15 pl_target_remoteSmbShare + "\t" + //16 pl_target_directory_name + "\t" + //17 pl_target_remote_addr + "\t" + //18 pl_target_remote_port + "\t" + //19 pl_target_remote_hostname + "\t" + //20 item.getTargetRemoteDomain() + "\t" + //21 fl + "\t" + dl + "\t" + wifi_wl + "\t" + sync_root_dir_file_tobe_processed + "\t" + //22 sync_process_override_delete + "\t" + //23 sync_confirm_override_delete + "\t" + //24 sync_force_last_mod_use_smbsync + "\t" + //25 sync_not_used_last_mod_for_remote + "\t" + //26 sync_retry_count + "\t" + //27 sync_sync_empty_dir + "\t" + //28 sync_sync_hidden_file + "\t" + //29 sync_sync_hidden_dir + "\t" + //30 sync_sync_sub_dir + "\t" + //31 sync_use_small_io_buf + "\t" + //32 sync_sync_test_mode + "\t" + //33 sync_file_copy_by_diff_file + "\t" + //34 sync_sync_diff_file_by_last_mod + "\t" + //35 sync_sync_use_file_copy_by_temp_name + "\t" + //36 sync_sync_wifi_status_option + "\t" + //37 sync_result_last_time + "\t" + //38 sync_result_last_status + "\t" + //39 sync_pos + "\t" + //40 pl_master_use_usb_folder + "\t" + //41 pl_target_use_usb_folder + "\t" + //42 "end"; // Log.v("","write pl="+pl); util.addDebugMsg(9, "I", "saveProfileToFile=" + pl); if (sdcard) { if (encrypt_required) { String enc = Base64Compat.encodeToString(EncryptUtil.encrypt(pl, cp), Base64Compat.NO_WRAP); pw.println(CURRENT_SMBSYNC_PROFILE_VERSION + enc); } else { pw.println(CURRENT_SMBSYNC_PROFILE_VERSION + pl); } } else { pw.println(CURRENT_SMBSYNC_PROFILE_VERSION + pl); } } } CommonUtilities.saveSettingsParmsToFile(c, pw, encrypt_required, cp); pw.close(); bw.close(); } catch (IOException e) { e.printStackTrace(); util.addLogMsg("E", String.format(mGp.appContext.getString(R.string.msgs_save_to_profile_error), ofp)); util.addLogMsg("E", e.toString()); result = false; } return result; }; static private void addImportSettingsParm(String pl, ArrayList<PreferenceParmListIItem> ispl) { String tmp_ps = pl;//pl.substring(7,pl.length()); String[] tmp_pl = tmp_ps.split("\t");// {"type","name","active",options...}; if (tmp_pl[0] != null && tmp_pl.length >= 5 && tmp_pl[0].equals(SMBSYNC_PROF_TYPE_SETTINGS)) { // String[] val = new String[]{parm[2],parm[3],parm[4]}; PreferenceParmListIItem ppli = new PreferenceParmListIItem(); if (tmp_pl[1] != null) ppli.parms_key = tmp_pl[1]; if (tmp_pl[2] != null) ppli.parms_type = tmp_pl[2]; if (tmp_pl[3] != null) ppli.parms_value = tmp_pl[3]; if (!ppli.parms_key.equals("") && !ppli.parms_type.equals("")) { // Log.v("","key="+tmp_pl[2]+", value="+tmp_pl[4]+", type="+tmp_pl[3]); ispl.add(ppli); } } }; public class FilterAdapterSort implements Comparator<String> { @Override public int compare(String s1, String s2) { return s1.compareTo(s2); } } }