Enderman8843/Click BUG

Click Extensions

Double clicking and long pressing errors trigger clicks.(双击和长按错误触发点击。)

I don't know how to pack.(我不会打包。)help me。

AI modification instructions:(AI修改说明:)

  1. Double click detection logic adjustment: Set a 400ms delay task to trigger Click when clicking for the first time. If clicking again within 400ms (i=2), cancel the delay task and trigger DoubleClick to avoid accidentally triggering a single click when double clicking.
  2. 双击检测逻辑调整:第一次点击时设置400ms延迟任务触发 Click ,若400ms内再次点击(i=2),则取消延迟任务并触发 DoubleClick ,避免双击时误触发单次点击。
  3. Long press event handling: Change the return value of onLongClick to true, indicating the consumption of the long press event to prevent the system from continuing to propagate the event and triggering the click.
  4. 长按事件处理:将 onLongClick 返回值改为 true ,表示消耗该长按事件,防止系统继续传播事件导致触发点击。

Modified:(修改后的:)

package io.clic.sashi;

import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import android.os.Handler;
import android.view.View;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.runtime.Component;


@DesignerComponent(
        version = 1,
        description = "",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,
        iconName = "")

@SimpleObject(external = true)
//Libraries
@UsesLibraries(libraries = "")
//Permissions
@UsesPermissions(permissionNames = "")

public class Clic extends AndroidNonvisibleComponent {

    //Activity and Context
    private Context context;
    private Activity activity;
     private int i=0;

    public Clic(ComponentContainer container){
        super(container.$form());
        this.activity = container.$context();
        this.context = container.$context();
    }

    @SimpleEvent
    public void Click(AndroidViewComponent component){
        EventDispatcher.dispatchEvent(this,"Click",component);
    }
    @SimpleEvent
    public void LongClick(AndroidViewComponent component){
        EventDispatcher.dispatchEvent(this,"LongClick",component);
    }
    @SimpleEvent
    public void DoubleClick(AndroidViewComponent component){
        EventDispatcher.dispatchEvent(this,"DoubleClick",component);
    }
    @SimpleFunction
    public void PerformClick(final AndroidViewComponent component){
        component.getView().performClick();
    }
    @SimpleFunction
    public void PerformLongClick(final AndroidViewComponent component){
        component.getView().performLongClick();
    }
    @SimpleFunction
    public void PerformDoubleClick(final AndroidViewComponent component){
        component.getView().performClick();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    component.getView().performClick();
                }
            },200);
    }
    @SimpleFunction
    public void SetClickable(final AndroidViewComponent component ,final boolean clickable){
        component.getView().setClickable(clickable);
        if (clickable) {
            final Handler clickHandler = new Handler();
            final Runnable[] singleClickRunnable = new Runnable[1]; // 使用数组存储Runnable以便在内部类中修改
            component.getView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    i++;
                    if (i == 1) {
                        // 第一次点击时设置延迟任务触发单次点击
                        singleClickRunnable[0] = new Runnable() {
                            @Override
                            public void run() {
                                Click(component);
                                i = 0; // 超时后重置计数
                            }
                        };
                        clickHandler.postDelayed(singleClickRunnable[0], 400); // 400ms作为双击判定间隔
                    } else if (i == 2) {
                        // 第二次点击时取消延迟任务并触发双击事件
                        clickHandler.removeCallbacks(singleClickRunnable[0]);
                        DoubleClick(component);
                        i = 0; // 触发双击后重置计数
                    }
                }
            });
            component.getView().setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View view) {
                    LongClick(component);
                    return true; // 返回true表示消耗长按事件,避免触发后续点击
                }
            });
        }
    }
}

If you want to know how to pack a aix, you can check with the tool: Fast