Created
June 22, 2019 07:56
-
-
Save pratheepchowdhary/f728e6ae9d3a71dc82ecc7983652214d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package in.androidhunt.musicDEmo; | |
import android.app.Application; | |
import android.content.Context; | |
import android.os.Handler; | |
import com.android.volley.Request; | |
import com.android.volley.RequestQueue; | |
import com.android.volley.toolbox.Volley; | |
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator; | |
import com.nostra13.universalimageloader.core.ImageLoader; | |
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; | |
import com.nostra13.universalimageloader.core.assist.QueueProcessingType; | |
public class App extends Application { | |
public static final String TAG = App.class.getSimpleName(); | |
public static final boolean ENCRYPTED = true; | |
public static volatile Handler applicationHandler = null; | |
private static App application; | |
private static Context mContext; | |
private static App mInstance; | |
private RequestQueue mRequestQueue; | |
public static Context getContext() { | |
return mContext; | |
} | |
public static synchronized App getInstance() { | |
return mInstance; | |
} | |
public static void initImageLoader(Context context) { | |
ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); | |
config.threadPriority(Thread.NORM_PRIORITY - 2); | |
config.denyCacheImageMultipleSizesInMemory(); | |
config.diskCacheFileNameGenerator(new Md5FileNameGenerator()); | |
config.diskCacheSize(50 * 1024 * 1024); // 50 MiB | |
config.tasksProcessingOrder(QueueProcessingType.LIFO); | |
config.writeDebugLogs(); // Remove for release app | |
// Initialize ImageLoader with configuration. | |
ImageLoader.getInstance().init(config.build()); | |
} | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
mInstance = this; | |
initImageLoader(getApplicationContext()); | |
application = this; | |
} | |
public RequestQueue getRequestQueue() { | |
if (mRequestQueue == null) { | |
mRequestQueue = Volley.newRequestQueue(getApplicationContext()); | |
} | |
return mRequestQueue; | |
} | |
public <T> void addToRequestQueue(Request<T> req) { | |
req.setTag(TAG); | |
getRequestQueue().add(req); | |
} | |
@Override | |
public void onTerminate() { | |
super.onTerminate(); | |
application = null; | |
} | |
@Override | |
public void onLowMemory() { | |
super.onLowMemory(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment