Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use @ActivityInfo.ScreenOrientation

I try to create a method which returns me the screenorientation dependend on wether the Device is a handheld or a tablet.

public int getScreenOrientation(boolean isTablet){
    if(isTablet){
        return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    } else {
        return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    }
}

But when I use setRequestedOrientation(getScreenOrientation)); I get a lint-error Must be one of: ActivityInfo.SCREEN_ORIENTATION_......... which I can suppress, but that doesn't look like clean code.

So I found, that getRequestedOrientation uses the @ActivityInfo.ScreenOrientation Annotation. So I tried to use it myself:

@ActivityInfo.ScreenOrientation
public int getScreenOrientation(boolean isTablet){
    .
    .
    .
}

But the IDE gives me an error stating that the Annotation @ActivityInfo.ScreenOrientation could not be found. But it is declared public in the official-android-source.

like image 401
JDurstberger Avatar asked Feb 17 '15 08:02

JDurstberger


1 Answers

Put the following comment above the annoying statement where the magic constant inspection for @IntDef and @StringDef annotation is triggered, for example:

//noinspection ResourceType
setRequestOrientation(lock);
like image 82
ecle Avatar answered Oct 14 '22 08:10

ecle