Skip to content

Instantly share code, notes, and snippets.

Ryan Ford ryancford

  • Los Angeles, CA
View GitHub Profile
@ryancford
ryancford / getStatusBarHeight.java
Created Dec 8, 2015
Returns the height of the status bar in pixels.
View getStatusBarHeight.java
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 Dec 8, 2015
Returns dimension size in pixels for a given Theme Attribute.
View getThemeAttributeDimensionSize.java
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 Dec 3, 2015
Log calls to onTrimMemory().
View TrimMemory.java
@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;
View ScrollDirectionDetection.java
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);
You can’t perform that action at this time.