Skip to content

Commit

Permalink
feat: 增加智能识别跳转开关,以防止智能识别失败的原因。故不作为默认开启功能。
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKayJr committed Sep 7, 2024
1 parent 7cba885 commit 40f27f1
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 2
versionName = "1.9"
versionName = "2.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
52 changes: 52 additions & 0 deletions app/src/main/java/cn/martinkay/autocheckinplugin/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ import android.annotation.SuppressLint
import android.app.AlertDialog
import android.app.TimePickerDialog
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.PowerManager
import android.provider.Settings
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.CompoundButton
import android.widget.Switch
import android.widget.Toast
import androidx.annotation.ColorInt
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -96,6 +103,51 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
lockWifiService()
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
val enableSmartRecognitionJump: Boolean =
SharePrefHelper.getBoolean(ENABLE_SMART_RECOGNITION_JUMP, false)

when (item.itemId) {
R.id.action_settings -> {
val inflate = layoutInflater.inflate(R.layout.setting_dialog, null as ViewGroup?)
val builder = AlertDialog.Builder(this)
builder.setTitle("设置")

// 显示Toast
val enableSmartRecognitionJumpSwitch =
inflate.findViewById<Switch>(R.id.smart_recognition_jump)
enableSmartRecognitionJumpSwitch.isChecked = enableSmartRecognitionJump
enableSmartRecognitionJumpSwitch.setOnClickListener {
SharePrefHelper.putBoolean(
ENABLE_SMART_RECOGNITION_JUMP,
enableSmartRecognitionJumpSwitch.isChecked
)
Toast.makeText(
this,
"${if (enableSmartRecognitionJumpSwitch.isChecked) "开启" else "关闭"}智能识别跳转",
Toast.LENGTH_SHORT
).show()
}
val saveBtn = inflate.findViewById<Button>(R.id.setting_save)
saveBtn.setOnClickListener {

}

builder.setView(inflate)
.setPositiveButton("完成", null as DialogInterface.OnClickListener?).create()
.show()
}
R.id.compatible_config -> {
}
}
return super.onOptionsItemSelected(item)
}

private fun initViewModel() {
lifecycleScope.launch {
AutoSignPermissionUtils.notifyCalendarSchemeEvent.collect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const val SIGN_CALENDAR_SCHEME_CACHE = "sign_calendar_scheme_cache"

const val VERSION_UPDATE_FLAG = "version_update_flag"

const val ENABLE_SMART_RECOGNITION_JUMP = "enable_smart_recognition_jump"

object SharePrefHelper {

private var mShare: SharedPreferences? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cn.martinkay.autocheckinplugin.handler.pageprocessor.weixin;

import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;

import cn.martinkay.autocheckinplugin.handler.pageprocessor.BasePageProcessor;
import cn.martinkay.autocheckinplugin.service.MyAccessibilityService;
import cn.martinkay.autocheckinplugin.util.AccessibilityHelper;

public class LoginProcessor extends BasePageProcessor {
@Override
public boolean canParse(AccessibilityEvent event, MyAccessibilityService myAccessibilityService) {
AccessibilityNodeInfo topTextView = AccessibilityHelper.getNodeById(myAccessibilityService, "com.tencent.wework:id/lkw", 0);

return false;
}

@Override
public void processPage(AccessibilityEvent event, MyAccessibilityService myAccessibilityService) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public void processPage(AccessibilityEvent event, MyAccessibilityService myAcces
public boolean canParse(AccessibilityEvent event, MyAccessibilityService myAccessibilityService) {
// 顶部的文字
AccessibilityNodeInfo topTextView = AccessibilityHelper.getNodeById(myAccessibilityService, "com.tencent.wework:id/lkw", 0);
if (topTextView!=null) {
if (topTextView != null) {
return topTextView.getText().toString().contains("工作台");
}else {
} else {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.martinkay.autocheckinplugin.utils

import android.util.Log
import cn.martinkay.autocheckinplugin.ENABLE_SMART_RECOGNITION_JUMP
import cn.martinkay.autocheckinplugin.IS_OPEN_AFTERNOON_OFF_WORK_SIGN_TASK
import cn.martinkay.autocheckinplugin.IS_OPEN_AFTERNOON_START_WORK_SIGN_TASK
import cn.martinkay.autocheckinplugin.IS_OPEN_MORNING_OFF_WORK_SIGN_TASK
Expand Down Expand Up @@ -70,6 +71,13 @@ object AutoSignPermissionUtils {
}

fun isMobileAutoSignLaunch(): Boolean {
// 判断是否开启智能识别跳转 如果关闭则直接返回true
val enableSmartRecognitionJump = SharePrefHelper.getBoolean(
ENABLE_SMART_RECOGNITION_JUMP, false
)
if (!enableSmartRecognitionJump) {
return true
}
val startTime = SharePrefHelper.getLong(SIGN_OPEN_INTENT_START_TIME, 0)
if (System.currentTimeMillis() - startTime > 5000) {
Log.i("CompleteProcessor", "不是由程序打开的,忽略")
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/layout/setting_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="6dp">

<Switch
android:id="@+id/smart_recognition_jump"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/smart_recognition_jump"
tools:ignore="UseSwitchCompatOrMaterialXml" />

<Button
android:id="@+id/setting_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/settings_save" />

</LinearLayout>
15 changes: 15 additions & 0 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />

<item
android:id="@+id/compatible_config"
android:orderInCategory="100"
android:title="@string/compatible_config"
app:showAsAction="never" />
</menu>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<string name="msg_yesno_def_message">你确定吗?</string>
<string name="acc_desc">打开开关,自动帮你打卡</string>
<string name="accessibility_service_description">该服务用于自动签到</string>
<string name="action_settings">设置</string>
<string name="compatible_config">兼容配置</string>
<string name="smart_recognition_jump">智能识别跳转(用于判断当前跳转是人为打开还是自动打开,来决定是否要自动操作,防止与人抢屏幕)</string>
<string name="settings_save">保存</string>
</resources>

0 comments on commit 40f27f1

Please sign in to comment.