Back to project page FAST.
The source code is released under:
GNU General Public License
If you think the Android project FAST listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.ligi.axt.helpers; /*www .ja v a 2 s . co m*/ import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.Activity; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.view.View; public class ActivityHelper extends ContextHelper { private final Activity activity; public ActivityHelper(Activity activity) { super (activity); this.activity =activity; } public <T extends View> T findById(int id) { return (T) activity.findViewById(id); } /** * dynamically disable rotation * to be used in onCreate * slightly modified from http://stackoverflow.com/a/8765901/322642 */ // @TargetApi(5) // TODO find out why the above is not working and I need to use SupressLint to get rid of the error @SuppressLint("newApi") public void disableRotation() { switch (activity.getResources().getConfiguration().orientation){ case Configuration.ORIENTATION_PORTRAIT: if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO){ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); if(rotation == android.view.Surface.ROTATION_90|| rotation == android.view.Surface.ROTATION_180){ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } break; case Configuration.ORIENTATION_LANDSCAPE: if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO){ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); if(rotation == android.view.Surface.ROTATION_0 || rotation == android.view.Surface.ROTATION_90){ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } break; }//switch } /** * dynamically enable rotation * counterpart to enableRotation * slightly modified from http://stackoverflow.com/a/8765901/322642 */ public void enableRotation() { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } }