// Path: src/main/java/com/google/android/apps/common/testing/accessibility/framework/AccessibilityCheckResult.java
// public enum AccessibilityCheckResultType {
//   /** Clearly an accessibility bug, for example no speakable text on a clicked button */
//   ERROR(ResultTypeProto.ERROR),
//   /**
//    * Potentially an accessibility bug, for example finding another view with the same speakable
//    * text as a clicked view
//    */
//   WARNING(ResultTypeProto.WARNING),
//   /**
//    * Information that may be helpful when evaluating accessibility, for example a listing of all
//    * speakable text in a view hierarchy in the traversal order used by an accessibility service.
//    */
//   INFO(ResultTypeProto.INFO),
//   /**
//    * Indication that a potential issue was identified, but it was resolved as not an accessibility
//    * problem.
//    */
//   RESOLVED(ResultTypeProto.RESOLVED),
//   /** A signal that the check was not run at all (ex. because the API level was too low) */
//   NOT_RUN(ResultTypeProto.NOT_RUN),
//   /**
//    * A result that has been explicitly suppressed from throwing any Exceptions, used to allow for
//    * known issues.
//    */
//   SUPPRESSED(ResultTypeProto.SUPPRESSED);
// 
//   private static final Map<Integer, AccessibilityCheckResultType> PROTO_NUMBER_MAP =
//       new HashMap<>();
// 
//   static {
//     for (AccessibilityCheckResultType type : values()) {
//       PROTO_NUMBER_MAP.put(type.protoNumber, type);
//     }
//   }
// 
//   final int protoNumber;
// 
//   private AccessibilityCheckResultType(ResultTypeProto proto) {
//     this.protoNumber = proto.getNumber();
//   }
// 
//   public static AccessibilityCheckResultType fromProto(ResultTypeProto proto) {
//     AccessibilityCheckResultType type = PROTO_NUMBER_MAP.get(proto.getNumber());
//     checkArgument(
//         (type != null),
//         "Failed to create AccessibilityCheckResultType from proto with unknown value: %s",
//         proto.getNumber());
//     return checkNotNull(type);
//   }
// 
//   public ResultTypeProto toProto() {
//     return ResultTypeProto.forNumber(protoNumber);
//   }
// }
// 
// Path: src/main/java/com/google/android/apps/common/testing/accessibility/framework/strings/StringManager.java
// public final class StringManager {
// 
//   private static final String STRINGS_PACKAGE_NAME =
//       "com.google.android.apps.common.testing.accessibility.framework";
//   private static final String STRINGS_FILE_NAME = "strings";
//   private static @Nullable ResourceBundleProvider resourceBundleProvider;
// 
//   private StringManager() {
//   }
// 
//   /**
//    * Override the default resource bundle used by {@link StringManager}. If no provider is set, a
//    * default ResourceBundle will be used.
//    *
//    * <p>Example usage : If Accessibility Testing Framework is used outside the
//    * AndroidXmlResourceBundle environment or if the ClassLoader does not recognize the xml in
//    * specific package {@link #STRINGS_PACKAGE_NAME}, use this to override the resource provider.
//    */
//   public static void setResourceBundleProvider(ResourceBundleProvider provider) {
//     resourceBundleProvider = provider;
//   }
// 
//   /**
//    * @param locale the desired locale
//    * @param name the name of the {@link String} to get from properties
//    * @return a localized {@link String} corresponding to the given name and locale
//    * @throws MissingResourceException if the string is not found
//    */
//   public static String getString(Locale locale, String name) {
//     return getResourceBundle(locale).getString(name);
//   }
// 
//   private static ResourceBundle getResourceBundle(Locale locale) {
//     if (resourceBundleProvider != null) {
//       return resourceBundleProvider.getResourceBundle(locale);
//     }
// 
//     // ResourceBundle handles necessary caching.
//     try {
//       // Try to load the resources from under the package directory. This is location used for
//       // resource files in JAR files within Google.
//       return ResourceBundle.getBundle(
//           AndroidXMLResourceBundle.Control.getBaseName(STRINGS_PACKAGE_NAME, STRINGS_FILE_NAME),
//           locale,
//           checkNotNull(StringManager.class.getClassLoader()),
//           new AndroidXMLResourceBundle.Control());
//     } catch (MissingResourceException e) {
// 
//       // If that doesn't work, try again, this time without the package name. This is the location
//       // used for assets in an AAR file.
//       return ResourceBundle.getBundle(
//           AndroidXMLResourceBundle.Control.getBaseName("", STRINGS_FILE_NAME),
//           locale,
//           checkNotNull(StringManager.class.getClassLoader()),
//           new AndroidXMLResourceBundle.Control());
//     }
//   }
// 
//   /**
//    * Provider for resource bundle. Use this to override the default resource bundle to use in {@link
//    * StringManager}.
//    */
//   public interface ResourceBundleProvider {
// 
//     /** Returns {@link ResourceBundle} that is suitable for the env, and the ClassLoader. */
//     ResourceBundle getResourceBundle(Locale locale);
//   }
// }


import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResult.AccessibilityCheckResultType;
import com.google.android.apps.common.testing.accessibility.framework.strings.StringManager;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Locale;
/*
 * Copyright (C) 2015 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.android.apps.common.testing.accessibility.framework;


/**
 * Check which may be used to flag use of {@link View#announceForAccessibility(CharSequence)} or
 * dispatch of {@link AccessibilityEvent}s of type {@link AccessibilityEvent#TYPE_ANNOUNCEMENT}. The
 * use of these events, expect in specific situations, can be disruptive to the user.
 */
public class AnnouncementEventCheck extends AccessibilityEventCheck {

  @Override
  public boolean shouldHandleEvent(AccessibilityEvent event) {
    return (event != null) && (event.getEventType() == AccessibilityEvent.TYPE_ANNOUNCEMENT);
  }

  @Override
  public List<AccessibilityEventCheckResult> runCheckOnEvent(AccessibilityEvent event) {

    String message =
// Path: src/main/java/com/google/android/apps/common/testing/accessibility/framework/AccessibilityCheckResult.java
// public enum AccessibilityCheckResultType {
//   /** Clearly an accessibility bug, for example no speakable text on a clicked button */
//   ERROR(ResultTypeProto.ERROR),
//   /**
//    * Potentially an accessibility bug, for example finding another view with the same speakable
//    * text as a clicked view
//    */
//   WARNING(ResultTypeProto.WARNING),
//   /**
//    * Information that may be helpful when evaluating accessibility, for example a listing of all
//    * speakable text in a view hierarchy in the traversal order used by an accessibility service.
//    */
//   INFO(ResultTypeProto.INFO),
//   /**
//    * Indication that a potential issue was identified, but it was resolved as not an accessibility
//    * problem.
//    */
//   RESOLVED(ResultTypeProto.RESOLVED),
//   /** A signal that the check was not run at all (ex. because the API level was too low) */
//   NOT_RUN(ResultTypeProto.NOT_RUN),
//   /**
//    * A result that has been explicitly suppressed from throwing any Exceptions, used to allow for
//    * known issues.
//    */
//   SUPPRESSED(ResultTypeProto.SUPPRESSED);
// 
//   private static final Map<Integer, AccessibilityCheckResultType> PROTO_NUMBER_MAP =
//       new HashMap<>();
// 
//   static {
//     for (AccessibilityCheckResultType type : values()) {
//       PROTO_NUMBER_MAP.put(type.protoNumber, type);
//     }
//   }
// 
//   final int protoNumber;
// 
//   private AccessibilityCheckResultType(ResultTypeProto proto) {
//     this.protoNumber = proto.getNumber();
//   }
// 
//   public static AccessibilityCheckResultType fromProto(ResultTypeProto proto) {
//     AccessibilityCheckResultType type = PROTO_NUMBER_MAP.get(proto.getNumber());
//     checkArgument(
//         (type != null),
//         "Failed to create AccessibilityCheckResultType from proto with unknown value: %s",
//         proto.getNumber());
//     return checkNotNull(type);
//   }
// 
//   public ResultTypeProto toProto() {
//     return ResultTypeProto.forNumber(protoNumber);
//   }
// }
// 
// Path: src/main/java/com/google/android/apps/common/testing/accessibility/framework/strings/StringManager.java
// public final class StringManager {
// 
//   private static final String STRINGS_PACKAGE_NAME =
//       "com.google.android.apps.common.testing.accessibility.framework";
//   private static final String STRINGS_FILE_NAME = "strings";
//   private static @Nullable ResourceBundleProvider resourceBundleProvider;
// 
//   private StringManager() {
//   }
// 
//   /**
//    * Override the default resource bundle used by {@link StringManager}. If no provider is set, a
//    * default ResourceBundle will be used.
//    *
//    * <p>Example usage : If Accessibility Testing Framework is used outside the
//    * AndroidXmlResourceBundle environment or if the ClassLoader does not recognize the xml in
//    * specific package {@link #STRINGS_PACKAGE_NAME}, use this to override the resource provider.
//    */
//   public static void setResourceBundleProvider(ResourceBundleProvider provider) {
//     resourceBundleProvider = provider;
//   }
// 
//   /**
//    * @param locale the desired locale
//    * @param name the name of the {@link String} to get from properties
//    * @return a localized {@link String} corresponding to the given name and locale
//    * @throws MissingResourceException if the string is not found
//    */
//   public static String getString(Locale locale, String name) {
//     return getResourceBundle(locale).getString(name);
//   }
// 
//   private static ResourceBundle getResourceBundle(Locale locale) {
//     if (resourceBundleProvider != null) {
//       return resourceBundleProvider.getResourceBundle(locale);
//     }
// 
//     // ResourceBundle handles necessary caching.
//     try {
//       // Try to load the resources from under the package directory. This is location used for
//       // resource files in JAR files within Google.
//       return ResourceBundle.getBundle(
//           AndroidXMLResourceBundle.Control.getBaseName(STRINGS_PACKAGE_NAME, STRINGS_FILE_NAME),
//           locale,
//           checkNotNull(StringManager.class.getClassLoader()),
//           new AndroidXMLResourceBundle.Control());
//     } catch (MissingResourceException e) {
// 
//       // If that doesn't work, try again, this time without the package name. This is the location
//       // used for assets in an AAR file.
//       return ResourceBundle.getBundle(
//           AndroidXMLResourceBundle.Control.getBaseName("", STRINGS_FILE_NAME),
//           locale,
//           checkNotNull(StringManager.class.getClassLoader()),
//           new AndroidXMLResourceBundle.Control());
//     }
//   }
// 
//   /**
//    * Provider for resource bundle. Use this to override the default resource bundle to use in {@link
//    * StringManager}.
//    */
//   public interface ResourceBundleProvider {
// 
//     /** Returns {@link ResourceBundle} that is suitable for the env, and the ClassLoader. */
//     ResourceBundle getResourceBundle(Locale locale);
//   }
// }


// Path: src/main/java/com/google/android/apps/common/testing/accessibility/framework/AnnouncementEventCheck.java
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResult.AccessibilityCheckResultType;
import com.google.android.apps.common.testing.accessibility.framework.strings.StringManager;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Locale;

/*
 * Copyright (C) 2015 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.android.apps.common.testing.accessibility.framework;


/**
 * Check which may be used to flag use of {@link View#announceForAccessibility(CharSequence)} or
 * dispatch of {@link AccessibilityEvent}s of type {@link AccessibilityEvent#TYPE_ANNOUNCEMENT}. The
 * use of these events, expect in specific situations, can be disruptive to the user.
 */
public class AnnouncementEventCheck extends AccessibilityEventCheck {

  @Override
  public boolean shouldHandleEvent(AccessibilityEvent event) {
    return (event != null) && (event.getEventType() == AccessibilityEvent.TYPE_ANNOUNCEMENT);
  }

  @Override
  public List<AccessibilityEventCheckResult> runCheckOnEvent(AccessibilityEvent event) {

    String message =
        StringManager.getString(Locale.getDefault(), "result_message_disruptive_announcement");