处理nikon nikonObjectAddedInSdram 情况
增加照片原图展示

ffib 6 gadi atpakaļ
vecāks
revīzija
069b8521df

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

@@ -3,10 +3,12 @@ package ai.pai.ptp.test;
3 3
 import android.app.Activity;
4 4
 import android.content.Intent;
5 5
 import android.graphics.Bitmap;
6
+import android.media.Image;
6 7
 import android.os.Bundle;
7 8
 import android.os.Handler;
8 9
 import android.os.Message;
9 10
 import android.view.View;
11
+import android.widget.AdapterView;
10 12
 import android.widget.GridView;
11 13
 import android.widget.ImageView;
12 14
 import android.widget.ListView;
@@ -22,11 +24,12 @@ import java.util.ArrayList;
22 24
 import ai.pai.ptp.R;
23 25
 
24 26
 
25
-public class MyTestActivity extends Activity implements Handler.Callback, Camera.CameraListener, Camera.StorageInfoListener, Camera.RetrieveImageInfoListener {
27
+public class MyTestActivity extends Activity implements Handler.Callback, Camera.CameraListener, Camera.StorageInfoListener, Camera.RetrieveImageInfoListener  {
26 28
 
27 29
     private ImageView photoIv;
28 30
     private TestLogListAdapter adapter;
29 31
     private GridView photoGridView;
32
+    private ImageView photo_detail;
30 33
     private TestPhotoGridAdapter photoGridAdapter;
31 34
     private PtpService ptp;
32 35
     private Camera camera;
@@ -55,6 +58,8 @@ public class MyTestActivity extends Activity implements Handler.Callback, Camera
55 58
         photoGridAdapter = new TestPhotoGridAdapter(this, photoGridView);
56 59
         photoGridView.setAdapter(photoGridAdapter);
57 60
 
61
+        photo_detail = (ImageView) findViewById(R.id.photo_detail);
62
+
58 63
         findViewById(R.id.btn_get_devece_info).setOnClickListener(new View.OnClickListener() {
59 64
             @Override
60 65
             public void onClick(View v) {
@@ -97,6 +102,21 @@ public class MyTestActivity extends Activity implements Handler.Callback, Camera
97 102
                 }
98 103
             }
99 104
         });
105
+
106
+        ((GridView) findViewById(R.id.gridview_photos)).setOnItemClickListener(new AdapterView.OnItemClickListener() {
107
+            @Override
108
+            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
109
+                photo_detail.setVisibility(View.VISIBLE);
110
+                photo_detail.setImageBitmap(((Photo) photoGridAdapter.getItem(i)).origin);
111
+            }
112
+        });
113
+
114
+        findViewById(R.id.photo_detail).setOnClickListener(new View.OnClickListener() {
115
+            @Override
116
+            public void onClick(View view) {
117
+                photo_detail.setVisibility(View.INVISIBLE);
118
+            }
119
+        });
100 120
     }
101 121
 
102 122
     @Override
@@ -133,7 +153,7 @@ public class MyTestActivity extends Activity implements Handler.Callback, Camera
133 153
             if (camera != null) {
134 154
                 mainHandler.removeMessages(MSG_CHECK_STORAGE);
135 155
                 camera.retrieveImageHandles(MyTestActivity.this, 0xFFFFFFFF, PtpConstants.ObjectFormat.EXIF_JPEG);
136
-                mainHandler.sendEmptyMessageDelayed(MSG_CHECK_STORAGE, 1000);
156
+                mainHandler.sendEmptyMessageDelayed(MSG_CHECK_STORAGE, 100000);
137 157
             }
138 158
         }
139 159
         return false;
@@ -237,16 +257,15 @@ public class MyTestActivity extends Activity implements Handler.Callback, Camera
237 257
     }
238 258
 
239 259
     @Override
240
-    public void onObjectAdded(int handle, int format) {
241
-        adapter.addInfo("相机系统发现新文件 ,文件句柄 =" + handle + " format = " + format);
260
+    public void onObjectAdded(int handle) {
261
+        adapter.addInfo("相机系统发现新文件 ,文件句柄 =" + handle);
242 262
         if (camera == null) {
243 263
             return;
244 264
         }
245
-        if (format == PtpConstants.ObjectFormat.EXIF_JPEG) {
246
-            camera.retrievePicture(handle);
247
-        }
265
+        camera.retrievePicture(handle);
248 266
     }
249 267
 
268
+
250 269
     @Override
251 270
     public void onLogMessage(String msg) {
252 271
         adapter.addInfo(msg);
@@ -314,6 +333,7 @@ public class MyTestActivity extends Activity implements Handler.Callback, Camera
314 333
         });
315 334
     }
316 335
 
336
+
317 337
     public void retrieveImageInfo(final int handle) {
318 338
         mainHandler.post(new Runnable() {
319 339
             @Override

+ 8 - 0
app/src/main/java/ai/pai/ptp/test/TestPhotoGridAdapter.java

@@ -3,6 +3,7 @@ package ai.pai.ptp.test;
3 3
 import android.view.LayoutInflater;
4 4
 import android.view.View;
5 5
 import android.view.ViewGroup;
6
+import android.widget.AdapterView;
6 7
 import android.widget.BaseAdapter;
7 8
 import android.widget.GridView;
8 9
 import android.widget.ImageView;
@@ -26,6 +27,13 @@ public class TestPhotoGridAdapter extends BaseAdapter {
26 27
         inflater = LayoutInflater.from(context);
27 28
         int screenW = context.getResources().getDisplayMetrics().widthPixels;
28 29
         height = (int) (screenW - 4 * 3 * context.getResources().getDisplayMetrics().density) / 3;
30
+
31
+        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
32
+            @Override
33
+            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
34
+
35
+            }
36
+        });
29 37
     }
30 38
 
31 39
     @Override

+ 1 - 1
app/src/main/java/com/remoteyourcam/usb/ptp/Camera.java

@@ -88,7 +88,7 @@ public interface Camera {
88 88
 
89 89
         void onFocusPointsChanged();
90 90
 
91
-        void onObjectAdded(int handle, int format);
91
+        void onObjectAdded(int handle);
92 92
 
93 93
         void onLogMessage(String msg);
94 94
     }

+ 1 - 1
app/src/main/java/com/remoteyourcam/usb/ptp/EosCamera.java

@@ -66,7 +66,7 @@ public class EosCamera extends PtpCamera {
66 66
     }
67 67
 
68 68
     public void onEventDirItemCreated(int objectHandle, int storageId, int objectFormat, String filename) {
69
-        onEventObjectAdded(objectHandle, objectFormat);
69
+        onEventObjectAdded(objectHandle);
70 70
     }
71 71
 
72 72
     @Override

+ 7 - 0
app/src/main/java/com/remoteyourcam/usb/ptp/NikonCamera.java

@@ -24,6 +24,7 @@ import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
24 24
 import com.remoteyourcam.usb.ptp.commands.GetDevicePropDescCommand;
25 25
 import com.remoteyourcam.usb.ptp.commands.InitiateCaptureCommand;
26 26
 import com.remoteyourcam.usb.ptp.commands.RetrieveAddedObjectInfoAction;
27
+import com.remoteyourcam.usb.ptp.commands.RetrievePictureAction;
27 28
 import com.remoteyourcam.usb.ptp.commands.SimpleCommand;
28 29
 import com.remoteyourcam.usb.ptp.commands.nikon.NikonAfDriveCommand;
29 30
 import com.remoteyourcam.usb.ptp.commands.nikon.NikonCloseSessionAction;
@@ -168,6 +169,12 @@ public class NikonCamera extends PtpCamera {
168 169
         this.vendorPropCodes = vendorPropCodes;
169 170
     }
170 171
 
172
+    @Override
173
+    public void retrievePicture(int objectHandle) {
174
+        queue.add(new RetrievePictureAction(this, objectHandle, pictureSampleSize));
175
+        queue.add(new SimpleCommand(this, PtpConstants.Operation.NikonDeleteImagesInSdram, objectHandle));
176
+    }
177
+
171 178
     public void onEventObjectAdded(int objectHandle) {
172 179
         queue.add(new RetrieveAddedObjectInfoAction(this, objectHandle));
173 180
     }

+ 4 - 4
app/src/main/java/com/remoteyourcam/usb/ptp/PtpCamera.java

@@ -34,6 +34,7 @@ import com.remoteyourcam.usb.ptp.commands.RetrieveImageAction;
34 34
 import com.remoteyourcam.usb.ptp.commands.RetrieveImageInfoAction;
35 35
 import com.remoteyourcam.usb.ptp.commands.RetrievePictureAction;
36 36
 import com.remoteyourcam.usb.ptp.commands.SetDevicePropValueCommand;
37
+import com.remoteyourcam.usb.ptp.commands.SimpleCommand;
37 38
 import com.remoteyourcam.usb.ptp.model.DeviceInfo;
38 39
 import com.remoteyourcam.usb.ptp.model.DevicePropDesc;
39 40
 import com.remoteyourcam.usb.ptp.model.LiveViewData;
@@ -110,7 +111,7 @@ public abstract class PtpCamera implements Camera {
110 111
     protected final int productId;
111 112
 
112 113
     private WorkerListener workerListener;
113
-    private int pictureSampleSize;
114
+    protected int pictureSampleSize;
114 115
 
115 116
     public PtpCamera(PtpUsbConnection connection, CameraListener listener, WorkerListener workerListener) {
116 117
         this.connection = connection;
@@ -376,12 +377,12 @@ public abstract class PtpCamera implements Camera {
376 377
         }
377 378
     }
378 379
 
379
-    public void onEventObjectAdded(final int handle, final int format) {
380
+    public void onEventObjectAdded(final int handle) {
380 381
         handler.post(new Runnable() {
381 382
             @Override
382 383
             public void run() {
383 384
                 if (listener != null) {
384
-                    listener.onObjectAdded(handle, format);
385
+                    listener.onObjectAdded(handle);
385 386
                 }
386 387
             }
387 388
         });
@@ -883,5 +884,4 @@ public abstract class PtpCamera implements Camera {
883 884
     public void setCapturedPictureSampleSize(int sampleSize) {
884 885
         this.pictureSampleSize = sampleSize;
885 886
     }
886
-
887 887
 }

+ 7 - 2
app/src/main/java/com/remoteyourcam/usb/ptp/PtpConstants.java

@@ -119,6 +119,11 @@ public class PtpConstants {
119 119
         public static final int NikonGetObjectPropDesc = 0x9802;
120 120
         public static final int NikonGetObjectPropValue = 0x9803;
121 121
         public static final int NikonGetObjectPropList = 0x9805;
122
+        public static final int NikonGetVendorStorageIDs = 0x9209;
123
+        public static final int NIKONStartMovieRecInCard = 0x920a;
124
+        public static final int NIKONEndMovieRec = 0x920b;
125
+        public static final int NIKONTerminateCapture = 0x920c;
126
+        public static final int NIKONGetPartialObjectHiSpeed = 0x920b;
122 127
 
123 128
         // Canon EOS
124 129
         public static final int EosTakePicture = 0x910F;
@@ -156,9 +161,9 @@ public class PtpConstants {
156 161
         public static final int CaptureComplete = 0x400D;
157 162
 
158 163
         // Nikon
159
-        public static final int NikonObjectAddedInSdram = 0xC101;
164
+        public static final int NikonObjectAddedInSdram = 0xffffC101;
160 165
         public static final int NikonCaptureCompleteRecInSdram = 0xC102;
161
-        public static final int NikonPreviewImageAdded = 0xC104;
166
+        public static final int NikonPreviewImageAdded = 0xffffC104;
162 167
 
163 168
         // Canon EOS
164 169
         public static final int EosObjectAdded = 0xC181; // ? dir item request transfer or dir item created

+ 1 - 1
app/src/main/java/com/remoteyourcam/usb/ptp/commands/RetrieveAddedObjectInfoAction.java

@@ -42,7 +42,7 @@ public class RetrieveAddedObjectInfoAction implements PtpAction {
42 42
             return;
43 43
         }
44 44
 
45
-        camera.onEventObjectAdded(objectHandle, getInfo.getObjectInfo().objectFormat);
45
+        camera.onEventObjectAdded(objectHandle);
46 46
     }
47 47
 
48 48
     @Override

+ 5 - 0
app/src/main/java/com/remoteyourcam/usb/ptp/commands/nikon/NikonEventCheckCommand.java

@@ -70,6 +70,11 @@ public class NikonEventCheckCommand extends NikonCommand {
70 70
             case Event.CaptureComplete:
71 71
                 camera.onEventCaptureComplete();
72 72
                 break;
73
+            case Event.NikonObjectAddedInSdram:
74
+                //libgphoto2 相关处理
75
+                if (eventParam == 0) { eventParam = 0xffff001; }
76
+                camera.onEventObjectAdded(eventParam);
77
+                break;
73 78
             }
74 79
         }
75 80
     }

+ 14 - 4
app/src/main/res/layout/activity_my_test.xml

@@ -1,7 +1,10 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    xmlns:app="http://schemas.android.com/apk/res-auto"
4
+    xmlns:tools="http://schemas.android.com/tools"
3 5
     android:layout_width="match_parent"
4 6
     android:layout_height="match_parent"
7
+    android:background="#fff"
5 8
     android:orientation="vertical">
6 9
 
7 10
     <Button
@@ -53,15 +56,22 @@
53 56
             android:horizontalSpacing="4dp"
54 57
             android:listSelector="@android:color/transparent"
55 58
             android:numColumns="3"
56
-            android:verticalSpacing="4dp"
57
-            />
59
+            android:verticalSpacing="4dp" />
58 60
 
59 61
         <ImageView
60 62
             android:id="@+id/iv_latest_photo"
61 63
             android:layout_width="match_parent"
62 64
             android:layout_height="match_parent"
63
-            android:visibility="gone"
64
-            android:scaleType="fitCenter" />
65
+            android:scaleType="fitCenter"
66
+            android:visibility="gone" />
67
+
68
+        <ImageView
69
+            android:id="@+id/photo_detail"
70
+            android:layout_width="wrap_content"
71
+            android:layout_height="wrap_content"
72
+            android:visibility="invisible"
73
+            tools:src="@tools:sample/backgrounds/scenic" />
74
+
65 75
     </RelativeLayout>
66 76
 
67 77
 </LinearLayout>