1/* 2 * Copyright (C) 2009 The Android Open Source Project 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 17package com.android.inputmethod.deprecated.voice; 18 19import android.os.Bundle; 20 21import java.util.ArrayList; 22import java.util.List; 23 24/** 25 * A set of text fields where speech has been explicitly enabled. 26 */ 27public class Whitelist { 28 private List<Bundle> mConditions; 29 30 public Whitelist() { 31 mConditions = new ArrayList<Bundle>(); 32 } 33 34 public Whitelist(List<Bundle> conditions) { 35 this.mConditions = conditions; 36 } 37 38 public void addApp(String app) { 39 Bundle bundle = new Bundle(); 40 bundle.putString("packageName", app); 41 mConditions.add(bundle); 42 } 43 44 /** 45 * @return true if the field is a member of the whitelist. 46 */ 47 public boolean matches(FieldContext context) { 48 for (Bundle condition : mConditions) { 49 if (matches(condition, context.getBundle())) { 50 return true; 51 } 52 } 53 return false; 54 } 55 56 /** 57 * @return true of all values in condition are matched by a value 58 * in target. 59 */ 60 private boolean matches(Bundle condition, Bundle target) { 61 for (String key : condition.keySet()) { 62 if (!condition.getString(key).equals(target.getString(key))) { 63 return false; 64 } 65 } 66 return true; 67 } 68} 69