1 /* 2 * Copyright (C) 2009 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17 package com.android.inputmethod.voice; 18 19 import android.os.Bundle; 20 import java.util.ArrayList; 21 import java.util.List; 22 23 /** 24 * A set of text fields where speech has been explicitly enabled. 25 */ 26 public class Whitelist { 27 private List<Bundle> mConditions; 28 29 public Whitelist() { 30 mConditions = new ArrayList<Bundle>(); 31 } 32 33 public Whitelist(List<Bundle> conditions) { 34 this.mConditions = conditions; 35 } 36 37 public void addApp(String app) { 38 Bundle bundle = new Bundle(); 39 bundle.putString("packageName", app); 40 mConditions.add(bundle); 41 } 42 43 /** 44 * @return true if the field is a member of the whitelist. 45 */ 46 public boolean matches(FieldContext context) { 47 for (Bundle condition : mConditions) { 48 if (matches(condition, context.getBundle())) { 49 return true; 50 } 51 } 52 return false; 53 } 54 55 /** 56 * @return true of all values in condition are matched by a value 57 * in target. 58 */ 59 private boolean matches(Bundle condition, Bundle target) { 60 for (String key : condition.keySet()) { 61 if (!condition.getString(key).equals(target.getString(key))) { 62 return false; 63 } 64 } 65 return true; 66 } 67 } 68