ryc使用

chengzhenyu 6 anos atrás
pai
commit
6ff28aa838

+ 128 - 6
app/src/main/java/ai/pai/ptp/test/MyTestActivity.java

@@ -2,29 +2,46 @@ package ai.pai.ptp.test;
2 2
 
3 3
 import android.app.Activity;
4 4
 import android.content.Intent;
5
+import android.graphics.Bitmap;
5 6
 import android.os.Bundle;
7
+import android.os.Handler;
6 8
 import android.view.View;
7 9
 import android.widget.ImageView;
8 10
 import android.widget.ListView;
9 11
 
12
+import com.remoteyourcam.usb.ptp.Camera;
13
+import com.remoteyourcam.usb.ptp.PtpConstants;
14
+import com.remoteyourcam.usb.ptp.PtpService;
15
+import com.remoteyourcam.usb.ptp.model.LiveViewData;
16
+
10 17
 import ai.pai.ptp.R;
11 18
 
12 19
 
13
-public class MyTestActivity extends Activity {
20
+public class MyTestActivity extends Activity implements Camera.CameraListener {
14 21
 
15 22
     private ImageView photoIv;
16 23
     private ListView infoListView;
17 24
     private MyTestAdapter adapter;
18 25
 
19 26
 
27
+    private final String TAG = MyTestActivity.class.getSimpleName();
28
+
29
+    private final Handler handler = new Handler();
30
+
31
+    private PtpService ptp;
32
+    private Camera camera;
33
+    private boolean isInStart;
34
+
20 35
     @Override
21 36
     protected void onCreate(Bundle savedInstanceState) {
22 37
         super.onCreate(savedInstanceState);
23 38
         setContentView(R.layout.activity_my_test);
24 39
 
25
-        photoIv = (ImageView)findViewById(R.id.iv_latest_photo);
26
-        infoListView = (ListView)findViewById(R.id.list_info);
27
-        adapter = new MyTestAdapter(this,infoListView);
40
+        ptp = PtpService.Singleton.getInstance(this);
41
+
42
+        photoIv = (ImageView) findViewById(R.id.iv_latest_photo);
43
+        infoListView = (ListView) findViewById(R.id.list_info);
44
+        adapter = new MyTestAdapter(this, infoListView);
28 45
         infoListView.setAdapter(adapter);
29 46
 
30 47
         findViewById(R.id.btn_get_devece_info).setOnClickListener(new View.OnClickListener() {
@@ -45,18 +62,123 @@ public class MyTestActivity extends Activity {
45 62
     @Override
46 63
     protected void onStart() {
47 64
         super.onStart();
48
-
65
+        isInStart = true;
66
+        ptp.setCameraListener(this);
67
+        ptp.initialize(this, getIntent());
49 68
     }
50 69
 
51 70
     @Override
52 71
     protected void onStop() {
53 72
         super.onStop();
54
-
73
+        isInStart = false;
74
+        ptp.setCameraListener(null);
75
+        if (isFinishing()) {
76
+            ptp.shutdown();
77
+        }
55 78
     }
56 79
 
57 80
     @Override
58 81
     protected void onNewIntent(Intent intent) {
59 82
         super.onNewIntent(intent);
83
+        this.setIntent(intent);
84
+        if (isInStart) {
85
+            ptp.initialize(this, intent);
86
+        }
87
+    }
88
+
89
+    @Override
90
+    public void onCameraStarted(Camera camera) {
91
+        this.camera = camera;
92
+    }
93
+
94
+    @Override
95
+    public void onCameraStopped(Camera camera) {
96
+        this.camera = null;
97
+    }
98
+
99
+    @Override
100
+    public void onNoCameraFound() {
101
+        adapter.addInfo("没有发现相机设备");
102
+    }
103
+
104
+    @Override
105
+    public void onError(String message) {
106
+        adapter.addInfo("发生错误 " + message);
107
+    }
108
+
109
+    @Override
110
+    public void onPropertyChanged(int property, int value) {
111
+
112
+    }
113
+
114
+    @Override
115
+    public void onPropertyStateChanged(int property, boolean enabled) {
116
+
117
+    }
118
+
119
+    @Override
120
+    public void onPropertyDescChanged(int property, int[] values) {
121
+
122
+    }
123
+
124
+    @Override
125
+    public void onLiveViewStarted() {
126
+
127
+    }
128
+
129
+    @Override
130
+    public void onLiveViewData(LiveViewData data) {
131
+
132
+    }
133
+
134
+    @Override
135
+    public void onLiveViewStopped() {
136
+
137
+    }
138
+
139
+    @Override
140
+    public void onCapturedPictureReceived(int objectHandle, String filename, Bitmap thumbnail, Bitmap bitmap) {
141
+        adapter.addInfo("收到新照片 ");
142
+        photoIv.setImageBitmap(thumbnail);
143
+    }
144
+
145
+    @Override
146
+    public void onBulbStarted() {
147
+
148
+    }
149
+
150
+    @Override
151
+    public void onBulbExposureTime(int seconds) {
152
+
60 153
     }
61 154
 
155
+    @Override
156
+    public void onBulbStopped() {
157
+
158
+    }
159
+
160
+    @Override
161
+    public void onFocusStarted() {
162
+
163
+    }
164
+
165
+    @Override
166
+    public void onFocusEnded(boolean hasFocused) {
167
+
168
+    }
169
+
170
+    @Override
171
+    public void onFocusPointsChanged() {
172
+
173
+    }
174
+
175
+    @Override
176
+    public void onObjectAdded(int handle, int format) {
177
+        if (camera == null) {
178
+            return;
179
+        }
180
+        if (format == PtpConstants.ObjectFormat.EXIF_JPEG) {
181
+            camera.retrievePicture(handle);
182
+        }
183
+    }
62 184
 }

+ 0 - 1
app/src/main/java/com/remoteyourcam/usb/AppConfig.java

@@ -17,7 +17,6 @@ package com.remoteyourcam.usb;
17 17
 
18 18
 public class AppConfig {
19 19
     public static final boolean LOG = true;
20
-    public static final boolean USE_ACRA = false;
21 20
     public static final boolean LOG_PACKETS = false;
22 21
 
23 22
     public static final int EVENTCHECK_PERIOD = 700;

+ 0 - 80
app/src/main/java/com/remoteyourcam/usb/AppSettings.java

@@ -1,80 +0,0 @@
1
-/**
2
- * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- *     http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-package com.remoteyourcam.usb;
17
-
18
-import android.content.Context;
19
-import android.content.SharedPreferences;
20
-
21
-public class AppSettings {
22
-
23
-    private final SharedPreferences prefs;
24
-
25
-    public AppSettings(Context context) {
26
-        prefs = context.getSharedPreferences("app_settings", Context.MODE_PRIVATE);
27
-    }
28
-
29
-    public boolean showChangelog(int nextNumber) {
30
-        int last = prefs.getInt("internal.last_changelog_number", -1);
31
-        if (last == -1 || nextNumber > last) {
32
-            prefs.edit().putInt("internal.last_changelog_number", nextNumber).apply();
33
-        }
34
-        return last != -1 && nextNumber > last;
35
-    }
36
-
37
-    public boolean isGalleryOrderReversed() {
38
-        return prefs.getBoolean("internal.gallery.reverse_order", false);
39
-    }
40
-
41
-    public void setGalleryOrderReversed(boolean reversed) {
42
-        prefs.edit().putBoolean("internal.gallery.reverse_order", reversed).apply();
43
-    }
44
-
45
-    public int getShowCapturedPictureDuration() {
46
-        return getIntFromStringPreference("liveview.captured_picture_duration", -1);
47
-    }
48
-
49
-    public boolean isShowCapturedPictureNever() {
50
-        return getShowCapturedPictureDuration() == -2;
51
-    }
52
-
53
-    public boolean isShowCapturedPictureDurationManual() {
54
-        return getShowCapturedPictureDuration() == -1;
55
-    }
56
-
57
-    public int getNumPicturesInStream() {
58
-        return getIntFromStringPreference("picturestream.num_pictures", 6);
59
-    }
60
-
61
-    public boolean isShowFilenameInStream() {
62
-        return prefs.getBoolean("picturestream.show_filename", true);
63
-    }
64
-
65
-    public int getCapturedPictureSampleSize() {
66
-        return getIntFromStringPreference("memory.picture_sample_size", 2);
67
-    }
68
-
69
-    private int getIntFromStringPreference(String key, int defaultValue) {
70
-        try {
71
-            String value = prefs.getString(key, null);
72
-            if (value != null) {
73
-                return Integer.parseInt(value);
74
-            }
75
-        } catch (NumberFormatException e) {
76
-            // nop
77
-        }
78
-        return defaultValue;
79
-    }
80
-}