├── Client ├── .gitignore ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── administrator │ │ │ └── client │ │ │ └── ApplicationTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ ├── ClientSocket │ │ │ │ ├── ClientSocket.java │ │ │ │ ├── ClientSocket_down.java │ │ │ │ └── ClientSocket_update.java │ │ │ ├── Database │ │ │ │ ├── Down.java │ │ │ │ └── DownDB.java │ │ │ ├── Ip_Port │ │ │ │ └── Ip_Port.java │ │ │ ├── Menu_file │ │ │ │ └── Menu_file.java │ │ │ ├── MyAdapter │ │ │ │ ├── MyAdapter.java │ │ │ │ └── MyAdapter_Down_Update.java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── administrator │ │ │ │ └── client │ │ │ │ ├── MainActivity.java │ │ │ │ └── Manage │ │ │ │ ├── down_manage.java │ │ │ │ └── update_manage.java │ │ └── res │ │ │ ├── drawable │ │ │ ├── base_action_bar_back_normal.png │ │ │ ├── doc.jpg │ │ │ ├── end.jpg │ │ │ ├── menu.jpg │ │ │ ├── notification.jpg │ │ │ ├── return_butt.jpg │ │ │ └── start.jpg │ │ │ ├── layout │ │ │ ├── activity_down_manage.xml │ │ │ ├── activity_main.xml │ │ │ ├── activity_update_manage.xml │ │ │ ├── down_manage_layout.xml │ │ │ ├── down_update_content_layout.xml │ │ │ ├── menu_layout.xml │ │ │ └── update_manage_layout.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── administrator │ │ └── client │ │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle └── Service └── 12 ├── .classpath ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── bin ├── Excel │ └── CreateExcel.class ├── Thread │ └── Task.class ├── family │ └── Server.class └── operator │ ├── Dir.class │ ├── Down_duan.class │ ├── Downland.class │ ├── Open.class │ └── Update.class └── src ├── Excel └── CreateExcel.java ├── Thread └── Task.java ├── family └── Server.java └── operator ├── Dir.java ├── Down_duan.java ├── Downland.java ├── Open.java └── Update.java /Client/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /Client/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Client/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.example.administrator.client" 9 | minSdkVersion 19 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:24.0.0-alpha2' 26 | } 27 | -------------------------------------------------------------------------------- /Client/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\ANDROID_SDK_HOME/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Client/app/src/androidTest/java/com/example/administrator/client/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.example.administrator.client; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /Client/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Client/app/src/main/java/ClientSocket/ClientSocket.java: -------------------------------------------------------------------------------- 1 | package ClientSocket; 2 | 3 | import android.util.Log; 4 | 5 | import java.io.IOException; 6 | import java.io.InputStreamReader; 7 | import java.io.OutputStreamWriter; 8 | import java.io.Reader; 9 | import java.io.Writer; 10 | import java.net.Socket; 11 | import java.net.SocketTimeoutException; 12 | import java.util.ArrayList; 13 | 14 | import Ip_Port.Ip_Port; 15 | 16 | /** 17 | * Created by lenovo on 2017/3/23. 18 | */ 19 | public class ClientSocket { 20 | 21 | public ArrayList arrayList = new ArrayList<>(); 22 | private Socket client; 23 | private Writer writer; 24 | public String str_out_2; 25 | 26 | //与服务器端进行连接 27 | public void doConnect(String cmd,String type) { 28 | 29 | //与服务端建立连接 30 | //客户端进行写操作 31 | 32 | try { 33 | 34 | client = new Socket(Ip_Port.getIP(), Ip_Port.getPort()); 35 | writer = new OutputStreamWriter(client.getOutputStream(), "utf-8"); 36 | 37 | writer.write(type); 38 | writer.write(cmd); 39 | writer.write("eof\n"); 40 | 41 | Log.e("string", cmd); 42 | writer.flush();//写完后要记得flush 43 | 44 | if(type.equals("8")||type.equals("9")) 45 | { 46 | writer.close(); 47 | } 48 | //读取从服务器端传过来的数据 49 | else { 50 | ReadString(type); 51 | } 52 | 53 | } catch (IOException e) { 54 | e.printStackTrace(); 55 | } 56 | //建立连接后就可以往服务端发送数据 57 | } 58 | 59 | //读取从服务器端传过来的数据 60 | private void ReadString(String type) throws IOException { 61 | Reader reader = new InputStreamReader(client.getInputStream(), "utf-8"); 62 | client.setSoTimeout(20 * 1000); 63 | char chars[] = new char[64]; 64 | int len=-1; 65 | StringBuffer sb = new StringBuffer(); 66 | String temp = ""; 67 | int index; 68 | 69 | try { 70 | while ((len = reader.read(chars)) != -1) { 71 | temp = new String(chars, 0, len); 72 | if ((index = temp.indexOf("eof")) != -1) //遇到eof就结束 73 | { 74 | sb.append(temp.substring(0, index)); 75 | break; 76 | } 77 | sb.append(new String(chars, 0, len)); 78 | 79 | } 80 | } catch (SocketTimeoutException ex) { 81 | sb.append("timeout"); 82 | } catch (IOException e) { 83 | e.printStackTrace(); 84 | } 85 | 86 | String str_out = sb.toString(); 87 | 88 | str_out_2=str_out; 89 | if(type=="1") { 90 | PutString(str_out); //将string存放入arraylist中 91 | } 92 | 93 | //断点下载 94 | else if(type=="4") 95 | { 96 | //获取传回来的文件长度 97 | getFileSize(); 98 | 99 | } 100 | 101 | writer.close(); 102 | reader.close(); 103 | client.close(); 104 | } 105 | 106 | //将string存放入arraylist中 107 | private void PutString(String str_out) { 108 | int len_str = str_out.length(); 109 | int in2; 110 | int index2 = 0; 111 | int index3; 112 | 113 | if ((in2 = str_out.indexOf("timeout")) == 0) { 114 | arrayList.clear(); 115 | } else { 116 | while (len_str > 0) { 117 | if ((index3 = str_out.indexOf("\n\r")) != -1) { 118 | String out_string = str_out.substring(0, index3); 119 | index2 = index3 + 2; 120 | 121 | str_out = str_out.substring(index2, len_str); 122 | len_str = len_str - index3 - 2; 123 | arrayList.add(out_string); 124 | 125 | } 126 | } 127 | } 128 | } 129 | 130 | public ArrayList getArrayList() { 131 | return arrayList; 132 | } 133 | 134 | public String getStr_out_2(){return str_out_2;} 135 | 136 | //获取传回来的文件长度 137 | public Long getFileSize() 138 | { 139 | return Long.valueOf(str_out_2); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /Client/app/src/main/java/ClientSocket/ClientSocket_down.java: -------------------------------------------------------------------------------- 1 | package ClientSocket; 2 | 3 | import android.app.Notification; 4 | import android.os.Handler; 5 | import android.content.ContentValues; 6 | import android.content.Context; 7 | import android.content.SharedPreferences; 8 | import android.database.Cursor; 9 | import android.database.sqlite.SQLiteDatabase; 10 | import android.os.Message; 11 | import android.util.Log; 12 | import java.lang.String; 13 | import java.io.BufferedInputStream; 14 | import java.io.BufferedOutputStream; 15 | import java.io.DataInputStream; 16 | import java.io.DataOutputStream; 17 | import java.io.File; 18 | import java.io.FileNotFoundException; 19 | import java.io.FileOutputStream; 20 | import java.io.IOException; 21 | import java.io.OutputStreamWriter; 22 | import java.io.Writer; 23 | import java.net.Socket; 24 | import java.util.ArrayList; 25 | 26 | import Database.Down; 27 | import Database.DownDB; 28 | 29 | import Ip_Port.Ip_Port; 30 | import MyAdapter.MyAdapter_Down_Update; 31 | 32 | 33 | /** 34 | * Created by lenovo on 2017/4/11. 35 | */ 36 | public class ClientSocket_down { 37 | 38 | private Socket client; 39 | private Writer writer; 40 | private String path; 41 | private String str_down; 42 | private Long file_size; 43 | private Long down_size; 44 | private BufferedInputStream bis = null; 45 | private DataInputStream dis = null; 46 | private FileOutputStream fos = null; 47 | private BufferedOutputStream bos = null; 48 | private DataOutputStream dos = null; 49 | private Context context; 50 | private SQLiteDatabase db_down; 51 | private DownDB mydb; 52 | private String cmd; 53 | private Handler handler; 54 | private int position; 55 | private String url_down_path; 56 | 57 | //与服务器端进行连接 58 | public void doConnect(Context context, String cmd, String type, String path2, String str_down2, Long file_size, Long down_size , Handler handler,int position,String url_down_path) { 59 | 60 | //与服务端建立连接 61 | //客户端进行写操作 62 | this.path = path2; //下载后的文件夹路径 63 | this.str_down = str_down2; 64 | this.file_size = file_size; //文件的原始大小 65 | this.down_size = down_size; //上次记录的文件开始 66 | this.context=context; 67 | this.cmd=cmd; 68 | mydb=new DownDB(context); 69 | this.handler=handler; 70 | this.position=position; 71 | this.url_down_path=url_down_path; //服务器端文件夹路径 72 | 73 | try { 74 | 75 | client = new Socket(Ip_Port.getIP(), Ip_Port.getPort()); 76 | writer = new OutputStreamWriter(client.getOutputStream(), "utf-8"); 77 | writer.write(type); 78 | writer.write(cmd); 79 | 80 | if (type.equals("5")) { 81 | writer.write("[Path]"); 82 | writer.write(String.valueOf(down_size)); 83 | } 84 | 85 | writer.write("eof\n"); 86 | writer.flush();//写完后要记得flush 87 | 88 | //读取从服务器端传过来的数据 89 | ReadString(type); 90 | 91 | } catch (IOException e) { 92 | e.printStackTrace(); 93 | } 94 | //建立连接后就可以往服务端发送数据 95 | } 96 | 97 | //读取从服务器端传过来的数据 98 | private void ReadString(String type) throws IOException { 99 | 100 | client.setSoTimeout(200 * 1000); 101 | if (type.equals("2") || type.equals("5")) //下载或者断点下载命令 102 | { 103 | 104 | bis = new BufferedInputStream(client.getInputStream()); 105 | dis = new DataInputStream(bis); 106 | 107 | File file = new File(path); 108 | if (!file.isDirectory()) { 109 | file.mkdirs(); //创建文件夹 110 | } 111 | 112 | try { 113 | 114 | File db = new File(file + File.separator + str_down); 115 | 116 | //如果断点下载的文件不存在或者是下载不管存不存在 117 | if (down_size == 0) { 118 | File myfile = new File(file, str_down); 119 | try { 120 | myfile.createNewFile(); //创建文件 121 | 122 | } catch (IOException e) { 123 | e.printStackTrace(); 124 | } 125 | 126 | if (type.equals("2")) { //下载不能追加,一下下完 127 | fos = new FileOutputStream(db); 128 | } else if (type.equals("5")) //断点下载可以追加 129 | { 130 | fos = new FileOutputStream(db, true); //可以追加 131 | 132 | } 133 | bos = new BufferedOutputStream(fos); 134 | dos = new DataOutputStream(bos); 135 | 136 | byte[] by = new byte[1024]; 137 | 138 | int len = -1; // 按字节读取剩余的内容 139 | while ((len = dis.read(by)) != -1) { 140 | SharedPreferences sharedPreferences3 = context.getSharedPreferences("config", context.MODE_PRIVATE); 141 | String duan_state = sharedPreferences3.getString("duan_state", "run"); 142 | Log.e("duan_state",duan_state); 143 | if(duan_state.equals("run")) { 144 | down_size += len; 145 | System.out.println(down_size); 146 | dos.write(by, 0, len); 147 | 148 | if(type.equals("5")) { 149 | Message msg = new Message(); 150 | msg.what = position; 151 | Down down = new Down(str_down, cmd, url_down_path, file_size, down_size); 152 | msg.obj = down; 153 | handler.sendMessage(msg); 154 | } 155 | 156 | } 157 | else 158 | { 159 | dos.flush(); 160 | dos.close(); 161 | 162 | //将新的文件下载大小存入数据库中 163 | db_down=mydb.getWritableDatabase(); //得到数据库实例 164 | update(cmd,Long.valueOf(down_size)); 165 | 166 | } 167 | 168 | } 169 | 170 | 171 | } else { //如果断点下载的文件已经存在 172 | File db2 = new File(file + File.separator + str_down); 173 | fos = new FileOutputStream(db2, true); //可以追加内容 174 | bos = new BufferedOutputStream(fos); 175 | dos = new DataOutputStream(bos); 176 | 177 | byte[] by = new byte[1024]; 178 | 179 | int len = -1; // 按字节读取剩余的内容 180 | while ((len = dis.read(by)) != -1) { 181 | SharedPreferences sharedPreferences3 = context.getSharedPreferences("config", context.MODE_PRIVATE); 182 | String duan_state = sharedPreferences3.getString("duan_state", "run"); 183 | Log.e("duan_state",duan_state); 184 | if(duan_state.equals("run")) { 185 | down_size += len; 186 | System.out.println(down_size); 187 | dos.write(by, 0, len); 188 | 189 | if(type.equals("5")) { 190 | Message msg = new Message(); 191 | Down down = new Down(str_down, cmd, path, file_size, down_size); 192 | msg.what = position; 193 | msg.obj = down; 194 | handler.sendMessage(msg); 195 | } 196 | 197 | } 198 | else 199 | { 200 | dos.flush(); 201 | dos.close(); 202 | 203 | //将新的文件下载大小存入数据库中 204 | db_down=mydb.getWritableDatabase(); //得到数据库实例 205 | update(cmd,Long.valueOf(down_size)); 206 | 207 | } 208 | 209 | } 210 | } 211 | 212 | dos.flush(); 213 | 214 | dis.close(); 215 | bis.close(); 216 | fos.close(); 217 | dos.close(); 218 | //将新的文件下载大小存入数据库中 219 | db_down=mydb.getWritableDatabase(); //得到数据库实例 220 | update(cmd,Long.valueOf(down_size)); 221 | 222 | writer.close(); 223 | Log.e("stop","stop5"); 224 | 225 | 226 | } catch (FileNotFoundException e) { 227 | e.printStackTrace(); 228 | } catch (IOException e) { 229 | e.printStackTrace(); 230 | } 231 | client.close(); 232 | } 233 | 234 | } 235 | 236 | 237 | //修改下载内容 238 | private void update(String cmd , Long index) { 239 | ContentValues cv=new ContentValues(); 240 | 241 | String where="Url_down=?"; 242 | String[] whereValue={cmd}; 243 | cv.put("index_down",index); 244 | db_down.update(DownDB.table_name,cv,where,whereValue); 245 | } 246 | 247 | } 248 | -------------------------------------------------------------------------------- /Client/app/src/main/java/ClientSocket/ClientSocket_update.java: -------------------------------------------------------------------------------- 1 | package ClientSocket; 2 | 3 | import android.util.Log; 4 | 5 | import java.io.BufferedInputStream; 6 | import java.io.BufferedOutputStream; 7 | import java.io.DataInputStream; 8 | import java.io.DataOutputStream; 9 | import java.io.File; 10 | import java.io.FileInputStream; 11 | import java.io.FileNotFoundException; 12 | import java.io.FileOutputStream; 13 | import java.io.IOException; 14 | import java.io.InputStreamReader; 15 | import java.io.OutputStreamWriter; 16 | import java.io.Reader; 17 | import java.io.Writer; 18 | import java.net.ServerSocket; 19 | import java.net.Socket; 20 | 21 | import Ip_Port.Ip_Port; 22 | 23 | /** 24 | * Created by lenovo on 2017/4/13. 25 | */ 26 | public class ClientSocket_update { 27 | private Socket client; 28 | private Writer writer; 29 | private String str_out_update; 30 | private String path; 31 | private String path_str_1; 32 | 33 | //与服务器端进行连接 34 | public void doConnect(String cmd,String type,String path_str) { 35 | 36 | //与服务端建立连接 37 | //客户端进行写操作 38 | 39 | path=cmd; //文件夹路径 40 | path_str_1=path_str; //SD卡中的文件路径 41 | int index=-1; 42 | int len_str=-1; 43 | len_str=path_str_1.length(); 44 | String str_down=""; 45 | if ((index = path_str_1.lastIndexOf("/")) != -1) { 46 | str_down=path_str_1.substring(index+1,len_str); //上传的文件名称 47 | Log.e("str_down",str_down); 48 | } 49 | try { 50 | 51 | client = new Socket(Ip_Port.getIP(), Ip_Port.getPort()); 52 | writer = new OutputStreamWriter(client.getOutputStream(), "utf-8"); 53 | writer.write(type); 54 | writer.write(path+"[Director]"); //文件夹路径 55 | writer.write(str_down); 56 | writer.write("eof\n"); 57 | 58 | Log.e("string", path); 59 | writer.flush();//写完后要记得flush 60 | 61 | //读取上传文件的相关信息 62 | ReadString(type); 63 | 64 | } catch (IOException e) { 65 | e.printStackTrace(); 66 | } 67 | //建立连接后就可以往服务端发送数据 68 | } 69 | 70 | //读取上传文件的相关信息 71 | private void ReadString(String type) throws IOException { 72 | 73 | client.setSoTimeout(200 * 1000); 74 | 75 | if(type.equals("3")) 76 | { 77 | File file=null; 78 | FileInputStream fi=null; 79 | BufferedInputStream bis=null; 80 | DataInputStream dis=null; 81 | 82 | try { 83 | 84 | Log.e("path_str",path_str_1); 85 | file=new File(path_str_1); 86 | fi=new FileInputStream(file); 87 | bis=new BufferedInputStream(fi); 88 | dis=new DataInputStream(bis); 89 | 90 | //按字节读取剩余的内容 91 | try { 92 | 93 | BufferedOutputStream bos=null; 94 | DataOutputStream dos=null; 95 | bos=new BufferedOutputStream(client.getOutputStream()); 96 | dos=new DataOutputStream(bos); 97 | 98 | byte[] by = new byte[1024]; 99 | 100 | int len = -1; // 按字节读取剩余的内容 101 | while((len=dis.read(by))!=-1) { 102 | Log.e("len", String.valueOf(len)); 103 | dos.write(by, 0, len); 104 | } 105 | dos.flush(); 106 | dos.close(); 107 | fi.close(); 108 | bis.close(); 109 | dis.close(); 110 | writer.close(); 111 | client.close(); 112 | } catch (IOException e) { 113 | e.printStackTrace(); 114 | } 115 | 116 | } catch (FileNotFoundException e) { 117 | e.printStackTrace(); 118 | } 119 | } 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /Client/app/src/main/java/Database/Down.java: -------------------------------------------------------------------------------- 1 | package Database; 2 | 3 | /** 4 | * Created by lenovo on 2017/5/8. 5 | */ 6 | public class Down { 7 | 8 | private String title; //名字 9 | private String url_down; //链接 10 | private String url_down_path; //文件夹路径 11 | private long index_state; //进度 12 | private long state; //状态 13 | 14 | public Down(String title, String url_down, String url_down_path,long state,long index_state){ 15 | this.title=title; 16 | this.url_down=url_down; 17 | this.state=state; 18 | this.index_state=index_state; 19 | this.url_down_path=url_down_path; 20 | } 21 | 22 | public String getTitle() { 23 | return title; 24 | } 25 | public void setTitle(String title) { 26 | this.title = title; 27 | } 28 | 29 | public String getUrl() 30 | { 31 | return url_down; 32 | } 33 | public void setUrl(String url_down) { 34 | this.url_down = url_down; 35 | } 36 | 37 | public String getUrl_down_path() 38 | { 39 | return url_down_path; 40 | } 41 | public void setUrl_down_path(String url_down_path) { 42 | this.url_down_path = url_down_path; 43 | } 44 | 45 | public long getIndex_state() { 46 | return index_state; 47 | } 48 | public void setIndex_state(long index_state) { 49 | this.index_state = index_state; 50 | } 51 | 52 | public long getState() { 53 | return state; 54 | } 55 | public void setState(long state) { 56 | this.state = state; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /Client/app/src/main/java/Database/DownDB.java: -------------------------------------------------------------------------------- 1 | package Database; 2 | 3 | 4 | import android.content.Context; 5 | import android.database.sqlite.SQLiteDatabase; 6 | import android.database.sqlite.SQLiteOpenHelper; 7 | 8 | 9 | /** 10 | * Created by lenovo on 2017/5/8. 11 | */ 12 | public class DownDB extends SQLiteOpenHelper{ 13 | 14 | public static String Title_down="title_down"; 15 | public static String Url_down="url_down"; 16 | public static String State_down="state_down"; 17 | public static String Index_down="index_down"; 18 | public static String Url_down_path="url_down_path"; 19 | private static final String database_name="wyq_db_3.db"; 20 | public static String table_name="mytable"; 21 | public DownDB(Context context){ 22 | 23 | super(context,database_name,null,1); //创建数据库 24 | } 25 | @Override 26 | public void onCreate(SQLiteDatabase db) { 27 | String sql="create table if not exists mytable(_id integer primary key autoincrement," + 28 | "Title_down text,Url_down text,Url_down_path text,State_down long,Index_down long)"; //创建一张表,_id会自增 29 | db.execSQL(sql); //执行sql语句 30 | 31 | } 32 | 33 | @Override 34 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 35 | 36 | db.execSQL("drop table if exists constants"); //删除表 37 | onCreate(db); //并没有更新,只是重新建了一张表 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Client/app/src/main/java/Ip_Port/Ip_Port.java: -------------------------------------------------------------------------------- 1 | package Ip_Port; 2 | 3 | /** 4 | * Created by lenovo on 2017/5/11. 5 | */ 6 | public class Ip_Port { //用于保存IP地址以及端口号 7 | 8 | private static String IP="192.168.160.1"; //要连接的服务器的ip地址 9 | private static int Port = 5507; //要连接的服务端对应的监听端口 10 | 11 | public static String getIP() 12 | { 13 | return IP; 14 | } 15 | 16 | public static void setIP(String IP) 17 | { 18 | Ip_Port.IP=IP; 19 | } 20 | 21 | public static int getPort() 22 | { 23 | return Port; 24 | } 25 | 26 | public static void setPort(int Port) 27 | { 28 | Ip_Port.Port=Port; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Client/app/src/main/java/Menu_file/Menu_file.java: -------------------------------------------------------------------------------- 1 | package Menu_file; 2 | 3 | /** 4 | * Created by lenovo on 2017/4/5. 5 | */ 6 | public class Menu_file { 7 | private String title; 8 | private String type; 9 | private String date; 10 | private String size; 11 | 12 | public Menu_file(String title, String type, String date, String size) 13 | { 14 | this.title=title; 15 | this.type=type; 16 | this.date=date; 17 | this.size=size; 18 | } 19 | public String getTitle() { 20 | return title; 21 | } 22 | 23 | public void setTitle(String title) { 24 | this.title = title; 25 | } 26 | 27 | public String getType() { 28 | return type; 29 | } 30 | 31 | public void setType(String type) { 32 | this.type = type; 33 | } 34 | 35 | public String getDate() { 36 | return date; 37 | } 38 | 39 | public void setDate(String date) { 40 | this.date = date; 41 | } 42 | 43 | public String getSize() { 44 | return size; 45 | } 46 | 47 | public void setSize(String size) { 48 | this.size = size; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Client/app/src/main/java/MyAdapter/MyAdapter.java: -------------------------------------------------------------------------------- 1 | package MyAdapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.example.administrator.client.R; 12 | 13 | import java.util.ArrayList; 14 | 15 | import Menu_file.Menu_file; 16 | 17 | /** 18 | * Created by lenovo on 2017/3/23. 19 | */ 20 | public class MyAdapter extends BaseAdapter { 21 | 22 | 23 | LayoutInflater inflater; 24 | private ArrayList listItem; 25 | 26 | public MyAdapter(Context context, ArrayList listItems) 27 | { 28 | inflater= LayoutInflater.from(context); //所使用的布局是哪一个 29 | this.listItem=listItems; 30 | } 31 | 32 | //返回listItem的数量 33 | @Override 34 | public int getCount() { 35 | return listItem.size(); 36 | } 37 | 38 | @Override 39 | public Menu_file getItem(int i) { 40 | return listItem.get(i); 41 | } 42 | 43 | @Override 44 | public long getItemId(int i) { 45 | return i; 46 | } 47 | 48 | @Override 49 | public View getView(int i, View view, ViewGroup viewGroup) { 50 | //将写好的listcontent_layout.xml文件转化为一个view 51 | View view1=inflater.inflate(R.layout.menu_layout,null); 52 | ImageView image=(ImageView)view1.findViewById(R.id.list_image); 53 | TextView tv_title=(TextView)view1.findViewById(R.id.title_content); 54 | TextView tv_date=(TextView)view1.findViewById(R.id.list_date); 55 | TextView tv_size=(TextView)view1.findViewById(R.id.list_size); 56 | String type; 57 | 58 | if(listItem.get(i).getType()=="1") 59 | { 60 | tv_title.setText(listItem.get(i).getTitle()); 61 | tv_date.setText(listItem.get(i).getDate()); 62 | tv_size.setVisibility(View.GONE); //设为不可见 63 | image.setImageResource(R.drawable.menu); 64 | } 65 | else 66 | { 67 | tv_title.setText(listItem.get(i).getTitle()); 68 | tv_date.setText(listItem.get(i).getDate()); 69 | tv_size.setText(listItem.get(i).getSize()); //设为不可见 70 | image.setImageResource(R.drawable.doc); 71 | } 72 | 73 | return view1; 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /Client/app/src/main/java/MyAdapter/MyAdapter_Down_Update.java: -------------------------------------------------------------------------------- 1 | package MyAdapter; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.util.Log; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.BaseAdapter; 10 | import android.widget.ImageView; 11 | import android.widget.ProgressBar; 12 | import android.widget.TextView; 13 | 14 | import com.example.administrator.client.R; 15 | 16 | import java.util.ArrayList; 17 | 18 | import javax.security.auth.callback.Callback; 19 | 20 | import Database.Down; 21 | 22 | 23 | /** 24 | * Created by lenovo on 2017/5/8. 25 | */ 26 | public class MyAdapter_Down_Update extends BaseAdapter{ 27 | LayoutInflater inflater; 28 | private static final String TAG="MyAdapter_Down_Update"; 29 | private ArrayList listItem; 30 | private Callback2 mCallback; 31 | 32 | //自定义接口,用于回调image点击事件到activity 33 | public interface Callback2 34 | { 35 | void click(View v,int i); //点击的是哪一个开始按钮 36 | void click_end(View v,int i); //点击的是哪一个暂停按钮 37 | } 38 | 39 | 40 | public MyAdapter_Down_Update(Context context, ArrayList listItems,Callback2 callback) 41 | { 42 | inflater= LayoutInflater.from(context); //所使用的布局是哪一个 43 | this.listItem=listItems; 44 | this.mCallback=callback; 45 | } 46 | 47 | 48 | //返回listItem的数量 49 | @Override 50 | public int getCount() { 51 | return listItem.size(); 52 | } 53 | 54 | @Override 55 | public Down getItem(int i) { 56 | return listItem.get(i); 57 | } 58 | 59 | @Override 60 | public long getItemId(int i) { 61 | return i; 62 | } 63 | 64 | @Override 65 | public View getView(int i, final View view, ViewGroup viewGroup) { 66 | //将写好的listcontent_layout.xml文件转化为一个view 67 | final View view1 = inflater.inflate(R.layout.down_update_content_layout, null); 68 | 69 | TextView title_down_update = (TextView) view1.findViewById(R.id.title_content_down_update); //标题 70 | ProgressBar pb = (ProgressBar) view1.findViewById(R.id.pb); //进度条 71 | TextView index_down_update = (TextView) view1.findViewById(R.id.index_content); //进度 72 | title_down_update.setText(listItem.get(i).getTitle()); 73 | 74 | Long index_do=listItem.get(i).getIndex_state(); 75 | Long state_do=listItem.get(i).getState(); 76 | int percent= (int) (((index_do+1)*1.0/state_do)*100); 77 | pb.setProgress(percent); 78 | if(percent==100) 79 | { 80 | index_down_update.setText("完成"); 81 | } 82 | else { 83 | index_down_update.setText(String.valueOf(percent)); 84 | } 85 | ImageView image=(ImageView)view1.findViewById(R.id.start); //开始按钮 86 | ImageView image_end=(ImageView)view1.findViewById(R.id.end); //暂停按钮 87 | 88 | //点击的是哪一个开始按钮 89 | final int p=i; 90 | image.setOnClickListener(new View.OnClickListener() { 91 | @Override 92 | public void onClick(View v) { 93 | mCallback.click(v,p); //调用接口中的点击事件 94 | 95 | } 96 | }); 97 | //点击的是哪一个暂停按钮 98 | image_end.setOnClickListener(new View.OnClickListener() { 99 | @Override 100 | public void onClick(View view) { 101 | mCallback.click_end(view,p); 102 | } 103 | }); 104 | 105 | return view1; 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /Client/app/src/main/java/com/example/administrator/client/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.administrator.client; 2 | 3 | import android.content.ContentResolver; 4 | import android.content.ContentValues; 5 | import android.content.Intent; 6 | import android.database.Cursor; 7 | import android.database.sqlite.SQLiteDatabase; 8 | import android.net.Uri; 9 | import android.os.Environment; 10 | import android.os.Handler; 11 | import android.os.Message; 12 | import android.provider.MediaStore; 13 | import android.support.v7.app.AppCompatActivity; 14 | import android.os.Bundle; 15 | import android.util.Log; 16 | import android.util.Xml; 17 | import android.view.ContextMenu; 18 | import android.view.Menu; 19 | import android.view.MenuItem; 20 | import android.view.View; 21 | import android.widget.AdapterView; 22 | import android.widget.Button; 23 | import android.widget.EditText; 24 | import android.widget.ImageView; 25 | import android.widget.ListView; 26 | import android.widget.RelativeLayout; 27 | import android.widget.Toast; 28 | 29 | import java.io.FileOutputStream; 30 | import com.example.administrator.client.Manage.down_manage; 31 | 32 | import org.xmlpull.v1.XmlSerializer; 33 | 34 | import java.io.File; 35 | import java.sql.Date; 36 | import java.util.ArrayList; 37 | 38 | import ClientSocket.ClientSocket; 39 | import ClientSocket.ClientSocket_down; 40 | import ClientSocket.ClientSocket_update; 41 | import Database.DownDB; 42 | import Menu_file.Menu_file; 43 | import MyAdapter.MyAdapter; 44 | 45 | public class MainActivity extends AppCompatActivity { 46 | 47 | private Handler handler; 48 | private EditText edit; 49 | private ListView list; 50 | private ImageView image_return; 51 | private Button button; 52 | private ArrayList arrayList; 53 | private ArrayList last_arrayList; //保存之前遍历的文件路径 54 | private ArrayList listItems; 55 | 56 | private String edit_text; 57 | private String result; 58 | private RelativeLayout layout_menu; 59 | private MyAdapter adapter; 60 | //上下文菜单 61 | private static final int ITEM6 = Menu.FIRST + 5; 62 | private static final int ITEM7 = Menu.FIRST + 6; 63 | private static final int ITEM8 = Menu.FIRST + 7; 64 | 65 | //选项菜单 66 | private static final int ITEM1 = Menu.FIRST; 67 | private static final int ITEM2 = Menu.FIRST + 1; 68 | private static final int ITEM3 = Menu.FIRST + 2; 69 | private static final int ITEM4 = Menu.FIRST + 3; 70 | private static final int ITEM5 = Menu.FIRST + 4; 71 | private static final int ITEM9 = Menu.FIRST + 8; 72 | 73 | private String str_down = ""; 74 | private SQLiteDatabase db; 75 | private DownDB mydb = new DownDB(this); 76 | Cursor cursor; 77 | long _id; 78 | Long size_duan_down = Long.valueOf(0); //要下载的文件大小 79 | 80 | @Override 81 | protected void onCreate(Bundle savedInstanceState) { 82 | super.onCreate(savedInstanceState); 83 | 84 | setContentView(R.layout.activity_main); 85 | edit = (EditText) findViewById(R.id.edit1); 86 | list = (ListView) findViewById(R.id.listview); 87 | button = (Button) findViewById(R.id.butt); 88 | image_return = (ImageView) findViewById(R.id.image_return); 89 | arrayList = new ArrayList<>(); 90 | last_arrayList = new ArrayList<>(); 91 | edit_text = ""; 92 | 93 | layout_menu = (RelativeLayout) findViewById(R.id.menu_layout); //这个代表的是menu_layout 94 | last_arrayList.add("我的电脑"); 95 | edit.setText("我的电脑"); 96 | newThread("我的电脑", "1", ""); //初始时访问的是系统的根目录 97 | 98 | listItems = new ArrayList<>(); 99 | listItems = arrayList; 100 | adapter = new MyAdapter(MainActivity.this, listItems); 101 | list.setAdapter(adapter); 102 | 103 | handler = new Handler(new Handler.Callback() { 104 | @Override 105 | public boolean handleMessage(Message msg) { 106 | 107 | adapter.notifyDataSetChanged(); 108 | return false; 109 | } 110 | }); 111 | 112 | list.setOnItemClickListener(new AdapterView.OnItemClickListener() { 113 | @Override 114 | public void onItemClick(AdapterView parent, View view, int position, long id) { 115 | result = arrayList.get(position).getTitle(); 116 | 117 | //打开文件夹 118 | String str; 119 | if ((str = arrayList.get(position).getType()) == "1") { 120 | arrayList.clear(); 121 | edit_text = edit_text + result + File.separator; 122 | edit.setText(edit_text); 123 | last_arrayList.add(edit_text); 124 | newThread(edit.getText().toString(), "1", ""); //new一个新线程 125 | } 126 | } 127 | }); 128 | 129 | button.setOnClickListener(new View.OnClickListener() { 130 | @Override 131 | public void onClick(View v) { 132 | 133 | edit_text = edit.getText().toString() + "/"; 134 | last_arrayList.add(edit_text); 135 | newThread(edit.getText().toString(), "1", ""); //new一个新的线程 136 | } 137 | }); 138 | 139 | image_return.setOnClickListener(new View.OnClickListener() { 140 | @Override 141 | public void onClick(View v) { 142 | int leng_last = last_arrayList.size(); 143 | if (leng_last > 1) { 144 | newThread(last_arrayList.get(leng_last - 2).toString(), "1", ""); 145 | edit.setText(last_arrayList.get(leng_last - 2).toString()); 146 | edit_text = edit.getText().toString(); 147 | if (edit_text.equals("我的电脑")) { 148 | edit_text = ""; 149 | } 150 | last_arrayList.remove(leng_last - 1); 151 | } 152 | } 153 | }); 154 | 155 | //注册上下文菜单 156 | this.registerForContextMenu(list); 157 | } 158 | 159 | //new一个新的线程 160 | private void newThread(final String input, final String type, final String str) { 161 | new Thread(new Runnable() { 162 | 163 | @Override 164 | public void run() { 165 | 166 | //1 遍历 167 | //2 下载 168 | //3 上传 169 | //4 加入下载列表 170 | //5 开始断点下载 171 | //6 暂停断点下载 172 | 173 | //8 在服务器端打开 174 | //9 打开服务器端浏览器 175 | 176 | if (type.equals("1")) //遍历目录 177 | { 178 | ClientSocket clientSocket = new ClientSocket(); 179 | clientSocket.doConnect(input, type); //与服务器连接 180 | 181 | arrayList.clear(); 182 | int inde = clientSocket.getArrayList().size(); 183 | for (int i = 0; i < inde; i++) { 184 | final String str_re = clientSocket.getArrayList().get(i); //title,date,type,size等信息的一条字符串 185 | Menu_file menus = null; 186 | int in; 187 | int in2; 188 | int in3; 189 | 190 | //将每一个字段都分出来 文件夹 191 | if ((in = str_re.indexOf("[menu]")) != -1) { 192 | 193 | String title_str = str_re.substring(0, in); 194 | 195 | in2 = str_re.indexOf("[date]"); 196 | in3 = str_re.indexOf("[size]"); 197 | String date_str = "更新时间:" + str_re.substring(in + 6, in2); 198 | menus = new Menu_file(title_str, "1", date_str, "-1"); //构造menu对象 199 | 200 | } 201 | //文件 202 | else { 203 | 204 | in = str_re.indexOf("[file]"); 205 | String title_str = str_re.substring(0, in); 206 | 207 | in2 = str_re.indexOf("[date]"); 208 | in3 = str_re.indexOf("[size]"); 209 | String date_str = "更新时间:" + str_re.substring(in + 6, in2); 210 | String size_str = str_re.substring(in2 + 6, in3) + " B"; 211 | menus = new Menu_file(title_str, "2", date_str, size_str); 212 | } 213 | arrayList.add(menus); 214 | } 215 | } else if (type.equals("2")) //下载小文件 216 | { 217 | /* String path="/data"+ Environment.getDataDirectory().getAbsolutePath() 218 | +File.separator+getPackageName() 219 | +File.separator+"file"+File.separator; */ //文件夹路径 220 | 221 | String path = "/storage/emulated/0" + File.separator + "file" + File.separator; 222 | ClientSocket_down clientSocket_down = new ClientSocket_down(); 223 | clientSocket_down.doConnect(getBaseContext(), input, type, path, str_down, (long) 0, (long) 0, null, -1, null); //与服务器连接 224 | 225 | } else if (type.equals("3"))//上传小文件 226 | { 227 | ClientSocket_update clientSocket_update = new ClientSocket_update(); 228 | clientSocket_update.doConnect(input, type, str); //与服务器连接 229 | 230 | } else if (type.equals("4")) //断点下载 //因为是4,所以只会传输文件大小,没有其他内容 231 | { 232 | ClientSocket clientSocket_down_duan = new ClientSocket(); 233 | clientSocket_down_duan.doConnect(input, type); 234 | size_duan_down = clientSocket_down_duan.getFileSize(); //获取的断点续传原始文件大小 235 | } else if (type.equals("8")) //在服务器端打开 236 | { 237 | ClientSocket clientSocket = new ClientSocket(); 238 | clientSocket.doConnect(input, type); 239 | } else if (type.equals("9")) //打开服务器端浏览器 240 | { 241 | ClientSocket clientSocket = new ClientSocket(); 242 | clientSocket.doConnect(input, type); 243 | } 244 | handler.sendEmptyMessage(0); 245 | } 246 | }).start(); 247 | } 248 | 249 | //上下文菜单 250 | @Override 251 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { 252 | if (v == list) { 253 | menu.add(0, ITEM6, 0, "下载此文件"); 254 | menu.add(0, ITEM7, 1, "加入下载列表"); 255 | menu.add(0, ITEM8, 2, "在服务器端打开"); 256 | 257 | } 258 | } 259 | 260 | @Override 261 | public boolean onContextItemSelected(MenuItem item) { 262 | switch (item.getItemId()) { 263 | //下载小文件 264 | case ITEM6: 265 | 266 | AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); 267 | final int position_longclick = info.position; 268 | 269 | result = arrayList.get(position_longclick).getTitle(); 270 | Log.e("result", result); 271 | //下载文件 272 | String str; 273 | if ((str = arrayList.get(position_longclick).getType()) != "1") { 274 | str_down = result; 275 | newThread(edit_text + result, "2", ""); //new一个新线程 276 | } 277 | break; 278 | 279 | //加入下载列表 280 | case ITEM7: 281 | 282 | AdapterView.AdapterContextMenuInfo info1 = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); 283 | final int position_longclick1 = info1.position; 284 | 285 | //加入下载列表 286 | String str1; 287 | if ((str1 = arrayList.get(position_longclick1).getType()) != "1") { 288 | 289 | //发送消息,获取文件的大小 290 | String str_duan_down = arrayList.get(position_longclick1).getTitle(); 291 | newThread(edit_text + str_duan_down, "4", ""); 292 | 293 | db = mydb.getWritableDatabase(); //得到数据库实例 294 | String title_1 = arrayList.get(position_longclick1).getTitle(); 295 | String url_1 = edit_text + str_duan_down; 296 | Long index_1 = Long.valueOf(0); 297 | insert(title_1, url_1, edit_text, size_duan_down, index_1); //size_duan_down的内容是获取的断点下载文件的原始大小 298 | } 299 | break; 300 | 301 | 302 | //在服务器端打开某个文件 303 | case ITEM8: 304 | AdapterView.AdapterContextMenuInfo info2 = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); 305 | final int position_longclick2 = info2.position; 306 | 307 | String str2; 308 | if ((str1 = arrayList.get(position_longclick2).getType()) != "1") { //如果是文件的话 309 | 310 | //发送消息,在服务器端打开文件 311 | String str_duan_down = arrayList.get(position_longclick2).getTitle(); 312 | newThread(edit_text + str_duan_down, "8", ""); 313 | 314 | } 315 | break; 316 | 317 | } 318 | return true; 319 | } 320 | 321 | //选项菜单 322 | @Override 323 | public boolean onCreateOptionsMenu(Menu menu) { 324 | super.onCreateOptionsMenu(menu); 325 | menu.add(0, ITEM1, 0, "上传文件"); 326 | menu.add(0, ITEM2, 1, "加入上传列表"); 327 | menu.add(0, ITEM3, 2, "下载列表"); 328 | menu.add(0, ITEM4, 3, "上传列表"); 329 | menu.add(0, ITEM5, 4, "打开服务器端浏览器"); 330 | menu.add(0, ITEM9, 5, "备份短信"); 331 | return true; 332 | } 333 | 334 | @Override 335 | public boolean onOptionsItemSelected(MenuItem item) { 336 | switch (item.getItemId()) { 337 | case ITEM1: //上传文件 338 | Intent intent = new Intent(Intent.ACTION_GET_CONTENT); //本地文件 339 | intent.setType("file/*"); 340 | // "file/*"设置数据对象为文件类型,则系统会默认调用文件浏览器, 341 | intent.addCategory(Intent.CATEGORY_OPENABLE); 342 | startActivityForResult(intent, 0); 343 | break; 344 | 345 | case ITEM2: //加入上传列表 346 | 347 | break; 348 | 349 | case ITEM3: //下载列表 350 | Intent intent1 = new Intent(); 351 | intent1.setClass(MainActivity.this, down_manage.class); 352 | startActivity(intent1); 353 | // startActivityForResult(intent1,0); //传递intent参数 354 | 355 | break; 356 | 357 | case ITEM4: //上传列表 358 | 359 | break; 360 | 361 | case ITEM5: //打开服务器端浏览器 362 | 363 | newThread("baidu.com", "9", ""); 364 | break; 365 | 366 | //备份短信 367 | case ITEM9: 368 | // Intent intent3 = new Intent(this,BackupSmsService.class); 369 | // startService(intent3); 370 | 371 | try { 372 | //创建一个存储备份短信的文件对象 373 | File smsBackUpFile = new File("/storage/emulated/0" + File.separator + "file" + File.separator+"message.xml"); 374 | 375 | //创建一个xml文件的生成器。 376 | XmlSerializer serializer = Xml.newSerializer(); 377 | //完成序列化器初始化操作。 378 | FileOutputStream os = new FileOutputStream(smsBackUpFile); 379 | serializer.setOutput(os, "utf-8"); 380 | //内容提供者。 381 | //获取到一个数据库的内容的解析者 382 | ContentResolver resolver = getContentResolver(); 383 | //游标(结果集) 384 | Cursor cursor3 = resolver.query(Uri.parse("content://sms"), 385 | new String[]{"address","date","type","body"}, null, null, null); 386 | //生成xml文件的头 387 | serializer.startDocument("utf-8", true); 388 | serializer.startTag(null, "smss"); 389 | while(cursor3.moveToNext()){ 390 | serializer.startTag(null, "sms"); 391 | String address = cursor3.getString(0); 392 | String date = cursor3.getString(1); 393 | String type = cursor3.getString(2); 394 | String body = cursor3.getString(3); 395 | 396 | serializer.startTag(null, "address"); 397 | serializer.text(address); 398 | serializer.endTag(null, "address"); 399 | 400 | serializer.startTag(null, "date"); 401 | serializer.text(date); 402 | serializer.endTag(null, "date"); 403 | 404 | serializer.startTag(null, "body"); 405 | serializer.text(body); 406 | serializer.endTag(null, "body"); 407 | 408 | serializer.startTag(null, "type"); 409 | serializer.text(type); 410 | serializer.endTag(null, "type"); 411 | 412 | serializer.endTag(null, "sms"); 413 | } 414 | cursor3.close(); 415 | serializer.endTag(null, "smss"); 416 | serializer.endDocument(); 417 | os.close(); 418 | Toast.makeText(getApplicationContext(), "备份完成",Toast.LENGTH_LONG).show(); 419 | 420 | } catch (Exception e) { 421 | e.printStackTrace(); 422 | } 423 | 424 | //然后将xml文件上传到服务器端 425 | newThread("D:/Message", "3", "/storage/emulated/0" + File.separator + "file" + File.separator+"message.xml"); 426 | break; 427 | } 428 | return super.onOptionsItemSelected(item); 429 | } 430 | 431 | //将图片的映射路径转换为真实路径 432 | public String getRealFilePath(final Uri uri) { 433 | String res = null; 434 | String[] proj = {MediaStore.Images.Media.DATA}; 435 | Cursor cursor = getContentResolver().query(uri, proj, null, null, null); 436 | if (cursor.moveToFirst()) { 437 | ; 438 | int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 439 | res = cursor.getString(column_index); 440 | } 441 | cursor.close(); 442 | return res; 443 | 444 | } 445 | 446 | @Override 447 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 448 | 449 | if (resultCode == RESULT_OK) { 450 | 451 | Uri uri = data.getData(); 452 | String path = uri.getPath(); 453 | 454 | //将图片的映射路径转换为真实路径 455 | if (uri.toString().contains("content://")) { 456 | path = getRealFilePath(uri); 457 | } 458 | Log.e("requestCode", "ok"); 459 | Toast.makeText(this, path, Toast.LENGTH_SHORT).show(); 460 | newThread(edit_text, "3", path); 461 | 462 | } 463 | super.onActivityResult(requestCode, resultCode, data); 464 | } 465 | 466 | //增加下载内容 467 | private void insert(String title, String url, String url_path, Long state, Long index) { 468 | ContentValues cv = new ContentValues(); 469 | cv.put(DownDB.Title_down, title); 470 | cv.put(DownDB.Url_down, url); 471 | cv.put(DownDB.Url_down_path, url_path); 472 | cv.put(DownDB.State_down, state); 473 | cv.put(DownDB.Index_down, index); 474 | db.insert(DownDB.table_name, DownDB.Title_down, cv); 475 | } 476 | 477 | } 478 | -------------------------------------------------------------------------------- /Client/app/src/main/java/com/example/administrator/client/Manage/down_manage.java: -------------------------------------------------------------------------------- 1 | package com.example.administrator.client.Manage; 2 | 3 | import android.content.SharedPreferences; 4 | import android.database.Cursor; 5 | import android.database.sqlite.SQLiteDatabase; 6 | import android.os.Handler; 7 | import android.os.Message; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.os.Bundle; 10 | import android.view.View; 11 | import android.widget.ImageView; 12 | import android.widget.ListView; 13 | import android.widget.Toast; 14 | 15 | import com.example.administrator.client.R; 16 | 17 | import java.io.File; 18 | import java.util.ArrayList; 19 | 20 | import ClientSocket.ClientSocket_down; 21 | import Database.Down; 22 | import Database.DownDB; 23 | import MyAdapter.MyAdapter_Down_Update; 24 | 25 | 26 | public class down_manage extends AppCompatActivity implements MyAdapter_Down_Update.Callback2 { 27 | 28 | ImageView image_return; 29 | ListView list_down_manage; 30 | MyAdapter_Down_Update adapter; 31 | private Handler handler; 32 | public ArrayList mDown_List = new ArrayList(); 33 | private DownDB mDown_DB; 34 | private ArrayList mDown_title = new ArrayList(); //标题 35 | private ArrayList mDown_Url = new ArrayList(); //链接 36 | private ArrayList mDown_state = new ArrayList(); //状态 37 | private ArrayList mDown_index = new ArrayList(); //进度 38 | private ArrayList mDown_Url_Path = new ArrayList(); //文件夹路径 39 | private SQLiteDatabase db; 40 | private SQLiteDatabase db2; 41 | private DownDB mydb = new DownDB(this); 42 | Cursor cursor; 43 | Cursor cursor2; 44 | 45 | @Override 46 | protected void onCreate(Bundle savedInstanceState) { 47 | super.onCreate(savedInstanceState); 48 | setContentView(R.layout.down_manage_layout); 49 | 50 | //返回按钮 51 | image_return = (ImageView) findViewById(R.id.return_down); 52 | image_return.setOnClickListener(new View.OnClickListener() { 53 | @Override 54 | public void onClick(View view) { 55 | switch (view.getId()) { 56 | case R.id.return_down: 57 | finish(); 58 | break; 59 | 60 | default: 61 | break; 62 | } 63 | } 64 | }); 65 | 66 | //下载列表 67 | db = mydb.getWritableDatabase(); //得到数据库实例 68 | //查询数据库 69 | cursor = db.rawQuery("select _id,title_down,url_down,url_down_path,state_down,index_down from mytable order by title_down", null); //游标 70 | list_down_manage = (ListView) findViewById(R.id.listview_down); 71 | 72 | handler = new Handler() { 73 | @Override 74 | public void handleMessage(Message msg) { 75 | 76 | super.handleMessage(msg); 77 | 78 | Down down2=(Down)msg.obj; 79 | int position=msg.what; 80 | mDown_List.set(position,down2); 81 | adapter.notifyDataSetChanged(); 82 | 83 | } 84 | 85 | }; 86 | 87 | ReadCursor(); 88 | adapter = new MyAdapter_Down_Update(down_manage.this, mDown_List, this); 89 | list_down_manage.setAdapter(adapter); 90 | } 91 | 92 | //遍历数据库 93 | public void ReadCursor() { 94 | //遍历数据库 95 | cursor.moveToFirst(); //要定位到第一列 96 | while (!cursor.isAfterLast()) { 97 | int id = cursor.getInt(0); 98 | String title_d = cursor.getString(1); 99 | String url_d = cursor.getString(2); 100 | String url_d_p = cursor.getString(3); 101 | long state_d = cursor.getLong(4); 102 | long index_d = cursor.getLong(5); 103 | mDown_title.add(title_d); //标题 104 | mDown_Url.add(url_d); //链接 105 | mDown_state.add(state_d); //状态(实际为文件的大小) 106 | mDown_index.add(index_d); //进度 107 | mDown_Url_Path.add(url_d_p); //文件夹路径 108 | 109 | Down down = new Down(title_d, url_d, url_d_p, state_d, index_d); 110 | mDown_List.add(down); 111 | 112 | cursor.moveToNext(); 113 | } 114 | cursor.close(); 115 | } 116 | 117 | //点击开始按钮命令 118 | @Override 119 | public void click(View v, int i) { 120 | 121 | int position_image_start = i; //点击的ImageView是哪一个 122 | Long down_size = mDown_index.get(position_image_start); //下载了多少 123 | Long file_size = mDown_state.get(position_image_start); //文件原始大小 124 | String url_down = mDown_Url.get(position_image_start); //文件的路径 125 | String url_down_path = mDown_Url_Path.get(position_image_start); //文件夹的路径 126 | String title_down = mDown_title.get(position_image_start); //文件的名字 127 | 128 | db2 = mydb.getReadableDatabase(); 129 | String[] columns = {DownDB.Index_down}; 130 | String[] str = {url_down}; 131 | cursor2 = db2.query(DownDB.table_name, null, "Url_down=?", str, null, null, null, null); 132 | cursor2.moveToFirst(); //要定位到第一列 133 | Long down_size3 = Long.valueOf(down_size); 134 | 135 | while (!cursor2.isAfterLast()) { 136 | 137 | down_size3 = cursor2.getLong(5); 138 | cursor2.moveToNext(); 139 | } 140 | cursor2.close(); 141 | 142 | //还没有下载完毕(包括已经下载和没有下载) 143 | if (down_size3 < file_size) { 144 | 145 | String path = "/storage/emulated/0" + File.separator + "file" + File.separator; 146 | newThread(url_down, "5", path, title_down, file_size, down_size3, position_image_start,url_down_path); 147 | } 148 | //已经下载完毕 149 | else if (down_size3 >= file_size) { 150 | Toast.makeText(down_manage.this, title_down + "下载已完成", Toast.LENGTH_LONG).show(); 151 | } 152 | } 153 | 154 | //点击暂停按钮命令 155 | @Override 156 | public void click_end(View v, int i) { 157 | 158 | Long down_size = mDown_index.get(i); //下载了多少 159 | Long file_size = mDown_state.get(i); //文件原始大小 160 | String url_down = mDown_Url.get(i); //文件的路径 161 | 162 | //还没下载完毕 163 | if (down_size < file_size) { 164 | //发送暂停命令 165 | int position_image_start = i; //点击的ImageView是哪一个 166 | Long down_size2 = mDown_index.get(position_image_start); //下载了多少 167 | Long file_size2 = mDown_state.get(position_image_start); //文件原始大小 168 | String url_down2 = mDown_Url.get(position_image_start); //文件的路径 169 | String url_down_path2 = mDown_Url_Path.get(position_image_start); //文件夹的路径 170 | String title_down2 = mDown_title.get(position_image_start); //文件的名字 171 | 172 | String path = "/storage/emulated/0" + File.separator + "file" + File.separator; 173 | 174 | newThread(url_down, "6", path, title_down2, file_size2, down_size2, position_image_start,url_down_path2); 175 | 176 | } 177 | } 178 | 179 | private void newThread(final String url_down, final String type, final String path, final String title_down, final Long file_size, final Long down_size, final int i, final String url_down_path) { 180 | new Thread(new Runnable() { 181 | 182 | String title = title_down; 183 | 184 | @Override 185 | public void run() { 186 | 187 | 188 | if (type.equals("5")) //断点续传 189 | { 190 | //开始执行下载命令 191 | ClientSocket_down clientSocket_duan_start = new ClientSocket_down(); 192 | clientSocket_duan_start.doConnect(getBaseContext(), url_down, "5", path, title_down, file_size, down_size, handler,i,url_down_path); 193 | SharedPreferences sharedPreferences = getSharedPreferences("config", MODE_PRIVATE); 194 | SharedPreferences.Editor editor = sharedPreferences.edit(); 195 | editor.putString("duan_state", "run"); 196 | editor.commit(); 197 | 198 | } else if (type.equals("6")) //停止断点续传 199 | { 200 | 201 | SharedPreferences sharedPreferences = getSharedPreferences("config", MODE_PRIVATE); 202 | SharedPreferences.Editor editor = sharedPreferences.edit(); 203 | editor.putString("duan_state", "stop"); 204 | editor.commit(); 205 | 206 | } 207 | } 208 | }).start(); 209 | 210 | } 211 | 212 | } 213 | -------------------------------------------------------------------------------- /Client/app/src/main/java/com/example/administrator/client/Manage/update_manage.java: -------------------------------------------------------------------------------- 1 | package com.example.administrator.client.Manage; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | import com.example.administrator.client.R; 7 | 8 | public class update_manage extends AppCompatActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_update_manage); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Client/app/src/main/res/drawable/base_action_bar_back_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinghuayu2377/myFTPDemo/6dabac6dd434192d05092cdb5edb27b08aa3e202/Client/app/src/main/res/drawable/base_action_bar_back_normal.png -------------------------------------------------------------------------------- /Client/app/src/main/res/drawable/doc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinghuayu2377/myFTPDemo/6dabac6dd434192d05092cdb5edb27b08aa3e202/Client/app/src/main/res/drawable/doc.jpg -------------------------------------------------------------------------------- /Client/app/src/main/res/drawable/end.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinghuayu2377/myFTPDemo/6dabac6dd434192d05092cdb5edb27b08aa3e202/Client/app/src/main/res/drawable/end.jpg -------------------------------------------------------------------------------- /Client/app/src/main/res/drawable/menu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinghuayu2377/myFTPDemo/6dabac6dd434192d05092cdb5edb27b08aa3e202/Client/app/src/main/res/drawable/menu.jpg -------------------------------------------------------------------------------- /Client/app/src/main/res/drawable/notification.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinghuayu2377/myFTPDemo/6dabac6dd434192d05092cdb5edb27b08aa3e202/Client/app/src/main/res/drawable/notification.jpg -------------------------------------------------------------------------------- /Client/app/src/main/res/drawable/return_butt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinghuayu2377/myFTPDemo/6dabac6dd434192d05092cdb5edb27b08aa3e202/Client/app/src/main/res/drawable/return_butt.jpg -------------------------------------------------------------------------------- /Client/app/src/main/res/drawable/start.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinghuayu2377/myFTPDemo/6dabac6dd434192d05092cdb5edb27b08aa3e202/Client/app/src/main/res/drawable/start.jpg -------------------------------------------------------------------------------- /Client/app/src/main/res/layout/activity_down_manage.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Client/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 17 | 18 | 23 | 24 | 29 | 30 | 35 | 36 | 37 | 38 |