Skip to content

Commit

Permalink
Update auto send emoji funtion.
Browse files Browse the repository at this point in the history
  • Loading branch information
xbdcc committed Feb 9, 2021
1 parent 4ea68e6 commit 49d1fe5
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ https://github.com/xbdcc/CUtils
- 延迟时间说明:为防止秒抢拉仇恨加了延迟功能,延迟可以选择0-9秒。
- 自定义拆红包坐标点说明:自定义红包拆按钮的横纵坐标,解决部分Android7.0以上机型无法自动拆红包的问题。

最新版适配微信7.0.3,7.0.4,7.0.5,7.0.8,7.0.9,7.0.10,7.0.11,7.0.12,7.0.16版本,代码开源仅供学习使用,请勿用作商业用途。
最新版适配微信7.0.3,7.0.4,7.0.5,7.0.8,7.0.9,7.0.10,7.0.11,7.0.12,7.0.16,8.0.0,8.0.1版本,代码开源仅供学习使用,请勿用作商业用途。



Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ android {
applicationId "com.carlos.grabredenvelope"
minSdkVersion 18
targetSdkVersion 28
versionCode 13
versionCode 330
versionName "3.3.0"
flavorDimensions "13" //和versionCode相同
flavorDimensions "330" //和versionCode相同
ndk {
//选择要添加的对应 cpu 类型的 .so 库。
abiFilters 'armeabi-v7a', 'x86'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ open class MainActivity : BaseActivity() {
private val WECHAT_SERVICE_NAME = "com.carlos.grabredenvelope/.services.WechatService"

var fragments = mutableListOf<Fragment>(ControlFragment(), GuideFragment(), AboutFragment(),
CodeFragment(), RewardFragment(), RecordFragment(), RecordDingDIngFragment()
CodeFragment(), RewardFragment(), RecordFragment(), EmojiFragment()
)
var titles = mutableListOf("控制", "教程", "说明", "源码", "打赏", "微信", "钉钉")
var titles = mutableListOf("控制", "教程", "说明", "源码", "打赏", "微信", "表情")

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ object RedEnvelopePreferences :

private const val WECHAT_CONTROL = "wechat_control"
private const val USE_STATUS = "use_status"
private const val EMOJI_TEXT = "emoji_text"
private const val EMOJI_TIMES = "emoji_times"
private const val EMOJI_INTERVAL = "emoji_interval"

var wechatControl: WechatControlVO
get() {
Expand All @@ -72,6 +75,24 @@ object RedEnvelopePreferences :
set(value) {
setBoolean(USE_STATUS, value)
}

var autoText: String
get() = getString(EMOJI_TEXT, "[烟花]")
set(value) {
setString(EMOJI_TEXT, value)
}

var emojiTimes: Int
get() = getInt(EMOJI_TIMES, 0)
set(value) {
setInt(EMOJI_TIMES, value)
}

var emojiInterval: Int
get() = getInt(EMOJI_INTERVAL, 0)
set(value) {
setInt(EMOJI_INTERVAL, value)
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.carlos.grabredenvelope.fragment

import android.content.Intent
import android.os.Bundle
import android.provider.Settings
import android.view.View
import android.widget.Toast
import androidx.core.widget.doAfterTextChanged
import com.carlos.grabredenvelope.R
import com.carlos.grabredenvelope.data.RedEnvelopePreferences
import kotlinx.android.synthetic.main.fragment_emoji.*

/**
* _ooOoo_
* o8888888o
* 88" . "88
* (| -_- |)
* O\ = /O
* ____/`---'\____
* .' \\| |// `.
* / \\||| : |||// \
* / _||||| -:- |||||- \
* | | \\\ - /// | |
* | \_| ''\---/'' | |
* \ .-\__ `-` ___/-. /
* ___`. .' /--.--\ `. . __
* ."" '< `.___\_<|>_/___.' >'"".
* | | : `- \`.;`\ _ /`;.`/ - ` : | |
* \ \ `-. \_ __\ /__ _/ .-` / /
* ======`-.____`-.___\_____/___.-`____.-'======
* `=---='
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* 佛祖保佑 永无BUG
* 佛曰:
* 写字楼里写字间,写字间里程序员;
* 程序人员写程序,又拿程序换酒钱。
* 酒醒只在网上坐,酒醉还来网下眠;
* 酒醉酒醒日复日,网上网下年复年。
* 但愿老死电脑间,不愿鞠躬老板前;
* 奔驰宝马贵者趣,公交自行程序员。
* 别人笑我忒疯癫,我笑自己命太贱;
* 不见满街漂亮妹,哪个归得程序员?
*/

/**
* Created by Carlos on 2021/2/8.
*/
class EmojiFragment : BaseFragment(R.layout.fragment_emoji) {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
init()
}

private fun init() {
tv_control.setOnClickListener {
startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS))
Toast.makeText(view?.context, "辅助功能找到(抢微信红包)开启或关闭。", Toast.LENGTH_SHORT)
.show()
}

et_emoji.setText(RedEnvelopePreferences.autoText)
et_emoji.doAfterTextChanged {
RedEnvelopePreferences.autoText = et_emoji.text.toString()
}

np_times.minValue = 0
np_times.maxValue = 100
np_times.value = RedEnvelopePreferences.emojiTimes
np_times.setOnValueChangedListener { picker, oldVal, newVal ->
RedEnvelopePreferences.emojiTimes = newVal
}

np_interval.minValue = 0
np_interval.maxValue = 3000
np_interval.value = RedEnvelopePreferences.emojiInterval
np_interval.setOnValueChangedListener { picker, oldVal, newVal ->
RedEnvelopePreferences.emojiInterval = newVal
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,43 @@ import android.os.Bundle
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import android.widget.EditText
import com.carlos.cutils.util.LogUtils
import com.carlos.grabredenvelope.data.RedEnvelopePreferences
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
* _ooOoo_
* o8888888o
* 88" . "88
* (| -_- |)
* O\ = /O
* ____/`---'\____
* .' \\| |// `.
* / \\||| : |||// \
* / _||||| -:- |||||- \
* | | \\\ - /// | |
* | \_| ''\---/'' | |
* \ .-\__ `-` ___/-. /
* ___`. .' /--.--\ `. . __
* ."" '< `.___\_<|>_/___.' >'"".
* | | : `- \`.;`\ _ /`;.`/ - ` : | |
* \ \ `-. \_ __\ /__ _/ .-` / /
* ======`-.____`-.___\_____/___.-`____.-'======
* `=---='
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* 佛祖保佑 永无BUG
* 佛曰:
* 写字楼里写字间,写字间里程序员;
* 程序人员写程序,又拿程序换酒钱。
* 酒醒只在网上坐,酒醉还来网下眠;
* 酒醉酒醒日复日,网上网下年复年。
* 但愿老死电脑间,不愿鞠躬老板前;
* 奔驰宝马贵者趣,公交自行程序员。
* 别人笑我忒疯癫,我笑自己命太贱;
* 不见满街漂亮妹,哪个归得程序员?
*/

/**
* Created by Carlos on 2021/2/9.
Expand All @@ -12,19 +49,41 @@ class EmojiService : BaseAccessibilityService() {

private var windowClassName = ""
private val CHAT_ACTIVITY = "com.tencent.mm.ui.LauncherUI" //微信红包弹框
private var text = ""
private var times = 0
private var interval = 0
private var count = 0

override fun monitorContentChanged(event: AccessibilityEvent) {
}

override fun monitorWindowChanged(event: AccessibilityEvent) {
windowClassName = event.className.toString()
loadConfig()
sendMessage()
}

private fun loadConfig() {
text = RedEnvelopePreferences.autoText
times = RedEnvelopePreferences.emojiTimes
interval = RedEnvelopePreferences.emojiInterval
count = 0
LogUtils.d("text:$text")
LogUtils.d("times:$times")
LogUtils.d("interval:$interval")
LogUtils.d("count:$count")
}

/**
* 找到文本框输入表情,找到发送按钮点击循环执行
*/
private fun sendMessage() {
if (windowClassName != CHAT_ACTIVITY) return
if (count >= times && times != 0) {
return
}
LogUtils.d("count:$count")

val accessibilityNodeInfo =
rootInActiveWindow?.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/auj")
?: return
Expand All @@ -34,7 +93,7 @@ class EmojiService : BaseAccessibilityService() {
val arguments = Bundle()
arguments.putCharSequence(
AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE,
"[烟花]"
text
)
editText.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments)

Expand All @@ -45,7 +104,11 @@ class EmojiService : BaseAccessibilityService() {

}

sendMessage()
count++
GlobalScope.launch {
delay(interval.toLong())
sendMessage()
}

}

Expand Down
84 changes: 84 additions & 0 deletions app/src/main/res/layout/fragment_emoji.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">

<TextView
android:id="@+id/tv_control"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textSize="@dimen/text_size_small"
android:text="自动发表情插件(点击跳转开启)"
android:textColor="@color/blue_light"
android:gravity="center"
/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textSize="@dimen/text_size_small"
android:text="可快速自动发送烟花制造聊天对话页连续放烟花的效果,过年庆祝下,平时也可以快速丢炸弹玩。需先找到辅助功能【自动发送表情】开启才有效"
/>

<View
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
style="@style/view_line"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置发送文本,如表情[烟花]:"/>
<EditText
android:id="@+id/et_emoji"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="[炸弹]"
android:text="[烟花]"
android:singleLine="true"
/>

<View
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
style="@style/view_line"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置进入一次聊天页自动发送次数(0为无限):"/>
<NumberPicker
android:id="@+id/np_times"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

<View
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
style="@style/view_line"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置每次发送间隔时间(ms):"/>
<NumberPicker
android:id="@+id/np_interval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

</LinearLayout>

</ScrollView>
12 changes: 8 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
<string name="auto_send_emoji">自动发送表情</string>

<string name="how_to_use">
该版本适配微信7.0.3,7.0.4,7.0.5,7.0.8,7.0.9,7.0.10,7.0.11,7.0.12,7.0.16,其他版本未适配可能无效。长时间服务后台可能被杀,如果服务被杀需要关闭重新开启无障碍服务。
该版本适配微信7.0.3,7.0.4,7.0.5,7.0.8,7.0.9,7.0.10,7.0.11,7.0.12,7.0.16,8.0.0,8.0.1,其他版本未适配可能无效。长时间服务后台可能被杀,如果服务被杀需要关闭重新开启无障碍服务。
\n\n控制说明:
\n1.微信红包监控开关:点击进入设置找到无障碍服务辅助功能开启【抢微信红包】,开启后下面操作才有效;
\n2.通知监控开关:开启后通知收到微信红包则会自动点击该通知,若开启后无效请确认通知权限是否开启;
\n3.聊天列表页监控开关:开启后停留在首页聊天列表页时会监听,若收到红包会自动点击;
\n4.是否抢自己发的红包:开启则自己发的也会抢;
\n5.领红包延迟时间:设置时间后拆红包会停留设置的时间后点击;
\n6.红包领取页关闭时间:设置后在红包领取详情页面会停留设置的时间后关闭;
\n7.自定义拆红包按钮坐标:该功能针对Android7.0以上设备开放,为了解决之前版本出现的部分机型会自动点击红包但不会自动拆的问题,开启后才有效。
关于如何找红包坐标点的方法有很多种,简书上之前分享的文章《Android通过辅助功能实现抢微信红包原理简单介绍》,图3其实就可以看到坐标范围,
这里介绍手机上查看的两个方法,设置里开发者选项中的显示指针位置或显示布局边界,然后在红包弹窗手指触摸顶部可以看到x坐标和y坐标,使用比较简单详情可百度。
\n7.自定义拆红包按钮坐标:该功能针对Android7.0以上设备开放,为了解决之前版本出现的部分机型会自动点击红包但不会自动拆的问题,当能自动点击红包但不会自动点击拆按钮时可开启使用自定义拆按钮坐标点。
\n\n
\n代码开源仅供学习使用,请勿用作商业用途
<!-- \nAPP说明:http://xbdcc.cn/GrabRedEnvelope/index.html-->
Expand All @@ -33,6 +31,12 @@
\n\n如果有遇到说明里除已知bug外的问题, 欢迎通过 GitHub Issue 反馈:https://github.com/xbdcc/GrabRedEnvelope。
\n\n有问题也可联系偶尔会使用的微信:xbdcc1。
\n\n ——made by 小不点</string>
<string name="emoji_description">
使用指南:使用前仔细看APP使用说明。辅助功能开启【自动发送表情】,支持设置自动输入文本、发送次数、发送间隔时间。代码开源仅供学习使用,请勿用作商业用途。
\n\n如果有遇到说明里除已知bug外的问题, 欢迎通过 GitHub Issue 反馈:https://github.com/xbdcc/GrabRedEnvelope。
\n\n有问题也可联系偶尔会使用的微信:xbdcc1。
\n\n ——made by 小不点</string>

<string name="dingding_description">基于钉钉5.0.5版本开发,不做版本适配,只监听当前对话页面红包</string>


Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/emoji_service.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- android:packageNames="com.tencent.mm"在9.0中会无法监听通知内容,这里去掉在代码里判断。links:https://stackoverflow.com/questions/55472464/type-notification-state-changed-event-is-not-getting-received-by-accessibility-s -->
<accessibility-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/wechat_description"
android:description="@string/emoji_description"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFeedbackType="feedbackAllMask"
android:notificationTimeout="100"
Expand Down

0 comments on commit 49d1fe5

Please sign in to comment.