Created
March 13, 2014 15:15
-
-
Save Kursulla/9530370 to your computer and use it in GitHub Desktop.
Small utils for Android
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.app.Activity; | |
import android.content.Context; | |
import android.content.pm.ActivityInfo; | |
import android.content.res.Configuration; | |
/** | |
* Created by kursulla on 3/13/14. | |
*/ | |
public class AndroidUtil { | |
public static boolean isTablet(Context context) { | |
boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4); | |
boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE); | |
return (xlarge || large); | |
} | |
/** | |
* Set only portrait orientation for phones, and only landscape orientation for tablets | |
* | |
* @param activity Activity for accessing system resources | |
*/ | |
public static void setScreenOrientation(Activity activity) { | |
if (AndroidUtil.isTablet(activity)) { | |
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | |
} else { | |
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment