├── .gitignore ├── .idea ├── .gitignore ├── compiler.xml ├── deploymentTargetSelector.xml ├── gradle.xml ├── kotlinc.xml ├── migrations.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── app ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── bhznjns │ │ └── autoswipper │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── bhznjns │ │ │ └── autoswipper │ │ │ ├── MainActivity.kt │ │ │ └── SwipeService.kt │ └── res │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ └── ic_launcher_foreground.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-anydpi │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── values-land │ │ └── dimens.xml │ │ ├── values-night │ │ └── themes.xml │ │ ├── values-v23 │ │ └── themes.xml │ │ ├── values-w1240dp │ │ └── dimens.xml │ │ ├── values-w600dp │ │ └── dimens.xml │ │ ├── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── themes.xml │ │ └── xml │ │ ├── accessibility_service_config.xml │ │ ├── backup_rules.xml │ │ └── data_extraction_rules.xml │ └── test │ └── java │ └── com │ └── bhznjns │ └── autoswipper │ └── ExampleUnitTest.kt ├── build.gradle.kts ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle.kts /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/deploymentTargetSelector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/migrations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | alias(libs.plugins.android.application) 3 | alias(libs.plugins.kotlin.android) 4 | } 5 | 6 | android { 7 | namespace = "com.bhznjns.autoswipper" 8 | compileSdk = 34 9 | 10 | defaultConfig { 11 | applicationId = "com.bhznjns.autoswipper" 12 | minSdk = 26 13 | targetSdk = 34 14 | versionCode = 1 15 | versionName = "1.0" 16 | 17 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | isMinifyEnabled = false 23 | proguardFiles( 24 | getDefaultProguardFile("proguard-android-optimize.txt"), 25 | "proguard-rules.pro" 26 | ) 27 | } 28 | } 29 | compileOptions { 30 | sourceCompatibility = JavaVersion.VERSION_11 31 | targetCompatibility = JavaVersion.VERSION_11 32 | } 33 | kotlinOptions { 34 | jvmTarget = "11" 35 | } 36 | buildFeatures { 37 | viewBinding = true 38 | } 39 | } 40 | 41 | dependencies { 42 | 43 | implementation(libs.androidx.core.ktx) 44 | implementation(libs.androidx.appcompat) 45 | implementation(libs.material) 46 | implementation(libs.androidx.constraintlayout) 47 | implementation(libs.androidx.navigation.fragment.ktx) 48 | implementation(libs.androidx.navigation.ui.ktx) 49 | testImplementation(libs.junit) 50 | androidTestImplementation(libs.androidx.junit) 51 | androidTestImplementation(libs.androidx.espresso.core) 52 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/com/bhznjns/autoswipper/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.bhznjns.autoswipper 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.bhznjns.autoswipper", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | 27 | 28 | 29 | 30 | 31 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/bhznjns/autoswipper/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.bhznjns.autoswipper 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import android.widget.Button 6 | import android.provider.Settings 7 | import android.widget.Toast 8 | import androidx.appcompat.app.AppCompatActivity 9 | 10 | class MainActivity : AppCompatActivity() { 11 | private lateinit var btnStartSwipe: Button 12 | private lateinit var btnStopSwipe: Button 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | setContentView(R.layout.activity_main) 17 | 18 | btnStartSwipe = findViewById(R.id.btn_start_swipe) 19 | btnStopSwipe = findViewById(R.id.btn_stop_swipe) 20 | 21 | btnStartSwipe.setOnClickListener { 22 | saveSwipeState(true) // 启用滑屏 23 | Toast.makeText(this, "滑屏功能已启动", Toast.LENGTH_SHORT).show() 24 | } 25 | 26 | btnStopSwipe.setOnClickListener { 27 | saveSwipeState(false) // 停止滑屏 28 | Toast.makeText(this, "滑屏功能已停止", Toast.LENGTH_SHORT).show() 29 | } 30 | 31 | if (!isAccessibilityServiceEnabled()) { 32 | startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)) 33 | } 34 | } 35 | 36 | private fun saveSwipeState(enabled: Boolean) { 37 | val sharedPrefs = getSharedPreferences("swipe_prefs", MODE_PRIVATE) 38 | sharedPrefs.edit().putBoolean("swipe_enabled", enabled).apply() 39 | } 40 | 41 | private fun isAccessibilityServiceEnabled(): Boolean { 42 | val service = "${packageName}/.MyAccessibilityService" 43 | val enabledServices = Settings.Secure.getString(contentResolver, Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES) 44 | return enabledServices?.contains(service) == true 45 | } 46 | } -------------------------------------------------------------------------------- /app/src/main/java/com/bhznjns/autoswipper/SwipeService.kt: -------------------------------------------------------------------------------- 1 | package com.bhznjns.autoswipper 2 | 3 | import android.accessibilityservice.AccessibilityService 4 | import android.accessibilityservice.GestureDescription 5 | import android.content.SharedPreferences 6 | import android.graphics.Path 7 | import android.os.Handler 8 | import android.os.Looper 9 | import android.util.Log 10 | 11 | import android.content.Context 12 | import android.graphics.Point 13 | import android.os.Build 14 | import android.view.WindowManager 15 | import kotlin.random.Random 16 | 17 | fun getScreenDimensions(context: Context): Point { 18 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { 19 | // API 30+ 使用 WindowMetrics 获取屏幕尺寸 20 | val metrics = context.resources.displayMetrics 21 | Point(metrics.widthPixels, metrics.heightPixels) 22 | } else { 23 | // API 29 及以下使用旧方法获取屏幕尺寸 24 | val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager 25 | val display = windowManager.defaultDisplay 26 | val point = Point() 27 | display.getRealSize(point) 28 | point 29 | } 30 | } 31 | class SwipeService : AccessibilityService() { 32 | private val handler = Handler(Looper.getMainLooper()) 33 | private var swipeTask: Runnable? = null 34 | private lateinit var sharedPrefs: SharedPreferences 35 | 36 | override fun onServiceConnected() { 37 | super.onServiceConnected() 38 | sharedPrefs = getSharedPreferences("swipe_prefs", MODE_PRIVATE) 39 | sharedPrefs.edit().putBoolean("swipe_enabled", false).apply() 40 | observeSwipeState() 41 | } 42 | 43 | override fun onAccessibilityEvent(event: android.view.accessibility.AccessibilityEvent?) { 44 | // 不需要处理事件 45 | } 46 | 47 | override fun onInterrupt() { 48 | stopAutoSwipe() 49 | } 50 | 51 | private fun observeSwipeState() { 52 | swipeTask = object : Runnable { 53 | override fun run() { 54 | val isSwipeEnabled = sharedPrefs.getBoolean("swipe_enabled", false) 55 | val randomDelay = Random.nextLong(4000, 9000) 56 | handler.postDelayed(this, randomDelay) 57 | if (isSwipeEnabled) { 58 | performSwipe() 59 | } 60 | } 61 | } 62 | handler.post(swipeTask!!) 63 | } 64 | 65 | private fun stopAutoSwipe() { 66 | swipeTask?.let { handler.removeCallbacks(it) } 67 | } 68 | 69 | private fun performSwipe() { 70 | Log.i("swipe", "Swiping started") 71 | val screenDimensions = getScreenDimensions(this) // 直接使用 this 72 | val screenWidth = screenDimensions.x 73 | val screenHeight = screenDimensions.y 74 | val centerX = (screenWidth / 2).toFloat() // 屏幕中央的 X 坐标 75 | val startY = (screenHeight * 0.7).toFloat() // 起点:屏幕高度的 70% 76 | val endY = (screenHeight * 0.3).toFloat() // 终点:屏幕高度的 30% 77 | val path = Path().apply { 78 | moveTo(centerX, startY) // 起点 79 | lineTo(centerX, endY) // 终点 80 | } 81 | 82 | val gestureBuilder = GestureDescription.Builder().apply { 83 | addStroke(GestureDescription.StrokeDescription(path, 0, 300)) 84 | } 85 | 86 | val result = dispatchGesture(gestureBuilder.build(), object : GestureResultCallback() { 87 | override fun onCompleted(gestureDescription: GestureDescription?) { 88 | super.onCompleted(gestureDescription) 89 | Log.d("swipe", "Swipe gesture completed") 90 | } 91 | 92 | override fun onCancelled(gestureDescription: GestureDescription?) { 93 | super.onCancelled(gestureDescription) 94 | Log.d("swipe", "Swipe gesture cancelled") 95 | } 96 | }, null) 97 | 98 | if (!result) { 99 | Log.d("swipe", "Gesture dispatch failed") 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 16 | 17 |