/ime/latinime/src/com/googlecode/eyesfree/inputmethod/voice/Whitelist.java

http://eyes-free.googlecode.com/ · Java · 68 lines · 34 code · 9 blank · 25 comment · 4 complexity · 09e6df6f01a8a04d67ac4db83e06e8b2 MD5 · raw file

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