界面添加获取SD卡照片

chengzhenyu лет %!s(int64=6): %!d(string=назад)
Родитель
Сommit
b198c19c7a
2 измененных файлов с 37 добавлено и 12 удалено
  1. 18 7
      app/src/main/java/ai/pai/ptp/test/MyTestActivity.java
  2. 19 5
      app/src/main/res/layout/activity_my_test.xml

+ 18 - 7
app/src/main/java/ai/pai/ptp/test/MyTestActivity.java

@@ -20,12 +20,8 @@ import ai.pai.ptp.R;
20 20
 public class MyTestActivity extends Activity implements Camera.CameraListener,Camera.StorageInfoListener,Camera.RetrieveImageInfoListener{
21 21
 
22 22
     private ImageView photoIv;
23
-    private ListView infoListView;
24 23
     private MyTestAdapter adapter;
25 24
 
26
-
27
-    private final String TAG = MyTestActivity.class.getSimpleName();
28
-
29 25
     private PtpService ptp;
30 26
     private Camera camera;
31 27
     private boolean isInStart;
@@ -38,7 +34,7 @@ public class MyTestActivity extends Activity implements Camera.CameraListener,Ca
38 34
         ptp = PtpService.Singleton.getInstance(this);
39 35
 
40 36
         photoIv = (ImageView) findViewById(R.id.iv_latest_photo);
41
-        infoListView = (ListView) findViewById(R.id.list_info);
37
+        ListView infoListView = (ListView) findViewById(R.id.list_info);
42 38
         adapter = new MyTestAdapter(this, infoListView);
43 39
         infoListView.setAdapter(adapter);
44 40
 
@@ -49,15 +45,29 @@ public class MyTestActivity extends Activity implements Camera.CameraListener,Ca
49 45
                     adapter.addInfo(camera.getDeviceInfo());
50 46
                 }else{
51 47
                     adapter.addInfo("未发现相机设备");
48
+                    ptp.initialize(MyTestActivity.this, getIntent());
52 49
                 }
53 50
             }
54 51
         });
55 52
 
56
-        findViewById(R.id.btn_get_photo).setOnClickListener(new View.OnClickListener() {
53
+        findViewById(R.id.btn_capture_photo).setOnClickListener(new View.OnClickListener() {
57 54
             @Override
58 55
             public void onClick(View v) {
59 56
                 if(camera!=null){
60 57
                     camera.capture();
58
+                }else{
59
+                    ptp.initialize(MyTestActivity.this, getIntent());
60
+                }
61
+            }
62
+        });
63
+
64
+        findViewById(R.id.btn_get_photos).setOnClickListener(new View.OnClickListener() {
65
+            @Override
66
+            public void onClick(View v) {
67
+                if(camera!=null){
68
+                    camera.retrieveStorages(MyTestActivity.this);
69
+                }else{
70
+                    ptp.initialize(MyTestActivity.this, getIntent());
61 71
                 }
62 72
             }
63 73
         });
@@ -94,7 +104,7 @@ public class MyTestActivity extends Activity implements Camera.CameraListener,Ca
94 104
     public void onCameraStarted(Camera camera) {
95 105
         this.camera = camera;
96 106
         adapter.addInfo("开始会话");
97
-        camera.retrieveStorages(this);
107
+
98 108
     }
99 109
 
100 110
     @Override
@@ -111,6 +121,7 @@ public class MyTestActivity extends Activity implements Camera.CameraListener,Ca
111 121
     @Override
112 122
     public void onError(String message) {
113 123
         adapter.addInfo("发生错误 " + message);
124
+        camera = null;
114 125
     }
115 126
 
116 127
     @Override

+ 19 - 5
app/src/main/res/layout/activity_my_test.xml

@@ -16,13 +16,27 @@
16 16
         android:layout_width="match_parent"
17 17
         android:divider="@android:color/transparent"
18 18
         android:layout_height="200dp" />
19
-    <Button
20
-        android:id="@+id/btn_get_photo"
19
+    <LinearLayout
21 20
         android:layout_width="match_parent"
22 21
         android:layout_height="48dp"
23
-        android:layout_margin="4dp"
24
-        android:gravity="center"
25
-        android:text="获取最新照片"/>
22
+        android:layout_margin="4dp">
23
+
24
+        <Button
25
+            android:id="@+id/btn_capture_photo"
26
+            android:layout_width="0dp"
27
+            android:layout_weight="1"
28
+            android:layout_height="match_parent"
29
+            android:gravity="center"
30
+            android:text="拍摄"/>
31
+
32
+        <Button
33
+            android:id="@+id/btn_get_photos"
34
+            android:layout_width="0dp"
35
+            android:layout_weight="1"
36
+            android:layout_height="match_parent"
37
+            android:gravity="center"
38
+            android:text="获取相机SD卡照片"/>
39
+    </LinearLayout>
26 40
 
27 41
 
28 42
     <ImageView