whycxzp
2024-07-19 339df2d21fc3c2784300db90eeb2299e0f89dc84
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
package com.whyc;
 
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.KeyEvent;
 
import com.rokid.glass.imusdk.core.IMUView;
import com.whyc.adapter.IMUImageAdapter;
import com.whyc.adapter.IMUImageItem;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @Author: sunchao
 * @CreateDate: 2020/7/18 2:52 PM
 */
public class IMUActivity extends AppCompatActivity {
    private IMUView mImuView;
    private List<IMUImageItem> mItems;
    private IMUImageAdapter mAdapter;
 
    private int[] resId = new int[]{R.mipmap.ic_1, R.mipmap.ic_2,
            R.mipmap.ic_3, R.mipmap.ic_4, R.mipmap.ic_5, R.mipmap.ic_6,
            R.mipmap.ic_7, R.mipmap.ic_8, R.mipmap.ic_9, R.mipmap.ic_10};
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_imu);
 
        initViews();
        initData();
    }
 
    private void initViews() {
        mImuView = findViewById(R.id.ui_recycler_view);
        getLifecycle().addObserver(mImuView);
 
        mAdapter = new IMUImageAdapter();
        mImuView.setAdapter(mAdapter);
        mImuView.setSlow();
    }
 
    private void initData() {
        mItems = new ArrayList<>();
        for (int i = 0; i < resId.length; i++) {
            mItems.add(new IMUImageItem().setResId(resId[i]).setName("姓名" + i));
        }
 
        mAdapter.setData(mItems);
    }
 
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_DPAD_CENTER:
            case KeyEvent.KEYCODE_ENTER://此处做点击事件的响应
                Log.d("position", "current pos  =" + mAdapter.getCurrentPosition() + "    keyCode = " + keyCode);
                IMUImageItem data = mAdapter.getItem(mAdapter.getCurrentPosition());
                if (null == data) {
                    return super.onKeyUp(keyCode, event);
                }
//                enterItem(data);
                break;
 
        }
        return super.onKeyDown(keyCode, event);
    }
 
}