标签:exists 截图 安卓 toast fun com tle open screen
环境 安卓7.0或以上 网易公开课app
/**
* 关注用户
* @return bool true or false
*/
function followUser() {
waitForActivity("com.netease.vopen.feature.timeline.ui.UserTimelineActivity");
if (id('timeline_profile_care_btn').exists()) {
var text = id('timeline_profile_care_btn').findOnce().text();
if (text == "关注") {
id('timeline_profile_care_btn').click();
log('关注成功');
return true;
} else if (text == "已关注") {
log('已关注');
return true;
} else {
log('关注失败');
return false;
}
} else {
log("ERROR:未找到控件");
return false;
}
}
/**
* 获取用户性别
* @return str gender
*/
function getUserGender() {
if (!requestScreenCapture()) {
toast("请求截图失败");
exit();
}
waitForActivity("com.netease.vopen.feature.timeline.ui.UserTimelineActivity");
if (id('timeline_profile_gender').exists()) {
var rect = id('timeline_profile_gender').findOnce().bounds();
var img = captureScreen();
var point = findColor(img, -622207, {
region: [rect.left, rect.top, rect.width(), rect.height()],
threshold: 4
});
if (point) {
return "女";
} else {
var point = findColor(img, -7943189, {
region: [rect.left, rect.top, rect.width(), rect.height()],
threshold: 4
});
if (point) {
return "男";
}
};
} else {
return "未知";
}
}
/**
* 获取用户昵称
* @return str userName
*/
function getUserName() {
var userName = '';
//等待个人人资料页面出现
waitForActivity("com.netease.vopen.feature.timeline.ui.UserTimelineActivity");
if (id('mid_title').exists()) {
userName = id('mid_title').findOnce().text();
} else {
log('ERROR:未获取到用户昵称');
}
return userName;
}
标签:exists 截图 安卓 toast fun com tle open screen
原文地址:https://www.cnblogs.com/qinsilandiao/p/12128723.html