【Android显示系统初探】多屏显示Presentation的使用

Presentation通过指定displayID来决定显示在哪个屏幕上,这样就实现了多屏幕的显示(如果手机有多个显示设备),

也就让不同的屏幕可以显示不同的画面,

在只有一个显示设备的情况下,我们可以打开开发者选项中的设置来模拟多屏,进而来测试Presentation。

在开发者选项的Drawing中有

Simulate secondary displays开关

打开后,在界面可以显示一个模拟出来的小屏幕

 

dumpsys display

可以查看到模拟屏幕的信息

Logical Displays: size=2

  Display 0:

    mDisplayId=0

 

  Display 5:

    mDisplayId=5

    mLayerStack=5

    mHasContent=false

    mRequestedMode=0

    mRequestedColorMode=0

    mDisplayOffset=(0, 0)

    mPrimaryDisplayDevice=Overlay #1

 

这里我们直接使用Display 5来进行测试

public class MainActivity extends ActionBarActivity {

 

  private Button mButton;

  private Button mButton2;

  private Button mButton3;

 

  private String  TAG = "testvirsual";

 

  private DisplayManager mDisplayManager;

    private static final int BLUEISH = 0xff1122ee;

   

  @SuppressLint("NewApi")

  private final class TestPresentation extends Presentation {

        private final int mColor;

        private final int mWindowType;

        private final int mWindowFlags;

       

protected void finalize( )

{

// finalization code here

Log.d(TAG, "======= finalize ()");

}

        public TestPresentation(Context context, Display display,

                                int color, int windowType, int windowFlags) {   

            super(context, display);

            Log.d(TAG, "======= TestPresentation ()");

            mColor = color;

            mWindowType = windowType;

            mWindowFlags = windowFlags;

        }

 

        @Override

        protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

Log.d(TAG, "======= TestPresentation onCreate");

            setTitle(TAG);

            getWindow().setType(mWindowType);

            getWindow().addFlags(mWindowFlags);

 

            // Create a solid color image to use as the content of the presentation.

            ImageView view = new ImageView(getContext());

            view.setImageDrawable(new ColorDrawable(mColor));

            view.setLayoutParams(new LayoutParams(

                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

            setContentView(view);

 Log.d(TAG, "======= TestPresentation onCreate done");

        }

    }

 

public TestPresentation mpresentation;

public Display defaultDisplay;

 

   private void assertDisplayCanShowPresentation(String message, final Display display,

             final int color, final int windowType, final int windowFlags) {

//final TestPresentation[] presentation = new TestPresentation[1];

// mpresentation = new TestPresentation[1];

      try {

 

        Log.d(TAG, "======== TestPresentation run called");

        mpresentation = new TestPresentation(MainActivity.this, display,

        color, windowType, windowFlags);

        Log.d(TAG, "======== TestPresentation show called");

        mpresentation.show();

 

       } finally {

 

       }

   }

 

 

      mButton3.setOnClickListener(new OnClickListener() {          

          @Override

          public void onClick(View arg0) {

             Log.d(TAG, "======= going to call assertDisplayCanShowPresentation");

             Display aDisplay = mDisplayManager.getDisplay(5);

               // Show a private presentation on the display.

               assertDisplayCanShowPresentation("presentation window",

                    aDisplay, BLUEISH,

                       WindowManager.LayoutParams.TYPE_TOAST, 0);

          }

 

 

 

可以在模拟屏上显示查看到实际存在的另外一个屏幕的效果

发布了336 篇原创文章 · 获赞 13 · 访问量 33万+

猜你喜欢

转载自blog.csdn.net/aaajj/article/details/90575622