Methods Summary |
---|
public void | addGesture(java.lang.String entryName, Gesture gesture)Add a gesture for the entry
if (entryName == null || entryName.length() == 0) {
return;
}
ArrayList<Gesture> gestures = mNamedGestures.get(entryName);
if (gestures == null) {
gestures = new ArrayList<Gesture>();
mNamedGestures.put(entryName, gestures);
}
gestures.add(gesture);
mClassifier.addInstance(
Instance.createInstance(mSequenceType, mOrientationStyle, gesture, entryName));
mChanged = true;
|
public java.util.Set | getGestureEntries()Get all the gesture entry names in the library
return mNamedGestures.keySet();
|
public java.util.ArrayList | getGestures(java.lang.String entryName)Get all the gestures of an entry
ArrayList<Gesture> gestures = mNamedGestures.get(entryName);
if (gestures != null) {
return new ArrayList<Gesture>(gestures);
} else {
return null;
}
|
Learner | getLearner()
return mClassifier;
|
public int | getOrientationStyle()
return mOrientationStyle;
|
public int | getSequenceType()
return mSequenceType;
|
public boolean | hasChanged()
return mChanged;
|
public void | load(java.io.InputStream stream)Load the gesture library
load(stream, false);
|
public void | load(java.io.InputStream stream, boolean closeStream)
DataInputStream in = null;
try {
in = new DataInputStream((stream instanceof BufferedInputStream) ? stream :
new BufferedInputStream(stream, GestureConstants.IO_BUFFER_SIZE));
long start;
if (PROFILE_LOADING_SAVING) {
start = SystemClock.elapsedRealtime();
}
// Read file format version number
final short versionNumber = in.readShort();
switch (versionNumber) {
case 1:
readFormatV1(in);
break;
}
if (PROFILE_LOADING_SAVING) {
long end = SystemClock.elapsedRealtime();
Log.d(LOG_TAG, "Loading gestures library = " + (end - start) + " ms");
}
} finally {
if (closeStream) GestureUtils.closeStream(in);
}
|
private void | readFormatV1(java.io.DataInputStream in)
final Learner classifier = mClassifier;
final HashMap<String, ArrayList<Gesture>> namedGestures = mNamedGestures;
namedGestures.clear();
// Number of entries in the library
final int entriesCount = in.readInt();
for (int i = 0; i < entriesCount; i++) {
// Entry name
final String name = in.readUTF();
// Number of gestures
final int gestureCount = in.readInt();
final ArrayList<Gesture> gestures = new ArrayList<Gesture>(gestureCount);
for (int j = 0; j < gestureCount; j++) {
final Gesture gesture = Gesture.deserialize(in);
gestures.add(gesture);
classifier.addInstance(
Instance.createInstance(mSequenceType, mOrientationStyle, gesture, name));
}
namedGestures.put(name, gestures);
}
|
public java.util.ArrayList | recognize(Gesture gesture)Recognize a gesture
Instance instance = Instance.createInstance(mSequenceType,
mOrientationStyle, gesture, null);
return mClassifier.classify(mSequenceType, mOrientationStyle, instance.vector);
|
public void | removeEntry(java.lang.String entryName)Remove a entry of gestures
mNamedGestures.remove(entryName);
mClassifier.removeInstances(entryName);
mChanged = true;
|
public void | removeGesture(java.lang.String entryName, Gesture gesture)Remove a gesture from the library. If there are no more gestures for the
given entry, the gesture entry will be removed.
ArrayList<Gesture> gestures = mNamedGestures.get(entryName);
if (gestures == null) {
return;
}
gestures.remove(gesture);
// if there are no more samples, remove the entry automatically
if (gestures.isEmpty()) {
mNamedGestures.remove(entryName);
}
mClassifier.removeInstance(gesture.getID());
mChanged = true;
|
public void | save(java.io.OutputStream stream)Save the gesture library
save(stream, false);
|
public void | save(java.io.OutputStream stream, boolean closeStream)
DataOutputStream out = null;
try {
long start;
if (PROFILE_LOADING_SAVING) {
start = SystemClock.elapsedRealtime();
}
final HashMap<String, ArrayList<Gesture>> maps = mNamedGestures;
out = new DataOutputStream((stream instanceof BufferedOutputStream) ? stream :
new BufferedOutputStream(stream, GestureConstants.IO_BUFFER_SIZE));
// Write version number
out.writeShort(FILE_FORMAT_VERSION);
// Write number of entries
out.writeInt(maps.size());
for (Map.Entry<String, ArrayList<Gesture>> entry : maps.entrySet()) {
final String key = entry.getKey();
final ArrayList<Gesture> examples = entry.getValue();
final int count = examples.size();
// Write entry name
out.writeUTF(key);
// Write number of examples for this entry
out.writeInt(count);
for (int i = 0; i < count; i++) {
examples.get(i).serialize(out);
}
}
out.flush();
if (PROFILE_LOADING_SAVING) {
long end = SystemClock.elapsedRealtime();
Log.d(LOG_TAG, "Saving gestures library = " + (end - start) + " ms");
}
mChanged = false;
} finally {
if (closeStream) GestureUtils.closeStream(out);
}
|
public void | setOrientationStyle(int style)Specify how the gesture library will handle orientation.
Use ORIENTATION_INVARIANT or ORIENTATION_SENSITIVE
mOrientationStyle = style;
|
public void | setSequenceType(int type)
mSequenceType = type;
|