WMS 之 多屏

 WMS (Android全面解析之Window机制WMS ( 负责管理window, window可绑定一个或多个Display物理设备, 也可生成镜像 到 VirtualDisplay  

以下通过模拟器 模拟一个扩展屏

 选择其中一项  默认会复制主屏的内容 我们通过代码设置后 辅屏就可以显示独立的内容了

常见的HDMI 及车载多屏app 基本都通过Presentation 实现

public class Presentation extends Dialog  

可见Presentation也是个window通过下面的方法切换显示设备

    /**
     * Return a new Context object for the current Context but whose resources
     * are adjusted to match the metrics of the given Display.  Each call to this method
     * returns a new instance of a Context object; Context objects are not
     * shared, however common state (ClassLoader, other Resources for the
     * same configuration) may be so the Context itself can be fairly lightweight.
     *
     * To obtain an instance of a {@link WindowManager} (see {@link #getSystemService(String)}) that
     * is configured to show windows on the given display call
     * {@link #createWindowContext(int, Bundle)} on the returned display Context or use an
     * {@link android.app.Activity}.
     *
     * @param display A {@link Display} object specifying the display for whose metrics the
     * Context's resources should be tailored.
     *
     * @return A {@link Context} for the display.
     */
    public abstract Context createDisplayContext(@NonNull Display display);

 生成了新的ContextThemWrapper  ,下面是主要代码

fun showSecond() {
        val wm = windowManager
        val displaService = getSystemService(DISPLAY_SERVICE) as DisplayManager
        val displays = displaService.displays
        for (display in displays) {
            Log.d("display", display.toString())
        }
        if (displays.size > 1) {
//            createDisplayContext(displays[1])
            val presentation: Presentation = SecondPresentation(this, displays[1])
            presentation.show()


        }
    }



class SecondPresentation(outerContext: Context?, display: Display?) :
    Presentation(outerContext, display) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_second_dispaly_p);
        initViews()
    }

    private fun initViews() {
        findViewById<TextView>(R.id.tv).setOnClickListener { v ->
            Toast.makeText(context, "tv", Toast.LENGTH_LONG).show()
        }

        findViewById<Button>(R.id.button).setOnClickListener {
            Toast.makeText(context, "bt", Toast.LENGTH_LONG).show()

        }


    }


}

自定义GL环境的 openGL 关联的本地窗口默认如下   多屏应用中则需要修改对应的设备ID

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值