Yang Li | 35aa84b | 2009-05-18 18:29:05 -0700 | [diff] [blame] | 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 | |
Romain Guy | db567c3 | 2009-05-21 16:23:21 -0700 | [diff] [blame] | 17 | package android.gesture; |
Yang Li | 35aa84b | 2009-05-18 18:29:05 -0700 | [diff] [blame] | 18 | |
| 19 | import java.util.ArrayList; |
| 20 | |
| 21 | /** |
| 22 | * The abstract class of a gesture learner |
| 23 | */ |
| 24 | abstract class Learner { |
Yang Li | 35aa84b | 2009-05-18 18:29:05 -0700 | [diff] [blame] | 25 | 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 Guy | c534727 | 2009-05-20 10:37:13 -0700 | [diff] [blame] | 55 | if (id == instance.id) { |
Yang Li | 35aa84b | 2009-05-18 18:29:05 -0700 | [diff] [blame] | 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 | */ |
| 67 | void removeInstances(String name) { |
Romain Guy | c534727 | 2009-05-20 10:37:13 -0700 | [diff] [blame] | 68 | final ArrayList<Instance> toDelete = new ArrayList<Instance>(); |
| 69 | final ArrayList<Instance> instances = mInstances; |
| 70 | final int count = instances.size(); |
| 71 | |
Yang Li | 35aa84b | 2009-05-18 18:29:05 -0700 | [diff] [blame] | 72 | for (int i = 0; i < count; i++) { |
Romain Guy | c534727 | 2009-05-20 10:37:13 -0700 | [diff] [blame] | 73 | final Instance instance = instances.get(i); |
| 74 | // the label can be null, as specified in Instance |
Kenny Root | ea46dea | 2010-02-17 10:04:20 -0800 | [diff] [blame] | 75 | if ((instance.label == null && name == null) |
| 76 | || (instance.label != null && instance.label.equals(name))) { |
Yang Li | 35aa84b | 2009-05-18 18:29:05 -0700 | [diff] [blame] | 77 | toDelete.add(instance); |
| 78 | } |
| 79 | } |
Romain Guy | c534727 | 2009-05-20 10:37:13 -0700 | [diff] [blame] | 80 | instances.removeAll(toDelete); |
Yang Li | 35aa84b | 2009-05-18 18:29:05 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Yang Li | 4758f12 | 2009-12-14 15:41:07 -0800 | [diff] [blame] | 83 | abstract ArrayList<Prediction> classify(int sequenceType, int orientationType, float[] vector); |
Yang Li | 35aa84b | 2009-05-18 18:29:05 -0700 | [diff] [blame] | 84 | } |