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