Skip to content

Instantly share code, notes, and snippets.

View ryancford's full-sized avatar

Ryan Ford ryancford

  • Fandango
  • Los Angeles, CA
  • 17:47 (UTC -08:00)
View GitHub Profile
@ryancford
ryancford / getStatusBarHeight.java
Created December 8, 2015 02:25
Returns the height of the status bar in pixels.
public static int getStatusBarHeight() {
int result = 0;
int resourceId = mContext.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = mContext.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
@ryancford
ryancford / getThemeAttributeDimensionSize.java
Created December 8, 2015 02:25
Returns dimension size in pixels for a given Theme Attribute.
public static int getThemeAttributeDimensionSize(Context context, int attr)
{
TypedArray a = null;
try{
a = context.getTheme().obtainStyledAttributes(new int[] { attr });
return a.getDimensionPixelSize(0, 0);
}finally{
if(a != null){
a.recycle();
}
@ryancford
ryancford / TrimMemory.java
Created December 3, 2015 01:06
Log calls to onTrimMemory().
@Override
public void onTrimMemory(int level) {
super.onTrimMemory(level);
String levelString = "TRIM_MEMORY_RUNNING_MODERATE";
switch (level) {
case TRIM_MEMORY_RUNNING_MODERATE: levelString = "TRIM_MEMORY_RUNNING_MODERATE"; break;
case TRIM_MEMORY_RUNNING_LOW: levelString = "TRIM_MEMORY_RUNNING_LOW"; break;
case TRIM_MEMORY_RUNNING_CRITICAL: levelString = "TRIM_MEMORY_RUNNING_CRITICAL"; break;
@ryancford
ryancford / ScrollDirectionDetection.java
Created December 1, 2015 03:12
Manual scroll detection.
private static final String DEBUG_TAG = "ScrollDirectionDebug";
private float y = -1;
private String mScrollDirection = "";
// OnTouchEvent is picked up by the child view that handles the event
// So we use dispatchTouchEvent which all events pass through
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
Log.d(DEBUG_TAG, "Action was " + event.toString());
int action = MotionEventCompat.getActionMasked(event);