This commit is contained in:
lihongwei 2025-06-30 16:08:15 +08:00
parent 427f0b12c4
commit 4d7f9b8f39
17 changed files with 142 additions and 220 deletions

View File

@ -12,12 +12,5 @@ import java.util.List;
@Dao @Dao
public interface EventEntityDao { public interface EventEntityDao {
@Insert @Insert
long insertEventEntity(EventEntity eventEntity); // 返回新插入的 eventId long insertEventEntity(EventEntity eventEntity);
@Delete
int deleteEventEntity(EventEntity eventEntity);
// 查询某个方案下的所有事件实体按顺序排序
@Query("SELECT * FROM events WHERE solution_id = :solutionId ORDER BY order_in_solution ASC")
List<EventEntity> getEventsForSolution(long solutionId);
} }

View File

@ -20,26 +20,10 @@ public interface SolutionDao {
@Query("SELECT * FROM solutions") @Query("SELECT * FROM solutions")
List<Solution> getAllSolutions(); List<Solution> getAllSolutions();
@Query("SELECT * FROM solutions WHERE solutionId = :solutionId LIMIT 1")
Solution getSolutionById(long solutionId);
@Query("SELECT * FROM solutions WHERE solution_name = :solutionName LIMIT 1")
Solution getSolutionByName(String solutionName);
@Delete
int deleteSolution(Solution solution);
@Update
int updateSolution(Solution solution);
@Transaction @Transaction
@Query("SELECT * FROM solutions WHERE solutionId = :solutionId LIMIT 1") @Query("SELECT * FROM solutions WHERE solutionId = :solutionId LIMIT 1")
SolutionWithEventsAndPoints getSolutionWithEventsAndPoints(long solutionId); SolutionWithEventsAndPoints getSolutionWithEventsAndPoints(long solutionId);
@Transaction
@Query("SELECT * FROM solutions")
List<SolutionWithEventsAndPoints> getAllSolutionsWithEventsAndPoints();
@Query("UPDATE solutions SET solution_name = :newName WHERE solutionId = :solutionId") @Query("UPDATE solutions SET solution_name = :newName WHERE solutionId = :solutionId")
int updateSolutionName(long solutionId, String newName); int updateSolutionName(long solutionId, String newName);

View File

@ -11,14 +11,5 @@ import com.auto.clicker.autoclicker.room.entity.TouchPoint;
@Dao @Dao
public interface TouchPointDao { public interface TouchPointDao {
@Insert @Insert
long insertPoint(TouchPoint touchPoint); // 返回新插入的 pointId long insertPoint(TouchPoint touchPoint);
@Query("SELECT * FROM touchPoints WHERE pointId = :pointId LIMIT 1")
TouchPoint getPointById(long pointId);
@Delete
int deletePoint(TouchPoint touchPoint);
@Update
int updatePoint(TouchPoint touchPoint);
} }

View File

@ -61,7 +61,7 @@ public class EventRepository {
throw new RuntimeException("Failed to insert touch point for PointEvent."); throw new RuntimeException("Failed to insert touch point for PointEvent.");
EventEntity eventEntity = new EventEntity( EventEntity eventEntity = new EventEntity(
solutionId, // 使用 long 类型的 solutionId solutionId,
wrapper.getType().name(), wrapper.getType().name(),
order, order,
pointId, pointId,
@ -86,13 +86,13 @@ public class EventRepository {
throw new RuntimeException("Failed to insert end touch point for SlideEvent."); throw new RuntimeException("Failed to insert end touch point for SlideEvent.");
EventEntity eventEntity = new EventEntity( EventEntity eventEntity = new EventEntity(
solutionId, // 使用 long 类型的 solutionId solutionId,
wrapper.getType().name(), wrapper.getType().name(),
order, order,
null, null,
startPointId, startPointId,
endPointId, endPointId,
0 // duration for slide events, you might want to get this from SlideEvent 0
); );
eventEntityId = eventEntityDao.insertEventEntity(eventEntity); eventEntityId = eventEntityDao.insertEventEntity(eventEntity);
if (eventEntityId == -1) if (eventEntityId == -1)
@ -198,7 +198,7 @@ public class EventRepository {
} }
EventEntity newEventEntity = new EventEntity( EventEntity newEventEntity = new EventEntity(
newSolutionId, // 关联到新生成的方案ID newSolutionId,
eventWithPoints.eventEntity.eventType, eventWithPoints.eventEntity.eventType,
eventWithPoints.eventEntity.orderInSolution, eventWithPoints.eventEntity.orderInSolution,
newClickPointId, newClickPointId,
@ -235,7 +235,6 @@ public class EventRepository {
public void saveDuplicateSolution(SolutionWithEventsAndPoints originalData, RepositoryCallback<Void> callback) { public void saveDuplicateSolution(SolutionWithEventsAndPoints originalData, RepositoryCallback<Void> callback) {
databaseWriteExecutor.execute(() -> { databaseWriteExecutor.execute(() -> {
try { try {
// 创建新的 Solution 实例
Solution newSolution = new Solution(originalData.solution.solutionName + " (1)", originalData.solution.mode); Solution newSolution = new Solution(originalData.solution.solutionName + " (1)", originalData.solution.mode);
long newSolutionId = solutionDao.insertSolution(newSolution); long newSolutionId = solutionDao.insertSolution(newSolution);
@ -268,7 +267,6 @@ public class EventRepository {
throw new RuntimeException("Failed to duplicate slide end point."); throw new RuntimeException("Failed to duplicate slide end point.");
} }
// 创建新的 EventEntity 实例
EventEntity newEventEntity = new EventEntity( EventEntity newEventEntity = new EventEntity(
newSolutionId, newSolutionId,
eventWithPoints.eventEntity.eventType, eventWithPoints.eventEntity.eventType,

View File

@ -153,19 +153,18 @@ public class AutoClickService extends AccessibilityService {
isRunning = true; isRunning = true;
currentEventIndex = 0; currentEventIndex = 0;
currentLoop = 0; // 重置循环计数 currentLoop = 0;
startTimeMillis = System.currentTimeMillis(); // 记录开始时间 startTimeMillis = System.currentTimeMillis();
EventViewBinder.setAllTouchPointsDraggable(false); EventViewBinder.setAllTouchPointsDraggable(false);
// 根据循环设置调整日志输出
String loopInfo; String loopInfo;
if (loopCount > 0) { if (loopCount > 0) {
loopInfo = "循环 " + (loopCount == 1 ? "1 次" : loopCount + ""); loopInfo = "循环 " + (loopCount == 1 ? "1 次" : loopCount + "");
} else if (loopTimeMillis > 0) { } else if (loopTimeMillis > 0) {
loopInfo = "循环 " + (loopTimeMillis / 1000) + ""; loopInfo = "循环 " + (loopTimeMillis / 1000) + "";
} else { } else {
loopInfo = "无限循环"; // 如果两者都为0 loopInfo = "无限循环";
} }
logDebug("开始执行事件队列 - 共 " + runtimeEvents.size() + " 个事件. " + loopInfo); logDebug("开始执行事件队列 - 共 " + runtimeEvents.size() + " 个事件. " + loopInfo);
@ -266,7 +265,7 @@ public class AutoClickService extends AccessibilityService {
int finalClickY = correctedViewTopY + touchPointSize / 2; int finalClickY = correctedViewTopY + touchPointSize / 2;
Path path = new Path(); Path path = new Path();
path.moveTo(finalClickX, finalClickY); // 使用最终计算出的点击中心坐标 path.moveTo(finalClickX, finalClickY);
GestureDescription.StrokeDescription stroke = GestureDescription.StrokeDescription stroke =
new GestureDescription.StrokeDescription(path, 0, clickDuration); new GestureDescription.StrokeDescription(path, 0, clickDuration);
GestureDescription gesture = GestureDescription gesture =
@ -278,8 +277,7 @@ public class AutoClickService extends AccessibilityService {
logDebug("点击完成"); logDebug("点击完成");
if (isRunning) { if (isRunning) {
int feedbackIndex = currentEventIndex; int feedbackIndex = currentEventIndex;
currentEventIndex++; // 事件索引递增 currentEventIndex++;
// 延迟执行下一个事件循环逻辑在executeEventsByType中处理
handler.postDelayed(() -> executeEventsByType(), clickInterval); handler.postDelayed(() -> executeEventsByType(), clickInterval);
flashTouchFeedback(feedbackIndex); flashTouchFeedback(feedbackIndex);
} }
@ -289,8 +287,7 @@ public class AutoClickService extends AccessibilityService {
public void onCancelled(GestureDescription gestureDescription) { public void onCancelled(GestureDescription gestureDescription) {
Log.e(TAG, "点击被取消"); Log.e(TAG, "点击被取消");
if (isRunning) { if (isRunning) {
currentEventIndex++; // 事件索引递增 currentEventIndex++;
// 延迟执行下一个事件
handler.postDelayed(() -> executeEventsByType(), clickInterval + 300); handler.postDelayed(() -> executeEventsByType(), clickInterval + 300);
} }
} }
@ -324,7 +321,6 @@ public class AutoClickService extends AccessibilityService {
logDebug("滑动终点(修正后): (" + finalEndX + ", " + finalEndY + ")"); logDebug("滑动终点(修正后): (" + finalEndX + ", " + finalEndY + ")");
Path path = new Path(); Path path = new Path();
// 这里必须使用修正后的坐标才能确保手势在正确的位置执行
path.moveTo(finalStartX, finalStartY); path.moveTo(finalStartX, finalStartY);
path.lineTo(finalEndX, finalEndY); path.lineTo(finalEndX, finalEndY);
@ -339,8 +335,7 @@ public class AutoClickService extends AccessibilityService {
logDebug("滑动完成"); logDebug("滑动完成");
if (isRunning) { if (isRunning) {
int feedbackIndex = currentEventIndex; int feedbackIndex = currentEventIndex;
currentEventIndex++; // 事件索引递增 currentEventIndex++;
// 延迟执行下一个事件
handler.postDelayed(() -> executeEventsByType(), clickInterval); handler.postDelayed(() -> executeEventsByType(), clickInterval);
flashTouchFeedback(feedbackIndex); flashTouchFeedback(feedbackIndex);
} }
@ -353,8 +348,7 @@ public class AutoClickService extends AccessibilityService {
public void onCancelled(GestureDescription gestureDescription) { public void onCancelled(GestureDescription gestureDescription) {
Log.e(TAG, "滑动被取消"); Log.e(TAG, "滑动被取消");
if (isRunning) { if (isRunning) {
currentEventIndex++; // 事件索引递增 currentEventIndex++;
// 延迟执行下一个事件
handler.postDelayed(() -> executeEventsByType(), clickInterval + 300); handler.postDelayed(() -> executeEventsByType(), clickInterval + 300);
} }
logDebug("--- onCancelled: 下一个事件将是 index " + currentEventIndex + " ---"); logDebug("--- onCancelled: 下一个事件将是 index " + currentEventIndex + " ---");

View File

@ -44,6 +44,8 @@ public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding; private ActivityMainBinding binding;
private boolean isPermissionFlowActive = false;
public static final int FLOATING_NONE = 0; public static final int FLOATING_NONE = 0;
public static final int FLOATING_SINGLE = 1; public static final int FLOATING_SINGLE = 1;
public static final int FLOATING_MULTI = 2; public static final int FLOATING_MULTI = 2;
@ -66,10 +68,6 @@ public class MainActivity extends AppCompatActivity {
isFloatingShown = intent.getIntExtra("isShown", FLOATING_NONE); isFloatingShown = intent.getIntExtra("isShown", FLOATING_NONE);
logDebug("接收到浮窗状态广播: isShown = " + isFloatingShown); logDebug("接收到浮窗状态广播: isShown = " + isFloatingShown);
if (isFloatingShown == FLOATING_NONE) {
} else {
selectedFloatingMode = isFloatingShown;
}
updateSelectionButtons(); updateSelectionButtons();
} }
}; };
@ -95,9 +93,19 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
logDebug("onResume: 检查权限和同步服务状态"); logDebug("onResume: 同步服务状态并更新启动按钮状态");
checkPermissions();
syncServiceState(); syncServiceState();
updateStartButtonState();
if (isPermissionFlowActive) {
binding.getRoot().postDelayed(this::checkAllPermissionsAndRequestInSequence, 300);
}
}
private void updateStartButtonState() {
boolean accessibilityGranted = isAccessibilityServiceEnabled();
boolean overlayGranted = Settings.canDrawOverlays(this);
boolean batteryOptimizationIgnored = isIgnoringBatteryOptimizations();
setStartButtonEnabled(accessibilityGranted && overlayGranted && batteryOptimizationIgnored);
} }
private void initData() { private void initData() {
@ -116,10 +124,7 @@ public class MainActivity extends AppCompatActivity {
permissionLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> { permissionLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
logDebug("权限回调结果: " + result.getResultCode()); logDebug("权限回调结果: " + result.getResultCode());
binding.getRoot().postDelayed(() -> { binding.getRoot().postDelayed(this::checkAllPermissionsAndRequestInSequence, 300);
checkPermissions();
syncServiceState();
}, 300);
}); });
setVideo(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.bolangblue)); setVideo(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.bolangblue));
@ -141,7 +146,12 @@ public class MainActivity extends AppCompatActivity {
startActivity(intent); startActivity(intent);
}); });
binding.animatedView.setOnClickListener(v -> onToggleFloatingWindowClicked()); binding.animatedView.setOnClickListener(v -> {
if (checkAllPermissionsAndRequestInSequence()) {
isPermissionFlowActive = false;
onToggleFloatingWindowClicked();
}
});
binding.single.setOnClickListener(v -> { binding.single.setOnClickListener(v -> {
if (isFloatingShown != FLOATING_NONE) { if (isFloatingShown != FLOATING_NONE) {
@ -155,7 +165,7 @@ public class MainActivity extends AppCompatActivity {
binding.multi.setOnClickListener(v -> { binding.multi.setOnClickListener(v -> {
if (isFloatingShown != FLOATING_NONE) { if (isFloatingShown != FLOATING_NONE) {
Toast.makeText(this, "请先关闭悬浮窗再切换模式", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Please close the floating window first and then switch the mode", Toast.LENGTH_SHORT).show();
return; return;
} }
selectedFloatingMode = FLOATING_MULTI; selectedFloatingMode = FLOATING_MULTI;
@ -166,11 +176,47 @@ public class MainActivity extends AppCompatActivity {
handleIncomingIntent(getIntent()); handleIncomingIntent(getIntent());
} }
private boolean checkAllPermissionsAndRequestInSequence() {
boolean accessibilityGranted = isAccessibilityServiceEnabled();
boolean overlayGranted = Settings.canDrawOverlays(this);
boolean batteryOptimizationIgnored = isIgnoringBatteryOptimizations();
logDebug("检查权限 (序列流程): 无障碍服务=" + accessibilityGranted + ", 悬浮窗=" + overlayGranted + ", 电池优化=" + batteryOptimizationIgnored);
if (!accessibilityGranted) {
logDebug("无障碍服务未启用,请求权限");
showPermissionRequest(Settings.ACTION_ACCESSIBILITY_SETTINGS, "Please enable accessibility services to ensure the application works properly", "Accessibility Settings cannot be enabled");
setStartButtonEnabled(false);
return false;
}
if (!overlayGranted) {
logDebug("悬浮窗权限未授予,请求权限");
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
showPermissionRequest(intent, "Please grant the floating window permission; otherwise, the floating window cannot be displayed", "The floating window setting cannot be opened");
setStartButtonEnabled(false);
return false;
}
if (!batteryOptimizationIgnored) {
logDebug("电池优化未忽略,请求权限");
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + getPackageName()));
showPermissionRequest(intent, "Please disable battery optimization to ensure the stable operation of the application in the background", "The battery optimization Settings cannot be opened");
setStartButtonEnabled(false);
return false;
}
logDebug("所有权限均已授予");
setStartButtonEnabled(true);
isPermissionFlowActive = false;
return true;
}
@Override @Override
protected void onNewIntent(@NonNull Intent intent) { protected void onNewIntent(@NonNull Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
// 如果 MainActivity 已经在运行并且再次通过 Intent 启动会调用 onNewIntent setIntent(intent);
setIntent(intent); // 更新当前的 Intent
handleIncomingIntent(intent); handleIncomingIntent(intent);
} }
@ -197,7 +243,7 @@ public class MainActivity extends AppCompatActivity {
if (!accessibilityGranted) { if (!accessibilityGranted) {
logDebug("无障碍服务未启用,请求权限"); logDebug("无障碍服务未启用,请求权限");
showPermissionRequest(Settings.ACTION_ACCESSIBILITY_SETTINGS, "请启用无障碍服务以便应用正常工作", "无法打开无障碍设置"); showPermissionRequest(Settings.ACTION_ACCESSIBILITY_SETTINGS, "Please enable accessibility services to ensure the application works properly", "Accessibility Settings cannot be enabled");
setStartButtonEnabled(false); setStartButtonEnabled(false);
return; return;
@ -206,7 +252,7 @@ public class MainActivity extends AppCompatActivity {
if (!overlayGranted) { if (!overlayGranted) {
logDebug("悬浮窗权限未授予,请求权限"); logDebug("悬浮窗权限未授予,请求权限");
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
showPermissionRequest(intent, "请授予悬浮窗权限,否则无法显示浮窗", "无法打开悬浮窗设置"); showPermissionRequest(intent, "Please grant the floating window permission; otherwise, the floating window cannot be displayed", "The floating window setting cannot be opened");
setStartButtonEnabled(false); setStartButtonEnabled(false);
return; return;
@ -216,7 +262,7 @@ public class MainActivity extends AppCompatActivity {
logDebug("电池优化未忽略,请求权限"); logDebug("电池优化未忽略,请求权限");
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + getPackageName())); intent.setData(Uri.parse("package:" + getPackageName()));
showPermissionRequest(intent, "请禁用电池优化,以确保应用在后台稳定运行", "无法打开电池优化设置"); showPermissionRequest(intent, "Please disable battery optimization to ensure the stable operation of the application in the background", "The battery optimization Settings cannot be opened");
setStartButtonEnabled(false); setStartButtonEnabled(false);
return; return;
@ -424,9 +470,9 @@ public class MainActivity extends AppCompatActivity {
private void showDebounceToast() { private void showDebounceToast() {
if (debounceToast == null) { if (debounceToast == null) {
debounceToast = Toast.makeText(this, "点击太频繁", Toast.LENGTH_SHORT); debounceToast = Toast.makeText(this, "Click too frequently", Toast.LENGTH_SHORT);
} else { } else {
debounceToast.setText("点击太频繁"); debounceToast.setText("Click too frequently");
} }
debounceToast.show(); debounceToast.show();
} }

View File

@ -155,13 +155,13 @@ public class ScriptsActivity extends AppCompatActivity implements SolutionAdapte
private void showRenameDialog(final Solution solution) { private void showRenameDialog(final Solution solution) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("重命名方案"); builder.setTitle("Renaming script");
final EditText input = new EditText(this); final EditText input = new EditText(this);
input.setText(solution.getSolutionName()); input.setText(solution.getSolutionName());
builder.setView(input); builder.setView(input);
builder.setPositiveButton("确定", (dialog, which) -> { builder.setPositiveButton("Sure", (dialog, which) -> {
String newName = input.getText().toString().trim(); String newName = input.getText().toString().trim();
if (!newName.isEmpty() && !newName.equals(solution.getSolutionName())) { if (!newName.isEmpty() && !newName.equals(solution.getSolutionName())) {
floatingViewManager.getEventRepository().updateSolutionName(solution.getSolutionId(), newName, new EventRepository.RepositoryCallback<Void>() { floatingViewManager.getEventRepository().updateSolutionName(solution.getSolutionId(), newName, new EventRepository.RepositoryCallback<Void>() {
@ -181,7 +181,7 @@ public class ScriptsActivity extends AppCompatActivity implements SolutionAdapte
}); });
} }
}); });
builder.setNegativeButton("取消", (dialog, which) -> dialog.cancel()); builder.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel());
builder.show(); builder.show();
} }
@ -220,10 +220,10 @@ public class ScriptsActivity extends AppCompatActivity implements SolutionAdapte
private void showDeleteConfirmationDialog(final Solution solution) { private void showDeleteConfirmationDialog(final Solution solution) {
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setTitle("删除方案") .setTitle("Delete the script")
.setMessage("确定要删除方案 '" + solution.getSolutionName() + "' 吗?\n此操作不可撤销") .setMessage("Are you sure you want to delete the script '" + solution.getSolutionName() + "'?\nThis action cannot be undone!")
.setPositiveButton("删除", (dialog, which) -> deleteSolution(solution)) .setPositiveButton("Delete", (dialog, which) -> deleteSolution(solution))
.setNegativeButton("取消", null) .setNegativeButton("Cancel", null)
.show(); .show();
} }
@ -300,12 +300,11 @@ public class ScriptsActivity extends AppCompatActivity implements SolutionAdapte
SolutionWithEventsAndPoints importedData = floatingViewManager.getEventRepository().importSolutionFromJson(jsonString); SolutionWithEventsAndPoints importedData = floatingViewManager.getEventRepository().importSolutionFromJson(jsonString);
if (importedData != null && importedData.solution != null) { if (importedData != null && importedData.solution != null) {
// 保存到数据库
floatingViewManager.getEventRepository().importSolutionFromData(importedData, new EventRepository.RepositoryCallback<Void>() { floatingViewManager.getEventRepository().importSolutionFromData(importedData, new EventRepository.RepositoryCallback<Void>() {
@Override @Override
public void onComplete(Void result) { public void onComplete(Void result) {
new Handler(Looper.getMainLooper()).post(() -> { new Handler(Looper.getMainLooper()).post(() -> {
loadSolutions(); // 刷新列表 loadSolutions();
}); });
} }

View File

@ -23,7 +23,6 @@ public class SolutionAdapter extends RecyclerView.Adapter<SolutionAdapter.Soluti
private OnSolutionClickListener listener; private OnSolutionClickListener listener;
private OnOptionMenuClickListener optionMenuListener; private OnOptionMenuClickListener optionMenuListener;
// 新增接口定义
public interface OnOptionMenuClickListener { public interface OnOptionMenuClickListener {
void onRenameClick(Solution solution); void onRenameClick(Solution solution);
@ -44,11 +43,10 @@ public class SolutionAdapter extends RecyclerView.Adapter<SolutionAdapter.Soluti
this.optionMenuListener = optionMenuListener; this.optionMenuListener = optionMenuListener;
} }
// 新增构造函数用于不需要选项菜单的情况
public SolutionAdapter(List<Solution> solutionList, OnSolutionClickListener listener) { public SolutionAdapter(List<Solution> solutionList, OnSolutionClickListener listener) {
this.solutionList = solutionList; this.solutionList = solutionList;
this.listener = listener; this.listener = listener;
this.optionMenuListener = null; // 设置为 null表示不需要选项菜单 this.optionMenuListener = null;
} }
@NonNull @NonNull
@ -56,7 +54,7 @@ public class SolutionAdapter extends RecyclerView.Adapter<SolutionAdapter.Soluti
public SolutionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { public SolutionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()) View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_solution, parent, false); .inflate(R.layout.item_solution, parent, false);
return new SolutionViewHolder(view, parent.getContext()); // 传递 Context return new SolutionViewHolder(view, parent.getContext());
} }
@Override @Override
@ -103,7 +101,7 @@ public class SolutionAdapter extends RecyclerView.Adapter<SolutionAdapter.Soluti
TextView mode; TextView mode;
ImageView play; ImageView play;
ImageView option; ImageView option;
Context context; // 保存 Context Context context;
SolutionViewHolder(View itemView, Context context) { SolutionViewHolder(View itemView, Context context) {
super(itemView); super(itemView);

View File

@ -57,7 +57,7 @@ public class ActionFragment extends Fragment {
saveSettingsButton = binding.save; saveSettingsButton = binding.save;
saveSettingsButton.setOnClickListener(v -> { saveSettingsButton.setOnClickListener(v -> {
applySettingsToService(); applySettingsToService();
Toast.makeText(getContext(), "设置已保存并应用", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "The Settings have been saved and applied", Toast.LENGTH_SHORT).show();
}); });
return binding.getRoot(); return binding.getRoot();
@ -113,9 +113,9 @@ public class ActionFragment extends Fragment {
binding.advancedSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { binding.advancedSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) { if (isChecked) {
Toast.makeText(getContext(), "防检测模式已开启", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "The anti-detection mode has been enabled", Toast.LENGTH_SHORT).show();
} else { } else {
Toast.makeText(getContext(), "防检测模式已关闭", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "The anti-detection mode has been turned off", Toast.LENGTH_SHORT).show();
} }
}); });
} }
@ -246,11 +246,11 @@ public class ActionFragment extends Fragment {
private void showInputValue(int type, String value, String unitText) { private void showInputValue(int type, String value, String unitText) {
String typeName = ""; String typeName = "";
switch (type) { switch (type) {
case TYPE_INTERVAL: typeName = "点击间隔"; break; case TYPE_INTERVAL: typeName = "Click interval"; break;
case TYPE_SWIPE_DURATION: typeName = "滑动时长"; break; case TYPE_SWIPE_DURATION: typeName = "Sliding duration"; break;
case TYPE_REPEAT: typeName = "循环模式"; break; case TYPE_REPEAT: typeName = "Circular mode"; break;
} }
String message = typeName + " : " + (value.isEmpty() ? "未输入" : value) + ", 单位: " + unitText; String message = typeName + " Value: " + (value.isEmpty() ? "Not entered" : value) + ", Unit: " + unitText;
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
} }
@ -293,7 +293,7 @@ public class ActionFragment extends Fragment {
AutoClickService service = AutoClickService.getInstance(); AutoClickService service = AutoClickService.getInstance();
if (service == null) { if (service == null) {
Toast.makeText(getContext(), "自动点击服务未运行,无法应用设置。", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "The auto-click service is not running and the Settings cannot be applied.", Toast.LENGTH_SHORT).show();
Log.e(TAG, "AutoClickService 实例为空,无法应用设置。"); Log.e(TAG, "AutoClickService 实例为空,无法应用设置。");
return; return;
} }
@ -311,7 +311,7 @@ public class ActionFragment extends Fragment {
Log.d(TAG, "应用点击间隔到服务: " + intervalValue + "ms"); Log.d(TAG, "应用点击间隔到服务: " + intervalValue + "ms");
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e(TAG, "点击间隔值解析错误: " + currentIntervalValue, e); Log.e(TAG, "点击间隔值解析错误: " + currentIntervalValue, e);
Toast.makeText(getContext(), "点击间隔值无效,请输入有效数字。", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "The click interval value is invalid. Please enter a significant number.", Toast.LENGTH_SHORT).show();
} }
} else { } else {
Log.d(TAG, "点击间隔值为空,未应用到服务。"); Log.d(TAG, "点击间隔值为空,未应用到服务。");
@ -328,7 +328,7 @@ public class ActionFragment extends Fragment {
Log.d(TAG, "应用滑动时长到服务: " + slideDurationValue + "ms"); Log.d(TAG, "应用滑动时长到服务: " + slideDurationValue + "ms");
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e(TAG, "滑动时长值解析错误: " + currentDurationValue, e); Log.e(TAG, "滑动时长值解析错误: " + currentDurationValue, e);
Toast.makeText(getContext(), "滑动时长值无效,请输入有效数字。", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "The sliding duration value is invalid. Please enter a significant number.", Toast.LENGTH_SHORT).show();
} }
} else { } else {
Log.d(TAG, "滑动时长值为空,未应用到服务。"); Log.d(TAG, "滑动时长值为空,未应用到服务。");
@ -347,7 +347,7 @@ public class ActionFragment extends Fragment {
Log.d(TAG, "应用重复时长: " + repeatDurationMillis + "ms。"); Log.d(TAG, "应用重复时长: " + repeatDurationMillis + "ms。");
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e(TAG, "重复时长值解析错误: " + currentRepeatValue, e); Log.e(TAG, "重复时长值解析错误: " + currentRepeatValue, e);
Toast.makeText(getContext(), "重复时长值无效,请输入有效数字或正确的时间格式。", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Repeated duration values are invalid. Please enter significant figures or the correct time format.", Toast.LENGTH_SHORT).show();
service.setLoopTime(0); service.setLoopTime(0);
} }
} else { } else {
@ -364,7 +364,7 @@ public class ActionFragment extends Fragment {
Log.d(TAG, "应用重复次数: " + repeatCount + "次。"); Log.d(TAG, "应用重复次数: " + repeatCount + "次。");
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e(TAG, "重复次数值解析错误: " + currentRepeatValue, e); Log.e(TAG, "重复次数值解析错误: " + currentRepeatValue, e);
Toast.makeText(getContext(), "重复次数值无效,请输入有效数字。", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Duplicate values are invalid. Please enter significant figures.", Toast.LENGTH_SHORT).show();
service.setLoopCount(1); service.setLoopCount(1);
} }
} else { } else {

View File

@ -41,7 +41,7 @@ public class UISizeFragment extends Fragment {
setupPointSizeControl(); setupPointSizeControl();
setupControlBarSizeControl(); setupControlBarSizeControl();
} else { } else {
Toast.makeText(getContext(), "自动化服务未运行UI大小设置功能不可用。", Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), "The automated service is not running and the UI size setting function is unavailable.", Toast.LENGTH_LONG).show();
disableAllControlUI(); disableAllControlUI();
} }
@ -74,7 +74,7 @@ public class UISizeFragment extends Fragment {
int finalSize = seekBar.getProgress() + MIN_POINT_SIZE; int finalSize = seekBar.getProgress() + MIN_POINT_SIZE;
floatingViewManager.setTouchPointSize(finalSize); floatingViewManager.setTouchPointSize(finalSize);
Log.d(TAG, "触摸点大小设置为: " + finalSize + "px"); Log.d(TAG, "触摸点大小设置为: " + finalSize + "px");
Toast.makeText(getContext(), "触摸点大小已更新", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "The size of the touch points has been updated", Toast.LENGTH_SHORT).show();
} }
}); });
} }
@ -109,7 +109,7 @@ public class UISizeFragment extends Fragment {
int finalWidthPx = seekBar.getProgress() + minControlBarWidthPx; int finalWidthPx = seekBar.getProgress() + minControlBarWidthPx;
floatingViewManager.setControlBarSize(finalWidthPx); floatingViewManager.setControlBarSize(finalWidthPx);
Log.d(TAG, "控制栏大小设置为: " + pxToDp(finalWidthPx) + "dp (" + finalWidthPx + "px)"); Log.d(TAG, "控制栏大小设置为: " + pxToDp(finalWidthPx) + "dp (" + finalWidthPx + "px)");
Toast.makeText(getContext(), "控制栏大小已更新", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "The size of the control bar has been updated", Toast.LENGTH_SHORT).show();
} }
}); });
} }

View File

@ -1,61 +1,8 @@
package com.auto.clicker.autoclicker.util; package com.auto.clicker.autoclicker.util;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
public class DraggableHelper { public class DraggableHelper {
public interface DragCallback { public interface DragCallback {
void onPositionChanged(int x, int y); void onPositionChanged(int x, int y);
} }
public static void makeDraggable(View view,
WindowManager.LayoutParams params,
WindowManager windowManager,
int screenWidth, int screenHeight,
DragCallback callback) {
view.setOnTouchListener(new View.OnTouchListener() {
private float lastX, lastY;
private float paramX, paramY;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
lastX = event.getRawX();
lastY = event.getRawY();
paramX = params.x;
paramY = params.y;
return true;
case MotionEvent.ACTION_MOVE:
float dx = event.getRawX() - lastX;
float dy = event.getRawY() - lastY;
int newX = (int) (paramX + dx);
int newY = (int) (paramY + dy);
newX = Math.max(0, Math.min(newX, screenWidth - view.getWidth()));
newY = Math.max(0, Math.min(newY, screenHeight - view.getHeight()));
params.x = newX;
params.y = newY;
windowManager.updateViewLayout(view, params);
if (callback != null) {
callback.onPositionChanged(newX, newY);
}
return true;
case MotionEvent.ACTION_UP:
v.performClick();
return true;
}
return false;
}
});
}
} }

View File

@ -103,7 +103,6 @@ public class EventViewBinder {
startView.setOnTouchListener(startTouchListener); startView.setOnTouchListener(startTouchListener);
activeDragListeners.put(startView, startTouchListener); // 保存监听器 activeDragListeners.put(startView, startTouchListener); // 保存监听器
// 拖动终点 - 创建并保存监听器
View.OnTouchListener endTouchListener = createTouchListener( View.OnTouchListener endTouchListener = createTouchListener(
endView, endParams, windowManager, screenWidth, screenHeight, endView, endParams, windowManager, screenWidth, screenHeight,
(x, y) -> { (x, y) -> {
@ -113,7 +112,7 @@ public class EventViewBinder {
if (callback != null) callback.onPositionChanged(x, y); if (callback != null) callback.onPositionChanged(x, y);
}); });
endView.setOnTouchListener(endTouchListener); endView.setOnTouchListener(endTouchListener);
activeDragListeners.put(endView, endTouchListener); // 保存监听器 activeDragListeners.put(endView, endTouchListener);
windowManager.addView(lineView, lineParams); windowManager.addView(lineView, lineParams);
windowManager.addView(startView, startParams); windowManager.addView(startView, startParams);

View File

@ -15,28 +15,20 @@ import com.auto.clicker.autoclicker.R;
public class ConnectingLineView extends View { public class ConnectingLineView extends View {
// 画笔用于绘制连接带设置为填充样式
private final Paint connectionBandPaint; private final Paint connectionBandPaint;
// 连接带的宽度单位 dp
private final float CONNECTION_BAND_WIDTH_DP = 30f; private final float CONNECTION_BAND_WIDTH_DP = 30f;
// 连接带在屏幕上的实际像素宽度
private float connectionBandWidthPx; private float connectionBandWidthPx;
// 绘制时连接带的逻辑起始点和结束点 View 自身的坐标系中
private float drawStartX, drawStartY, drawEndX, drawEndY; private float drawStartX, drawStartY, drawEndX, drawEndY;
// 连接带的长度
private float lineLength; private float lineLength;
// 连接带的旋转角度以度为单位
private float rotationAngle; private float rotationAngle;
// 用于表示方向的 Drawable 图标
private Drawable startArrowDrawable; private Drawable startArrowDrawable;
private Drawable endArrowDrawable; private Drawable endArrowDrawable;
public ConnectingLineView(Context context) { public ConnectingLineView(Context context) {
super(context); super(context);
// dp 单位的宽度转换为像素单位以便在 Canvas 上绘制
connectionBandWidthPx = dpToPx(context, CONNECTION_BAND_WIDTH_DP); connectionBandWidthPx = dpToPx(context, CONNECTION_BAND_WIDTH_DP);
connectionBandPaint = new Paint(); connectionBandPaint = new Paint();
@ -56,16 +48,11 @@ public class ConnectingLineView extends View {
public void setPoints(float startX, float startY, float endX, float endY) { public void setPoints(float startX, float startY, float endX, float endY) {
// 计算两点间的X和Y坐标差
float deltaX = endX - startX; float deltaX = endX - startX;
float deltaY = endY - startY; float deltaY = endY - startY;
// 计算连接带的长度两点间的直线距离
this.lineLength = (float) Math.sqrt(deltaX * deltaX + deltaY * deltaY); this.lineLength = (float) Math.sqrt(deltaX * deltaX + deltaY * deltaY);
// 计算连接带的旋转角度
// Math.atan2(y, x) 返回的是从X轴正向到点(x,y)的弧度范围是-PI到PI
// Math.toDegrees 将弧度转换为度数
this.rotationAngle = (float) Math.toDegrees(Math.atan2(deltaY, deltaX)); this.rotationAngle = (float) Math.toDegrees(Math.atan2(deltaY, deltaX));
this.drawStartX = startX; this.drawStartX = startX;
@ -85,34 +72,21 @@ public class ConnectingLineView extends View {
} }
// 保存当前画布的状态 // 保存当前画布的状态
// 这允许我们对画布进行平移和旋转操作而不会影响后续或外部的绘制
canvas.save(); canvas.save();
// 1. 平移画布到连接带的起始点
// 这样在绘制时连接带的逻辑起始点就变成了 (0,0)
canvas.translate(drawStartX, drawStartY); canvas.translate(drawStartX, drawStartY);
// 2. 旋转画布
// 围绕当前的画布原点即连接带的起始点旋转画布
// 之后绘制的所有内容都会以这个角度显示
canvas.rotate(rotationAngle); canvas.rotate(rotationAngle);
// 3. 绘制连接带的矩形
// RectF 定义了一个矩形由于画布已经旋转和平移
// 这里的 (0, -connectionBandWidthPx / 2) 是矩形的左上角
// (lineLength, connectionBandWidthPx / 2) 是矩形的右下角
// 这样矩形就会以当前 Y 轴为中心从当前 X 轴原点0延伸到 lineLength
RectF rect = new RectF(0, -connectionBandWidthPx / 2, lineLength, connectionBandWidthPx / 2); RectF rect = new RectF(0, -connectionBandWidthPx / 2, lineLength, connectionBandWidthPx / 2);
canvas.drawRect(rect, connectionBandPaint); canvas.drawRect(rect, connectionBandPaint);
// 4. 绘制起始方向图标
if (startArrowDrawable != null) { if (startArrowDrawable != null) {
int arrowSize = (int) (connectionBandWidthPx / 2); int arrowSize = (int) (connectionBandWidthPx / 2);
// 设置图标的边界这里的坐标是相对于当前已旋转和平移的画布
// 确保图标垂直居中于连接带
startArrowDrawable.setBounds( startArrowDrawable.setBounds(
75, 75,
(int) (-arrowSize / 2),// 垂直居中 (int) (-arrowSize / 2),
75 + arrowSize, 75 + arrowSize,
(int) (arrowSize / 2) (int) (arrowSize / 2)
); );

View File

@ -114,7 +114,7 @@ public class FloatingSettingDialogManager {
saveCurrentSettings(); saveCurrentSettings();
applySettingsToService(); applySettingsToService();
removeFloatingTabDialog(); removeFloatingTabDialog();
showToastOnUi(context, "设置已保存"); showToastOnUi(context, "The Settings have been saved.");
}); });
} else { } else {
Log.e(TAG, "Save button not found!"); Log.e(TAG, "Save button not found!");
@ -123,7 +123,7 @@ public class FloatingSettingDialogManager {
if (closeButton != null) { if (closeButton != null) {
closeButton.setOnClickListener(v -> { closeButton.setOnClickListener(v -> {
removeFloatingTabDialog(); removeFloatingTabDialog();
showToastOnUi(context, "设置已关闭,未保存更改"); showToastOnUi(context, "The Settings have been turned off and no changes have been saved");
}); });
} else { } else {
Log.e(TAG, "Close button not found!"); Log.e(TAG, "Close button not found!");
@ -134,10 +134,10 @@ public class FloatingSettingDialogManager {
Log.d(TAG, "浮动标签页弹窗已显示"); Log.d(TAG, "浮动标签页弹窗已显示");
} catch (WindowManager.BadTokenException e) { } catch (WindowManager.BadTokenException e) {
Log.e(TAG, "无法添加浮动标签页弹窗,可能是权限问题或上下文无效", e); Log.e(TAG, "无法添加浮动标签页弹窗,可能是权限问题或上下文无效", e);
showToastOnUi(context, "显示弹窗失败,请检查权限"); showToastOnUi(context, "The pop-up window failed to display. Please check the permissions");
} catch (SecurityException e) { } catch (SecurityException e) {
Log.e(TAG, "需要悬浮窗权限才能显示浮动弹窗", e); Log.e(TAG, "需要悬浮窗权限才能显示浮动弹窗", e);
showToastOnUi(context, "请授予悬浮窗权限以便显示"); showToastOnUi(context, "Please grant the floating window permission for display");
} }
} }
@ -320,7 +320,7 @@ public class FloatingSettingDialogManager {
String unitText = context.getString(R.string.duration_unit); String unitText = context.getString(R.string.duration_unit);
repeatSelectedUnit.setText(unitText); repeatSelectedUnit.setText(unitText);
currentRepeatUnit = unitText; currentRepeatUnit = unitText;
etRepeatValue.setText(""); // 清空以便用户输入新值 etRepeatValue.setText("");
etRepeatValue.setEnabled(true); etRepeatValue.setEnabled(true);
etRepeatValue.setInputType(InputType.TYPE_CLASS_NUMBER); etRepeatValue.setInputType(InputType.TYPE_CLASS_NUMBER);
popupWindow.dismiss(); popupWindow.dismiss();
@ -359,7 +359,7 @@ public class FloatingSettingDialogManager {
AutoClickService service = AutoClickService.getInstance(); AutoClickService service = AutoClickService.getInstance();
if (service == null) { if (service == null) {
Log.e(TAG, "AutoClickService 实例为空,无法应用设置。"); Log.e(TAG, "AutoClickService 实例为空,无法应用设置。");
showToastOnUi(context, "自动点击服务未运行,无法应用设置"); showToastOnUi(context, "The auto-click service is not running and the Settings cannot be applied");
return; return;
} }
@ -377,7 +377,7 @@ public class FloatingSettingDialogManager {
Log.d(TAG, "应用点击间隔到服务: " + intervalValue + "ms"); Log.d(TAG, "应用点击间隔到服务: " + intervalValue + "ms");
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e(TAG, "点击间隔值解析错误: " + currentIntervalValue, e); Log.e(TAG, "点击间隔值解析错误: " + currentIntervalValue, e);
showToastOnUi(context, "点击间隔值无效,请输入有效数字"); showToastOnUi(context, "The click interval value is invalid. Please enter a significant number");
} }
} else { } else {
Log.d(TAG, "点击间隔值为空,未应用到服务。"); Log.d(TAG, "点击间隔值为空,未应用到服务。");
@ -394,7 +394,7 @@ public class FloatingSettingDialogManager {
Log.d(TAG, "应用滑动时长到服务: " + slideDurationValue + "ms"); Log.d(TAG, "应用滑动时长到服务: " + slideDurationValue + "ms");
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e(TAG, "滑动时长值解析错误: " + currentDurationValue, e); Log.e(TAG, "滑动时长值解析错误: " + currentDurationValue, e);
showToastOnUi(context, "滑动时长值无效,请输入有效数字"); showToastOnUi(context, "The sliding duration value is invalid. Please enter a significant number");
} }
} else { } else {
Log.d(TAG, "滑动时长值为空,未应用到服务。"); Log.d(TAG, "滑动时长值为空,未应用到服务。");
@ -413,7 +413,7 @@ public class FloatingSettingDialogManager {
Log.d(TAG, "应用重复时长: " + repeatDurationMillis + "ms。"); Log.d(TAG, "应用重复时长: " + repeatDurationMillis + "ms。");
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e(TAG, "重复时长值解析错误: " + currentRepeatValue, e); Log.e(TAG, "重复时长值解析错误: " + currentRepeatValue, e);
showToastOnUi(context, "重复时长值无效,请输入有效数字"); showToastOnUi(context, "Repeated duration values are invalid. Please enter valid numbers");
service.setLoopTime(0); // 错误时取消时间循环 service.setLoopTime(0); // 错误时取消时间循环
} }
} else { } else {
@ -430,7 +430,7 @@ public class FloatingSettingDialogManager {
Log.d(TAG, "应用重复次数: " + repeatCount + "次。"); Log.d(TAG, "应用重复次数: " + repeatCount + "次。");
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e(TAG, "重复次数值解析错误: " + currentRepeatValue, e); Log.e(TAG, "重复次数值解析错误: " + currentRepeatValue, e);
showToastOnUi(context, "重复次数值无效,请输入有效数字"); showToastOnUi(context, "Duplicate values are invalid. Please enter significant figures");
service.setLoopCount(1); // 错误时设置为执行一次 service.setLoopCount(1); // 错误时设置为执行一次
} }
} else { } else {
@ -465,17 +465,16 @@ public class FloatingSettingDialogManager {
if (!currentSwipeDurationUnit.isEmpty()) { if (!currentSwipeDurationUnit.isEmpty()) {
tvSelectedUnit.setText(currentSwipeDurationUnit); tvSelectedUnit.setText(currentSwipeDurationUnit);
} else { } else {
tvSelectedUnit.setText(context.getString(R.string.milliseconds_unit)); // 默认单位 tvSelectedUnit.setText(context.getString(R.string.milliseconds_unit));
currentSwipeDurationUnit = context.getString(R.string.milliseconds_unit); currentSwipeDurationUnit = context.getString(R.string.milliseconds_unit);
} }
// 恢复重复设置 // 恢复重复设置
repeatSwitch.setChecked(isRepeatSwitchChecked); repeatSwitch.setChecked(isRepeatSwitchChecked);
updateRepeatUI(isRepeatSwitchChecked); // 根据开关状态更新UI updateRepeatUI(isRepeatSwitchChecked);
if (isRepeatSwitchChecked) { if (isRepeatSwitchChecked) {
if (currentRepeatUnit.isEmpty()) { if (currentRepeatUnit.isEmpty()) {
// 如果没有保存的单位默认为无限次
repeatSelectedUnit.setText(context.getString(R.string.infinitely_unit)); repeatSelectedUnit.setText(context.getString(R.string.infinitely_unit));
currentRepeatUnit = context.getString(R.string.infinitely_unit); currentRepeatUnit = context.getString(R.string.infinitely_unit);
etRepeatValue.setText(""); etRepeatValue.setText("");

View File

@ -123,7 +123,7 @@ public class FloatingTabDialogManager {
Toast.makeText(context, "正在加载方案: " + solution.getSolutionName(), Toast.LENGTH_SHORT).show(); Toast.makeText(context, "正在加载方案: " + solution.getSolutionName(), Toast.LENGTH_SHORT).show();
} else { } else {
Log.e(TAG, "FloatingViewManager 未设置!无法加载方案。"); Log.e(TAG, "FloatingViewManager 未设置!无法加载方案。");
Toast.makeText(context, "加载功能不可用,请联系开发者。", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "The loading function is unavailable. Please contact the developer.", Toast.LENGTH_SHORT).show();
} }
removeFloatingTabDialog(); removeFloatingTabDialog();
}); });
@ -138,10 +138,10 @@ public class FloatingTabDialogManager {
Log.d(TAG, "浮动标签页弹窗已显示"); Log.d(TAG, "浮动标签页弹窗已显示");
} catch (WindowManager.BadTokenException e) { } catch (WindowManager.BadTokenException e) {
Log.e(TAG, "无法添加浮动标签页弹窗,可能是权限问题或上下文无效", e); Log.e(TAG, "无法添加浮动标签页弹窗,可能是权限问题或上下文无效", e);
Toast.makeText(context, "显示弹窗失败,请检查权限。", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "The pop-up window failed to display. Please check the permissions.", Toast.LENGTH_SHORT).show();
} catch (SecurityException e) { } catch (SecurityException e) {
Log.e(TAG, "需要悬浮窗权限才能显示浮动弹窗", e); Log.e(TAG, "需要悬浮窗权限才能显示浮动弹窗", e);
Toast.makeText(context, "请授予悬浮窗权限以便显示", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "Please grant the floating window permission for display", Toast.LENGTH_SHORT).show();
} }
} }
@ -174,7 +174,7 @@ public class FloatingTabDialogManager {
if (floatingViewManager == null) { if (floatingViewManager == null) {
Log.e(TAG, "FloatingViewManager 未设置,无法加载方案列表。"); Log.e(TAG, "FloatingViewManager 未设置,无法加载方案列表。");
new Handler(Looper.getMainLooper()).post(() -> new Handler(Looper.getMainLooper()).post(() ->
Toast.makeText(context, "加载方案列表功能不可用", Toast.LENGTH_SHORT).show() Toast.makeText(context, "The function of loading the list of schemes is not available", Toast.LENGTH_SHORT).show()
); );
return; return;
} }
@ -184,7 +184,7 @@ public class FloatingTabDialogManager {
new Handler(Looper.getMainLooper()).post(() -> { new Handler(Looper.getMainLooper()).post(() -> {
solutionsAdapter.setSolutions(solutions); solutionsAdapter.setSolutions(solutions);
if (solutions.isEmpty()) { if (solutions.isEmpty()) {
Toast.makeText(context, "没有可加载的方案", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "There is no loadable scheme", Toast.LENGTH_SHORT).show();
} }
}); });
} }
@ -193,7 +193,7 @@ public class FloatingTabDialogManager {
public void onError(Exception e) { public void onError(Exception e) {
new Handler(Looper.getMainLooper()).post(() -> { new Handler(Looper.getMainLooper()).post(() -> {
Log.e(TAG, "加载方案列表失败: " + e.getMessage(), e); Log.e(TAG, "加载方案列表失败: " + e.getMessage(), e);
Toast.makeText(context, "加载方案列表失败", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "The loading of the scheme list failed", Toast.LENGTH_SHORT).show();
}); });
} }
}); });

View File

@ -113,7 +113,7 @@ public class FloatingViewManager {
public void showFloatingViews(int mode) throws SecurityException { public void showFloatingViews(int mode) throws SecurityException {
if (!Settings.canDrawOverlays(context)) { if (!Settings.canDrawOverlays(context)) {
throw new SecurityException("需要悬浮窗许可"); throw new SecurityException("A floating window permit is required");
} }
this.mode = mode; this.mode = mode;
@ -285,7 +285,7 @@ public class FloatingViewManager {
} }
if (runtimeEvents.isEmpty()) { if (runtimeEvents.isEmpty()) {
Toast.makeText(context, "请添加一个触摸点或者滑动事件", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "Please add a touch point or a sliding event", Toast.LENGTH_SHORT).show();
return; return;
} }
@ -303,7 +303,7 @@ public class FloatingViewManager {
private void addPointEvent() { private void addPointEvent() {
if (isMultipleRunning) { if (isMultipleRunning) {
Toast.makeText(context, "请停止点击", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "Please stop clicking.", Toast.LENGTH_SHORT).show();
return; return;
} }
@ -322,7 +322,7 @@ public class FloatingViewManager {
private void addSlideEvent() { private void addSlideEvent() {
if (isMultipleRunning) { if (isMultipleRunning) {
Toast.makeText(context, "请先停止点击", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "Please stop clicking first", Toast.LENGTH_SHORT).show();
return; return;
} }
@ -428,12 +428,12 @@ public class FloatingViewManager {
private void removeLastEvent() { private void removeLastEvent() {
if (isMultipleRunning) { if (isMultipleRunning) {
Toast.makeText(context, "请先停止点击", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "Please stop clicking first", Toast.LENGTH_SHORT).show();
return; return;
} }
if (runtimeEvents.isEmpty()) { if (runtimeEvents.isEmpty()) {
Toast.makeText(context, "没有更多的事件需要删除", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "There are no more events to be deleted", Toast.LENGTH_SHORT).show();
return; return;
} }
@ -449,7 +449,7 @@ public class FloatingViewManager {
service.stopClicking(); service.stopClicking();
} else { } else {
Log.d(TAG, "自动点击服务没有初始化"); Log.d(TAG, "自动点击服务没有初始化");
Toast.makeText(context, "请同意无障碍服务权限", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "Please agree to the accessibility service permission", Toast.LENGTH_SHORT).show();
} }
removeAllFloatingViews(); removeAllFloatingViews();
@ -467,7 +467,7 @@ public class FloatingViewManager {
service.startClicking(); service.startClicking();
Log.d(TAG, "开始多点点击事件 " + runtimeEvents.size()); Log.d(TAG, "开始多点点击事件 " + runtimeEvents.size());
Toast.makeText(context, "多点点击开始", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "Click more to start", Toast.LENGTH_SHORT).show();
updateTouchPointsBackground(R.drawable.touch_point); updateTouchPointsBackground(R.drawable.touch_point);
@ -476,7 +476,7 @@ public class FloatingViewManager {
private void stopMultiClicking(AutoClickService service) { private void stopMultiClicking(AutoClickService service) {
service.stopClicking(); service.stopClicking();
Toast.makeText(context, "多点点击停止", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "Click more to stop", Toast.LENGTH_SHORT).show();
updateTouchPointsBackground(R.drawable.ring_has_bg); updateTouchPointsBackground(R.drawable.ring_has_bg);
@ -592,7 +592,7 @@ public class FloatingViewManager {
private void handleMissingService() { private void handleMissingService() {
Log.e(TAG, "自动点击服务没有初始化"); Log.e(TAG, "自动点击服务没有初始化");
Toast.makeText(context, "请在设置里同意无障碍服务", Toast.LENGTH_LONG).show(); Toast.makeText(context, "Please agree to accessibility services in the Settings", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent); context.startActivity(intent);
@ -650,14 +650,14 @@ public class FloatingViewManager {
public void saveCurrentEventsAsSolution(String solutionName, EventRepository.RepositoryCallback<Long> callback) { public void saveCurrentEventsAsSolution(String solutionName, EventRepository.RepositoryCallback<Long> callback) {
if (solutionName == null || solutionName.trim().isEmpty()) { if (solutionName == null || solutionName.trim().isEmpty()) {
Toast.makeText(context, "方案名称不能为空", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "The script name cannot be empty", Toast.LENGTH_SHORT).show();
if (callback != null) { if (callback != null) {
callback.onComplete(-1L); callback.onComplete(-1L);
} }
return; return;
} }
if (runtimeEvents.isEmpty()) { if (runtimeEvents.isEmpty()) {
Toast.makeText(context, "当前没有事件可以保存", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "There are no events that can be saved at present", Toast.LENGTH_SHORT).show();
if (callback != null) { if (callback != null) {
callback.onComplete(-1L); callback.onComplete(-1L);
} }
@ -676,9 +676,9 @@ public class FloatingViewManager {
@Override @Override
public void onError(Exception e) { public void onError(Exception e) {
Log.e(TAG, "保存方案失败: " + e.getMessage(), e); Log.e(TAG, "保存方案失败: " + e.getMessage(), e);
Toast.makeText(context, "保存方案失败: " + e.getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(context, "Failed to save the script: " + e.getMessage(), Toast.LENGTH_SHORT).show();
if (callback != null) { if (callback != null) {
callback.onError(e); // 将错误传递给调用者 callback.onError(e);
} }
} }
}); });

View File

@ -21,7 +21,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:text="选项卡一" android:text="Save"
android:textColor="@color/black" /> android:textColor="@color/black" />
<Button <Button
@ -30,7 +30,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:text="选项卡二" android:text="Load"
android:textColor="@color/gray" /> android:textColor="@color/gray" />
</LinearLayout> </LinearLayout>