blob: a105652d45969262915a79d07e946c2d133cc8f6 [file] [log] [blame]
Yang Li35aa84b2009-05-18 18:29:05 -07001/*
2 * Copyright (C) 2008-2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Romain Guydb567c32009-05-21 16:23:21 -070017package android.gesture;
Yang Li35aa84b2009-05-18 18:29:05 -070018
19import java.util.ArrayList;
20
21/**
22 * The abstract class of a gesture learner
23 */
24abstract class Learner {
Yang Li35aa84b2009-05-18 18:29:05 -070025 private final ArrayList<Instance> mInstances = new ArrayList<Instance>();
26
27 /**
28 * Add an instance to the learner
29 *
30 * @param instance
31 */
32 void addInstance(Instance instance) {
33 mInstances.add(instance);
34 }
35
36 /**
37 * Retrieve all the instances
38 *
39 * @return instances
40 */
41 ArrayList<Instance> getInstances() {
42 return mInstances;
43 }
44
45 /**
46 * Remove an instance based on its id
47 *
48 * @param id
49 */
50 void removeInstance(long id) {
51 ArrayList<Instance> instances = mInstances;
52 int count = instances.size();
53 for (int i = 0; i < count; i++) {
54 Instance instance = instances.get(i);
Romain Guyc5347272009-05-20 10:37:13 -070055 if (id == instance.id) {
Yang Li35aa84b2009-05-18 18:29:05 -070056 instances.remove(instance);
57 return;
58 }
59 }
60 }
61
62 /**
63 * Remove all the instances of a category
64 *
65 * @param name the category name
66 */
67 void removeInstances(String name) {
Romain Guyc5347272009-05-20 10:37:13 -070068 final ArrayList<Instance> toDelete = new ArrayList<Instance>();
69 final ArrayList<Instance> instances = mInstances;
70 final int count = instances.size();
71
Yang Li35aa84b2009-05-18 18:29:05 -070072 for (int i = 0; i < count; i++) {
Romain Guyc5347272009-05-20 10:37:13 -070073 final Instance instance = instances.get(i);
74 // the label can be null, as specified in Instance
Kenny Rootea46dea2010-02-17 10:04:20 -080075 if ((instance.label == null && name == null)
76 || (instance.label != null && instance.label.equals(name))) {
Yang Li35aa84b2009-05-18 18:29:05 -070077 toDelete.add(instance);
78 }
79 }
Romain Guyc5347272009-05-20 10:37:13 -070080 instances.removeAll(toDelete);
Yang Li35aa84b2009-05-18 18:29:05 -070081 }
82
Yang Li4758f122009-12-14 15:41:07 -080083 abstract ArrayList<Prediction> classify(int sequenceType, int orientationType, float[] vector);
Yang Li35aa84b2009-05-18 18:29:05 -070084}