Skip to content

Instantly share code, notes, and snippets.

View viralsavani's full-sized avatar

Viral Savani viralsavani

  • Long Beach, California, United States
View GitHub Profile
@viralsavani
viralsavani / ImageLoader.java
Created March 22, 2017 04:31
Image Loading Backoff
// Originally appeared in https://android-developers.googleblog.com/2017/03/getting-santa-tracker-into-shape.html
// Naive way to load bitmap
private LruCache<Integer, Drawable> mMemoryCache;
private BitmapFactory.Options mOptions;
public void init() {
// Initialize the cache
mMemoryCache = new LruCache<Integer, Drawable>(240);
// Start with no Bitmap sampling
mOptions = new BitmapFactory.Options();
@viralsavani
viralsavani / gist:d51e2aa56fd7343ad52a78d0e273a47d
Created June 10, 2016 21:24 — forked from mediavrog/gist:5625602
Filter out Intents you don"t want to show from a IntentChooser dialog. For example your own app, competing apps or just apps you have a share integration by SDK already :) Based on http://stackoverflow.com/questions/5734678/custom-filtering-of-intent-chooser-based-on-installed-android-package-name/8550043#8550043
// Usage:
// blacklist
String[] blacklist = new String[]{"com.any.package", "net.other.package"};
// your share intent
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "some text");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "a subject");
// ... anything else you want to add
// invoke custom chooser
public int findArray(int[] array, int[] subArray) {
/**
* Assuming that null argument may result in Exception. We can also return -1
* if not an exception
*/
if (array == null || subArray == null){
throw new IllegalArgumentException("Entered array cannot be null");
}