Search in sources :

Example 6 with Implementation

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");
    }
}
Also used : RealObject(org.robolectric.annotation.RealObject) Implementation(org.robolectric.annotation.Implementation)

Example 7 with Implementation

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;
    }
}
Also used : HttpResponseCache(android.net.http.HttpResponseCache) Implementation(org.robolectric.annotation.Implementation)

Example 8 with Implementation

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));
}
Also used : Calendar(java.util.Calendar) Implementation(org.robolectric.annotation.Implementation)

Example 9 with Implementation

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;
}
Also used : Toast(android.widget.Toast) Implementation(org.robolectric.annotation.Implementation)

Example 10 with Implementation

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);
}
Also used : ArrayList(java.util.ArrayList) AndroidManifest(org.robolectric.manifest.AndroidManifest) File(java.io.File) Implementation(org.robolectric.annotation.Implementation)

Aggregations

Implementation (org.robolectric.annotation.Implementation)114 Bitmap (android.graphics.Bitmap)17 HiddenApi (org.robolectric.annotation.HiddenApi)10 BitmapDrawable (android.graphics.drawable.BitmapDrawable)6 View (android.view.View)6 IOException (java.io.IOException)6 ContentProvider (android.content.ContentProvider)5 IContentProvider (android.content.IContentProvider)5 AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)5 Rect (android.graphics.Rect)4 Message (android.os.Message)4 RealObject (org.robolectric.annotation.RealObject)4 FileTypedResource (org.robolectric.res.FileTypedResource)4 Point (android.graphics.Point)3 AccessibilityWindowInfo (android.view.accessibility.AccessibilityWindowInfo)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 LinkedList (java.util.LinkedList)3 Activity (android.app.Activity)2 Dialog (android.app.Dialog)2