Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "Organize Imports" in Android Studio for static imports

I'm using version 0.3.7 of Android Studio, and I'm trying out OpenGL ES programming. This requires a lot of imports from such classes as "android.opengl.GLES20"

Instead of auto importing GLES20 and accessing for example, the GL_COMPILE_STATUS variable like so:

glGetShaderiv(shaderObjectID, GLES20.GL_COMPILE_STATUS, compileStatus, 0);

I'd rather type in GL_COMPILE_STATUS and have it auto import the following:

import static android.opengl.GLES20.GL_COMPILE_STATUS;
...
glGetShaderiv(shaderObjectID, GL_COMPILE_STATUS, compileStatus, 0);

And have the above import found as I type in GL_COMPILE_STATUS.

But the current system will not know that GL_COMPILE_STATUS comes from the GLES20 class. So my question is this, is there a way to assist the organize imports functionality in Android Studio for finding these variable? I'd like to keep my code to a minimum, and having to write GLES20. in front of everything is a little off putting - and I won't use a wildcard import as I consider that bad practice.

like image 787
Adam Hoddinott Avatar asked Oct 03 '22 05:10

Adam Hoddinott


1 Answers

The answers of this post will help you.

  1. set the packages you want import in Settings -> Code Style -> Java -> Imports
  2. press ctrl+space two times and then alt + enter to import it statically without full qualifier.
like image 168
Stefan Avatar answered Oct 10 '22 01:10

Stefan