@@ -17,7 +17,7 @@ import com.remoteyourcam.usb.ptp.model.ObjectInfo; |
||
17 | 17 |
import ai.pai.ptp.R; |
18 | 18 |
|
19 | 19 |
|
20 |
-public class MyTestActivity extends Activity implements Camera.CameraListener,Camera.StorageInfoListener,Camera.RetrieveImageInfoListener{ |
|
20 |
+public class MyTestActivity extends Activity implements Camera.CameraListener, Camera.StorageInfoListener, Camera.RetrieveImageInfoListener { |
|
21 | 21 |
|
22 | 22 |
private ImageView photoIv; |
23 | 23 |
private MyTestAdapter adapter; |
@@ -41,9 +41,9 @@ public class MyTestActivity extends Activity implements Camera.CameraListener,Ca |
||
41 | 41 |
findViewById(R.id.btn_get_devece_info).setOnClickListener(new View.OnClickListener() { |
42 | 42 |
@Override |
43 | 43 |
public void onClick(View v) { |
44 |
- if(camera!=null){ |
|
44 |
+ if (camera != null) { |
|
45 | 45 |
adapter.addInfo(camera.getDeviceInfo()); |
46 |
- }else{ |
|
46 |
+ } else { |
|
47 | 47 |
adapter.addInfo("未发现相机设备"); |
48 | 48 |
ptp.initialize(MyTestActivity.this, getIntent()); |
49 | 49 |
} |
@@ -53,9 +53,9 @@ public class MyTestActivity extends Activity implements Camera.CameraListener,Ca |
||
53 | 53 |
findViewById(R.id.btn_capture_photo).setOnClickListener(new View.OnClickListener() { |
54 | 54 |
@Override |
55 | 55 |
public void onClick(View v) { |
56 |
- if(camera!=null){ |
|
56 |
+ if (camera != null) { |
|
57 | 57 |
camera.capture(); |
58 |
- }else{ |
|
58 |
+ } else { |
|
59 | 59 |
ptp.initialize(MyTestActivity.this, getIntent()); |
60 | 60 |
} |
61 | 61 |
} |
@@ -64,9 +64,9 @@ public class MyTestActivity extends Activity implements Camera.CameraListener,Ca |
||
64 | 64 |
findViewById(R.id.btn_get_photos).setOnClickListener(new View.OnClickListener() { |
65 | 65 |
@Override |
66 | 66 |
public void onClick(View v) { |
67 |
- if(camera!=null){ |
|
67 |
+ if (camera != null) { |
|
68 | 68 |
camera.retrieveStorages(MyTestActivity.this); |
69 |
- }else{ |
|
69 |
+ } else { |
|
70 | 70 |
ptp.initialize(MyTestActivity.this, getIntent()); |
71 | 71 |
} |
72 | 72 |
} |
@@ -192,7 +192,7 @@ public class MyTestActivity extends Activity implements Camera.CameraListener,Ca |
||
192 | 192 |
|
193 | 193 |
@Override |
194 | 194 |
public void onObjectAdded(int handle, int format) { |
195 |
- adapter.addInfo("相机系统发现新文件 ,文件句柄 ="+ handle + " format = "+ format); |
|
195 |
+ adapter.addInfo("相机系统发现新文件 ,文件句柄 =" + handle + " format = " + format); |
|
196 | 196 |
if (camera == null) { |
197 | 197 |
return; |
198 | 198 |
} |
@@ -207,23 +207,41 @@ public class MyTestActivity extends Activity implements Camera.CameraListener,Ca |
||
207 | 207 |
} |
208 | 208 |
|
209 | 209 |
@Override |
210 |
- public void onStorageFound(int handle, String label) { |
|
211 |
- adapter.addInfo("找到相机存储文件,句柄="+handle + " label = "+label); |
|
212 |
- |
|
210 |
+ public void onStorageFound(final int handle, String label) { |
|
211 |
+ adapter.addInfo("找到相机存储卡位置,句柄=" + handle + " label = " + label); |
|
212 |
+ photoIv.post(new Runnable() { |
|
213 |
+ @Override |
|
214 |
+ public void run() { |
|
215 |
+ camera.retrieveImageHandles(MyTestActivity.this, handle, PtpConstants.ObjectFormat.EXIF_JPEG); |
|
216 |
+ } |
|
217 |
+ }); |
|
213 | 218 |
} |
214 | 219 |
|
215 | 220 |
@Override |
216 | 221 |
public void onAllStoragesFound() { |
217 |
- adapter.addInfo("找到相机存储"); |
|
222 |
+ adapter.addInfo("相机存储卡查找完成"); |
|
218 | 223 |
} |
219 | 224 |
|
220 | 225 |
@Override |
221 |
- public void onImageHandlesRetrieved(int[] handles) { |
|
222 |
- adapter.addInfo("找到相机存储图像文件,共"+handles.length + "张"); |
|
226 |
+ public void onImageHandlesRetrieved(final int[] handles) { |
|
227 |
+ adapter.addInfo("找到相机存储图像文件,共" + handles.length + "张"); |
|
228 |
+ photoIv.post(new Runnable() { |
|
229 |
+ @Override |
|
230 |
+ public void run() { |
|
231 |
+ camera.retrieveImageInfo(MyTestActivity.this, handles[0]); |
|
232 |
+ } |
|
233 |
+ }); |
|
223 | 234 |
} |
224 | 235 |
|
225 | 236 |
@Override |
226 |
- public void onImageInfoRetrieved(int objectHandle, ObjectInfo objectInfo, Bitmap thumbnail) { |
|
227 |
- adapter.addInfo("找到相机存储图像文件,句柄="+objectHandle + " info = "+objectInfo); |
|
237 |
+ public void onImageInfoRetrieved(int objectHandle, ObjectInfo objectInfo, final Bitmap thumbnail) { |
|
238 |
+ adapter.addInfo("找到相机存储图像文件,句柄=" + objectHandle + " info = " + objectInfo); |
|
239 |
+ photoIv.post(new Runnable() { |
|
240 |
+ @Override |
|
241 |
+ public void run() { |
|
242 |
+ photoIv.setImageBitmap(thumbnail); |
|
243 |
+ } |
|
244 |
+ }); |
|
245 |
+ |
|
228 | 246 |
} |
229 | 247 |
} |
@@ -45,20 +45,22 @@ public class GetStorageInfosAction implements PtpAction { |
||
45 | 45 |
int ids[] = getStorageIds.getStorageIds(); |
46 | 46 |
for (int i = 0; i < ids.length; ++i) { |
47 | 47 |
int storageId = ids[i]; |
48 |
- GetStorageInfoCommand c = new GetStorageInfoCommand(camera, storageId); |
|
49 |
- io.handleCommand(c); |
|
48 |
+ if(storageId == 131073){ |
|
49 |
+ GetStorageInfoCommand c = new GetStorageInfoCommand(camera, storageId); |
|
50 |
+ io.handleCommand(c); |
|
50 | 51 |
|
51 |
- if (c.getResponseCode() != Response.Ok) { |
|
52 |
- listener.onAllStoragesFound(); |
|
53 |
- return; |
|
54 |
- } |
|
52 |
+ if (c.getResponseCode() != Response.Ok) { |
|
53 |
+ listener.onAllStoragesFound(); |
|
54 |
+ return; |
|
55 |
+ } |
|
55 | 56 |
|
56 |
- String label = c.getStorageInfo().volumeLabel.isEmpty() ? c.getStorageInfo().storageDescription : c |
|
57 |
- .getStorageInfo().volumeLabel; |
|
58 |
- if (label == null || label.isEmpty()) { |
|
59 |
- label = "Storage " + i; |
|
57 |
+ String label = c.getStorageInfo().volumeLabel.isEmpty() ? c.getStorageInfo().storageDescription : c |
|
58 |
+ .getStorageInfo().volumeLabel; |
|
59 |
+ if (label == null || label.isEmpty()) { |
|
60 |
+ label = "Storage " + i; |
|
61 |
+ } |
|
62 |
+ listener.onStorageFound(storageId, label); |
|
60 | 63 |
} |
61 |
- listener.onStorageFound(storageId, label); |
|
62 | 64 |
} |
63 | 65 |
|
64 | 66 |
listener.onAllStoragesFound(); |