use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowFilter method filter.
@Implementation
public void filter(CharSequence constraint, Filter.FilterListener listener) {
try {
Class<?> forName = Class.forName("android.widget.Filter$FilterResults");
Object filtering = ReflectionHelpers.callInstanceMethod(realObject, "performFiltering", ClassParameter.from(CharSequence.class, constraint));
ReflectionHelpers.callInstanceMethod(realObject, "publishResults", ClassParameter.from(CharSequence.class, constraint), ClassParameter.from(forName, filtering));
if (listener != null) {
int count = filtering == null ? -1 : (int) ReflectionHelpers.getField(filtering, "count");
listener.onFilterComplete(count);
}
} catch (ClassNotFoundException e) {
throw new RuntimeException("Cannot load android.widget.Filter$FilterResults");
}
}
use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowHttpResponseCache method install.
@Implementation
public static HttpResponseCache install(File directory, long maxSize) {
HttpResponseCache cache = newInstanceOf(HttpResponseCache.class);
ShadowHttpResponseCache shadowCache = Shadows.shadowOf(cache);
shadowCache.originalObject = cache;
shadowCache.directory = directory;
shadowCache.maxSize = maxSize;
synchronized (LOCK) {
installed = shadowCache;
return cache;
}
}
use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowTime method set.
@Implementation(maxSdk = KITKAT_WATCH)
public void set(long millis) {
Calendar c = getCalendar();
c.setTimeInMillis(millis);
set(c.get(Calendar.SECOND), c.get(Calendar.MINUTE), c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.MONTH), c.get(Calendar.YEAR));
}
use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowToast method makeText.
@Implementation
public static Toast makeText(Context context, CharSequence text, int duration) {
Toast toast = new Toast(context);
toast.setDuration(duration);
shadowOf(toast).text = text.toString();
return toast;
}
use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowTypeface method createFromAsset.
@Implementation
public static Typeface createFromAsset(AssetManager mgr, String path) {
AndroidManifest appManifest = Shadows.shadowOf(RuntimeEnvironment.application).getAppManifest();
ArrayList<String> paths = new ArrayList<>();
paths.add(getAssetsPath(appManifest, path));
List<AndroidManifest> libraryManifests = appManifest.getLibraryManifests();
for (AndroidManifest libraryManifest : libraryManifests) {
paths.add(getAssetsPath(libraryManifest, path));
}
for (String assetPath : paths) {
if (new File(assetPath).exists()) {
return createUnderlyingTypeface(path, Typeface.NORMAL);
}
}
throw new RuntimeException("Font not found at " + paths);
}
Aggregations