- LogHelper.d(TAG,"startSession get response string = "+response);
|
|
81
|
|
- try{
|
|
82
|
|
- JSONObject json = new JSONObject(response);
|
|
83
|
|
- int status = json.getInt("status");
|
|
84
|
|
- if(status == 200){
|
|
85
|
|
- return true;
|
|
86
|
|
- }
|
|
87
|
|
- }catch (Exception e){
|
|
88
|
|
- e.printStackTrace();
|
|
89
|
|
- }
|
|
90
|
|
- return false;
|
|
91
|
|
- }
|
|
92
|
49
|
|
|
93
|
|
- @Override
|
|
94
|
|
- protected void onPostFail() {
|
|
95
|
|
- LogHelper.d(TAG,"sessionStartTask onPostFail sessionId = "+randomSessionId);
|
|
96
|
|
- super.onPostFail();
|
|
97
|
|
- listener.onSessionStartError(sessionBean.sessionId);
|
|
98
|
|
- //即使session创建不成功,也继续工作,照片存lost目录
|
|
99
|
|
- isWorking = true;
|
|
100
|
|
- LogHelper.d(TAG,"即使session创建不成功,也继续工作,照片存lost目录 sessionStartTask onPostSuccess sessionId = "+randomSessionId + "and startCapture");
|
|
101
|
|
- startCapture();
|
|
102
|
|
- }
|
|
|
50
|
+ listener.onSessionStartSuccess(sessionBean.sessionId);
|
|
|
51
|
+ isWorking = true;
|
|
|
52
|
+ startCapture();
|
|
103
|
53
|
|
|
104
|
|
- @Override
|
|
105
|
|
- protected void onPostSuccess() {
|
|
106
|
|
- super.onPostSuccess();
|
|
107
|
|
- listener.onSessionStartSuccess(sessionBean.sessionId);
|
|
108
|
|
- isWorking = true;
|
|
109
|
|
- LogHelper.d(TAG,"sessionStartTask onPostSuccess sessionId = "+randomSessionId + "and startCapture");
|
|
110
|
|
- startCapture();
|
|
111
|
|
- }
|
|
112
|
|
- };
|
|
113
|
|
- sessionStartTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.SESSION_START_URL);
|
|
114
|
54
|
LogHelper.d(TAG,"startSession sessionStartTask execute");
|
|
115
|
55
|
}
|
|
116
|
56
|
|
|
|
|
@@ -123,12 +63,12 @@ public class SessionInteractor {
|
|
123
|
63
|
timer.schedule(new TimerTask() {
|
|
124
|
64
|
@Override
|
|
125
|
65
|
public void run() {
|
|
126
|
|
- fetchThumbnailTask();
|
|
|
66
|
+ fetchPhotoTask();
|
|
127
|
67
|
}
|
|
128
|
68
|
},5000,2000);
|
|
129
|
69
|
}
|
|
130
|
70
|
|
|
131
|
|
- private void fetchThumbnailTask(){
|
|
|
71
|
+ private void fetchPhotoTask(){
|
|
132
|
72
|
if(!isWorking){
|
|
133
|
73
|
return;
|
|
134
|
74
|
}
|
|
|
|
@@ -160,149 +100,15 @@ public class SessionInteractor {
|
|
160
|
100
|
bean.sessionSeq = sessionBean.sessionSeq;
|
|
161
|
101
|
bean.sessionDate = sessionBean.sessionDate;
|
|
162
|
102
|
bean.sessionCreateTime = sessionBean.createTime;
|
|
163
|
|
- new SavePhotoTask(bean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(),bean);
|
|
|
103
|
+ //TODO
|
|
164
|
104
|
return;
|
|
165
|
105
|
}
|
|
166
|
|
- HashMap<String,String> params = new HashMap<>();
|
|
167
|
|
- params.put("lensman",sessionBean.lensmanId);
|
|
168
|
|
- params.put("session",randomSessionId);
|
|
169
|
|
- params.put("maxid",String.valueOf(maxId));
|
|
170
|
|
- HttpPostTask fetchThumbnailTask = new HttpPostTask(params){
|
|
171
|
|
- ArrayList<PhotoBean> photoList = new ArrayList<>();
|
|
172
|
|
- @Override
|
|
173
|
|
- protected boolean parseResponse(String response) {
|
|
174
|
|
- LogHelper.d(TAG,"fetchThumbnailTask get response string = "+response);
|
|
175
|
|
- try{
|
|
176
|
|
- JSONObject json = new JSONObject(response);
|
|
177
|
|
- int status = json.getInt("status");
|
|
178
|
|
- if(status == 200){
|
|
179
|
|
- JSONObject data = json.getJSONObject("data");
|
|
180
|
|
- JSONArray files = data.getJSONArray("files");
|
|
181
|
|
- if(files!=null && files.length()>0){
|
|
182
|
|
- for(int k = 0 ; k< files.length();k++){
|
|
183
|
|
- JSONObject file = files.getJSONObject(k);
|
|
184
|
|
- PhotoBean bean = new PhotoBean();
|
|
185
|
|
- bean.photoName = file.getString("name");
|
|
186
|
|
- bean.photoId = file.getLong("id");
|
|
187
|
|
- bean.photoPath = file.getString("path");
|
|
188
|
|
- bean.captureTime = bean.photoId;
|
|
189
|
|
- bean.isRawPhoto = false;
|
|
190
|
|
- bean.uploadStatus = PhotoBean.UploadStatus.STATUS_NO_BEGIN;
|
|
191
|
|
- bean.sessionId = sessionBean.sessionId;
|
|
192
|
|
- bean.lensmanId = sessionBean.lensmanId;
|
|
193
|
|
- bean.sessionSeq = sessionBean.sessionSeq;
|
|
194
|
|
- bean.sessionDate = sessionBean.sessionDate;
|
|
195
|
|
- bean.sessionCreateTime = sessionBean.createTime;
|
|
196
|
|
- if(bean.photoId>maxId){
|
|
197
|
|
- maxId = bean.photoId;
|
|
198
|
|
- }
|
|
199
|
|
- photoList.add(bean);
|
|
200
|
|
- }
|
|
201
|
|
- }
|
|
202
|
|
- return true;
|
|
203
|
|
- }
|
|
204
|
|
- }catch (Exception e){
|
|
205
|
|
- LogHelper.e(TAG,"fetchThumbnailTask exception occurs "+e);
|
|
206
|
|
- }
|
|
207
|
|
- return false;
|
|
208
|
|
- }
|
|
209
|
106
|
|
|
210
|
|
- @Override
|
|
211
|
|
- protected void onPostFail() {
|
|
212
|
|
- LogHelper.d(TAG,"fetchThumbnailTask onPostFail");
|
|
213
|
|
- super.onPostFail();
|
|
214
|
|
- isLastQueryReturned = true;
|
|
215
|
|
- }
|
|
216
|
|
-
|
|
217
|
|
- @Override
|
|
218
|
|
- protected void onPostSuccess() {
|
|
219
|
|
- super.onPostSuccess();
|
|
220
|
|
- isLastQueryReturned = true;
|
|
221
|
|
- LogHelper.d(TAG,"fetchThumbnailTask onPostSuccess with photo number = "+photoList.size());
|
|
222
|
|
- for(PhotoBean bean :photoList){
|
|
223
|
|
- new SavePhotoTask(bean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(),bean);
|
|
224
|
|
- LogHelper.d(TAG,"SavePhotoTask starts "+bean);
|
|
225
|
|
- }
|
|
226
|
|
- }
|
|
227
|
|
- };
|
|
228
|
|
- fetchThumbnailTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.FETCH_THUMBNAIL_URL);
|
|
229
|
107
|
isLastQueryReturned = false;
|
|
230
|
|
- LogHelper.d(TAG,"fetchThumbnailTask starts");
|
|
|
108
|
+ LogHelper.d(TAG,"fetchPhotoTask starts");
|
|
231
|
109
|
}
|
|
232
|
110
|
|
|
233
|
111
|
|
|
234
|
|
- class SavePhotoTask extends AsyncTask<PhotoBean, Integer, Boolean> {
|
|
235
|
|
-
|
|
236
|
|
- private PhotoBean photoBean;
|
|
237
|
|
- public SavePhotoTask(PhotoBean bean){
|
|
238
|
|
- this.photoBean = bean;
|
|
239
|
|
- }
|
|
240
|
|
-
|
|
241
|
|
- @Override
|
|
242
|
|
- protected Boolean doInBackground(PhotoBean... params) {
|
|
243
|
|
- PhotoBean photoBean = params[0];
|
|
244
|
|
- String path = BoxUrlContainer.PHOTO_PATH_PREFIX_URL+photoBean.photoPath;
|
|
245
|
|
- if(BuildConfig.isTestMode){
|
|
246
|
|
- path = photoBean.photoPath;
|
|
247
|
|
- }
|
|
248
|
|
- LogHelper.d(TAG,"SavePhotoTask save photo to phone , photo remote url = "+path);
|
|
249
|
|
- FileOutputStream fOut = null;
|
|
250
|
|
- HttpURLConnection conn = null;
|
|
251
|
|
- InputStream inStream = null;
|
|
252
|
|
- try {
|
|
253
|
|
- URL url = new URL(path);
|
|
254
|
|
- conn = (HttpURLConnection) url.openConnection();
|
|
255
|
|
- conn.setConnectTimeout(5 * 1000);
|
|
256
|
|
- conn.setRequestMethod("GET");
|
|
257
|
|
- inStream = conn.getInputStream();
|
|
258
|
|
- if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
|
|
259
|
|
- String dirPath = Constants.APP_IMAGE_DIR +File.separator+photoBean.sessionId+File.separator+Constants.THUMBNAIL_DIR_NAME;
|
|
260
|
|
- File dir = new File(dirPath);
|
|
261
|
|
- dir.mkdirs();
|
|
262
|
|
- File file = new File(dir, photoBean.photoName);
|
|
263
|
|
- fOut = new FileOutputStream(file);
|
|
264
|
|
- byte[] buffer = new byte[2048];
|
|
265
|
|
- int len ;
|
|
266
|
|
- while((len=inStream.read(buffer))!=-1){
|
|
267
|
|
- fOut.write(buffer,0,len);
|
|
268
|
|
- fOut.flush();
|
|
269
|
|
- }
|
|
270
|
|
- fOut.flush();
|
|
271
|
|
- LogHelper.d(TAG,"SavePhotoTask save photo to local path = "+file.getAbsolutePath()+" photo bytes = "+file.length()+"\n");
|
|
272
|
|
- }
|
|
273
|
|
- return true;
|
|
274
|
|
- } catch (Exception e) {
|
|
275
|
|
- LogHelper.e(TAG,"SavePhotoTask exception occurs "+e);
|
|
276
|
|
- } finally {
|
|
277
|
|
- try{
|
|
278
|
|
- inStream.close();
|
|
279
|
|
- conn.disconnect();
|
|
280
|
|
- fOut.close();
|
|
281
|
|
- }catch (Exception e){
|
|
282
|
|
- e.printStackTrace();
|
|
283
|
|
- }
|
|
284
|
|
- }
|
|
285
|
|
- try{
|
|
286
|
|
- Thread.sleep(2000);
|
|
287
|
|
- }catch (Exception e){
|
|
288
|
|
- e.printStackTrace();
|
|
289
|
|
- }
|
|
290
|
|
- return false;
|
|
291
|
|
- }
|
|
292
|
|
-
|
|
293
|
|
- @Override
|
|
294
|
|
- protected void onPostExecute(Boolean result) {
|
|
295
|
|
- super.onPostExecute(result);
|
|
296
|
|
- if (result) {
|
|
297
|
|
- LogHelper.d(TAG,"SavePhotoTask onPostExecute success " + photoBean);
|
|
298
|
|
- listener.onSessionPhotoCaptured(photoBean);
|
|
299
|
|
- }else{
|
|
300
|
|
- LogHelper.d(TAG,"SavePhotoTask onPostExecute fail and retry "+photoBean);
|
|
301
|
|
- new SavePhotoTask(photoBean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(),photoBean);
|
|
302
|
|
- }
|
|
303
|
|
- }
|
|
304
|
|
- }
|
|
305
|
|
-
|
|
306
|
112
|
|
|
307
|
113
|
public void endSession(){
|
|
308
|
114
|
isWorking = false;
|
|
|
|
@@ -310,36 +116,14 @@ public class SessionInteractor {
|
|
310
|
116
|
timer.cancel();
|
|
311
|
117
|
timer = null;
|
|
312
|
118
|
}
|
|
313
|
|
-
|
|
314
|
|
- cancelTask(sessionEndTask);
|
|
315
|
|
- HashMap<String,String> params = new HashMap<>();
|
|
316
|
|
- params.put("lensman",sessionBean.lensmanId);
|
|
317
|
|
- params.put("session",randomSessionId);
|
|
318
|
|
- sessionEndTask = new HttpPostTask(params);
|
|
319
|
|
- sessionEndTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.SESSION_END_URL);
|
|
320
|
|
- LogHelper.d(TAG,"sessionEndTask execute ");
|
|
|
119
|
+ //TODO
|
|
321
|
120
|
listener.onSessionEnd(sessionBean.sessionId);
|
|
322
|
121
|
}
|
|
323
|
122
|
|
|
324
|
123
|
public void deletePhoto(PhotoBean photoBean){
|
|
325
|
|
- HashMap<String,String> params = new HashMap<>();
|
|
326
|
|
- params.put("lensman",photoBean.lensmanId);
|
|
327
|
|
- params.put("session",photoBean.sessionId);
|
|
328
|
|
- params.put("id",String.valueOf(photoBean.photoId));
|
|
329
|
|
- params.put("name",photoBean.photoName);
|
|
330
|
|
- params.put("path",photoBean.photoPath);
|
|
331
|
|
- HttpPostTask deleteTask = new HttpPostTask(params);
|
|
332
|
|
- deleteTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.DELETE_PHOTO_URL);
|
|
|
124
|
+ //TODO
|
|
333
|
125
|
LogHelper.d(TAG,"deletePhoto execute "+photoBean);
|
|
334
|
126
|
}
|
|
335
|
127
|
|
|
336
|
|
- private void cancelTask(HttpPostTask task){
|
|
337
|
|
- if(task==null){
|
|
338
|
|
- return;
|
|
339
|
|
- }
|
|
340
|
|
- if(task.getStatus()== AsyncTask.Status.RUNNING){
|
|
341
|
|
- task.cancel(true);
|
|
342
|
|
- }
|
|
343
|
|
- }
|
|
344
|
128
|
|
|
345
|
129
|
}
|
|
|
|
@@ -78,12 +78,7 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
|
|
78
|
78
|
|
|
79
|
79
|
@Override
|
|
80
|
80
|
public void onSessionStartError(String session) {
|
|
81
|
|
-// if (!isWorking) {
|
|
82
|
|
-// return;
|
|
83
|
|
-// }
|
|
84
|
81
|
sessionView.showToast("session启动失败");
|
|
85
|
|
-// interactor.startSession();
|
|
86
|
|
-// LogHelper.d(TAG,"onSessionStartError session启动失败,自动重试中");
|
|
87
|
82
|
}
|
|
88
|
83
|
|
|
89
|
84
|
@Override
|
|
|
|
@@ -3,17 +3,12 @@ package ai.pai.lensman.settings;
|
|
3
|
3
|
import android.content.Intent;
|
|
4
|
4
|
import android.os.Bundle;
|
|
5
|
5
|
import android.support.annotation.Nullable;
|
|
6
|
|
-import android.view.View;
|
|
7
|
|
-import android.widget.EditText;
|
|
8
|
|
-import android.widget.Toast;
|
|
9
|
6
|
|
|
10
|
7
|
import ai.pai.lensman.R;
|
|
11
|
8
|
import ai.pai.lensman.activities.AboutUsActivity;
|
|
12
|
9
|
import ai.pai.lensman.activities.FeedbackActivity;
|
|
13
|
10
|
import ai.pai.lensman.activities.WebViewActivity;
|
|
14
|
11
|
import ai.pai.lensman.base.BaseActivity;
|
|
15
|
|
-import ai.pai.lensman.utils.BoxUrlContainer;
|
|
16
|
|
-import butterknife.BindView;
|
|
17
|
12
|
import butterknife.ButterKnife;
|
|
18
|
13
|
import butterknife.OnClick;
|
|
19
|
14
|
|
|
|
|
@@ -1,26 +0,0 @@
|
|
1
|
|
-package ai.pai.lensman.utils;
|
|
2
|
|
-
|
|
3
|
|
-public class BoxUrlContainer {
|
|
4
|
|
-
|
|
5
|
|
- public static String BOX_IP = "192.168.8.101";
|
|
6
|
|
-
|
|
7
|
|
- private static String BASE_URL = "http://" + BOX_IP + ":8002/";
|
|
8
|
|
-
|
|
9
|
|
- public static String SESSION_START_URL = BASE_URL + "session_start";
|
|
10
|
|
-
|
|
11
|
|
- public static String SESSION_END_URL = BASE_URL + "session_end";
|
|
12
|
|
-
|
|
13
|
|
- public static String DELETE_PHOTO_URL = BASE_URL + "delete_photo";
|
|
14
|
|
-
|
|
15
|
|
- public static String FETCH_THUMBNAIL_URL = BASE_URL + "fetch_thumbnail";
|
|
16
|
|
-
|
|
17
|
|
- public static String PHOTO_PATH_PREFIX_URL = BASE_URL + "static/";
|
|
18
|
|
-
|
|
19
|
|
- /**
|
|
20
|
|
- * lensman # 摄影师唯一标识
|
|
21
|
|
- * session # Session
|
|
22
|
|
- * name # fetch_thumbnail 返回
|
|
23
|
|
- */
|
|
24
|
|
- public static String FETCH_ORIGIN_URL = BASE_URL +"fetch_origin";
|
|
25
|
|
-
|
|
26
|
|
-}
|
|
|
|
@@ -1,40 +0,0 @@
|
|
1
|
|
-<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
|
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
|
- android:layout_width="match_parent"
|
|
4
|
|
- android:layout_height="wrap_content"
|
|
5
|
|
- android:orientation="horizontal"
|
|
6
|
|
- android:paddingBottom="4dp"
|
|
7
|
|
- android:paddingTop="4dp">
|
|
8
|
|
-
|
|
9
|
|
- <LinearLayout
|
|
10
|
|
- android:layout_width="0dp"
|
|
11
|
|
- android:layout_height="wrap_content"
|
|
12
|
|
- android:layout_gravity="center_vertical"
|
|
13
|
|
- android:orientation="vertical"
|
|
14
|
|
- android:layout_weight="1">
|
|
15
|
|
-
|
|
16
|
|
- <TextView
|
|
17
|
|
- android:id="@+id/tv_device_name"
|
|
18
|
|
- android:layout_width="wrap_content"
|
|
19
|
|
- android:layout_height="wrap_content"
|
|
20
|
|
- android:textColor="@color/dark_grey"
|
|
21
|
|
- android:textSize="14sp" />
|
|
22
|
|
-
|
|
23
|
|
- <TextView
|
|
24
|
|
- android:id="@+id/tv_device_mac"
|
|
25
|
|
- android:layout_width="wrap_content"
|
|
26
|
|
- android:layout_height="wrap_content"
|
|
27
|
|
- android:paddingTop="3dp"
|
|
28
|
|
- android:textColor="@color/grey"
|
|
29
|
|
- android:textSize="12sp" />
|
|
30
|
|
- </LinearLayout>
|
|
31
|
|
-
|
|
32
|
|
- <TextView
|
|
33
|
|
- android:id="@+id/tv_device_status"
|
|
34
|
|
- android:layout_width="wrap_content"
|
|
35
|
|
- android:layout_height="wrap_content"
|
|
36
|
|
- android:layout_marginRight="12dp"
|
|
37
|
|
- android:layout_gravity="center_vertical"
|
|
38
|
|
- android:textColor="@color/grey"
|
|
39
|
|
- android:textSize="14sp" />
|
|
40
|
|
-</LinearLayout>
|