Last active
December 25, 2015 16:59
-
-
Save moizest89/7009635 to your computer and use it in GitHub Desktop.
Simple class to determinate if your device is tablet or phone from your size.
If size > 5 is tablet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.util.DisplayMetrics; | |
public class isTablet { | |
double size_device; | |
public double tabletSize(Context context) { | |
double size = 0; | |
try { | |
// Compute screen size | |
DisplayMetrics dm = context.getResources().getDisplayMetrics(); | |
float screenWidth = dm.widthPixels / dm.xdpi; | |
float screenHeight = dm.heightPixels / dm.ydpi; | |
size = Math.sqrt(Math.pow(screenWidth, 2) + | |
Math.pow(screenHeight, 2)); | |
} catch(Throwable t) { | |
System.out.println("Please verify divece: "+ t.getMessage()); | |
} | |
return size; | |
} | |
public boolean defineDevice(Context context){ | |
size_device = tabletSize(context); | |
if(size_device >= 5){ | |
//Define if are tablet | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment