List of usage examples for android.support.v4.content ContextCompat getExternalFilesDirs
public static File[] getExternalFilesDirs(Context context, String str)
From source file:org.digitalcampus.oppia.task.UpgradeManagerTask.java
protected void upgradeV49() { String location = prefs.getString(PrefsActivity.PREF_STORAGE_LOCATION, ""); if ((location == null) || !location.equals("")) { return;/* w w w .ja v a 2 s .c o m*/ } String source = Environment.getExternalStorageDirectory() + File.separator + FileUtils.APP_ROOT_DIR_NAME + File.separator; File[] dirs = ContextCompat.getExternalFilesDirs(ctx, null); if (dirs.length > 0) { String destination = dirs[0].getAbsolutePath(); File downloadSource = new File(source + FileUtils.APP_DOWNLOAD_DIR_NAME); File mediaSource = new File(source + FileUtils.APP_MEDIA_DIR_NAME); File courseSource = new File(source + FileUtils.APP_COURSES_DIR_NAME); publishProgress(this.ctx.getString(R.string.upgradev49_1, "")); try { org.apache.commons.io.FileUtils .forceDelete(new File(destination + File.separator + FileUtils.APP_DOWNLOAD_DIR_NAME)); } catch (IOException e) { // TODO Auto-generated catch block Log.d(TAG, "failed to delete: " + destination + File.separator + FileUtils.APP_DOWNLOAD_DIR_NAME); e.printStackTrace(); } try { org.apache.commons.io.FileUtils .forceDelete(new File(destination + File.separator + FileUtils.APP_MEDIA_DIR_NAME)); } catch (IOException e) { // TODO Auto-generated catch block Log.d(TAG, "failed to delete: " + destination + File.separator + FileUtils.APP_MEDIA_DIR_NAME); e.printStackTrace(); } try { org.apache.commons.io.FileUtils .forceDelete(new File(destination + File.separator + FileUtils.APP_COURSES_DIR_NAME)); } catch (IOException e) { // TODO Auto-generated catch block Log.d(TAG, "failed to delete: " + destination + File.separator + FileUtils.APP_COURSES_DIR_NAME); e.printStackTrace(); } // now copy over try { org.apache.commons.io.FileUtils.moveDirectoryToDirectory(downloadSource, new File(destination), true); Log.d(TAG, "completed"); } catch (IOException e) { // TODO Auto-generated catch block Log.d(TAG, "failed"); e.printStackTrace(); } try { org.apache.commons.io.FileUtils.moveDirectoryToDirectory(mediaSource, new File(destination), true); Log.d(TAG, "completed"); } catch (IOException e) { // TODO Auto-generated catch block Log.d(TAG, "failed"); e.printStackTrace(); } try { org.apache.commons.io.FileUtils.moveDirectoryToDirectory(courseSource, new File(destination), true); Log.d(TAG, "completed"); } catch (IOException e) { // TODO Auto-generated catch block Log.d(TAG, "failed"); e.printStackTrace(); } Editor editor = prefs.edit(); editor.putString(PrefsActivity.PREF_STORAGE_LOCATION, destination); editor.commit(); // delete original dir try { org.apache.commons.io.FileUtils.forceDelete(new File(source)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Log.d(TAG, "failed to delete original file"); } } }
From source file:com.sentaroh.android.Utilities.LocalMountPoint.java
@SuppressLint("SdCardPath") static public ArrayList<String> getLocalMountPointList(Context c) { String pkg_name = c.getClass().getPackage().getName(); String primary_esd = getExternalStorageDir(); ArrayList<String> ml = new ArrayList<String>(); addMountPointPrimary(primary_esd, ml); File lf = new File("/storage"); File[] fl_1 = lf.listFiles(); if (fl_1 != null) { for (int i = 0; i < fl_1.length; i++) { if (fl_1[i].getName().equals("emulated")) { File tlf = new File("/storage/emulated"); File[] tlist = tlf.listFiles(); if (tlist != null) { for (int j = 0; j < tlist.length; j++) { addMountPointPrimary(tlist[j].getPath(), ml); }/*from w w w . j a va 2 s .com*/ } } else { if (fl_1[i].getName().equals("sdcard0")) addMountPointPrimary(fl_1[i].getPath(), ml); else if (fl_1[i].getName().equals("remote")) addMountPointPrimary(fl_1[i].getPath(), ml); else if (fl_1[i].getName().equals("uicc0")) addMountPointPrimary(fl_1[i].getPath(), ml); else addMountPointPrimaryAndSecondary(fl_1[i].getPath(), ml, pkg_name); } } } lf = new File("/mnt"); fl_1 = lf.listFiles(); if (fl_1 != null) { for (int i = 0; i < fl_1.length; i++) { if (!fl_1[i].getPath().equals("/mnt/obb") && !fl_1[i].getPath().equals("/mnt/asec")) { addMountPointPrimary(fl_1[i].getPath(), ml); } } } addMountPointPrimary("/sdcard", ml); addMountPointPrimaryAndSecondary("/Removable/SD", ml, pkg_name); addMountPointPrimaryAndSecondary("/Removable/MicroSD", ml, pkg_name); addMountPointPrimary("/Removable/USBdisk1/Drive1", ml); addMountPointPrimary("/Removable/USBdisk2/Drive1", ml); addMountPointPrimary("/mnt/sdcard/usbStorage/sda1", ml); addMountPointPrimary("/mnt/sdcard/usbStorage/sdb1", ml); addMountPointPrimary("/mnt/sdcard/usbStorage/sdc1", ml); addMountPointPrimary("/mnt/sdcard/usbStorage/sdd1", ml); addMountPointPrimary(primary_esd + "/usbStorage/sda1", ml); addMountPointPrimary(primary_esd + "/usbStorage/sdb1", ml); addMountPointPrimary(primary_esd + "/usbStorage/sdc1", ml); addMountPointPrimary(primary_esd + "/usbStorage/sdd1", ml); String env = System.getenv("EXTERNAL_STORAGE2"); if (env != null) addMountPointPrimaryAndSecondary(env, ml, pkg_name); addMountPointPrimaryAndSecondary("/storage/extSdCard", ml, pkg_name); addMountPointPrimaryAndSecondary("/mnt/extSdCard", ml, pkg_name); addMountPointPrimaryAndSecondary("/sdcard/external_sd", ml, pkg_name); File[] ext_dirs = ContextCompat.getExternalFilesDirs(c, null); if (ext_dirs != null) { for (int i = 0; i < ext_dirs.length; i++) { if (ext_dirs[i] != null && ext_dirs[i].getPath() != null) { if (!ext_dirs[i].getPath().startsWith(primary_esd)) { boolean found = false; for (int j = 0; j < ml.size(); j++) { if (ext_dirs[i].getPath().equals(ml.get(j))) { found = true; break; } } if (!found) ml.add(ext_dirs[i].getPath()); } } } } Collections.sort(ml); return ml; }
From source file:org.panbox.mobile.android.identitymgmt.IdentityDebugApp.java
public void exportAddressbook() { File[] files = ContextCompat.getExternalFilesDirs(this.context, null); for (File f : files) { System.out.println(f.getAbsolutePath()); }// ww w . ja v a 2s . co m String rootPath = files[0].getAbsolutePath(); boolean createdDirs = files[0].mkdirs(); System.out.println("created dirs? " + createdDirs); File aBookFileTMP = new File(rootPath + File.separator + "abookTMP.vcf"); Collection<PanboxContact> contacts = identity.getAddressbook().getContacts(); LinkedList<VCard> vcards = new LinkedList<VCard>(); for (PanboxContact c : contacts) { vcards.add(AbstractAddressbookManager.contact2VCard(c)); } //export myself too vcards.add(AbstractAddressbookManager.contact2VCard(identity)); //temporary vcf file AbstractAddressbookManager.exportContacts(vcards, aBookFileTMP); char[] pass = null; try { pass = VCardProtector.generatePassword(); } catch (RandomDataGenerationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.err.println("Export password is: " + String.valueOf(pass)); //TODO: HACK for testing // pass = new char[]{'1','2','3'}; File aBookFile = new File(rootPath + File.separator + "abook.zip"); try { VCardProtector.protectVCF(aBookFile, aBookFileTMP, pass); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if (aBookFileTMP.exists()) { aBookFileTMP.delete(); } }
From source file:org.dkf.jed2k.android.LollipopFileSystem.java
private static String[] getExtSdCardPaths(Context context) { List<String> paths = new ArrayList<>(); File[] externals = ContextCompat.getExternalFilesDirs(context, "external"); File external = context.getExternalFilesDir("external"); for (int i = 0; i < externals.length; i++) { File file = externals[i]; if (file != null && !file.equals(external)) { String absolutePath = file.getAbsolutePath(); int index = absolutePath.lastIndexOf("/Android/data"); if (index >= 0) { String path = absolutePath.substring(0, index); try { path = new File(path).getCanonicalPath(); } catch (IOException e) { // Keep non-canonical path. }//from w w w.j av a 2s . c o m paths.add(path); } else { LOG.warn("ext sd card path wrong: {}", absolutePath); } } } // special hard coded paths for more security for (String path : FIXED_SDCARD_PATHS) { if (!paths.contains(path)) { paths.add(path); } } return paths.toArray(new String[0]); }
From source file:org.panbox.mobile.android.identitymgmt.IdentityDebugApp.java
public void importContacts() { File[] files = ContextCompat.getExternalFilesDirs(this.context, null); String rootPath = files[0].getAbsolutePath(); AbstractIdentityManager idm = IdentityManagerAndroid.getInstance(context); File aBookFileTMP = new File(rootPath + File.separator + "abookTMP.vcf"); File sourceFile = new File(rootPath + File.separator + "abook.zip"); /* try {// w w w . j av a 2 s . c om boolean hashMatch; hashMatch = VCardProtector.unwrapVCF(sourceFile, aBookFileTMP, new char[]{'6','w','2','y','r','a'}); System.out.println("Hash match?: " + hashMatch); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } */ //import example without password check try { try { VCardProtector.unwrapVCF(sourceFile, aBookFileTMP); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // idm.getAddressBookManager().importContacts(identity, aBookFileTMP); idm.getAddressBookManager().importContacts(identity, aBookFileTMP, true); } catch (ContactExistsException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (aBookFileTMP.exists()) { aBookFileTMP.delete(); } }
From source file:com.frostwire.android.LollipopFileSystem.java
private static String[] getExtSdCardPaths(Context context) { List<String> paths = new ArrayList<>(); File[] externals = ContextCompat.getExternalFilesDirs(context, "external"); File external = context.getExternalFilesDir("external"); for (File file : externals) { if (file != null && !file.equals(external)) { String absolutePath = file.getAbsolutePath(); int index = absolutePath.lastIndexOf("/Android/data"); if (index >= 0) { String path = absolutePath.substring(0, index); try { path = new File(path).getCanonicalPath(); } catch (IOException e) { // Keep non-canonical path. }//from w ww .ja va 2 s . c om paths.add(path); } else { LOG.warn("ext sd card path wrong: " + absolutePath); } } } // special hard coded paths for more security for (String path : FIXED_SDCARD_PATHS) { if (!paths.contains(path)) { paths.add(path); } } return paths.toArray(new String[0]); }
From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mGp = (GlobalParameters) getApplication(); mGp.loadSettingsParm();//from w ww . j av a 2s . c om mContext = this; mActivity = this; SafUtil.initWorkArea(this, mSafCA, mGp.debugLevel > 0); // requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); // // Set up the action bar. // final ActionBar actionBar = getSupportActionBar(); // actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // // OnTabListener otl=new OnTabListener(); // actionBar.addTab(actionBar.newTab() // .setText("tab1") // .setTabListener(otl)); // actionBar.addTab(actionBar.newTab() // .setText("tab2") // .setTabListener(otl)); mActionBar = getSupportActionBar(); mActionBar.setHomeButtonEnabled(false); mGp.SMBExplorerRootDir = localBase = LocalMountPoint.getExternalStorageDir(); if (ccMenu == null) ccMenu = new CustomContextMenu(getResources(), getSupportFragmentManager()); commonDlg = new CommonDialog(mContext, getSupportFragmentManager()); myUncaughtExceptionHandler.init(); // localUrl = SMBEXPLORER_ROOT_DIR; createTabAndView(); profileListView = (ListView) findViewById(R.id.explorer_profile_tab_listview); sendDebugLogMsg(1, "I", "onCreate entered"); if (mGp.settingsUseRootPrivilege) { if (initSuCmdProcess()) { sendDebugLogMsg(1, "I", "su command process was created"); } else { sendDebugLogMsg(1, "I", "su command process can not created"); } } mIsApplicationTerminate = false; initJcifsOption(); // DocumentFile df=DocumentFile.fromFile(new File("/sdcard")); // Log.v("","df="+df.getName()); // df.createDirectory("test"); // Log.v("","getDataDirectory()="+Environment.getDataDirectory()+ // ", getDownloadCacheDirectory()="+Environment.getDownloadCacheDirectory()+ // ", getExternalStorageDirectory()="+Environment.getExternalStorageDirectory()+ // ", getExternalStoragePublicDirectory()="+Environment.getExternalStoragePublicDirectory("test")+ // ", getRootDirectory()="+Environment.getRootDirectory() // ); ContextCompat.getExternalFilesDirs(mContext, null); // Log.v("","esd="+LocalMountPoint.getExternalStorageDir()); // Log.v("","getFilesDir()="+getFilesDir()); // Log.v("","getDir()="+getDir()); // File[] fl= getExternalMediaDirs(); //API21 // if (fl!=null) { // for(int i=0;i<fl.length;i++) if (fl[i]!=null) Log.v("","mn="+fl[i].getPath()); // } // File[] fl= ContextCompat.getExternalFilesDirs(mContext, null); // if (fl!=null) { // for(int i=0;i<fl.length;i++) { // if (fl[i]!=null) Log.v("","fn="+fl[i].getPath()); // } // } // System.setProperty( "jcifs.netbios.retryTimeout", "200"); // Log.v("","esd="+LocalMountPoint.getExternalStorageDir()); // ArrayList<String>mpl=LocalMountPoint.getLocalMountPointList(); // for (int i=0;i<mpl.size();i++) Log.v("","mp="+mpl.get(i)); // File lf=new File( "/storage/sdcard1/Android/data/com.sentaroh.android.SMBExplorer/files/test.txt"); // File nlf=new File("/storage/sdcard1/test.txt"); // try { // Log.v("","create="+lf.createNewFile()); // Log.v("","rename="+lf.renameTo(nlf)); // } catch (IOException e) { // e.printStackTrace(); // } // ArrayList<LocalMountPointListItem>mpl=getLocalMountPointListWithLink(mContext); // Log.v("","e="+LocalMountPoint.getExternalStorageDir()); // for(int i=0;i<mpl.size();i++) { // Log.v("","n="+mpl.get(i).mount_point_name+", l="+mpl.get(i).link_name); // } if (isTaskDataExisted()) {//Restore required if (restoreTaskData()) restartStatus = 2; else restartStatus = 0; } initSafExternalSdcardTreeUri(); // int adb = Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.ADB_ENABLED, 0); // Log.v("","debug="+adb); }
From source file:github.daneren2005.dsub.util.FileUtil.java
public static File getDefaultMusicDirectory(Context context) { if (DEFAULT_MUSIC_DIR == null) { File[] dirs;// www . j a v a 2 s . c o m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { dirs = context.getExternalMediaDirs(); } else { dirs = ContextCompat.getExternalFilesDirs(context, null); } DEFAULT_MUSIC_DIR = new File(getBestDir(dirs), "music"); if (!DEFAULT_MUSIC_DIR.exists() && !DEFAULT_MUSIC_DIR.mkdirs()) { Log.e(TAG, "Failed to create default dir " + DEFAULT_MUSIC_DIR); // Some devices seem to have screwed up the new media directory API. Go figure. Try again with standard locations if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { dirs = ContextCompat.getExternalFilesDirs(context, null); DEFAULT_MUSIC_DIR = new File(getBestDir(dirs), "music"); if (!DEFAULT_MUSIC_DIR.exists() && !DEFAULT_MUSIC_DIR.mkdirs()) { Log.e(TAG, "Failed to create default dir " + DEFAULT_MUSIC_DIR); } else { Log.w(TAG, "Stupid OEM's messed up media dir API added in 5.0"); } } } } return DEFAULT_MUSIC_DIR; }
From source file:com.sentaroh.android.SMBSync2.CommonUtilities.java
public void initAppSpecificExternalDirectory(Context c) { // if (Build.VERSION.SDK_INT>=19) { // c.getExternalFilesDirs(null); // } else { // }/* w w w . ja v a 2s . co m*/ ContextCompat.getExternalFilesDirs(c, null); }
From source file:com.sentaroh.android.Utilities.Dialog.FileSelectDialogFragment.java
private void initViewWidget() { if (mDebugEnable) Log.v(APPLICATION_TAG, "initViewWidget"); if (mDebugEnable) Log.v(APPLICATION_TAG, "Create=" + mDialogEnableCreate + ", Title=" + mDialogTitle + ", lurl=" + mDialogLocalUrl + ", ldir=" + mDialogLocalDir + ", file name=" + mDialogFileName); mThemeColorList = ThemeUtil.getThemeColorList(getActivity()); mDialog.setContentView(R.layout.file_select_edit_dlg); LinearLayout title_view = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_title_view); title_view.setBackgroundColor(mThemeColorList.dialog_title_background_color); TextView title = (TextView) mDialog.findViewById(R.id.file_select_edit_dlg_title); title.setTextColor(mThemeColorList.text_color_dialog_title); title.setText(mDialogTitle);/*from w w w . j a v a 2s . com*/ final TextView dlg_msg = (TextView) mDialog.findViewById(R.id.file_select_edit_dlg_msg); final Button btnHome = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_home_dir_btn); btnHome.setTextColor(mThemeColorList.text_color_primary); btnHome.setVisibility(Button.VISIBLE); final Button btnCreate = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_create_btn); btnCreate.setTextColor(mThemeColorList.text_color_primary); final Button btnOk = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_ok_btn); // btnOk.setTextColor(mThemeColorList.text_color_primary); final Button btnCancel = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_cancel_btn); btnCancel.setTextColor(mThemeColorList.text_color_primary); final Button btnRefresh = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_refresh_btn); btnRefresh.setTextColor(mThemeColorList.text_color_primary); LinearLayout ll_dlg_view = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_view); ll_dlg_view.setBackgroundColor(mThemeColorList.dialog_msg_background_color); final Activity activity = getActivity(); final Context context = activity.getApplicationContext(); if (mDialogEnableCreate) { btnCreate.setVisibility(TextView.VISIBLE); } mLocalMountPointSpinner = (Spinner) mDialog.findViewById(R.id.file_select_edit_dlg_rdir); setSpinnerBackground(context, mLocalMountPointSpinner, mThemeColorList.theme_is_light); mLocalMountPointSpinner.setVisibility(Spinner.VISIBLE); // Root directory spinner CustomSpinnerAdapter adapter = new CustomSpinnerAdapter(activity, R.layout.custom_simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mLocalMountPointSpinner.setPrompt(context.getString(R.string.msgs_file_select_edit_local_mount_point)); mLocalMountPointSpinner.setAdapter(adapter); int a_no = -1; ArrayList<String> ml = LocalMountPoint.getLocalMountPointList(context); mLocalMountPointSpinner.setOnItemSelectedListener(null); if (mDialogMpLimitInternalAndSdcard) { adapter.add(Environment.getExternalStorageDirectory().toString()); File[] fl = ContextCompat.getExternalFilesDirs(context, null); for (File item : fl) { if (!item.getPath().startsWith(Environment.getExternalStorageDirectory().toString())) { adapter.add(item.getPath().substring(0, item.getPath().indexOf("/Android"))); break; } } mLocalMountPointSpinner.setEnabled(true); for (int i = 0; i < adapter.getCount(); i++) { if (adapter.getItem(i).equals(mDialogLocalUrl)) { a_no = i; break; } } mLocalMountPointSpinner.setSelection(a_no); } else { if (ml.size() == 0) { if (mDialogIncludeRoot) adapter.add("/"); adapter.add(mDialogLocalUrl); mLocalMountPointSpinner.setEnabled(false); } else { mLocalMountPointSpinner.setEnabled(true); if (mDialogIncludeRoot) adapter.add("/"); for (int i = 0; i < ml.size(); i++) adapter.add(ml.get(i)); for (int i = 0; i < ml.size(); i++) { if (mDialogLocalUrl.startsWith(ml.get(i))) { a_no = i; break; } } mLocalMountPointSpinner.setSelection(a_no); } } LinearLayout ll_mp = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_mp_view); if (mDialogHideMp) ll_mp.setVisibility(LinearLayout.GONE); else ll_mp.setVisibility(LinearLayout.VISIBLE); // ll_mp.setVisibility(LinearLayout.GONE); // final TextView v_spacer=(TextView)mDialog.findViewById(R.id.file_select_edit_dlg_spacer); mTreeFileListView = (ListView) mDialog.findViewById(android.R.id.list); final CustomTextView dir_name = (CustomTextView) mDialog.findViewById(R.id.file_select_edit_dlg_dir_name); dir_name.setTextColor(mThemeColorList.text_color_primary); final EditText file_name = (EditText) mDialog.findViewById(R.id.file_select_edit_dlg_file_name); if (!mDialogSingleSelect) file_name.setVisibility(EditText.GONE); else file_name.setVisibility(EditText.VISIBLE); if (mDialogFileOnly) { file_name.setVisibility(EditText.VISIBLE); file_name.setEnabled(true); dir_name.setVisibility(EditText.VISIBLE); } else { if (mDialogDirectoryOnly) { file_name.setVisibility(EditText.GONE); file_name.setEnabled(false); dir_name.setVisibility(EditText.VISIBLE); btnHome.setVisibility(EditText.VISIBLE); } else { file_name.setVisibility(EditText.VISIBLE); file_name.setEnabled(true); dir_name.setVisibility(EditText.VISIBLE); btnHome.setVisibility(EditText.VISIBLE); } } file_name.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View arg0, int keyCode, KeyEvent event) { if (//event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { return true; } return false; } }); // if (dirs.size()<=2) v_spacer.setVisibility(TextView.VISIBLE); mTreeFilelistAdapter = new TreeFilelistAdapter(activity, mDialogSingleSelect, true); mTreeFileListView.setAdapter(mTreeFilelistAdapter); if (mDialogLocalUrl.equals("")) mDialogLocalUrl = ml.get(0); ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, mDialogLocalUrl, ""); if (tfl.size() == 0) { tfl.add(new TreeFilelistItem(context.getString(R.string.msgs_file_select_edit_dir_empty))); } else { mTreeFilelistAdapter.setDataList(tfl); if (!mDialogLocalDir.equals("")) { String sel_dir = mDialogLocalDir; String n_dir = "", e_dir = ""; if (sel_dir.startsWith("/")) n_dir = sel_dir.substring(1); else n_dir = sel_dir; if (n_dir.endsWith("/")) e_dir = n_dir.substring(0, n_dir.length() - 1); else e_dir = n_dir; // Log.v("","mp="+mDialogLocalUrl+", se;_dir="+sel_dir+", e_dir="+e_dir); selectLocalDirTree(e_dir); } if (!mDialogFileName.equals("")) selectLocalDirTreeFile(mDialogFileName); } mTreeFileListView.setScrollingCacheEnabled(false); mTreeFileListView.setScrollbarFadingEnabled(false); if (mSavedViewContentsValue != null && mSavedViewContentsValue.mainDialogFilename != null) { file_name.setText(mSavedViewContentsValue.mainDialogFilename); file_name.setSelection(mSavedViewContentsValue.mainDialogFilenameSelStart, mSavedViewContentsValue.mainDialogFilenameTextSelEnd); dir_name.setText(mSavedViewContentsValue.mainDialogDirName); } else { String d_name = mDialogLocalDir.equals("") ? mDialogLocalUrl + "/" : mDialogLocalUrl + mDialogLocalDir + "/"; dir_name.setText(d_name); file_name.setText(mDialogFileName); } if (!mDialogSingleSelect) btnOk.setEnabled(false); NotifyEvent cb_ntfy = new NotifyEvent(context); // set file list thread response listener cb_ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { int p = (Integer) o[0]; boolean p_chk = (Boolean) o[1]; String turl = (String) mLocalMountPointSpinner.getSelectedItem(); if (mDialogSingleSelect) { if (mTreeFilelistAdapter.getDataItem(p).isChecked() && !p_chk) { if (p != -1) { if (mTreeFilelistAdapter.getDataItem(p).isChecked()) { if (mTreeFilelistAdapter.getDataItem(p).isDir()) { dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath() + mTreeFilelistAdapter.getDataItem(p).getName() + "/"); // file_name.setText(""); } else { dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath()); file_name.setText(mTreeFilelistAdapter.getDataItem(p).getName()); } } } } if (mDialogFileOnly) { if (file_name.getText().length() > 0) { btnOk.setEnabled(true); putDlgMsg(dlg_msg, ""); } else { btnOk.setEnabled(false); putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified)); } } else { if (mTreeFilelistAdapter.isDataItemIsSelected() || file_name.getText().length() > 0) { btnOk.setEnabled(true); putDlgMsg(dlg_msg, ""); } else { putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_directory_not_selected)); btnOk.setEnabled(false); } } } else { if (mTreeFilelistAdapter.getDataItem(p).isDir()) { dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath() + mTreeFilelistAdapter.getDataItem(p).getName() + "/"); // file_name.setText(""); } else { dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath()); file_name.setText(mTreeFilelistAdapter.getDataItem(p).getName()); } putDlgMsg(dlg_msg, ""); btnOk.setEnabled(true); } } @Override public void negativeResponse(Context c, Object[] o) { boolean checked = false; // int p=(Integer) o[0]; boolean p_chk = (Boolean) o[1]; if (mDialogSingleSelect) { if (p_chk) { for (int i = 0; i < mTreeFilelistAdapter.getDataItemCount(); i++) { if (mTreeFilelistAdapter.getDataItem(i).isChecked()) { checked = true; break; } } if (checked) btnOk.setEnabled(true); else btnOk.setEnabled(false); } } else { // Log.v("","sel="+p_chk); btnOk.setEnabled(false); for (int i = 0; i < mTreeFilelistAdapter.getDataItemCount(); i++) { if (mTreeFilelistAdapter.getDataItem(i).isChecked()) { btnOk.setEnabled(true); break; } } } } }); mTreeFilelistAdapter.setCbCheckListener(cb_ntfy); if (mDialogLocalUrl.equals(file_name.getText().toString())) btnOk.setEnabled(false); if (mDialogFileOnly && mDialogFileName.equals("")) { btnOk.setEnabled(false); putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified)); } file_name.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { if (mDialogSingleSelect) { if (s.length() != 0) { btnOk.setEnabled(true); putDlgMsg(dlg_msg, ""); } else { btnOk.setEnabled(false); putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified)); } } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); NotifyEvent ntfy_expand_close = new NotifyEvent(context); ntfy_expand_close.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { int idx = (Integer) o[0]; final int pos = mTreeFilelistAdapter.getItem(idx); final TreeFilelistItem tfi = mTreeFilelistAdapter.getDataItem(pos); if (tfi.getName().startsWith("---")) return; String turl = (String) mLocalMountPointSpinner.getSelectedItem(); if (tfi.isDir()) processLocalDirTree(mDialogFileOnly, turl, pos, tfi, mTreeFilelistAdapter); else { mTreeFilelistAdapter.setDataItemIsSelected(pos); dir_name.setText((turl + mTreeFilelistAdapter.getDataItem(pos).getPath())); file_name.setText(mTreeFilelistAdapter.getDataItem(pos).getName()); if (mTreeFilelistAdapter.getDataItem(pos).isDir() && mDialogFileOnly) btnOk.setEnabled(false); else btnOk.setEnabled(true); } } @Override public void negativeResponse(Context c, Object[] o) { } }); mTreeFilelistAdapter.setExpandCloseListener(ntfy_expand_close); mTreeFileListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> items, View view, int idx, long id) { final int pos = mTreeFilelistAdapter.getItem(idx); final TreeFilelistItem tfi = mTreeFilelistAdapter.getDataItem(pos); if (tfi.getName().startsWith("---")) return; String turl = (String) mLocalMountPointSpinner.getSelectedItem(); if (tfi.isDir()) processLocalDirTree(mDialogFileOnly, turl, pos, tfi, mTreeFilelistAdapter); else { mTreeFilelistAdapter.setDataItemIsSelected(pos); dir_name.setText((turl + mTreeFilelistAdapter.getDataItem(pos).getPath())); file_name.setText(mTreeFilelistAdapter.getDataItem(pos).getName()); if (mTreeFilelistAdapter.getDataItem(pos).isDir() && mDialogFileOnly) btnOk.setEnabled(false); else btnOk.setEnabled(true); } } }); mTreeFileListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) { return true; } }); btnHome.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dir_name.setText(mLocalMountPointSpinner.getSelectedItem().toString() + "/"); } }); //Create button btnCreate.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { NotifyEvent ntfy = new NotifyEvent(context); // set file list thread response listener ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { // btnRefresh.performClick(); } @Override public void negativeResponse(Context c, Object[] o) { } }); fileSelectEditDialogCreateBtn(activity, context, dir_name.getText().substring(0, dir_name.getText().length() - 1), "", mLocalMountPointSpinner.getSelectedItem().toString(), mTreeFilelistAdapter, ntfy, mTreeFileListView); } }); //Refresh button btnRefresh.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String mp = mLocalMountPointSpinner.getSelectedItem().toString(); ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, mp, "");//mDialogLocalUrl,""); if (tfl.size() < 1) tfl.add(new TreeFilelistItem(context.getString(R.string.msgs_file_select_edit_dir_empty))); mTreeFilelistAdapter.setDataList(tfl); } }); //OK button // btnOk.setEnabled(false); btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (mDialogSingleSelect) { String[] sl_array = new String[] { dir_name.getText() + file_name.getText().toString() }; if (mNotifyEvent != null) mNotifyEvent.notifyToListener(true, sl_array); } else { ArrayList<String> sl = new ArrayList<String>(); ArrayList<TreeFilelistItem> tfl = mTreeFilelistAdapter.getDataList(); for (TreeFilelistItem li : tfl) { if (li.isChecked()) { if (li.isDir()) sl.add(li.getPath() + li.getName()); else sl.add(li.getPath() + li.getName()); } } String[] sl_array = new String[sl.size()]; String mp = mLocalMountPointSpinner.getSelectedItem().toString(); for (int i = 0; i < sl.size(); i++) { if (mDialogSelectedFilePathWithMountPoint) sl_array[i] = mp + sl.get(i); else sl_array[i] = sl.get(i); // Log.v("","sel="+sl_array[i]); } if (mNotifyEvent != null) mNotifyEvent.notifyToListener(true, sl_array); } // mDialog.dismiss(); mFragment.dismiss(); } }); // CANCEL? btnCancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // mDialog.dismiss(); mFragment.dismiss(); if (mNotifyEvent != null) mNotifyEvent.notifyToListener(false, null); } }); Handler hndl = new Handler(); hndl.postDelayed(new Runnable() { @Override public void run() { mLocalMountPointSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // Log.v("","MP selected="+position); Spinner spinner = (Spinner) parent; String turl = (String) spinner.getSelectedItem(); ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, turl, ""); if (tfl.size() < 1) tfl.add(new TreeFilelistItem( context.getString(R.string.msgs_file_select_edit_dir_empty))); mTreeFilelistAdapter.setDataList(tfl); mTreeFilelistAdapter.notifyDataSetChanged(); if (turl.startsWith(mSafFileMgr.getExternalSdcardPath())) { if (mSafFileMgr.getSdcardSafFile() == null) btnCreate.setEnabled(false); else btnCreate.setEnabled(true); } else btnCreate.setEnabled(true); dir_name.setText(turl + "/"); Handler hndl_sel = new Handler(); hndl_sel.post(new Runnable() { @Override public void run() { mTreeFileListView.setSelection(0); } }); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); } }, 100); }