danialgoodwin / core-android Goto Github PK
View Code? Open in Web Editor NEWA collection of short helper classes that I use in Android apps.
A collection of short helper classes that I use in Android apps.
I thought the additional method can come in handy, check it out:
/** Static methods related to device orientation. */
public class OrientationUtils {
private OrientationUtils() {}
/** Returns true if device in in landscape mode, otherwise false. */
public static boolean isLandscape(Context context) {
return context.getResources().getConfiguration().orientation
== Configuration.ORIENTATION_LANDSCAPE;
}
/** Returns true if device in in portrait mode, otherwise false. */
public static boolean isPortrait(Context context) {
return context.getResources().getConfiguration().orientation
== Configuration.ORIENTATION_PORTRAIT;
}
/** Returns the screen orientation, which can be any of the following:
* Configuration.ORIENTATION_LANDSCAPE
* Configuration.ORIENTATION_PORTRAIT
* Configuration.ORIENTATION_SQUARE
* Configuration.ORIENTATION_UNDEFINED
*/
@Deprecated
public static int getScreenOrientation(Activity activity) {
Display getOrient = activity.getWindowManager().getDefaultDisplay();
int orientation = Configuration.ORIENTATION_UNDEFINED;
if (getOrient.getWidth() == getOrient.getHeight()) {
orientation = Configuration.ORIENTATION_SQUARE;
} else {
if (getOrient.getWidth() < getOrient.getHeight()) {
orientation = Configuration.ORIENTATION_PORTRAIT;
} else {
orientation = Configuration.ORIENTATION_LANDSCAPE;
}
}
return orientation;
}
/** Locks the device window in landscape mode. */
public static void setOrientationLandscape(Activity activity) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
/** Locks the device window in portrait mode. */
public static void setOrientationPortrait(Activity activity) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
/** Locks the device window in the current orientation. */
public static void setCurrentOrientation(Activity activity) {
int orientation = Configuration.ORIENTATION_UNDEFINED;
activity.getRequestedOrientation();
int rotation = ((WindowManager) activity.getSystemService(
Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
switch (rotation) {
case Surface.ROTATION_0:
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
break;
case Surface.ROTATION_90:
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
break;
case Surface.ROTATION_180:
orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
break;
default:
orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
break;
}
activity.setRequestedOrientation(orientation);
}
/** Allows user to freely use portrait or landscape mode. */
public static void unlockOrientation(Activity activity) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.