|
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.