+ }
+
+ }
+ if (!dir.canRead() || !dir.canWrite()) {
+ return false;
+ }
+ // 目录此时为空,可以删除
+ return dir.delete();
+ }
private void noMedia(){
File noMedia = new File(Constants.APP_ROOT_DIR,".nomedia");
@@ -2,14 +2,28 @@ package ai.pai.lensman.dslr; |
||
2 | 2 |
|
3 | 3 |
public class CameraJNIInterface { |
4 | 4 |
|
5 |
+ |
|
5 | 6 |
static { |
6 |
- System.loadLibrary(""); |
|
7 |
+ System.loadLibrary("hello_jni"); |
|
8 |
+ } |
|
9 |
+ |
|
10 |
+ private static CameraJNIInterface instance; |
|
11 |
+ |
|
12 |
+ private CameraJNIInterface(){ |
|
13 |
+ |
|
14 |
+ } |
|
15 |
+ |
|
16 |
+ public static synchronized CameraJNIInterface getInstance(){ |
|
17 |
+ if(instance==null){ |
|
18 |
+ instance = new CameraJNIInterface(); |
|
19 |
+ } |
|
20 |
+ return instance; |
|
7 | 21 |
} |
8 | 22 |
|
9 | 23 |
public native int mygpcamerainit(); |
10 | 24 |
public native int mygpcameraexit(); |
11 | 25 |
public native String mygpcameragetsummary(); |
12 |
- public native int mygpcamerawaitforevent(String foldr_path, String file_name); |
|
26 |
+ public native String mygpcamerawaitforevent(String foldr_path); |
|
13 | 27 |
public native int mygpfilenewfromfd(String file_path); |
14 | 28 |
public native int mygpcamerafileget(String foldr_path, String file_name); |
15 | 29 |
public native int mygpfilefree(); |
@@ -1,22 +1,27 @@ |
||
1 | 1 |
package ai.pai.lensman.login; |
2 | 2 |
|
3 | 3 |
import android.content.Intent; |
4 |
-import android.graphics.Paint; |
|
5 | 4 |
import android.os.Bundle; |
6 | 5 |
import android.support.v4.app.FragmentActivity; |
7 |
-import android.text.Html; |
|
8 | 6 |
import android.text.SpannableString; |
9 | 7 |
import android.text.TextUtils; |
10 | 8 |
import android.text.style.UnderlineSpan; |
11 | 9 |
import android.view.View; |
10 |
+import android.widget.ImageView; |
|
12 | 11 |
import android.widget.TextView; |
13 | 12 |
import android.widget.Toast; |
14 | 13 |
|
14 |
+import com.android.common.utils.LogHelper; |
|
15 | 15 |
import com.android.views.progressbar.ProgressWheel; |
16 | 16 |
|
17 |
+import java.io.File; |
|
18 |
+ |
|
17 | 19 |
import ai.pai.lensman.R; |
18 | 20 |
import ai.pai.lensman.activities.WebViewActivity; |
21 |
+import ai.pai.lensman.dslr.CameraJNIInterface; |
|
19 | 22 |
import ai.pai.lensman.main.MainActivity; |
23 |
+import ai.pai.lensman.service.Constants; |
|
24 |
+import ai.pai.lensman.utils.ImageLoaderUtils; |
|
20 | 25 |
import butterknife.BindView; |
21 | 26 |
import butterknife.ButterKnife; |
22 | 27 |
import butterknife.OnClick; |
@@ -25,8 +30,9 @@ public class LoginActivity extends FragmentActivity implements LoginContract.Vie |
||
25 | 30 |
|
26 | 31 |
@BindView(R.id.wheel_wait_http) ProgressWheel progressWheel; |
27 | 32 |
@BindView(R.id.tv_agree_protocol) TextView protocolText; |
28 |
- |
|
33 |
+ @BindView(R.id.iv_login_logo) ImageView photoView; |
|
29 | 34 |
private LoginContract.Presenter presenter; |
35 |
+ private boolean isCancelled; |
|
30 | 36 |
|
31 | 37 |
@Override |
32 | 38 |
protected void onCreate(Bundle savedInstanceState) { |
@@ -37,8 +43,47 @@ public class LoginActivity extends FragmentActivity implements LoginContract.Vie |
||
37 | 43 |
content.setSpan(new UnderlineSpan(), 6, content.length(), 0); |
38 | 44 |
protocolText.setText(content); |
39 | 45 |
presenter = new LoginPresenter(this,this); |
46 |
+ int ret = CameraJNIInterface.getInstance().mygpcamerainit(); |
|
47 |
+ if(ret>=0){ |
|
48 |
+ String text = CameraJNIInterface.getInstance().mygpcameragetsummary(); |
|
49 |
+ LogHelper.d("czy","text="+text); |
|
50 |
+ protocolText.setText("text="+text); |
|
51 |
+// Toast.makeText(this,text,Toast.LENGTH_LONG).show(); |
|
52 |
+ }else{ |
|
53 |
+ LogHelper.d("czy","ret="+ret); |
|
54 |
+// Toast.makeText(this,"camera init return "+ret,Toast.LENGTH_LONG).show(); |
|
55 |
+ protocolText.setText("camera init return "+ret); |
|
56 |
+ } |
|
57 |
+ File dir = new File(Constants.APP_IMAGE_DIR); |
|
58 |
+ dir.mkdirs(); |
|
59 |
+ fetchPhotoTask(); |
|
40 | 60 |
} |
41 | 61 |
|
62 |
+ private void fetchPhotoTask(){ |
|
63 |
+ new Thread(new Runnable() { |
|
64 |
+ @Override |
|
65 |
+ public void run() { |
|
66 |
+ while (!isCancelled){ |
|
67 |
+ final String photoName = CameraJNIInterface.getInstance().mygpcamerawaitforevent(Constants.APP_IMAGE_DIR); |
|
68 |
+ LogHelper.d("czy","mygpcamerawaitforevent return "+photoName); |
|
69 |
+ photoView.post(new Runnable() { |
|
70 |
+ @Override |
|
71 |
+ public void run() { |
|
72 |
+ protocolText.setText("mygpcamerawaitforevent return "+photoName); |
|
73 |
+ if(photoName!=null && photoName.length()>0){ |
|
74 |
+ String sub = photoName.substring(0,1); |
|
75 |
+ if(TextUtils.isDigitsOnly(sub)){ |
|
76 |
+ ImageLoaderUtils.displayLocalImage(Constants.APP_IMAGE_DIR+File.separator+photoName,photoView,ImageLoaderUtils.getOptions(R.drawable.login_page_logo)); |
|
77 |
+ } |
|
78 |
+ } |
|
79 |
+ |
|
80 |
+ } |
|
81 |
+ }); |
|
82 |
+ } |
|
83 |
+ } |
|
84 |
+ }).start(); |
|
85 |
+ |
|
86 |
+ } |
|
42 | 87 |
|
43 | 88 |
@Override |
44 | 89 |
protected void onResume() { |
@@ -46,6 +91,13 @@ public class LoginActivity extends FragmentActivity implements LoginContract.Vie |
||
46 | 91 |
presenter.start(); |
47 | 92 |
} |
48 | 93 |
|
94 |
+ @Override |
|
95 |
+ protected void onDestroy() { |
|
96 |
+ super.onDestroy(); |
|
97 |
+ CameraJNIInterface.getInstance().mygpcameraexit(); |
|
98 |
+ isCancelled = true; |
|
99 |
+ } |
|
100 |
+ |
|
49 | 101 |
@OnClick(R.id.btn_login) |
50 | 102 |
public void login(){ |
51 | 103 |
presenter.login(); |
@@ -1,15 +1,19 @@ |
||
1 | 1 |
package ai.pai.lensman.session; |
2 | 2 |
|
3 |
+import android.widget.Toast; |
|
4 |
+ |
|
3 | 5 |
import com.android.common.utils.LogHelper; |
4 | 6 |
|
5 | 7 |
import java.util.ArrayList; |
6 | 8 |
import java.util.Timer; |
7 | 9 |
import java.util.TimerTask; |
8 | 10 |
|
11 |
+import ai.pai.lensman.App; |
|
9 | 12 |
import ai.pai.lensman.BuildConfig; |
10 | 13 |
import ai.pai.lensman.bean.PhotoBean; |
11 | 14 |
import ai.pai.lensman.bean.SessionBean; |
12 | 15 |
import ai.pai.lensman.db.DBService; |
16 |
+import ai.pai.lensman.dslr.CameraJNIInterface; |
|
13 | 17 |
|
14 | 18 |
public class SessionInteractor { |
15 | 19 |
|
@@ -55,6 +59,12 @@ public class SessionInteractor { |
||
55 | 59 |
} |
56 | 60 |
|
57 | 61 |
public void startCapture() { |
62 |
+ int result = CameraJNIInterface.getInstance().mygpcamerainit(); |
|
63 |
+ if(result>=0){ |
|
64 |
+ LogHelper.d(TAG,"相机信息--->\n"+CameraJNIInterface.getInstance().mygpcameragetsummary()); |
|
65 |
+ Toast.makeText(App.getAppContext(),CameraJNIInterface.getInstance().mygpcameragetsummary(),Toast.LENGTH_SHORT).show(); |
|
66 |
+ |
|
67 |
+ } |
|
58 | 68 |
if(timer!=null){ |
59 | 69 |
timer.cancel(); |
60 | 70 |
timer = null; |
@@ -65,13 +75,14 @@ public class SessionInteractor { |
||
65 | 75 |
public void run() { |
66 | 76 |
fetchPhotoTask(); |
67 | 77 |
} |
68 |
- },5000,2000); |
|
78 |
+ },5000,1000); |
|
69 | 79 |
} |
70 | 80 |
|
71 | 81 |
private void fetchPhotoTask(){ |
72 | 82 |
if(!isWorking){ |
73 | 83 |
return; |
74 | 84 |
} |
85 |
+ |
|
75 | 86 |
if(!isLastQueryReturned){ |
76 | 87 |
return; |
77 | 88 |
} |
@@ -0,0 +1,110 @@ |
||
1 |
+package com.android.common.utils; |
|
2 |
+ |
|
3 |
+import android.os.AsyncTask; |
|
4 |
+ |
|
5 |
+import java.io.File; |
|
6 |
+import java.io.FileOutputStream; |
|
7 |
+import java.io.InputStream; |
|
8 |
+import java.io.OutputStream; |
|
9 |
+import java.util.Enumeration; |
|
10 |
+import java.util.zip.ZipFile; |
|
11 |
+ |
|
12 |
+/** |
|
13 |
+ * zip文件解压缩任务,支持zip内多级目录结构 |
|
14 |
+ * |
|
15 |
+ * Created By chengzhenyu |
|
16 |
+ */ |
|
17 |
+public class FileUnzipTask { |
|
18 |
+ |
|
19 |
+ private String unZipDir; |
|
20 |
+ private String zipFilePath; |
|
21 |
+ private AsyncTask unzipTask; |
|
22 |
+ private FileUnzipListener listener; |
|
23 |
+ |
|
24 |
+ private boolean isCancelled; |
|
25 |
+ |
|
26 |
+ private static final int BUF_SIZE = 2048; |
|
27 |
+ |
|
28 |
+ private static final String TAG = "FileUnzipTask"; |
|
29 |
+ |
|
30 |
+ public interface FileUnzipListener { |
|
31 |
+ void onUnzipSuccess(String zipFilePath, String unZipDir); |
|
32 |
+ void onUnzipError(int errorCode, String zipFilePath, String unZipDir); |
|
33 |
+ } |
|
34 |
+ |
|
35 |
+ public FileUnzipTask(String zipFilePath, String unZipDir, FileUnzipListener listener) { |
|
36 |
+ this.listener = listener; |
|
37 |
+ this.unZipDir = unZipDir; |
|
38 |
+ this.zipFilePath = zipFilePath; |
|
39 |
+ } |
|
40 |
+ |
|
41 |
+ public void startUnZip() { |
|
42 |
+ isCancelled = false; |
|
43 |
+ |
|
44 |
+ unzipTask = new AsyncTask<Object, Integer, Boolean>() { |
|
45 |
+ |
|
46 |
+ @Override |
|
47 |
+ protected Boolean doInBackground(Object... params) { |
|
48 |
+ try { |
|
49 |
+ File desDir = new File(unZipDir); |
|
50 |
+ if (!desDir.exists()) { |
|
51 |
+ desDir.mkdirs(); |
|
52 |
+ } |
|
53 |
+ ZipFile zf = new ZipFile(zipFilePath); |
|
54 |
+ for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements();) { |
|
55 |
+ if(isCancelled){ |
|
56 |
+ break; |
|
57 |
+ } |
|
58 |
+ java.util.zip.ZipEntry entry = ((java.util.zip.ZipEntry)entries.nextElement()); |
|
59 |
+ InputStream in = zf.getInputStream(entry); |
|
60 |
+ String str = unZipDir + File.separator + entry.getName(); |
|
61 |
+ str = new String(str.getBytes("8859_1"), "GB2312"); |
|
62 |
+ File desFile = new File(str); |
|
63 |
+ if (!desFile.exists()) { |
|
64 |
+ File fileParentDir = desFile.getParentFile(); |
|
65 |
+ if (!fileParentDir.exists()) { |
|
66 |
+ fileParentDir.mkdirs(); |
|
67 |
+ } |
|
68 |
+ if(entry.isDirectory()){ |
|
69 |
+ desFile.mkdirs(); |
|
70 |
+ continue; |
|
71 |
+ }else{ |
|
72 |
+ desFile.createNewFile(); |
|
73 |
+ } |
|
74 |
+ } |
|
75 |
+ OutputStream out = new FileOutputStream(desFile); |
|
76 |
+ byte buffer[] = new byte[BUF_SIZE]; |
|
77 |
+ int realLength; |
|
78 |
+ while ((realLength = in.read(buffer)) > 0) { |
|
79 |
+ out.write(buffer, 0, realLength); |
|
80 |
+ } |
|
81 |
+ in.close(); |
|
82 |
+ out.close(); |
|
83 |
+ } |
|
84 |
+ return true; |
|
85 |
+ } catch (Exception e) { |
|
86 |
+ e.printStackTrace(); |
|
87 |
+ } |
|
88 |
+ return false; |
|
89 |
+ } |
|
90 |
+ |
|
91 |
+ @Override |
|
92 |
+ protected void onPostExecute(Boolean result) { |
|
93 |
+ LogHelper.d(TAG, "unzip task onPostExecute result=" + result); |
|
94 |
+ if (result) { |
|
95 |
+ listener.onUnzipSuccess(zipFilePath, unZipDir); |
|
96 |
+ } else { |
|
97 |
+ listener.onUnzipError(-1, zipFilePath, unZipDir); |
|
98 |
+ } |
|
99 |
+ } |
|
100 |
+ }; |
|
101 |
+ unzipTask.execute(); |
|
102 |
+ } |
|
103 |
+ |
|
104 |
+ public void cancelUnzip() { |
|
105 |
+ if (unzipTask != null) { |
|
106 |
+ isCancelled = true; |
|
107 |
+ unzipTask.cancel(true); |
|
108 |
+ } |
|
109 |
+ } |
|
110 |
+} |