package org.ligi.androidhelper.helpers;

import android.app.Activity;

public class ActivityHelper {

    private Activity mActivity;

    public ActivityHelper(Activity activity) {
        mActivity =activity;
    }

    public <T> T findById(int id) {
        return (T) mActivity.findViewById(id);
    }
}

package org.ligi.androidhelper.helpers;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;

public class ActivityHelper {

    private Activity mActivity;

    public ActivityHelper(Activity activity) {
        mActivity =activity;
    }

    public <T> T findById(int id) {
        return (T) mActivity.findViewById(id);
    }

    /**
     * dynamically disable rotation
     * to be used in onCreate
     * slightly modified from http://stackoverflow.com/a/8765901/322642
     */
    public void disableRotation() {
        switch (mActivity.getResources().getConfiguration().orientation){
            case Configuration.ORIENTATION_PORTRAIT:
                if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO){
                    mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                } else {
                    int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
                    if(rotation == android.view.Surface.ROTATION_90|| rotation == android.view.Surface.ROTATION_180){
                        mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                    } else {
                        mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                    }
                }
                break;

            case Configuration.ORIENTATION_LANDSCAPE:
                if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO){
                    mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                } else {
                    int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
                    if(rotation == android.view.Surface.ROTATION_0 || rotation == android.view.Surface.ROTATION_90){
                        mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                    } else {
                        mActivity.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() {
        mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    }
}

add function to enable and disable screen rotation