wxr
2024-04-11 9802cf8c8ad9f392c5c5342a352a17efeef55fc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using Android.Support.V7.App;
using Android.Views;
using Android.Widget;
using Com.Journeyapps.Barcodescanner;
 
namespace HDL_ON_Android
{
    [Activity(Label = "CustomCaptureActivity", Theme = "@style/MyTheme1", ScreenOrientation = ScreenOrientation.Portrait)]
    public class CustomCaptureActivity : AppCompatActivity//Activity
    {
 
        /**
         * 条形码扫描管理器
         */
        private CaptureManager mCaptureManager;
 
        /**
         * 条形码扫描视图
         */
        private DecoratedBarcodeView mBarcodeView;
 
 
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
 
            SetContentView(Resource.Layout.activity_zxing_layout);
            mBarcodeView = (DecoratedBarcodeView)FindViewById(Resource.Id.zxing_barcode_scanner);
 
            mCaptureManager = new CaptureManager(this, mBarcodeView);
            mCaptureManager.InitializeFromIntent(this.Intent, savedInstanceState);//getIntent(),
            mCaptureManager.Decode();
        }
 
 
        protected override void OnResume()
        {
            base.OnResume();
            mCaptureManager.OnResume();
        }
 
 
        protected override void OnPause()
        {
            base.OnPause();
            mCaptureManager.OnPause();
        }
 
        protected override void OnDestroy()
        {
            base.OnDestroy();
            mCaptureManager.OnDestroy();
        }
 
        protected override void OnSaveInstanceState(Bundle outState)
        {
            base.OnSaveInstanceState(outState);
            mCaptureManager.OnSaveInstanceState(outState);
        }
 
 
        /**
         * 权限处理
         */
        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
        {
            int[] rg = new int[grantResults.Length] ;
            foreach(var g in grantResults)
            {
                rg.Append((int)g);
            }
            mCaptureManager.OnRequestPermissionsResult(requestCode, permissions, rg);
        }
        //public override void OnRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults)
        //{
        //    mCaptureManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
        //}
 
        /**
         * 按键处理
         */
        public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e)
        {
            //return base.OnKeyDown(keyCode, e);
            return mBarcodeView.OnKeyDown(keyCode, e) || base.OnKeyDown(keyCode, e);
        }
        //public boolean onKeyDown(int keyCode, KeyEvent event) {
        //    return mBarcodeView.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
        //}
    }
}