@Override
	public void link(EventLinker.Configuration config) {

		final Object listenerTemplate = config.getContext();
		
		Set<Method> methods = config.getListenerTargets(EventCategory.TOUCH);
		
		for (final Method method : methods) {
			
			OnTouchListener onTouchListener = new OnTouchListener() {
				
				@Override
				public boolean onTouch(View v, MotionEvent event) {
					
					try {
						
						if(!method.isAccessible()) method.setAccessible(true);
						
						Class<?>[] params = method.getParameterTypes();
						
						Object[] args = new Object[params.length];
						boolean argsPopulated = false;

						if(params.length < 3) {
							
							argsPopulated = true;
							
							for(int i = 0; i < params.length; i++) {
							
								if(View.class.isAssignableFrom(params[i])) {
									
									args[i] = v;
								}
								else if(MotionEvent.class.isAssignableFrom(params[i])) {
									
									args[i] = event;
								}
								else {
									
									argsPopulated = false;
								}
							}
						}
							
						if(argsPopulated)
							method.invoke(listenerTemplate, args);
							
						else
							method.invoke(listenerTemplate);
					}
					catch (Exception e) {
						
						StringBuilder builder = new StringBuilder()
						.append("Invocation of ")
						.append(method.getName())
						.append(" at ")
						.append(listenerTemplate.getClass().getName())
						.append(" failed for event OnTouch.");
						
						Log.e(getClass().getName(), builder.toString(), e);
					}

					return false;
				}
			};
			
			try {
				
				int[] views = method.getAnnotation(Touch.class).value();
				
				for (int id : views) {

					try {
						
						if(ContextUtils.isActivity(listenerTemplate)) {
							
							ContextUtils.asActivity(listenerTemplate)
								.findViewById(id).setOnTouchListener(onTouchListener);
						}
						else if(ContextUtils.isFragment(listenerTemplate)) {
							
							ContextUtils.asFragment(listenerTemplate)
								.getView().findViewById(id).setOnTouchListener(onTouchListener);
						}
						else if(ContextUtils.isSupportFragment(listenerTemplate)) {
							
							ContextUtils.asSupportFragment(listenerTemplate)
								.getView().findViewById(id).setOnTouchListener(onTouchListener);
						}
					}
					catch (Exception e) {
						
						StringBuilder builder = new StringBuilder()
						.append("Touch listener linking failed on method ")
						.append(method.getName())
						.append(" at ")
						.append(listenerTemplate.getClass().getName())
						.append(" for view with ID ")
						.append(ContextUtils.isActivity(listenerTemplate)? 
							ContextUtils.asActivity(listenerTemplate).getResources().getResourceName(id)
							:ContextUtils.asFragment(listenerTemplate).getResources().getResourceName(id))
						.append(".");
						
						Log.e(getClass().getName(), builder.toString(), e);
					}
				}
			} 
			catch (Exception e) {
				
				StringBuilder builder = new StringBuilder()
				.append("Touch listener linking failed on method ")
				.append(method.getName())
				.append(" at ")
				.append(listenerTemplate.getClass().getName())
				.append(".");
				
				Log.e(getClass().getName(), builder.toString(), e);
			}
		}
	}
@ Override public void link ( EventLinker . Configuration config ) { final Object listenerTemplate = config . getContext ( ) ; Set < Method > methods = config . getListenerTargets ( EventCategory . TOUCH ) ; for ( final Method method : methods ) { OnTouchListener onTouchListener = new OnTouchListener ( ) { @ Override public boolean onTouch ( View v , MotionEvent event ) { try { if ( ! method . isAccessible ( ) ) method . setAccessible ( true ) ; Class < ? > [ ] params = method . getParameterTypes ( ) ; Object [ ] args = new Object [ params . length ] ; boolean argsPopulated = false ; if ( params . length < 3 ) { argsPopulated = true ; for ( int i = 0 ; i < params . length ; i ++ ) { if ( View . class . isAssignableFrom ( params [ i ] ) ) { args [ i ] = v ; } else if ( MotionEvent . class . isAssignableFrom ( params [ i ] ) ) { args [ i ] = event ; } else { argsPopulated = false ; } } } if ( argsPopulated ) method . invoke ( listenerTemplate , args ) ; else method . invoke ( listenerTemplate ) ; } catch ( Exception e ) { StringBuilder builder = new StringBuilder ( ) . append ( "Invocation of " ) . append ( method . getName ( ) ) . append ( " at " ) . append ( listenerTemplate . getClass ( ) . getName ( ) ) . append ( " failed for event OnTouch." ) ; Log . e ( getClass ( ) . getName ( ) , builder . toString ( ) , e ) ; } return false ; } } ; try { int [ ] views = method . getAnnotation ( Touch . class ) . value ( ) ; for ( int id : views ) { try { if ( ContextUtils . isActivity ( listenerTemplate ) ) { ContextUtils . asActivity ( listenerTemplate ) . findViewById ( id ) . setOnTouchListener ( onTouchListener ) ; } else if ( ContextUtils . isFragment ( listenerTemplate ) ) { ContextUtils . asFragment ( listenerTemplate ) . getView ( ) . findViewById ( id ) . setOnTouchListener ( onTouchListener ) ; } else if ( ContextUtils . isSupportFragment ( listenerTemplate ) ) { ContextUtils . asSupportFragment ( listenerTemplate ) . getView ( ) . findViewById ( id ) . setOnTouchListener ( onTouchListener ) ; } } catch ( Exception e ) { StringBuilder builder = new StringBuilder ( ) . append ( "Touch listener linking failed on method " ) . append ( method . getName ( ) ) . append ( " at " ) . append ( listenerTemplate . getClass ( ) . getName ( ) ) . append ( " for view with ID " ) . append ( ContextUtils . isActivity ( listenerTemplate ) ? ContextUtils . asActivity ( listenerTemplate ) . getResources ( ) . getResourceName ( id ) : ContextUtils . asFragment ( listenerTemplate ) . getResources ( ) . getResourceName ( id ) ) . append ( "." ) ; Log . e ( getClass ( ) . getName ( ) , builder . toString ( ) , e ) ; } } } catch ( Exception e ) { StringBuilder builder = new StringBuilder ( ) . append ( "Touch listener linking failed on method " ) . append ( method . getName ( ) ) . append ( " at " ) . append ( listenerTemplate . getClass ( ) . getName ( ) ) . append ( "." ) ; Log . e ( getClass ( ) . getName ( ) , builder . toString ( ) , e ) ; } } }
{@inheritDoc}