d> 18
 import java.util.Timer;
@@ -16,6 +21,7 @@ import java.util.TimerTask;
16 21
 import ai.pai.lensman.bean.PhotoBean;
17 22
 import ai.pai.lensman.bean.SessionBean;
18 23
 import ai.pai.lensman.box.BoxUrlContainer;
24
+import ai.pai.lensman.utils.Constants;
19 25
 import ai.pai.lensman.utils.HttpPostTask;
20 26
 
21 27
 public class SessionInteractor {
@@ -37,7 +43,7 @@ public class SessionInteractor {
37 43
 
38 44
         void onSessionStartSuccess(String session);
39 45
         void onSessionStartError(String session);
40
-        void onSessionPhotoCaptured(ArrayList<PhotoBean> bean);
46
+        void onSessionPhotoCaptured(PhotoBean bean);
41 47
         void onSessionEnd(String session);
42 48
     }
43 49
 
@@ -140,12 +146,78 @@ public class SessionInteractor {
140 146
             @Override
141 147
             protected void onPostSuccess() {
142 148
                 super.onPostSuccess();
143
-                listener.onSessionPhotoCaptured(photoList);
149
+                for(PhotoBean bean :photoList){
150
+                    new SavePhotoTask(bean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(),bean);
151
+                }
144 152
             }
145 153
         };
146 154
         fetchThumbnailTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.FETCH_THUMBNAIL_URL);
147 155
     }
148 156
 
157
+
158
+    class SavePhotoTask extends AsyncTask<PhotoBean, Integer, Boolean> {
159
+
160
+        private PhotoBean photoBean;
161
+        public SavePhotoTask(PhotoBean bean){
162
+            this.photoBean = bean;
163
+        }
164
+
165
+        @Override
166
+        protected Boolean doInBackground(PhotoBean... params) {
167
+            PhotoBean photoBean = params[0];
168
+            String  path = BoxUrlContainer.PHOTO_PATH_PREFIX_URL+photoBean.photoPath;
169
+            LogHelper.d(TAG,"保存照片到本地,图片链接地址为"+path);
170
+            FileOutputStream fOut = null;
171
+            HttpURLConnection conn = null;
172
+            InputStream inStream = null;
173
+            try {
174
+                URL url = new URL(path);
175
+                conn = (HttpURLConnection) url.openConnection();
176
+                conn.setConnectTimeout(5 * 1000);
177
+                conn.setRequestMethod("GET");
178
+                inStream = conn.getInputStream();
179
+                if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
180
+                    String dirPath = Constants.APP_IMAGE_DIR +File.separator+photoBean.sessionId+File.separator+Constants.THUMBNAIL_DIR_NAME;
181
+                    File dir = new File(dirPath);
182
+                    dir.mkdirs();
183
+                    File file = new File(dir, photoBean.photoName);
184
+                    fOut = new FileOutputStream(file);
185
+                    byte[] buffer = new byte[2048];
186
+                    int len ;
187
+                    while((len=inStream.read(buffer))!=-1){
188
+                        fOut.write(buffer,0,len);
189
+                        fOut.flush();
190
+                    }
191
+                    fOut.flush();
192
+                    LogHelper.d("czy","保存照片到本地,图片保存至"+file.getAbsolutePath()+"图片大小为"+file.length()+"字节\n\n");
193
+                }
194
+                return true;
195
+            } catch (Exception e) {
196
+                e.printStackTrace();
197
+            } finally {
198
+                try{
199
+                    inStream.close();
200
+                    conn.disconnect();
201
+                    fOut.close();
202
+                }catch (Exception e){
203
+                    e.printStackTrace();
204
+                }
205
+            }
206
+            return false;
207
+        }
208
+
209
+        @Override
210
+        protected void onPostExecute(Boolean result) {
211
+            super.onPostExecute(result);
212
+            if (result) {
213
+                listener.onSessionPhotoCaptured(photoBean);
214
+            }else{
215
+                new SavePhotoTask(photoBean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(),photoBean);
216
+            }
217
+        }
218
+    }
219
+
220
+
149 221
     public void endSession(){
150 222
         cancelTask(sessionEndTask);
151 223
         HashMap<String,String> params = new HashMap<>();

+ 3 - 5
app/src/main/java/ai/pai/lensman/session/SessionPresenter.java

@@ -43,12 +43,10 @@ public class SessionPresenter implements SessionContract.Presenter,SessionIntera
43 43
     }
44 44
 
45 45
     @Override
46
-    public void onSessionPhotoCaptured(final ArrayList<PhotoBean> beans) {
46
+    public void onSessionPhotoCaptured(final PhotoBean bean) {
47 47
         sessionView.showPhotoRecyclerView();
48
-        sessionView.showToast("发现新增照片"+beans.size()+"张");
49
-        for (PhotoBean bean : beans){
50
-            sessionView.addNewPhoto(bean);
51
-        }
48
+        sessionView.showToast("发现新增照片");
49
+        sessionView.addNewPhoto(bean);
52 50
     }
53 51
 
54 52
     @Override

+ 1 - 1
app/src/main/java/ai/pai/lensman/upload/UploadActivity.java

@@ -147,7 +147,7 @@ public class UploadActivity extends BaseActivity implements UploadContract.View
147 147
         sessionBean.lensmanId = Preferences.getInstance(this).getLensManId();
148 148
         sessionBean.sessionDate=20160813;
149 149
         sessionBean.sessionSeq = new Random().nextInt(10000);
150
-        sessionBean.sessionId ="chengzhenyu_test";
150
+        sessionBean.sessionId ="chengzhenyu_test"+sessionBean.sessionSeq;
151 151
         Intent intent = new Intent(this, SessionActivity.class);
152 152
         intent.putExtra("session",sessionBean);
153 153
         startActivity(intent);

+ 16 - 0
app/src/main/java/ai/pai/lensman/utils/Constants.java

@@ -0,0 +1,16 @@
1
+package ai.pai.lensman.utils;
2
+
3
+import android.os.Environment;
4
+
5
+/**
6
+ * Created by chengzhenyu on 2016/8/13.
7
+ */
8
+public class Constants {
9
+
10
+    public static final String APP_ROOT_DIR                    = Environment.getExternalStorageDirectory() + "/lensman";
11
+    public static final String APP_IMAGE_DIR                   = APP_ROOT_DIR + "/image";
12
+    public static final String ORIGIN_DIR_NAME                 = "origin";
13
+    public static final String THUMBNAIL_DIR_NAME              = "thumbnail";
14
+    public static final String TMP_DIR_NAME              = "tmp";
15
+
16
+}

+ 40 - 0
app/src/main/java/ai/pai/lensman/utils/ImageLoaderUtils.java

@@ -0,0 +1,40 @@
1
+package ai.pai.lensman.utils;
2
+
3
+import android.graphics.Bitmap;
4
+import android.widget.ImageView;
5
+
6
+import com.nostra13.universalimageloader.core.DisplayImageOptions;
7
+import com.nostra13.universalimageloader.core.ImageLoader;
8
+import com.nostra13.universalimageloader.core.assist.ImageScaleType;
9
+import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;
10
+
11
+public class ImageLoaderUtils {
12
+
13
+    /**
14
+     * display local image
15
+     * @param uri
16
+     * @param imageView
17
+     * @param options
18
+     */
19
+    public static void displayLocalImage(String uri, ImageView imageView, DisplayImageOptions options) {
20
+        ImageLoader.getInstance().displayImage("file://" + uri, new ImageViewAware(imageView), options, null, null);
21
+    }
22
+
23
+    /**
24
+     * display Drawable image
25
+     * @param uri
26
+     * @param imageView
27
+     * @param options
28
+     */
29
+    public static void displayDrawableImage(String uri, ImageView imageView, DisplayImageOptions options) {
30
+        ImageLoader.getInstance().displayImage("drawable://" + uri, new ImageViewAware(imageView), options, null, null);
31
+    }
32
+
33
+    public static DisplayImageOptions getOptions(int drawable) {
34
+        return new DisplayImageOptions.Builder()
35
+                .showImageForEmptyUri(drawable).showImageOnFail(drawable)
36
+                .cacheInMemory(true).cacheOnDisk(true).considerExifParams(true)
37
+                .bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2).build();
38
+    }
39
+
40
+}

kodo - Gogs: Go Git Service

暫無描述

Brightcells: b95db9c5c3 Basic gis command 6 年之前
..
__init__.py b95db9c5c3 Basic gis command 6 年之前