package com.shlb.comb.activity; import android.bluetooth.BluetoothAdapter; import android.content.pm.PackageManager; import android.os.Build; import android.view.View; import com.qmuiteam.qmui.widget.grouplist.QMUICommonListItemView; import com.qmuiteam.qmui.widget.grouplist.QMUIGroupListView; import com.shlb.comb.R; import com.shlb.comb.base.BaseActivity; import com.shlb.comb.event.UpdateEvent; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; public class CurrentDeviceActivity extends BaseActivity { private QMUIGroupListView mGroupHardware; private QMUIGroupListView mGroupBle; private QMUIGroupListView mGroupAudio; private QMUIGroupListView mGroupScreen; @Override protected void contentView() { setContentView(R.layout.activity_current_device); } @Override protected void initView() { super.initHead(); tv_center.setText("设备信息"); if (iv_right != null) iv_right.setVisibility(View.GONE); if (iv_left != null) { iv_left.setImageDrawable(getResources().getDrawable(R.mipmap.icon_back)); iv_left.setOnClickListener(v -> finish()); } mGroupHardware = findViewById(R.id.group_hardware); mGroupBle = findViewById(R.id.group_ble); mGroupAudio = findViewById(R.id.group_audio); mGroupScreen = findViewById(R.id.group_screen); } @Override protected void initData() { initHardwareInfo(); initBleInfo(); initAudioInfo(); initScreenInfo(); } @Override protected void initEvent() { } @Subscribe(threadMode = ThreadMode.MAIN) public void onEvent(UpdateEvent event) { // Required by BaseActivity's EventBus registration } private void initHardwareInfo() { QMUIGroupListView.newSection(this) .setTitle("硬件信息") .addItemView(createItem("设备名称", Build.DEVICE), null) .addItemView(createItem("Android 版本", Build.VERSION.RELEASE), null) .addItemView(createItem("制造商", Build.MANUFACTURER), null) .addItemView(createItem("型号", Build.MODEL), null) .addItemView(createItem("构建版本", Build.DISPLAY), null) .addItemView(createItem("主板", Build.BOARD), null) .addItemView(createItem("产品名", Build.PRODUCT), null) .addTo(mGroupHardware); } private void initBleInfo() { PackageManager pm = getPackageManager(); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); boolean isBleSupported = pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE); QMUIGroupListView.Section section = QMUIGroupListView.newSection(this) .setTitle("低功耗蓝牙"); section.addItemView(createItem("支持 BLE", isBleSupported ? "是" : "否", isBleSupported), null); if (adapter != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { boolean isOffloadedFilteringSupported = adapter.isOffloadedFilteringSupported(); boolean isOffloadedScanBatchingSupported = adapter.isOffloadedScanBatchingSupported(); boolean isMultipleAdvertisementSupported = adapter.isMultipleAdvertisementSupported(); section.addItemView(createItem("支持脱机过滤", isOffloadedFilteringSupported ? "是" : "否", isOffloadedFilteringSupported), null); section.addItemView(createItem("支持脱机扫描批处理", isOffloadedScanBatchingSupported ? "是" : "否", isOffloadedScanBatchingSupported), null); section.addItemView(createItem("支持多重广播", isMultipleAdvertisementSupported ? "是" : "否", isMultipleAdvertisementSupported), null); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { boolean isLe2MPhySupported = adapter.isLe2MPhySupported(); boolean isLeCodedPhySupported = adapter.isLeCodedPhySupported(); boolean isLeExtendedAdvertisingSupported = adapter.isLeExtendedAdvertisingSupported(); boolean isLePeriodicAdvertisingSupported = adapter.isLePeriodicAdvertisingSupported(); section.addItemView(createItem("支持高速 (PHY 2M)", isLe2MPhySupported ? "是" : "否", isLe2MPhySupported), null); section.addItemView(createItem("支持远距离 (PHY Coded)", isLeCodedPhySupported ? "是" : "否", isLeCodedPhySupported), null); section.addItemView(createItem("支持扩展广播", isLeExtendedAdvertisingSupported ? "是" : "否", isLeExtendedAdvertisingSupported), null); section.addItemView(createItem("支持周期性广播", isLePeriodicAdvertisingSupported ? "是" : "否", isLePeriodicAdvertisingSupported), null); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { int maxDataLength = adapter.isLeExtendedAdvertisingSupported() ? 1650 : 31; section.addItemView(createItem("最大广播数据长度", String.valueOf(maxDataLength)), null); } } section.addTo(mGroupBle); } private void initAudioInfo() { QMUIGroupListView.newSection(this) .setTitle("蓝牙音频") .addItemView(createItem("支持 LE Audio", "否", false), null) .addItemView(createItem("支持 LE 广播源", "否", false), null) .addItemView(createItem("支持 LE 广播助手", "否", false), null) .addItemView(createItem("最大连接音频设备数", "0"), null) .addTo(mGroupAudio); } private void initScreenInfo() { android.util.DisplayMetrics dm = getResources().getDisplayMetrics(); int screenWidth = dm.widthPixels; int screenHeight = dm.heightPixels; float density = dm.density; int densityDpi = dm.densityDpi; QMUIGroupListView.newSection(this) .setTitle("屏幕信息") .addItemView(createItem("分辨率", screenWidth + " x " + screenHeight), null) .addItemView(createItem("密度", density + " (" + densityDpi + " dpi)"), null) .addTo(mGroupScreen); } private QMUICommonListItemView createItem(String title, String detail) { return createItem(title, detail, true); } private QMUICommonListItemView createItem(String title, String detail, boolean isSupported) { QMUICommonListItemView item = mGroupHardware.createItemView(title); item.setOrientation(QMUICommonListItemView.HORIZONTAL); item.setDetailText(detail); return item; } }