/** * {@inheritDoc} {@linkplain com.camnter.robotlegs4android.core.IEventMap #unmapListeners} Removes * all listeners registered through <code>mapListener</code> 通过mapListener删除所有的侦听器注册 */ @Override public void unmapListeners() { Params params; IEventDispatcher dispatcher; while ((this.listeners.size() > 0) && ((params = (Params) this.listeners.remove(this.listeners.size() - 1)) != null)) { dispatcher = params.dispatcher; dispatcher.removeEventListener(params.type, params.callback, params.useCapture); } }
/** * {@inheritDoc} {@linkplain com.camnter.robotlegs4android.core.IEventMap #unmapListener} The same * as calling <code>removeEventListener</code> directly on the <code>IEventDispatcher</code>, but * updates our local list of listeners. 和调用IEventDispatcher里的removeEventListener一样,但是更新我们当地的侦听器列表。 * * @param dispatcher The <code>IEventDispatcher</code> * @param type The <code>Event</code> type * @param listener The <code>Event</code> handler * @param eventClass Optional Event class for a stronger mapping. Defaults to <code>Event</code>. * 可选事件类更强的映射。默认值为Event * @param useCapture useCapture */ @Override public void unmapListener( IEventDispatcher dispatcher, String type, IListener listener, Class<?> eventClass, Boolean useCapture) { if (eventClass == null) { eventClass = Event.class; } Params params; int i = this.listeners.size(); while (i-- != 0) { params = (Params) this.listeners.get(i); if ((params.dispatcher == dispatcher) && params.type.equals(type) && (params.listener == listener) && (params.useCapture == useCapture) && (params.eventClass == eventClass)) { dispatcher.removeEventListener(type, params.callback, useCapture); this.listeners.remove(i); return; } } }
/** * {@inheritDoc} {@linkplain com.camnter.robotlegs4android.core.IEventMap #mapListener} The same * as calling <code>addEventListener</code> directly on the <code>IEventDispatcher</code>, but * keeps a list of listeners for easy (usually automatic) removal. * 和直接在IEventDispatcher上调用addEventListener一样,但保持简单的侦听器列表(通常是自动)。 * * @param dispatcher The <code>IEventDispatcher</code> to listen to * @param type The <code>Event</code> type to listen for * @param listener The <code>Event</code> handler * @param eventClass Optional Event class for a stronger mapping. Defaults to <code>Event</code>. * 可选事件类更强的映射。默认值为Event * @param useCapture |false * @param priority |0 * @param useWeakReference |true */ @Override public void mapListener( IEventDispatcher dispatcher, String type, IListener listener, Class<?> eventClass, Boolean useCapture, int priority, Boolean useWeakReference) { if ((!this.getDispatcherListeningEnabled()) && (dispatcher == this.eventDispatcher)) { throw new ContextError(ContextError.E_EVENTMAP_NOSNOOPING); } if (eventClass == null) { eventClass = Event.class; } Params params; int i = this.listeners.size(); while (i-- > 0) { params = (Params) this.listeners.get(i); if ((params.dispatcher == dispatcher) && params.type.equals(type) && (params.listener == listener) && (params.useCapture == useCapture) && (params.eventClass == eventClass)) return; } IListener callback = new Callback(listener, eventClass); params = new Params(); params.dispatcher = dispatcher; params.type = type; params.listener = listener; params.useCapture = useCapture; params.eventClass = eventClass; params.callback = callback; this.listeners.add(params); dispatcher.addEventListener(type, callback, useCapture, priority, useWeakReference); }