package com.dailystudio.app.ui.utils;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Paint;
import android.os.Build;
import android.view.View;

import com.dailystudio.development.Logger;

import java.lang.reflect.Method;

public class ViewHelper {
	
	private final static int SCREENLAYOUT_SIZE_XLARGE = 4;
	
	public static void disableHardwareAccelerated(View view) {
		if (view == null) {
			return;
		}
		
		if (Build.VERSION.SDK_INT >= 11) {
			try {
				Method method = View.class.getMethod("setLayerType", 
						int.class,
						Paint.class);
				method.invoke(view, 1, new Paint()); 
			} catch (Exception e) {
				Logger.warn("setLayerType() failure: %s", e.toString());
			}
		}
	}
	
	public static boolean isLargeScreen(Context context) {
		if (context == null) {
			return false;
		}
		
		final Resources res = context.getResources();
		if (res == null) {
			return false;
		}
		
		final Configuration config = res.getConfiguration();
		if (config == null) {
			return false;
		}
		
        final int screenSize = 
        	(config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);
        
        return ((screenSize == Configuration.SCREENLAYOUT_SIZE_LARGE)
        		|| (screenSize == SCREENLAYOUT_SIZE_XLARGE));
	}

}

@@ -175,16 +175,46 @@
 .Paint;%0A
+import android.graphics.Rect;%0A
 import a
@@ -230,16 +230,16 @@
 .Build;%0A
-
 import a
@@ -419,17 +419,426 @@
 GE = 4;%0A
-%09
+%0A%09private static int%5B%5D sTempPos = new int%5B2%5D;%0A%0A%09public synchronized static Rect getBoundsOnScreen(View view) %7B%0A%09%09if (view == null) %7B%0A%09%09%09return new Rect(0, 0, 0, 0);%0A%09%09%7D%0A%0A%09%09view.getLocationOnScreen(sTempPos);%0A%0A%09%09Rect rect = new Rect();%0A%09%09rect.set(view.getLeft(), view.getTop(),%0A%09%09%09%09view.getRight(), view.getBottom());%0A%09%09rect.offset(sTempPos%5B0%5D - view.getLeft(), sTempPos%5B1%5D - view.getTop());%0A%0A%09%09return rect;%0A%09%7D%0A
 %0A%09public

add method of ViewHelper to get absolute location of view on the screen;