Skip to content

Commit 47a85d8

Browse files
committed
[NewFeature] Add SDCard utils.
1 parent 5e91d2c commit 47a85d8

File tree

3 files changed

+128
-1
lines changed

3 files changed

+128
-1
lines changed

.settings/org.eclipse.jdt.ui.prefs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.ui.javadoc=true
3+
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return the ${bare_field_name}\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} the ${bare_field_name} to set\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\r\n * Copyright 2014 Zhenguo Jin (jinzhenguo1990@gmail.com)\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the "License");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http\://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an "AS IS" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * @author ${user}\r\n *\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\r\n * ${see_to_overridden}\r\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\r\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>

src/com/worthed/util/DisplayUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2014 Zhenguo Jin
2+
* Copyright 2014 Zhenguo Jin (jinzhenguo1990@gmail.com)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/com/worthed/util/SDCardUtils.java

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/**
2+
* Copyright 2014 Zhenguo Jin (jinzhenguo1990@gmail.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.worthed.util;
17+
18+
import java.io.File;
19+
import java.io.FileInputStream;
20+
import java.io.FileOutputStream;
21+
22+
/**
23+
* SDcard操作工具类
24+
*
25+
* @author jingle1267@163.com
26+
*
27+
*/
28+
public class SDCardUtils {
29+
/**
30+
* Check the SD card
31+
*
32+
* @return
33+
*/
34+
public static boolean checkSDCardAvailable() {
35+
return android.os.Environment.getExternalStorageState().equals(
36+
android.os.Environment.MEDIA_MOUNTED);
37+
}
38+
39+
/**
40+
* Check if the file is exists
41+
*
42+
* @param filePath
43+
* @param fileName
44+
* @return
45+
*/
46+
public static boolean isFileExistsInSDCard(String filePath, String fileName) {
47+
boolean flag = false;
48+
if (checkSDCardAvailable()) {
49+
File file = new File(filePath, fileName);
50+
if (file.exists()) {
51+
flag = true;
52+
}
53+
}
54+
return flag;
55+
}
56+
57+
/**
58+
* Write file to SD card
59+
*
60+
* @param filePath
61+
* @param filename
62+
* @param content
63+
* @return
64+
* @throws Exception
65+
*/
66+
public static boolean saveFileToSDCard(String filePath, String filename,
67+
String content) throws Exception {
68+
boolean flag = false;
69+
if (checkSDCardAvailable()) {
70+
File dir = new File(filePath);
71+
if (!dir.exists()) {
72+
dir.mkdir();
73+
}
74+
File file = new File(filePath, filename);
75+
FileOutputStream outStream = new FileOutputStream(file);
76+
outStream.write(content.getBytes());
77+
outStream.close();
78+
flag = true;
79+
}
80+
return flag;
81+
}
82+
83+
/**
84+
* Read file as stream from SD card
85+
*
86+
* @param fileName
87+
* String PATH =
88+
* Environment.getExternalStorageDirectory().getAbsolutePath() +
89+
* "/dirName";
90+
* @return
91+
*/
92+
public static byte[] readFileFromSDCard(String filePath, String fileName) {
93+
byte[] buffer = null;
94+
try {
95+
if (checkSDCardAvailable()) {
96+
String filePaht = filePath + "/" + fileName;
97+
FileInputStream fin = new FileInputStream(filePaht);
98+
int length = fin.available();
99+
buffer = new byte[length];
100+
fin.read(buffer);
101+
fin.close();
102+
}
103+
} catch (Exception e) {
104+
e.printStackTrace();
105+
}
106+
return buffer;
107+
}
108+
109+
/**
110+
* Delete file
111+
*
112+
* @param filePath
113+
* @param fileName
114+
* filePath =
115+
* android.os.Environment.getExternalStorageDirectory().getPath()
116+
* @return
117+
*/
118+
public static boolean deleteSDFile(String filePath, String fileName) {
119+
File file = new File(filePath + "/" + fileName);
120+
if (file == null || !file.exists() || file.isDirectory())
121+
return false;
122+
return file.delete();
123+
}
124+
}

0 commit comments

Comments
 (0)