Skip to content

Commit 7438050

Browse files
committed
完善生命周期
1 parent 925806b commit 7438050

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

app/src/main/clojure/plain/someactivity2.clj

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@
2727
(defn fetch [url]
2828
(http/get url))
2929

30+
(defonce camera-view-atom (atom nil))
31+
(defonce classifier-atom (atom nil))
32+
33+
(defn some-onResume [^plain.someactivity2.MyActivity this ^android.os.Bundle bundle]
34+
(.superOnResume this bundle)
35+
(.start @camera-view-atom))
36+
37+
(defn some-onPause [^plain.someactivity2.MyActivity this ^android.os.Bundle bundle]
38+
(.stop @camera-view-atom)
39+
(.superOnPause this bundle))
40+
41+
(defn some-onDestroy [^plain.someactivity2.MyActivity this ^android.os.Bundle bundle]
42+
(.superOnDestroy this bundle)
43+
;; executor.execute(new Runnable() {
44+
;; @Override
45+
;; public void run() {
46+
;; classifier.close();
47+
;; }
48+
;; });
49+
)
50+
3051
(defn some-onCreate [^plain.someactivity2.MyActivity this ^android.os.Bundle bundle]
3152
(.superOnCreate this bundle)
3253
(.setContentView this com.example.ndksample.myapplication.R$layout/activity_main)
@@ -39,6 +60,7 @@
3960
(Log/i "已启动" "clojure repl server")))
4061

4162
(let [camera-view (.findViewById this com.example.ndksample.myapplication.R$id/cameraView)
63+
_ (reset! camera-view-atom camera-view)
4264
image-view-result (.findViewById this com.example.ndksample.myapplication.R$id/imageViewResult)
4365
text-view-result (.findViewById this com.example.ndksample.myapplication.R$id/textViewResult)
4466
_ (.setMovementMethod text-view-result (ScrollingMovementMethod.))
@@ -51,7 +73,12 @@
5173
(onError [^CameraKitError camera-kit-error]
5274
(Log/i "onError" (str camera-kit-error)) )
5375
(onImage [^CameraKitImage camera-kit-image]
54-
(Log/i "onImage" "......") )
76+
(Log/i "onImage" "......")
77+
(let [bitmap (.getBitmap camera-kit-image)
78+
bitmap (Bitmap/createScaledBitmap bitmap 224 224 false)
79+
_ (.setImageBitmap image-view-result bitmap)
80+
results (.recognizeImage @classifier-atom bitmap)]
81+
(.setText text-view-result (.toString results))) )
5582
(onVideo [^CameraKitVideo camera-kit-video] )))
5683
;;
5784
(.setOnClickListener btn-toggle-camera

0 commit comments

Comments
 (0)