Skip to content

Instantly share code, notes, and snippets.

@jmhend
jmhend / gist:5999958
Created July 15, 2013 13:32
Two methods from CircleImageView.java, which aims to display a circular image, with a white border and some shadow. Calling Canvas.saveLayer() on line 56 makes the CircleImageView display properly, but causes lots of UI lag (such as scrolling when the CircleImageView is in a ListView, or when a DrawerLayout is opened/closed on top of a View cont…
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (mRectFRound == null) {
return;
}
mRectFRound.set(0, 0, w, h);
mRectFRound.set(0, 0, w, h);
@jmhend
jmhend / gist:5921760
Created July 3, 2013 19:04
Exactly how dangerous is this?
// MyApplication.java
public class MyApplication extends Application {
private MyApplication sInstance;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init(this);
@jmhend
jmhend / gist:5896838
Last active December 19, 2015 04:28
Prevent notifying each of the ArrayAdapter's DataSetObservers on every single add(T object) call to the ArrayAdapter's dataset. Use similar logic for remove() calls.
public class BetterArrayAdapter<T> extends ArrayAdapter<T> {
//...
@Override
public void addAll(Collection<? extends T> collection) {
// Firmware is at least API 11, when ArrayAdapter#addAll() was introduced.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {