@@ -75,6 +75,11 @@ public class TouchHelperServiceImpl {
7575 private Set <PackageWidgetDescription > setWidgets ;
7676 private PackagePositionDescription packagePositionDescription ;
7777
78+ // try to click 5 times, first click after 300ms, and delayed for 500ms for future clicks
79+ static final int PackagePositionClickFirstDelay = 300 ;
80+ static final int PackagePositionClickRetryInterval = 500 ;
81+ static final int PackagePositionClickRetry = 5 ;
82+
7883 public TouchHelperServiceImpl (AccessibilityService service ) {
7984 this .service = service ;
8085 }
@@ -290,17 +295,22 @@ public void onAccessibilityEvent(AccessibilityEvent event) {
290295 }
291296
292297 // now to take different methods to skip ads
298+
299+ // first method is to skip ads by position in activity
293300 if (b_method_by_activity_position ) {
294- // Log.d(TAG, "method by position in STATE_CHANGED");
301+ // run this method for once only
302+ b_method_by_activity_position = false ;
303+
295304 packagePositionDescription = mapPackagePositions .get (currentPackageName );
296305 if (packagePositionDescription != null ) {
297- // the following codes might be run multiple times
298306 ShowToastInIntentService ("正在根据位置跳过广告..." );
307+
308+ // try to click the position in the activity for multiple times
299309 executorService .scheduleAtFixedRate (new Runnable () {
300310 int num = 0 ;
301311 @ Override
302312 public void run () {
303- if (num < packagePositionDescription . number ) {
313+ if (num < PackagePositionClickRetry ) {
304314 if (currentActivityName .equals (packagePositionDescription .activityName )) {
305315 // current activity is null, or current activity is the target activity
306316// Log.d(TAG, "Find skip-ad by position, simulate click now! ");
@@ -311,10 +321,7 @@ public void run() {
311321 throw new RuntimeException ();
312322 }
313323 }
314- }, packagePositionDescription .delay , packagePositionDescription .period , TimeUnit .MILLISECONDS );
315- } else {
316- // no customized positions for this package, don't try this method again
317- b_method_by_activity_position = false ;
324+ }, PackagePositionClickFirstDelay , PackagePositionClickRetryInterval , TimeUnit .MILLISECONDS );
318325 }
319326 }
320327
@@ -651,7 +658,7 @@ private void showActivityCustomizationDialog() {
651658
652659
653660 final PackageWidgetDescription widgetDescription = new PackageWidgetDescription ();
654- final PackagePositionDescription positionDescription = new PackagePositionDescription ("" , "" , 0 , 0 , 500 , 500 , 6 );
661+ final PackagePositionDescription positionDescription = new PackagePositionDescription ("" , "" , 0 , 0 );
655662
656663 final LayoutInflater inflater = LayoutInflater .from (service );
657664 // activity customization view
0 commit comments