Android Open Source - Chopping Task Helper






From Project

Back to project page Chopping.

License

The source code is released under:

Apache License

If you think the Android project Chopping 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.chopping.net;
/*from  w w  w  .  j  a  v  a2  s .  co  m*/
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageLoader.ImageCache;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;


public final class TaskHelper {

  private static final int MAX_IMAGE_CACHE_ENTIRES = 100;
  private static final Gson sGson = new Gson();
  private static RequestQueue sRequestQueue;
  private static ImageLoader sImageLoader;


  private TaskHelper() {
    // no instances
  }


  public static void init(Context _context) {
    sRequestQueue = Volley.newRequestQueue(_context);
    sImageLoader = new ImageLoader(sRequestQueue, new BitmapLruCache(MAX_IMAGE_CACHE_ENTIRES));
  }


  public static RequestQueue getRequestQueue() {
    if (sRequestQueue != null) {
      return sRequestQueue;
    } else {
      throw new IllegalStateException("RequestQueue not initialized");
    }
  }


  /**
   * Returns instance of ImageLoader initialized with {@see FakeImageCache}
   * which effectively means that no memory caching is used. This is useful
   * for images that you know that will be show only once.
   * 
   * @return
   */
  public static ImageLoader getImageLoader() {
    if (sImageLoader != null) {
      return sImageLoader;
    } else {
      throw new IllegalStateException("ImageLoader not initialized");
    }
  }


  public static Gson getGson() {
    return sGson;
  }


  public static class BitmapLruCache extends LruCache<String, Bitmap> implements ImageCache {

    public BitmapLruCache(int maxSize) {
      super(maxSize);
    }


    @Override
    protected int sizeOf(String _key, Bitmap _value) {
      return _value.getRowBytes() * _value.getHeight();
    }


    @Override
    public Bitmap getBitmap(String _url) {
      return get(_url);
    }


    @Override
    public void putBitmap(String _url, Bitmap _bitmap) {
      put(_url, _bitmap);
    }
  }
}




Java Source Code List

com.android.internal.telephony.ITelephony.java
com.chopping.ApplicationTest.java
com.chopping.activities.BaseActivity.java
com.chopping.activities.BrightnessRefreshActivity.java
com.chopping.activities.ErrorHandlerActivity.java
com.chopping.application.BasicPrefs.java
com.chopping.application.ErrorHandler.java
com.chopping.application.IApp.java
com.chopping.application.InstalledAppReceiver.java
com.chopping.application.LL.java
com.chopping.bus.AirplaneModeOnEvent.java
com.chopping.bus.ApplicationConfigurationDownloadedEvent.java
com.chopping.bus.ApplicationConfigurationLoadingIgnoredEvent.java
com.chopping.bus.CloseDrawerEvent.java
com.chopping.bus.ExternalAppChangedEvent.java
com.chopping.bus.LinkToExternalAppEvent.java
com.chopping.bus.ReloadEvent.java
com.chopping.data.AppListItem.java
com.chopping.data.AppList.java
com.chopping.exceptions.CanNotOpenOrFindAppPropertiesException.java
com.chopping.exceptions.InvalidAppPropertiesException.java
com.chopping.exceptions.OperationFailException.java
com.chopping.fragments.AppListFragment.java
com.chopping.fragments.BaseFragment.java
com.chopping.fragments.ErrorHandlerFragment.java
com.chopping.net.GsonRequestTask.java
com.chopping.net.TaskHelper.java
com.chopping.utils.Consts.java
com.chopping.utils.DeviceUtils.java
com.chopping.utils.IncomingCallReceiver.java
com.chopping.utils.MediaUtils.java
com.chopping.utils.NetworkUtils.java
com.chopping.utils.Utils.java
com.chopping.utils.views.OneDirectionScrollView.java