Getting Started with Android programming Development Folder Manager development file event actions-2

Source: Internet
Author: User

On a blog, we've got a list of folders, we need to add events to the File list subkey, for example, we clicked on the file and executed

Open the action, click on the folder to perform open folder operations, traverse the file list, and so on until the last file location, about the file

and the processing of the folder will be described later


In my program, I wrote a class to process the file, Fileopreationuitl:

Package Com.example.util;import Java.io.file;import Java.io.fileinputstream;import java.io.fileoutputstream;import Java.io.ioexception;import java.util.arraylist;import java.util.hashmap;import Java.util.List;import java.util.Map Import android.content.context;import android.util.log;import android.widget.toast;/** * File Operation class * @author engineer-jsp * @date 2014.10.27 */public class Fileopreationuitl {public static map<string,object> mp3_list=new have Hmap<string,object> ();p ublic static list<map<string, Object>>mp3_data=new ArrayList<Map< String,object>> ();p ublic static String mp3_listitem;//public static map<string,object> picture_list=new Hashmap<string,object> ();p ublic static list<map<string, Object>>picture_data=new ArrayList< Map<string,object>> ();p ublic static String picture_listitem;//public static map<string,object> Video_ List=new hashmap<string,object> ();p ublic static list<map<string, object>> Video_data=new arraylist<map<string,object>> ();p ublic static String video_listitem;//Delete file and directory public void DeleteFile (file path) {///If the argument path is a file, perform the delete operation directly if (Path.isfile ()) {///delete Path.delete ();//Otherwise, perform the following Operation}else{// Define file array receive parameters file list of path folder file[] Files=path.listfiles ();//cyclic calendar file for (file f:files) {//If the file is executed if (F.isfile ()) {// Delete F.delete ();} else{//calls itself recursive DeleteFile (f);}} Delete directory Path.delete ();}} Copy file public void CopyFile (file Currentpath,file srcpath) {file Newfile=new file (Srcpath, Currentpath.getname ()); Newfile.exists ()) {try {newfile.createnewfile (); FileInputStream fileinput=new FileInputStream (Currentpath); FileOutputStream fileout=new FileOutputStream (newFile); byte[] byt=new byte[1024 * 16];int length=0;while ((length= Fileinput.read (byt))!=-1) {fileout.write (byt,0,length);} Fileinput.close (); Fileout.close ();} catch (IOException e) {e.printstacktrace ();}} Else{//newfile.delete ();//copyfile (Currentpath, srcpath);//}}//copy folder public void CopyDirectory (File currentpath, File Srcpath){if (Currentpath.isfile ()) {CopyFile (Currentpath, Srcpath);} Else{file file=new File (Srcpath, Currentpath.getname ()), if (!file.exists ()) {File.mkdir ();} Else{//file.delete ();//}file[] Files=currentpath.listfiles (); for (file f:files) {copydirectory (f, file);} Delete directory//currentpath.delete ();}} New public void NewFile (File currentpath) {if (!currentpath.exists ()) {currentpath.mkdirs ();}} Music Classification/** * * @param grouppath If you want to get sdcard below so mp3 file you fill in the SDcard path * with a recursive way to get */public void Getreciver (File mp3_path) {// Loop gets the directory and file for the SDcard directory under for (int i=0; i< mp3_path.listfiles (). length; i++) {File childfile = Mp3_path.listfiles () [i];// If it is a directory, continue calling Getsdcardfile () to pass the Childfile as a parameter inside the IF (Childfile.isdirectory ()) {getreciver (childfile);} else{//if it is a file, decide whether to end it with a. mp3 and add it to the List if (childfile.tostring (). EndsWith (". mp3")) {Mp3_list.put (Mp3_listitem, Childfile.getname (). toString ()); Mp3_data.add (mp3_list);//File name System.out.println (Childfile.getname ()); LOG.D ("Xxxxxxxxxx", Childfile.getname ());//The path of the print file System.out.println (childfIle.getabsolutepath ());    LOG.D ("Xxxxxxxxxx", Childfile.getabsolutepath ());}}} Picture category public void Getpicture (file Picture_path) {//Loops get SDcard directory under directory and file for (int i=0; I<picture_path.listfiles (). Length i++) {File childfile =picture_path.listfiles () [i];//if it is a directory, continue to invoke Getsdcardfile () to pass Childfile as a parameter inside the IF ( Childfile.isdirectory ()) {getpicture (childfile);} else{//if it is a file, decide whether to end it with a. mp3 and add it to the list if (Childfile.tostring (). EndsWith (". png") | | Childfile.tostring (). EndsWith (". gif") | | Childfile.tostring (). EndsWith (". bmp") | | Childfile.tostring (). EndsWith (". jpg")) {Picture_list.put (Picture_listitem,childfile.getname (). toString ()); Picture_data.add (picture_list);//print file filename System.out.println (Childfile.getname ()); LOG.D ("Xxxxxxxxxx", Childfile.getname ());//The path of the print file System.out.println (Childfile.getabsolutepath ()); LOG.D ("Xxxxxxxxxx", Childfile.getabsolutepath ());}}} Video classification public void Getvideo (file Video_path) {//Loops get SDcard directory below directory and file for (int i=0; i<video_path.listfiles (). length; + +) {File Childfile = Video_path.listfileS () [i];//, if it is a directory, continue calling Getsdcardfile () to pass the Childfile as a parameter in the method inside if (Childfile.isdirectory ()) {Getvideo (Childfile)};} else{//if it is a file, the decision is not to end with. mp3, it is added to the list inside if (Childfile.tostring (). EndsWith (". mp4") | | Childfile.tostring (). EndsWith (". avi") | | Childfile.tostring (). EndsWith (". rmvb") | | Childfile.tostring (). EndsWith (". 3gp")) {Video_list.put (Video_listitem,childfile.getname (). toString ()); Video_ Data.add (video_list);//print file filename System.out.println (Childfile.getname ()); LOG.D ("Xxxxxxxxxx", Childfile.getname ());//The path of the print file System.out.println (Childfile.getabsolutepath ()); LOG.D ("Xxxxxxxxxx", Childfile.getabsolutepath ());}}} Search//public void Searchfile (File path) {////}}

With Multichoicemodelistener to perform multiple selection, better than Setchoicemode single selection, so that application can perform batch processing, including copy, delete, see the effect below:

To perform a new test, click on the upper right corner of the small + sign:



Click OK to generate the folder and refresh the list:



The following is a look at the bulk copy operation, long press the ListView item, the upper right corner of the small + sign disappears, the Generate Delete button and copy button, click on item selected, change the selected item background color:




Perform bulk paste, here I only ordered 5 items, so only paste 5 folders, we notice the top right corner of the icon, and restore to the time when the icon is not copied, in fact, after clicking the Copy button, will add a paste button, after pasting disappeared:



Bulk Delete operations:



File operation probably wrote these, there is a need to expand their own, I am here mainly to facilitate the study of everyone, thank you ~



Getting Started with Android programming Development Folder Manager development file event actions-2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.