Click here to Skip to main content
13,663,621 members
Click here to Skip to main content

Tagged as

Stats

33K views
442 downloads
31 bookmarked
Posted 14 Jan 2013
Licenced CPOL

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
res
drawable-hdpi
icon.png
drawable-ldpi
icon.png
drawable-mdpi
icon.png
layout
values
src
com
hfk
android
gestures
dsl
AndroidGestureDSLSample
.classpath
.project
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;

import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;

import android.graphics.Point;

public class TouchGesture implements IResetable  {

	public TouchGesture(String id) 
	{
		this.id = id;
	}
	
	public String getId()
	{
		return id;
	}
	
	public void addEvent(TouchEvent event)
	{
		TouchEventExecution eventExecution = new TouchEventExecution();
		eventExecution.touchEvent = event;
		eventExecution.isExecuted = false;
		eventList.add(eventExecution);
	}
	
	public TouchEvent getEvent(int index)
	{
		return eventList.get(index).touchEvent;
	}
	
	public int size()
	{
		return eventList.size();
	}
	
	public void reset()
	{		
		for(IResetable resetable:resetableList)
		{
			resetable.reset();
		}
		
		if(onResetAction != null)
		{
			onResetAction.executeAction(null, this);
		}
		
		isValid = true;
		index = 0;
		context = new Hashtable<String, Object>();
	}
	
	public void addResetable(IResetable resetable)
	{
		resetableList.add(resetable);
	}
	
	public void setResetAction(IGestureAction action)
	{
		onResetAction = action;
	}
	
	public void invalidate()
	{
		if(contextExists("TIMER_INSTALLED"))
		{
			TouchHandler handler = (TouchHandler)getContext("TIMER_INSTALLED");
			handler.invalidateTimer();
			removeContext("TIMER_INSTALLED");
		}
		isValid = false;
	}
	
	public boolean isValid()
	{
		return ((index < eventList.size()) && isValid);
	}
	
	public TouchEvent current()
	{
		return eventList.get(index).touchEvent;
	}
	
	public boolean isCurrentExecuted()
	{
		return eventList.get(index).isExecuted;
	}
	
	public void currentIsExecuted()
	{
		eventList.get(index).isExecuted = true;
	}
	
	public void moveNext()
	{
		index++;
	}
	
	public boolean isCompleted()
	{
		if(!isValid)
			return false;
		
		return (index >= eventList.size());
	}
	
	public void setAllEventsProcessed()
	{
		index = eventList.size();
	}
	
	public boolean contextExists(String key)
	{
		return context.containsKey(key);
	}
	
	public void addContext(String key, Object data)
	{
		context.put(key, data);
	}
	
	public void setContext(String key, Object data)
	{
		context.put(key, data);
	}
	
	public void removeContext(String key)
	{
		context.remove(key);
	}
	
	public Object getContext(String key)
	{
		return context.get(key);
	}

	private String id;
	private List<TouchEventExecution> eventList = new ArrayList<TouchEventExecution>();	
	private List<IResetable> resetableList = new ArrayList<IResetable>();	
	private IGestureAction onResetAction = null;
	private boolean isValid = true;
	private int index = 0;
	
	private Runnable timerAction;
	
	private Hashtable<String, Object> context = new Hashtable<String, Object>();
	
	private class TouchEventExecution
	{
		TouchEvent touchEvent;
		boolean isExecuted;
	}
	
}

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 | Cookies | Terms of Use | Mobile
Web06-2016 | 2.8.180810.1 | Last Updated 6 Dec 2013
Article Copyright 2013 by Serge Desmedt
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid