DemoActivity.kt 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package com.suyghur.dolin
  2. import android.app.Activity
  3. import android.app.AlertDialog
  4. import android.os.Bundle
  5. import android.view.KeyEvent
  6. import android.view.View
  7. import android.widget.Button
  8. import android.widget.LinearLayout
  9. import android.widget.TextView
  10. import com.suyghur.dolin.zap.Zap
  11. import kotlin.system.exitProcess
  12. /**
  13. * @author #Suyghur.
  14. * Created on 4/6/21
  15. */
  16. class DemoActivity : Activity(), View.OnClickListener {
  17. private lateinit var textView: TextView
  18. private val events: MutableList<Item> = mutableListOf(
  19. Item(0, "Zap日志测试"),
  20. Item(1, "申请多个危险权限")
  21. )
  22. override fun onCreate(savedInstanceState: Bundle?) {
  23. super.onCreate(savedInstanceState)
  24. initView()
  25. // initDeviceInfo()
  26. // Zap.d("test : ${Common.testLib()}")
  27. }
  28. private fun initView() {
  29. val layout = LinearLayout(this)
  30. layout.orientation = LinearLayout.VERTICAL
  31. textView = TextView(this)
  32. layout.addView(textView)
  33. for (event in events) {
  34. with(Button(this)) {
  35. tag = event.id
  36. text = event.text
  37. setOnClickListener(this@DemoActivity)
  38. layout.addView(this)
  39. }
  40. }
  41. setContentView(layout)
  42. }
  43. // private fun initDeviceInfo() {
  44. // val sb = StringBuilder()
  45. // sb.append("Android ID:").append(DeviceInfoUtils.getAndroidDeviceId(this)).append("\n")
  46. // sb.append("厂商:").append(DeviceInfoUtils.getDeviceBrand()).append("\n")
  47. // sb.append("型号:").append(DeviceInfoUtils.getModel()).append("\n")
  48. // sb.append("系统版本:").append(DeviceInfoUtils.getDeviceSoftWareVersion()).append("\n")
  49. // sb.append("cpu核数:").append(DeviceInfoUtils.getCpuCount()).append("\n")
  50. // sb.append("cpu架构:").append(DeviceInfoUtils.getCpuABI()).append("\n")
  51. // sb.append("本机内存:").append(DeviceInfoUtils.getRAM()).append("\n")
  52. // sb.append("本机剩余内存:").append(DeviceInfoUtils.getAvailMem(this)).append("M")
  53. // textView.text = sb.toString()
  54. // }
  55. override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
  56. if (keyCode == KeyEvent.KEYCODE_BACK) {
  57. AlertDialog.Builder(this)
  58. .setTitle("退出应用")
  59. .setCancelable(false)
  60. .setMessage("是否退出")
  61. .setPositiveButton("确认") { dialog, _ ->
  62. dialog?.dismiss()
  63. finish()
  64. }
  65. .setNegativeButton("取消") { dialog, _ ->
  66. dialog?.dismiss()
  67. }.show()
  68. return true
  69. }
  70. return super.onKeyDown(keyCode, event)
  71. }
  72. override fun onDestroy() {
  73. super.onDestroy()
  74. Zap.recycle()
  75. exitProcess(0)
  76. }
  77. override fun onClick(v: View?) {
  78. v?.apply {
  79. when (tag as Int) {
  80. 0 -> ZapActivity.start(this@DemoActivity)
  81. }
  82. }
  83. }
  84. }