• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package android.gesture;
18 
19 import java.util.ArrayList;
20 
21 /**
22  * The abstract class of a gesture learner
23  */
24 abstract class Learner {
25     private final ArrayList<Instance> mInstances = new ArrayList<Instance>();
26 
27     /**
28      * Add an instance to the learner
29      *
30      * @param instance
31      */
addInstance(Instance instance)32     void addInstance(Instance instance) {
33         mInstances.add(instance);
34     }
35 
36     /**
37      * Retrieve all the instances
38      *
39      * @return instances
40      */
getInstances()41     ArrayList<Instance> getInstances() {
42         return mInstances;
43     }
44 
45     /**
46      * Remove an instance based on its id
47      *
48      * @param id
49      */
removeInstance(long id)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);
55             if (id == instance.id) {
56                 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      */
removeInstances(String name)67     void removeInstances(String name) {
68         final ArrayList<Instance> toDelete = new ArrayList<Instance>();
69         final ArrayList<Instance> instances = mInstances;
70         final int count = instances.size();
71 
72         for (int i = 0; i < count; i++) {
73             final Instance instance = instances.get(i);
74             // the label can be null, as specified in Instance
75             if ((instance.label == null && name == null)
76                     || (instance.label != null && instance.label.equals(name))) {
77                 toDelete.add(instance);
78             }
79         }
80         instances.removeAll(toDelete);
81     }
82 
classify(int sequenceType, int orientationType, float[] vector)83     abstract ArrayList<Prediction> classify(int sequenceType, int orientationType, float[] vector);
84 }
85