All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robolectric.shadows.ShadowInputEventReceiver Maven / Gradle / Ivy

The newest version!
package org.robolectric.shadows;

import android.view.InputEventReceiver;
import dalvik.system.CloseGuard;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.ReflectorObject;
import org.robolectric.util.reflector.Accessor;
import org.robolectric.util.reflector.Direct;
import org.robolectric.util.reflector.ForType;

@Implements(value = InputEventReceiver.class, isInAndroidSdk = false)
public class ShadowInputEventReceiver {

  @ReflectorObject private InputEventReceiverReflector inputEventReceiverReflector;

  @Implementation
  @SuppressWarnings("robolectric.ShadowReturnTypeMismatch")
  public void consumeBatchedInputEvents(long frameTimeNanos) {
    // The real implementation of this calls a JNI method, and logs a statement if the native
    // object isn't present. Since the native object will never be present in Robolectric tests, it
    // ends up being rather spammy in test logs, so we no-op it.
  }

  @Implementation
  protected void dispose(boolean finalized) {
    CloseGuard closeGuard = inputEventReceiverReflector.getCloseGuard();
    // Suppresses noisy CloseGuard warning
    if (closeGuard != null) {
      closeGuard.close();
    }
    inputEventReceiverReflector.dispose(finalized);
  }

  /** Reflector interface for {@link InputEventReceiver}'s internals. */
  @ForType(InputEventReceiver.class)
  interface InputEventReceiverReflector {

    @Direct
    void dispose(boolean finalized);

    @Accessor("mCloseGuard")
    CloseGuard getCloseGuard();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy