Click here to Skip to main content
13,349,293 members (58,252 online)
Click here to Skip to main content

Stats

30K views
439 downloads
31 bookmarked
Posted 14 Jan 2013

A Domain Specific Language for Android touch events: Part 1: Description and usage of the DSL

, 6 Dec 2013
A DSL for creating touch gestures in Android.
AndroidGestureDSL Version 1.1
AndroidGestureDSL
.classpath
.project
default.properties
proguard.cfg
res
drawable-hdpi
icon.png
drawable-ldpi
icon.png
drawable-mdpi
icon.png
layout
values
src
com
hfk
android
gestures
dsl
AndroidGestureDSLSample
.classpath
.project
default.properties
proguard.cfg
res
drawable-hdpi
icon.png
drawable-ldpi
icon.png
drawable-mdpi
icon.png
layout
values
src
com
hfk
android
sample
actions
conditions
gestures
package com.hfk.android.gestures.dsl;

import com.hfk.android.gestures.DoInvalidateGestureGestureAction;
import com.hfk.android.gestures.GestureEvent;
import com.hfk.android.gestures.IGestureCondition;
import com.hfk.android.gestures.IfThenClause;
import com.hfk.android.gestures.TouchEvent;
import com.hfk.android.gestures.TouchGesture;

public class NextGestureAfterTouchDown {
	
	public NextGestureAfterTouchDown(TouchGesture gstr)
	{
		gesture = gstr;
	}
	
	public ActionAfterGestureOrConditional<NextGestureAfterMove> Move()
	{
	    TouchEvent moveEvent = new TouchEvent();
	    moveEvent.event = TouchEvent.TOUCH_MOVE;
	    moveEvent.isOptional = false;
	    
	    gesture.addEvent(moveEvent);
		
		ActionAfterGestureOrConditional<NextGestureAfterMove> result = new ActionAfterGestureOrConditional<NextGestureAfterMove>(NextGestureAfterMove.class, gesture, moveEvent);		
		return result;
	}
	
	public ActionAfterGestureOrConditional<NextGestureAfterMove> CanMove()
	{
	    TouchEvent moveEvent = new TouchEvent();
	    moveEvent.event = TouchEvent.TOUCH_MOVE;
	    moveEvent.isOptional = true;
	    
	    gesture.addEvent(moveEvent);
		
		ActionAfterGestureOrConditional<NextGestureAfterMove> result = new ActionAfterGestureOrConditional<NextGestureAfterMove>(NextGestureAfterMove.class, gesture, moveEvent);		
		return result;
	}
	
	public ActionAfterGestureOrConditional<NextGestureAfterTouchUp> TouchUp()
	{
		int size = gesture.size();
		if(size == 0)
		{
			// If no other events exist, 
			//	we insert a TOUCH_DOWN which is always accepted. You can not have a TOUCH_UP without having had a TOUCH_DOWN
		    TouchEvent upEvent = new TouchEvent();
		    upEvent.event = TouchEvent.TOUCH_DOWN;
			IfThenClause condition = new IfThenClause(
					new IGestureCondition()
					{
						public boolean checkCondition(GestureEvent motion, TouchGesture gesture)
						{
							return true;
						}
					}
			);
			upEvent.conditionList.add(condition);
		    gesture.addEvent(upEvent);
			
//			//	we insert a TOUCH_MOVE which always invalidates.
//		    TouchEvent moveEvent = new TouchEvent();
//		    moveEvent.event = TouchEvent.TOUCH_MOVE;
//		    gesture.addEvent(moveEvent);
		}
//		else
//		{		
//			TouchEvent previousEvent = gesture.getEvent(size - 1);
//			// If no TOUCH_MOVE exists, then insert one which, when executed, invalidates the gesture
//			if(previousEvent.event != TouchEvent.TOUCH_MOVE)
//			{
//			    TouchEvent moveEvent = new TouchEvent();
//			    moveEvent.event = TouchEvent.TOUCH_MOVE;
//				IfThenClause condition = new IfThenClause(
//						new IGestureCondition()
//						{
//							public boolean checkCondition(GestureEvent motion, TouchGesture gesture)
//							{
//								return true;
//							}
//						}
//				);
//				condition.setThenAction(new DoInvalidateGestureGestureAction());
//				moveEvent.conditionList.add(condition);
//			    gesture.addEvent(moveEvent);
//			}
//		}
		
	    TouchEvent upEvent = new TouchEvent();
	    upEvent.event = TouchEvent.TOUCH_UP;
	    
	    gesture.addEvent(upEvent);
		
		ActionAfterGestureOrConditional<NextGestureAfterTouchUp> move = new ActionAfterGestureOrConditional<NextGestureAfterTouchUp>(NextGestureAfterTouchUp.class, gesture, upEvent);
		return move;
	}
	
	TouchGesture gesture;

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Serge Desmedt
Software Developer (Senior)
Belgium Belgium
No Biography provided

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 6 Dec 2013
Article Copyright 2013 by Serge Desmedt
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid