All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bugvm.apple.uikit.UIGestureRecognizer Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2013-2015 RoboVM AB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bugvm.apple.uikit;

/**/
import java.io.*;
import java.nio.*;
import java.util.*;
import com.bugvm.objc.*;
import com.bugvm.objc.annotation.*;
import com.bugvm.objc.block.*;
import com.bugvm.rt.*;
import com.bugvm.rt.annotation.*;
import com.bugvm.rt.bro.*;
import com.bugvm.rt.bro.annotation.*;
import com.bugvm.rt.bro.ptr.*;
import com.bugvm.apple.foundation.*;
import com.bugvm.apple.coreanimation.*;
import com.bugvm.apple.coregraphics.*;
import com.bugvm.apple.coredata.*;
import com.bugvm.apple.coreimage.*;
import com.bugvm.apple.coretext.*;
import com.bugvm.apple.corelocation.*;
/**/

/**/
/**
 * @since Available in iOS 3.2 and later.
 */
/**/
/**/@Library("UIKit") @NativeClass/**/
/**/public/**/ class /**/UIGestureRecognizer/**/ 
    extends /**/NSObject/**/ 
    /**//**/ {

    /**/public static class UIGestureRecognizerPtr extends Ptr {}/**/
    /**/static { ObjCRuntime.bind(UIGestureRecognizer.class); }/**/
    /**//**/
    
    public interface OnGestureListener {
        void onGesture(UIGestureRecognizer gestureRecognizer);
    }
    
    private static final Selector handleGesture = Selector.register("handleGesture:");
    private static class ListenerWrapper extends NSObject {
        private final OnGestureListener listener;
        private ListenerWrapper(OnGestureListener listener) {
            this.listener = listener;
        }
        @Method(selector = "handleGesture:")
        private void handleGesture(UIGestureRecognizer gestureRecognizer) {
            listener.onGesture(gestureRecognizer);
        }
    }
    
    
    @SuppressWarnings("unchecked")
    private List getListeners(boolean create) {
        synchronized (UIGestureRecognizer.class) {
            List listeners = 
                    (List) getAssociatedObject(UIGestureRecognizer.class.getName() + ".listeners");
            if (listeners == null && create) {
                listeners = new LinkedList();
                setAssociatedObject(UIGestureRecognizer.class.getName() + ".listeners", listeners);
            }
            return listeners;
        }
    }
    public void addListener(OnGestureListener listener) {
        ListenerWrapper wrapper = new ListenerWrapper(listener);
        List listeners = getListeners(true);
        synchronized (listeners) {
            listeners.add(wrapper);
        }
        addTarget(wrapper, handleGesture);
    }
    
    public void removeListener(OnGestureListener listener) {
        List listeners = getListeners(false);
        if (listeners == null) {
            return;
        }
        synchronized (listeners) {
            for (Iterator it = listeners.iterator(); it.hasNext();) {
                ListenerWrapper wrapper = it.next();
                if (wrapper.listener == listener) {
                    removeTarget(wrapper, handleGesture);
                    it.remove();
                    break;
                }
            }
        }        
    }
    
    public UIGestureRecognizer(OnGestureListener listener) { 
        if (listener != null) addListener(listener);
    }
    /**/
    public UIGestureRecognizer() {}
    protected UIGestureRecognizer(SkipInit skipInit) { super(skipInit); }
    public UIGestureRecognizer(NSObject target, Selector action) { super((SkipInit) null); initObject(init(target, action)); }
    /**/
    /**/
    @Property(selector = "state")
    public native UIGestureRecognizerState getState();
    @Property(selector = "delegate")
    public native UIGestureRecognizerDelegate getDelegate();
    @Property(selector = "setDelegate:", strongRef = true)
    public native void setDelegate(UIGestureRecognizerDelegate v);
    @Property(selector = "isEnabled")
    public native boolean isEnabled();
    @Property(selector = "setEnabled:")
    public native void setEnabled(boolean v);
    @Property(selector = "view")
    public native UIView getView();
    @Property(selector = "cancelsTouchesInView")
    public native boolean cancelsTouchesInView();
    @Property(selector = "setCancelsTouchesInView:")
    public native void setCancelsTouchesInView(boolean v);
    @Property(selector = "delaysTouchesBegan")
    public native boolean delaysTouchesBegan();
    @Property(selector = "setDelaysTouchesBegan:")
    public native void setDelaysTouchesBegan(boolean v);
    @Property(selector = "delaysTouchesEnded")
    public native boolean delaysTouchesEnded();
    @Property(selector = "setDelaysTouchesEnded:")
    public native void setDelaysTouchesEnded(boolean v);
    /**/
    /**//**/
    /**/
    @Method(selector = "initWithTarget:action:")
    protected native @Pointer long init(NSObject target, Selector action);
    @Method(selector = "addTarget:action:")
    public native void addTarget(NSObject target, Selector action);
    @Method(selector = "removeTarget:action:")
    public native void removeTarget(NSObject target, Selector action);
    @Method(selector = "requireGestureRecognizerToFail:")
    public native void requireGestureRecognizerToFail(UIGestureRecognizer otherGestureRecognizer);
    @Method(selector = "locationInView:")
    public native @ByVal CGPoint getLocationInView(UIView view);
    @Method(selector = "numberOfTouches")
    public native @MachineSizedUInt long getNumberOfTouches();
    @Method(selector = "locationOfTouch:inView:")
    public native @ByVal CGPoint getLocationOfTouch(@MachineSizedUInt long touchIndex, UIView view);
    /**/
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy