c7797b38463b8c2b7R99">99
+ }
+ adapter.addInfo("搜素USB设备完成---------- ");
+ return device;
+ }
+
+ public void initDevice (UsbDevice device) {
+ if (device != null){
+ adapter.addInfo("初始化设备 "+ device.getDeviceName());
+ try {
+ bi = new BaselineInitiator (device, mUsbManager.openDevice(device));
+ // Select appropriate deviceInitiator, VIDs see http://www.linux-usb.org/usb.ids
+ if (bi.getDevice().getVendorId() == EosInitiator.CANON_VID) {
+ try {
+ bi.getClearStatus();
+ bi.close();
+ } catch (PTPException e) {e.printStackTrace();
+ adapter.addInfo("初始化设备异常 "+ e);
+ }
+ adapter.addInfo("初始化设备成功, 是Cannon");
+ bi = new EosInitiator (device, mUsbManager.openDevice(device));
+ }
+ else if (device.getVendorId() == NikonInitiator.NIKON_VID) {
+ try {
+ bi.getClearStatus();
+ bi.close();
+ } catch (PTPException e) {e.printStackTrace();
+ adapter.addInfo("初始化设备异常 "+ e);
+ }
+ adapter.addInfo("初始化设备成功, 是Nikon");
+ bi = new NikonInitiator (device, mUsbManager.openDevice(device));
+ }
+ adapter.addInfo("开始建立session");
+ bi.openSession();
+ } catch (PTPException e) {
+ e.printStackTrace();
+ adapter.addInfo("初始化设备发生错误 "+ e);
+ }
+ }
+ }
+
+ public void detachDevice () {
+ if (bi != null) {
+ if (bi.getDevice() != null) Log.d(TAG, "detachDevice: " +bi.getDevice().getDeviceName());
+ try {
+ bi.close();
+ } catch (PTPException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ private void registerUSBReceiver(){
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
+ filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
+ registerReceiver(mUsbReceiver, filter);
+ }
+}
@@ -0,0 +1,67 @@ |
||
| 1 |
+package com.ptplib.usbcamera.test; |
|
| 2 |
+ |
|
| 3 |
+import android.content.Context; |
|
| 4 |
+import android.view.LayoutInflater; |
|
| 5 |
+import android.view.View; |
|
| 6 |
+import android.view.ViewGroup; |
|
| 7 |
+import android.widget.BaseAdapter; |
|
| 8 |
+import android.widget.TextView; |
|
| 9 |
+ |
|
| 10 |
+import com.strickling.usbcamera.R; |
|
| 11 |
+ |
|
| 12 |
+import java.text.SimpleDateFormat; |
|
| 13 |
+import java.util.ArrayList; |
|
| 14 |
+import java.util.Date; |
|
| 15 |
+ |
|
| 16 |
+public class MyTestAdapter extends BaseAdapter {
|
|
| 17 |
+ |
|
| 18 |
+ private ArrayList<String> infoList; |
|
| 19 |
+ private Context context; |
|
| 20 |
+ private LayoutInflater inflater; |
|
| 21 |
+ private SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss\t");
|
|
| 22 |
+ |
|
| 23 |
+ public MyTestAdapter(Context context) {
|
|
| 24 |
+ this.context = context; |
|
| 25 |
+ infoList = new ArrayList<>(); |
|
| 26 |
+ inflater = LayoutInflater.from(context); |
|
| 27 |
+ } |
|
| 28 |
+ |
|
| 29 |
+ @Override |
|
| 30 |
+ public int getCount() {
|
|
| 31 |
+ return infoList.size(); |
|
| 32 |
+ } |
|
| 33 |
+ |
|
| 34 |
+ @Override |
|
| 35 |
+ public Object getItem(int position) {
|
|
| 36 |
+ return infoList.get(position); |
|
| 37 |
+ } |
|
| 38 |
+ |
|
| 39 |
+ @Override |
|
| 40 |
+ public long getItemId(int position) {
|
|
| 41 |
+ return position; |
|
| 42 |
+ } |
|
| 43 |
+ |
|
| 44 |
+ public void addInfo(String info){
|
|
| 45 |
+ infoList.add(formatter.format(new Date())+info); |
|
| 46 |
+ notifyDataSetChanged(); |
|
| 47 |
+ } |
|
| 48 |
+ |
|
| 49 |
+ @Override |
|
| 50 |
+ public View getView(int position, View convertView, ViewGroup parent) {
|
|
| 51 |
+ ViewHolder holder; |
|
| 52 |
+ if (convertView == null) {
|
|
| 53 |
+ convertView = inflater.inflate(R.layout.item_test_info, null); |
|
| 54 |
+ holder = new ViewHolder(); |
|
| 55 |
+ holder.info = (TextView) convertView.findViewById(R.id.tv_info); |
|
| 56 |
+ convertView.setTag(holder); |
|
| 57 |
+ } else {
|
|
| 58 |
+ holder = (ViewHolder) convertView.getTag(); |
|
| 59 |
+ } |
|
| 60 |
+ holder.info.setText(infoList.get(position)); |
|
| 61 |
+ return convertView; |
|
| 62 |
+ } |
|
| 63 |
+ |
|
| 64 |
+ final class ViewHolder {
|
|
| 65 |
+ public TextView info; |
|
| 66 |
+ } |
|
| 67 |
+} |
@@ -0,0 +1,34 @@ |
||
| 1 |
+<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 3 |
+ android:orientation="vertical" android:layout_width="match_parent" |
|
| 4 |
+ android:layout_height="match_parent"> |
|
| 5 |
+ |
|
| 6 |
+ <Button |
|
| 7 |
+ android:id="@+id/btn_get_devece_info" |
|
| 8 |
+ android:layout_width="match_parent" |
|
| 9 |
+ android:layout_height="48dp" |
|
| 10 |
+ android:layout_margin="4dp" |
|
| 11 |
+ android:gravity="center" |
|
| 12 |
+ android:text="获取设备信息"/> |
|
| 13 |
+ |
|
| 14 |
+ <ListView |
|
| 15 |
+ android:id="@+id/list_info" |
|
| 16 |
+ android:layout_width="match_parent" |
|
| 17 |
+ android:divider="@android:color/transparent" |
|
| 18 |
+ android:layout_height="200dp" /> |
|
| 19 |
+ <Button |
|
| 20 |
+ android:id="@+id/btn_get_photo" |
|
| 21 |
+ android:layout_width="match_parent" |
|
| 22 |
+ android:layout_height="48dp" |
|
| 23 |
+ android:layout_margin="4dp" |
|
| 24 |
+ android:gravity="center" |
|
| 25 |
+ android:text="获取最新照片"/> |
|
| 26 |
+ |
|
| 27 |
+ |
|
| 28 |
+ <ImageView |
|
| 29 |
+ android:id="@+id/iv_latest_photo" |
|
| 30 |
+ android:layout_width="match_parent" |
|
| 31 |
+ android:layout_height="match_parent" |
|
| 32 |
+ android:scaleType="centerInside"/> |
|
| 33 |
+ |
|
| 34 |
+</LinearLayout> |
@@ -0,0 +1,14 @@ |
||
| 1 |
+<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
+ |
|
| 3 |
+<TextView xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 4 |
+ android:id="@+id/tv_info" |
|
| 5 |
+ android:layout_width="match_parent" |
|
| 6 |
+ android:layout_height="wrap_content" |
|
| 7 |
+ android:textSize="14sp" |
|
| 8 |
+ android:textColor="@android:color/black" |
|
| 9 |
+ android:gravity="center_vertical" |
|
| 10 |
+ android:paddingLeft="8dp" |
|
| 11 |
+ android:paddingTop="4dp" |
|
| 12 |
+ android:paddingBottom="4dp" |
|
| 13 |
+ android:paddingRight="8dp" |
|
| 14 |
+ android:minHeight="20dp" /> |
@@ -3,7 +3,7 @@ |
||
| 3 | 3 |
|
| 4 | 4 |
<string name="desc">Description of an image</string> |
| 5 | 5 |
<string name="hello">Hello World, USBCamera Activity!</string> |
| 6 |
- <string name="app_name">USBCameraTest</string> |
|
| 6 |
+ <string name="app_name">Test</string> |
|
| 7 | 7 |
<string name="Button1">Get DeviceInfo</string> |
| 8 | 8 |
<string name="Button2">Detailed get DeviceInfo</string> |
| 9 | 9 |
<string name="Button3">Take Picture</string> |