org.robolectric.annotation.Implementation Java Examples

The following examples show how to use org.robolectric.annotation.Implementation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShadowAudioRecord.java    From science-journal with Apache License 2.0 6 votes vote down vote up
@Implementation
protected int read(short[] audioData, int offsetInShorts, int sizeInShorts) {
  synchronized (audioDataLock) {
    if (ShadowAudioRecord.audioData.size() > 0) {
      System.arraycopy(
          Shorts.toArray(
              ShadowAudioRecord.audioData.subList(
                  0,
                  sizeInShorts > ShadowAudioRecord.audioData.size()
                      ? ShadowAudioRecord.audioData.size()
                      : sizeInShorts)),
          0,
          audioData,
          offsetInShorts,
          sizeInShorts);
      if (ShadowAudioRecord.audioData.size() > 10) {
        ShadowAudioRecord.audioData =
            ShadowAudioRecord.audioData.subList(sizeInShorts, ShadowAudioRecord.audioData.size());
      } else {
        ShadowAudioRecord.audioData.clear();
      }
      return sizeInShorts;
    }
    return 0;
  }
}
 
Example #2
Source File: LocaleChangerShadow.java    From adamant-android with GNU General Public License v3.0 6 votes vote down vote up
@Implementation
public static void initialize(Context context,
                              List<Locale> supportedLocales,
                              MatchingAlgorithm matchingAlgorithm,
                              LocalePreference preference) {
    //Block Multiple Initialization Error
    if (calls.get() == 0) {
        calls.compareAndSet(0, 1);
        Shadow.directlyOn(
                LocaleChanger.class,
                "initialize",
                ReflectionHelpers.ClassParameter.from(Context.class, context),
                ReflectionHelpers.ClassParameter.from(List.class, supportedLocales),
                ReflectionHelpers.ClassParameter.from(MatchingAlgorithm.class, matchingAlgorithm),
                ReflectionHelpers.ClassParameter.from(LocalePreference.class, preference)
        );
    }
}
 
Example #3
Source File: ShadowBluetoothLEAdapter.java    From blessed-android with MIT License 6 votes vote down vote up
/**
 * Validate a Bluetooth address, such as "00:43:A8:23:10:F0"
 * <p>Alphabetic characters must be uppercase to be valid.
 *
 * @param address
 *         Bluetooth address as string
 * @return true if the address is valid, false otherwise
 */
@Implementation
public static boolean checkBluetoothAddress(String address) {
    if (address == null || address.length() != ADDRESS_LENGTH) {
        return false;
    }
    for (int i = 0; i < ADDRESS_LENGTH; i++) {
        char c = address.charAt(i);
        switch (i % 3) {
            case 0:
            case 1:
                if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) {
                    // hex character, OK
                    break;
                }
                return false;
            case 2:
                if (c == ':') {
                    break;  // OK
                }
                return false;
        }
    }
    return true;
}
 
Example #4
Source File: ShadowContextImpl.java    From JobSchedulerCompat with MIT License 5 votes vote down vote up
@Implementation
public void removeStickyBroadcast(Intent intent) {
    try {
        ShadowInstrumentation instrumentation = shadowOf(ShadowInstrumentation.getInstrumentation());
        Field field = ShadowInstrumentation.class.getDeclaredField("stickyIntents");
        field.setAccessible(true);
        @SuppressWarnings("unchecked")
        Map<String, Intent> stickyIntents = (Map<String, Intent>) field.get(instrumentation);
        stickyIntents.remove(intent.getAction());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #5
Source File: NetworkSecurityPolicyShadow.java    From android-perftracking with MIT License 5 votes vote down vote up
@SuppressWarnings("ClassNewInstance")
@Implementation
public static NetworkSecurityPolicy getInstance() {
  //noinspection OverlyBroadCatchBlock
  try {
    Class<?> shadow = Class.forName("android.security.NetworkSecurityPolicy");
    return (NetworkSecurityPolicy) shadow.newInstance();
  } catch (Exception e) {
    throw new AssertionError(e);
  }
}
 
Example #6
Source File: ShadowSnackbar.java    From fyber_mobile_offers with MIT License 5 votes vote down vote up
@Implementation
public static Snackbar make(@NonNull View view, @NonNull CharSequence text, int duration) {
    Snackbar snackbar = null;

    try {
        Constructor<Snackbar> constructor = Snackbar.class.getDeclaredConstructor(ViewGroup.class);

        //just in case, maybe they'll change the method signature in the future
        if (null == constructor)
            throw new IllegalArgumentException("Seems like the constructor was not found!");


        if (Modifier.isPrivate(constructor.getModifiers())) {
            constructor.setAccessible(true);
        }

        snackbar = constructor.newInstance(findSuitableParent(view));
        snackbar.setText(text);
        snackbar.setDuration(duration);
    } catch (Exception e) {
        e.printStackTrace();
    }

    shadowOf(snackbar).text = text.toString();

    shadowSnackbars.add(shadowOf(snackbar));

    return snackbar;
}
 
Example #7
Source File: ShadowPointF.java    From spruce-android with MIT License 5 votes vote down vote up
@Override @Implementation
public boolean equals(Object object) {
    if (object == null) return false;
    if (this == object) return true;
    if (object.getClass() != PointF.class) return false;

    PointF that = (PointF) object;
    if (this.realPointF.x == that.x && this.realPointF.y == that.y) return true;

    return false;
}
 
Example #8
Source File: ShadowAudioRecord.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@Implementation
protected void __constructor__(
    int audioSource,
    int sampleRateInHz,
    int channelConfig,
    int audioFormat,
    int bufferSizeInBytes)
    throws IllegalArgumentException {}
 
Example #9
Source File: ShadowLayout.java    From TextLayoutBuilder with Apache License 2.0 5 votes vote down vote up
@Implementation
public static float getDesiredWidth(CharSequence source, TextPaint paint) {
  if (LONG_TEXT.equals(source)) {
    return LONG_TEXT_LENGTH;
  } else if (SHORT_TEXT.equals(source)) {
    return SHORT_TEXT_LENGTH;
  }
  return 0;
}
 
Example #10
Source File: NetworkSecurityPolicyHack.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
@Implementation
public static NetworkSecurityPolicy getInstance() {
    try {
        Class<?> shadow = Class.forName("android.security.NetworkSecurityPolicy");
        return (NetworkSecurityPolicy) shadow.newInstance();
    } catch (Exception e) {
        throw new AssertionError();
    }
}
 
Example #11
Source File: ShadowAsynchUtil.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Implementation
public static void runAsynchronously(final Handler androidUIHandler,
                                     final Runnable call,
                                     final Runnable callback) {
  runnables.add(call);
  runnables.add(callback);
}
 
Example #12
Source File: ShadowStorageUtils.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Implementation
public static File getStorage() {
  try {
    File temp = File.createTempFile("osmdroid", "tmp");
    if (!temp.delete() || !temp.mkdirs()) {
      throw new IllegalStateException("Unable to create temporary directory.");
    }
    temp.deleteOnExit();
    return temp;
  } catch(IOException e) {
    throw new IllegalStateException("Unable to create temporary directory.");
  }
}
 
Example #13
Source File: TrackerShadow.java    From android-perftracking with MIT License 4 votes vote down vote up
@Implementation
public static int startMethod(Object object, String method) {
  return mockTracker.startMethod(object, method);
}
 
Example #14
Source File: ShadowQueryResponseSender.java    From OpenYOLO-Android with Apache License 2.0 4 votes vote down vote up
@Implementation
public void sendResponse(@NonNull BroadcastQuery query, @Nullable byte[] responseMessage) {
    mockQueryResponseSender.sendResponse(query, responseMessage);
}
 
Example #15
Source File: TrackerShadow.java    From android-perftracking with MIT License 4 votes vote down vote up
@Implementation
public static void endMethod(int trackingId) {
  mockTracker.endMethod(trackingId);
}
 
Example #16
Source File: ShadowAudioRecord.java    From science-journal with Apache License 2.0 4 votes vote down vote up
@Implementation
protected void stop() throws IllegalStateException {}
 
Example #17
Source File: TaskbarShadowScrollView.java    From Taskbar with Apache License 2.0 4 votes vote down vote up
@Implementation
public void scrollTo(int x, int y) {
    super.scrollTo(x, y);
}
 
Example #18
Source File: TrackerShadow.java    From android-perftracking with MIT License 4 votes vote down vote up
@Implementation
public static int startUrl(String url, String verb) {
  return mockTracker.startUrl(url, verb);
}
 
Example #19
Source File: ShadowTrafficStats.java    From Battery-Metrics with MIT License 4 votes vote down vote up
@Implementation
public static long getUidTxBytes(int uid) {
  return sTxBytes;
}
 
Example #20
Source File: ShadowAuthenticationDomain.java    From OpenYOLO-Android with Apache License 2.0 4 votes vote down vote up
@Implementation
public static AuthenticationDomain fromPackageName(
        @NonNull Context context,
        @NonNull String packageName) {
    return sAuthDomainLookup.get(packageName);
}
 
Example #21
Source File: TrackerShadow.java    From android-perftracking with MIT License 4 votes vote down vote up
@Implementation
public static void endMetric() {
  mockTracker.endMetric();
}
 
Example #22
Source File: TrackerShadow.java    From android-perftracking with MIT License 4 votes vote down vote up
@Implementation
public static void prolongMetric() {
  mockTracker.prolongMetric();
}
 
Example #23
Source File: TrackerShadow.java    From android-perftracking with MIT License 4 votes vote down vote up
@Implementation
public static void startMetric(String metricId) {
  mockTracker.startMetric(metricId);
}
 
Example #24
Source File: AndroidChannelBuilderTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Implementation(minSdk = N)
protected void registerDefaultNetworkCallback(
    ConnectivityManager.NetworkCallback networkCallback) {
  defaultNetworkCallbacks.add(networkCallback);
}
 
Example #25
Source File: ShadowPicture.java    From TextLayoutBuilder with Apache License 2.0 4 votes vote down vote up
@Implementation
public void __constructor__(int nativePicture) {
  // Do nothing.
}
 
Example #26
Source File: GooglePlayCallbackExtractorTest.java    From firebase-jobdispatcher-android with Apache License 2.0 4 votes vote down vote up
@Implementation
public void writeStrongBinder(IBinder binder) {
  int id = nextBinderId.getAndIncrement();
  binderMap.put(id, binder);
  realObject.writeInt(id);
}
 
Example #27
Source File: NetworkSecurityPolicyShadow.java    From android-perftracking with MIT License 4 votes vote down vote up
@Implementation
public boolean isCleartextTrafficPermitted(String hostname) {
  return true;
}
 
Example #28
Source File: StoreShadow.java    From android-perftracking with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Implementation
public CachingObservable<T> getObservable() {
  return new CachingObservable<>((T) cachedContent);
}
 
Example #29
Source File: TaskbarShadowLauncherApps.java    From Taskbar with Apache License 2.0 4 votes vote down vote up
@Implementation
protected boolean isPackageEnabled(String packageName, UserHandle user) {
    List<String> packages = enabledPackages.get(user);
    return packages != null && packages.contains(packageName);
}
 
Example #30
Source File: TrackerShadow.java    From android-perftracking with MIT License 4 votes vote down vote up
@Implementation
public static int startCustom(String measurementId) {
  return mockTracker.startCustom(measurementId);
}