Android Open Source - soas Volley Idling Resource






From Project

Back to project page soas.

License

The source code is released under:

Apache License

If you think the Android project soas listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.meg7.soas.espresso;
/*from www . j av a  2  s.c o m*/
import android.app.Activity;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.VolleyLog;
import com.google.android.apps.common.testing.ui.espresso.IdlingResource;
import com.google.common.base.Preconditions;
import com.meg7.soas.SoasApplication;

import java.lang.reflect.Field;
import java.util.Set;

// Based on https://github.com/bolhoso/espresso-volley-tests/blob/master/EspressoTest/src/com/example/espressovolley/test/MyTest.java
public class VolleyIdlingResource implements IdlingResource {

    private final String mResourceName;

    // Write on main thread, read from any thread.
    private volatile ResourceCallback mResourceCallback;

    private Field mCurrentRequests;
    private RequestQueue mVolleyRequestQueue;

    public VolleyIdlingResource(Activity activity, String resourceName) throws SecurityException, NoSuchFieldException {
        mResourceName = Preconditions.checkNotNull(resourceName);

        mVolleyRequestQueue = SoasApplication.getRequestQueue(activity);

        mCurrentRequests = RequestQueue.class.getDeclaredField("mCurrentRequests");
        mCurrentRequests.setAccessible(true);
    }

    @Override
    public String getName() {
        return mResourceName;
    }

    @Override
    public boolean isIdleNow() {
        try {
            Set<Request> set = (Set<Request>) mCurrentRequests.get(mVolleyRequestQueue);
            if (set != null) {
                int count = set.size();
                if (count == 0) {
                    VolleyLog.d("Volley is idle! With count :: " + count);
                    mResourceCallback.onTransitionToIdle();
                } else {
                    VolleyLog.d("Volley is Not idle! With count :: " + count);
                }

                return count == 0;
            }
        } catch (Exception e) {
            VolleyLog.e(e.getMessage());
        }

        VolleyLog.d("Something went wrong!");
        return true;
    }

    @Override
    public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
        mResourceCallback = resourceCallback;
    }

}




Java Source Code List

com.meg7.soas.ApplicationTest.java
com.meg7.soas.SoasApplication.java
com.meg7.soas.data.Location.java
com.meg7.soas.data.OfflineNote.java
com.meg7.soas.data.Photo.java
com.meg7.soas.data.Photos.java
com.meg7.soas.database.DatabaseHelper.java
com.meg7.soas.database.OfflineNotesDataSource.java
com.meg7.soas.database.provider.OfflineNotesProvider.java
com.meg7.soas.database.provider.ProviderConstants.java
com.meg7.soas.database.provider.ProviderConstants.java
com.meg7.soas.espresso.LongListMatchers.java
com.meg7.soas.espresso.PhotosListActivityEspressoTest.java
com.meg7.soas.espresso.VolleyIdlingResource.java
com.meg7.soas.http.HttpConstants.java
com.meg7.soas.http.HttpHeaderParser.java
com.meg7.soas.http.request.GsonGetRequest.java
com.meg7.soas.http.util.UrlBuilder.java
com.meg7.soas.ui.BaseActivity.java
com.meg7.soas.ui.PhotoDetailActivity.java
com.meg7.soas.ui.PhotosListActivity.java
com.meg7.soas.ui.adapter.BaseEndlessAdapter.java
com.meg7.soas.ui.adapter.BaseEndlessScrollListener.java
com.meg7.soas.ui.adapter.PhotosAdapter.java
com.meg7.soas.ui.fragment.PhotoDetailFragment.java
com.meg7.soas.ui.fragment.PhotosListFragment.java
com.meg7.soas.ui.fragment.SwipeRefreshListFragment.java
com.meg7.soas.ui.fragment.retained.PhotosListTaskFragment.java
com.meg7.soas.ui.view.PhotoView.java
com.meg7.soas.ui.widget.BaseFadeInNetworkImageView.java
com.meg7.soas.ui.widget.RectangleFadeInNetworkImageView.java
com.meg7.soas.ui.widget.RoundedFadeInNetworkImageView.java
com.meg7.soas.unit.PhotosListActivityUnitTest.java
com.meg7.soas.util.BitmapLruCache.java
com.meg7.soas.util.SdkUtils.java
com.meg7.widget.RecyclingBitmapDrawable.java
com.meg7.widget.RecyclingImageView.java