The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2029 lines
102KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. // This byte-code is generated from native/java/com/rmsl/juce/ComponentPeerView.java with min sdk version 16
  21. // See juce_core/native/java/README.txt on how to generate this byte-code.
  22. static const uint8 javaComponentPeerView[] =
  23. {31,139,8,8,244,59,63,97,0,3,74,97,118,97,68,101,120,66,121,116,101,67,111,100,101,46,100,101,120,0,165,155,9,120,91,197,181,
  24. 199,207,204,213,98,203,178,45,203,137,237,36,86,44,59,155,226,196,182,156,61,56,64,118,226,196,89,136,29,67,236,180,141,108,95,
  25. 219,74,228,43,69,146,55,66,31,41,80,8,75,41,75,216,67,129,54,165,27,143,165,44,31,229,81,186,1,165,101,41,180,240,160,45,180,
  26. 208,242,74,88,74,83,118,104,31,188,255,153,59,178,229,44,77,219,231,124,191,123,206,204,156,153,59,119,230,204,153,185,215,113,
  27. 151,57,228,9,207,157,79,197,179,155,15,182,174,201,59,197,108,45,216,252,173,174,187,158,170,250,166,177,120,119,238,69,203,47,
  28. 157,71,148,32,162,161,214,121,126,210,63,143,207,37,10,8,59,127,17,120,197,65,180,28,242,33,39,81,25,228,11,57,68,103,64,238,
  29. 207,37,66,17,197,242,137,14,76,39,122,19,242,242,0,209,62,112,53,184,14,124,21,220,2,30,4,63,2,15,131,71,193,227,224,41,240,43,
  30. 240,28,120,31,20,78,38,242,131,18,48,17,76,6,83,64,8,212,128,85,96,55,184,10,220,9,30,7,111,2,111,5,209,66,112,42,216,1,206,
  31. 2,87,130,219,192,207,193,123,192,19,36,154,10,182,129,207,131,59,192,43,160,188,146,168,9,164,192,141,224,73,80,88,69,116,26,
  32. 184,28,220,3,126,13,62,2,229,83,136,26,192,22,208,11,46,6,223,5,63,5,175,131,79,64,96,42,81,61,216,14,206,4,87,128,3,224,94,240,
  33. 0,248,57,120,2,60,13,158,7,47,128,87,192,235,224,16,120,15,124,4,62,1,198,52,162,28,80,0,252,96,34,8,128,42,16,2,53,96,30,56,
  34. 1,156,4,86,128,117,96,51,104,5,109,192,2,231,128,47,131,235,193,55,192,93,224,7,224,49,240,28,248,35,248,11,248,59,200,195,60,
  35. 86,130,153,96,1,88,10,218,65,55,136,130,51,193,185,224,98,176,15,220,48,221,158,251,59,193,131,224,73,240,34,248,19,248,51,240,
  36. 204,32,242,129,98,48,17,44,1,167,128,13,96,27,136,130,243,192,1,112,59,120,4,60,11,126,15,222,0,31,1,71,136,104,2,168,5,139,
  37. 193,90,112,58,136,128,29,96,16,92,0,174,5,183,129,239,131,39,192,27,224,175,224,3,240,49,200,155,137,241,3,117,224,36,176,14,
  38. 68,64,18,156,3,46,7,55,130,187,193,131,224,57,240,50,120,21,188,14,222,7,127,3,222,106,162,73,96,54,88,8,86,129,141,224,52,208,
  39. 9,250,192,94,112,5,216,15,238,1,15,129,199,192,111,192,75,224,32,56,4,222,1,31,1,57,11,237,130,137,160,10,132,64,45,88,6,90,65,
  40. 47,216,13,174,1,223,1,15,130,231,192,239,193,91,224,19,174,63,155,168,20,76,7,117,96,49,88,3,90,193,103,65,15,216,5,134,192,
  41. 185,224,10,112,29,248,30,120,0,60,12,94,3,238,26,248,28,40,6,83,64,61,88,11,218,64,47,56,27,92,11,238,5,63,1,191,4,191,3,111,
  42. 129,191,131,188,90,140,15,168,6,43,193,90,176,9,156,14,182,131,110,176,19,236,2,187,193,127,128,47,130,75,192,62,240,117,112,
  43. 7,248,49,120,26,188,8,94,2,127,4,175,130,55,192,95,192,59,224,3,224,66,12,66,72,162,60,80,2,74,201,142,83,19,192,68,48,9,148,
  44. 3,132,24,66,184,32,132,3,194,210,39,44,117,194,178,38,44,91,194,114,35,184,63,193,101,9,46,71,112,23,194,84,19,166,134,48,180,
  45. 132,97,33,60,26,225,118,84,7,194,160,30,204,1,8,151,132,48,74,243,193,2,176,80,199,205,197,224,4,208,0,150,128,19,193,73,224,
  46. 100,176,20,44,35,59,174,174,0,171,192,26,112,26,136,128,14,208,9,186,200,126,190,204,143,91,203,15,39,217,207,44,116,218,163,
  47. 117,206,231,113,144,58,223,155,209,49,0,133,89,109,249,245,152,229,232,252,2,157,95,168,203,50,250,120,173,251,244,184,114,251,
  48. 197,90,247,233,186,101,89,109,242,88,151,149,219,58,143,113,80,219,76,207,106,103,166,110,167,72,235,33,216,140,211,122,184,
  49. 220,190,39,143,249,34,221,14,235,75,117,59,53,186,157,241,122,30,214,148,219,253,225,185,216,84,110,143,225,28,109,211,168,117,
  50. 190,215,90,173,159,14,155,117,90,231,251,54,105,189,11,250,122,173,167,161,111,208,250,30,232,27,181,126,49,244,77,90,223,7,
  51. 125,179,214,247,103,229,31,200,210,111,133,222,162,245,187,179,242,127,152,165,63,154,165,63,149,213,230,243,89,249,47,65,111,
  52. 214,250,193,172,252,131,147,70,117,30,231,83,181,30,206,106,231,80,150,61,143,225,150,204,152,64,111,205,140,85,96,212,198,151,
  53. 165,151,5,108,127,156,171,199,243,116,173,7,145,191,85,235,161,44,125,30,244,54,173,47,133,222,174,245,53,208,183,105,189,5,250,
  54. 103,181,190,29,250,103,180,222,155,149,207,126,245,57,173,39,144,191,93,235,123,178,236,47,14,176,111,11,26,34,91,230,10,94,
  55. 235,211,40,73,182,188,75,73,65,247,106,121,159,150,223,211,242,126,45,255,75,219,63,162,134,33,72,46,97,203,66,193,177,98,46,
  56. 61,76,44,43,200,45,56,110,216,229,21,186,188,2,37,126,193,126,94,162,206,74,65,172,180,187,149,172,160,135,148,12,208,47,148,
  57. 156,75,255,163,100,30,29,84,126,62,157,86,67,58,17,121,254,66,188,38,93,244,101,37,199,211,13,144,185,136,92,134,146,115,233,
  58. 109,226,181,61,67,165,243,116,126,30,162,192,59,234,185,237,116,33,238,123,137,146,37,116,169,78,127,133,199,81,231,251,112,74,
  59. 187,66,167,175,81,210,160,107,201,94,139,215,105,121,189,146,130,190,166,229,1,226,181,39,105,159,146,33,250,42,241,58,155,170,
  60. 238,87,140,200,246,123,37,23,209,75,74,78,162,63,18,175,201,217,148,214,242,16,113,44,158,79,63,34,142,21,94,122,74,201,9,244,
  61. 22,251,149,238,247,4,172,108,150,229,136,142,223,85,114,38,189,175,228,73,42,152,5,176,194,13,53,47,121,116,142,146,101,116,190,
  62. 78,239,85,114,33,189,174,230,167,70,217,77,70,139,47,18,207,139,93,175,2,249,166,150,221,74,22,82,143,146,19,72,8,91,74,53,
  63. 127,211,148,125,16,51,210,171,100,45,69,149,92,74,59,148,44,166,157,90,198,148,60,153,250,148,156,64,131,90,158,169,228,2,218,
  64. 163,100,144,46,84,210,79,23,43,153,79,95,82,210,69,151,107,63,217,167,203,175,84,114,30,93,165,100,46,237,87,210,67,55,106,187,
  65. 155,148,204,161,155,149,180,231,33,136,17,186,69,203,111,104,249,77,37,39,211,183,180,252,182,206,255,142,246,195,91,181,252,
  66. 79,45,111,211,126,122,187,146,39,208,29,74,206,167,31,106,249,99,37,171,232,87,74,86,210,51,90,62,171,229,127,235,242,231,116,
  67. 250,121,45,127,173,100,1,253,70,201,233,244,91,37,103,209,11,74,158,72,191,83,210,246,159,160,246,31,78,191,172,228,28,250,131,
  68. 146,182,63,177,253,43,74,54,208,155,74,214,211,187,90,190,167,100,53,125,168,228,68,250,88,201,48,253,77,167,255,174,237,254,
  69. 87,203,79,116,249,167,122,92,124,130,247,164,82,186,154,88,46,163,31,168,117,41,233,251,74,22,81,129,224,125,199,246,211,89,88,
  70. 17,151,17,41,47,251,188,146,146,126,70,188,255,140,163,7,137,207,2,19,180,159,218,107,41,179,31,226,117,137,110,66,140,254,
  71. 178,222,144,38,235,124,222,207,56,118,115,249,125,144,183,233,242,10,93,127,86,86,253,71,81,254,35,93,30,36,123,207,228,253,238,
  72. 144,174,255,60,228,107,186,156,247,249,19,160,47,155,99,159,5,214,205,177,243,182,67,246,0,67,151,239,2,187,181,205,185,42,
  73. 223,80,250,199,181,246,153,160,93,120,40,225,227,222,180,203,60,204,101,14,90,225,123,57,235,236,115,145,95,180,116,120,104,151,
  74. 111,14,242,243,100,9,94,1,235,165,116,44,150,14,114,251,138,168,165,35,143,118,97,139,72,98,213,179,93,75,167,109,107,80,158,
  75. 99,215,166,121,180,188,223,35,23,203,63,127,106,249,120,60,220,190,208,171,14,125,255,73,117,246,249,164,10,35,154,240,13,171,
  76. 167,229,123,115,191,167,213,217,231,171,99,221,219,160,34,225,247,207,157,49,225,200,123,134,231,211,114,167,23,190,118,8,247,
  77. 228,253,193,35,172,224,52,68,39,175,8,253,233,72,235,5,202,58,244,26,199,89,135,234,79,67,157,61,119,45,9,219,142,75,74,164,58,
  78. 115,200,197,176,241,35,174,180,236,242,100,151,75,113,174,184,210,125,203,160,107,33,158,204,67,161,67,6,250,203,207,120,74,
  79. 29,199,117,140,172,63,31,207,152,70,158,159,182,249,188,234,252,149,131,20,63,235,166,58,123,31,45,118,141,163,42,233,133,29,
  80. 143,66,75,42,159,90,230,22,144,229,91,14,43,175,88,44,150,140,230,5,87,99,47,25,181,56,25,22,30,99,243,84,126,23,20,116,103,203,
  81. 101,100,56,230,111,159,72,91,82,24,7,163,132,252,198,54,104,25,251,150,116,62,250,93,139,39,241,58,184,255,14,53,14,115,105,133,
  82. 147,237,23,27,110,90,184,221,73,254,98,174,195,247,26,143,117,110,249,198,241,147,29,118,143,208,147,60,151,236,115,187,235,
  83. 236,243,90,187,191,64,63,103,21,198,48,17,156,9,15,111,247,129,226,66,245,204,66,253,35,186,168,206,254,150,144,240,241,169,174,
  84. 96,36,255,138,145,252,176,202,151,250,196,123,125,157,237,207,45,190,66,181,38,216,131,248,190,95,171,179,207,188,45,193,66,
  85. 244,145,79,214,120,206,74,31,122,61,17,119,46,24,177,251,246,49,237,38,41,187,2,120,60,63,201,157,176,123,156,253,206,237,47,
  86. 73,4,75,16,95,171,28,121,232,141,11,189,106,223,87,130,84,5,37,194,179,104,95,110,251,190,98,164,2,72,77,85,169,113,104,247,36,
  87. 204,181,215,49,209,25,71,187,152,65,232,21,142,18,212,43,162,114,135,19,121,187,176,207,122,28,139,28,159,161,10,15,167,121,63,
  88. 110,219,239,135,214,71,195,180,237,250,241,208,186,177,23,89,193,30,117,237,197,190,93,133,54,19,62,181,15,59,198,209,148,101,
  89. 243,104,186,224,211,158,21,116,160,231,45,220,39,39,214,111,208,73,220,162,27,119,245,27,150,175,95,247,228,3,242,79,159,210,
  90. 189,0,207,211,145,83,74,235,115,92,110,127,105,121,78,158,210,172,112,130,90,92,94,99,145,49,142,252,210,63,117,202,202,133,228,
  91. 119,238,242,165,48,14,94,215,122,151,195,233,31,239,87,210,10,15,209,21,14,246,52,246,110,126,42,187,247,251,40,116,115,190,35,
  92. 244,46,120,27,28,2,191,1,188,57,24,14,117,198,31,253,217,115,50,253,75,233,195,127,236,114,62,39,150,96,61,242,247,40,62,183,
  93. 72,35,116,173,152,113,181,168,189,82,200,217,55,136,234,235,5,233,232,130,53,28,182,125,166,57,232,87,113,214,161,34,31,98,75,
  94. 88,251,88,184,137,42,141,2,172,121,167,138,119,181,97,59,198,38,182,152,84,185,194,163,252,57,83,167,33,83,22,94,138,58,94,229,
  95. 131,153,178,149,35,101,75,70,202,220,234,148,135,119,12,93,54,224,58,85,69,6,110,211,169,215,253,182,176,189,102,154,151,250,
  96. 179,226,139,1,95,228,156,68,184,145,28,34,244,241,232,243,116,233,182,248,157,183,13,207,84,160,251,192,63,59,194,118,236,247,
  97. 251,10,71,214,76,58,156,89,51,227,84,159,50,249,103,232,252,45,190,241,234,254,82,175,189,61,97,251,189,210,242,173,84,125,85,
  98. 177,14,237,225,60,248,137,161,239,115,94,216,222,71,10,84,61,251,173,243,146,172,60,151,142,223,87,30,231,217,78,209,207,150,
  99. 177,255,202,113,236,215,140,140,133,221,143,111,28,165,31,183,31,37,239,222,172,60,135,190,215,247,195,246,183,0,191,224,175,
  100. 5,237,97,73,182,52,104,107,61,226,222,161,173,97,55,109,13,187,116,110,46,252,24,51,233,219,26,118,160,60,7,235,113,2,250,131,
  101. 51,159,40,210,207,203,115,242,120,216,222,171,143,222,255,150,229,120,99,216,188,137,28,167,134,62,100,223,48,148,255,61,115,
  102. 204,58,115,87,125,250,169,122,238,165,13,228,136,112,29,47,238,195,123,245,203,168,195,103,84,255,4,63,53,127,21,245,120,71,20,
  103. 210,177,8,123,120,203,205,69,152,187,114,158,59,236,22,6,113,164,243,98,173,120,114,44,95,62,100,158,235,217,47,124,74,179,4,
  104. 127,135,8,189,221,124,51,199,157,66,46,71,188,240,177,116,88,216,207,33,157,238,155,6,114,248,141,88,92,26,250,221,241,236,214,
  105. 219,118,63,63,158,221,70,219,142,95,208,132,67,125,215,224,49,224,249,224,243,19,127,111,201,69,138,199,50,191,222,254,222,226,
  106. 247,53,119,140,62,225,98,97,239,188,179,221,252,45,130,75,44,95,30,198,196,35,18,167,174,165,233,169,208,59,241,112,41,13,228,
  107. 96,247,125,203,242,45,194,204,132,248,101,65,218,99,157,249,62,196,223,23,242,53,30,148,240,253,66,245,246,119,6,191,24,185,159,
  108. 62,99,20,138,197,238,92,220,39,23,125,243,72,255,148,57,115,220,20,95,90,70,3,215,120,68,232,109,203,231,225,40,43,23,169,
  109. 211,141,173,91,193,1,220,195,163,250,151,216,132,126,25,254,162,208,139,246,156,243,189,86,214,219,223,50,198,206,185,253,100,
  110. 156,199,207,228,194,189,18,155,215,193,91,252,190,208,123,164,35,9,246,221,250,81,95,206,213,49,107,123,189,237,67,241,211,113,
  111. 18,26,200,110,117,17,238,105,175,157,56,214,14,215,41,212,62,180,11,197,229,104,168,249,105,88,27,60,186,194,80,163,43,10,133,
  112. 165,206,38,158,92,246,152,2,202,115,63,123,25,123,204,251,106,116,66,127,109,254,165,31,146,103,121,178,154,93,222,57,61,78,
  113. 158,101,72,151,251,105,246,6,156,112,138,66,47,28,223,114,163,109,249,211,227,91,110,128,165,229,227,61,218,147,231,47,90,56,
  114. 169,154,252,149,83,202,231,195,219,150,209,19,228,159,56,255,254,74,226,86,184,141,219,184,13,196,70,72,225,119,174,116,122,157,
  115. 103,111,121,100,188,21,44,182,115,74,86,186,188,174,179,187,31,41,201,180,251,188,7,51,249,18,250,113,206,56,193,47,11,247,92,
  116. 246,178,71,228,44,246,148,209,63,251,4,51,169,251,211,236,254,252,59,61,225,150,66,191,253,215,123,176,94,247,96,218,255,187,
  117. 7,235,85,15,120,109,218,95,28,217,183,56,254,213,105,201,235,148,191,117,164,148,239,73,117,86,58,88,111,127,31,69,31,113,222,
  118. 112,195,251,39,26,31,145,127,220,148,149,56,111,56,59,92,56,111,168,179,67,130,230,56,248,252,234,70,191,243,177,151,128,191,
  119. 251,253,83,170,112,218,48,248,180,145,131,19,197,122,135,52,248,148,177,75,134,222,202,151,161,55,193,235,224,32,251,123,17,250,
  120. 198,223,25,189,28,109,229,236,146,234,50,35,20,154,49,187,182,58,43,206,143,155,51,186,54,12,157,91,62,199,62,123,47,146,110,
  121. 226,17,217,9,139,2,242,47,13,253,141,159,79,191,103,204,177,191,47,241,217,141,79,217,19,229,3,234,236,86,137,187,85,224,189,
  122. 113,17,34,135,229,27,196,10,245,136,19,69,49,70,219,10,79,161,48,158,120,149,178,183,194,85,228,115,180,212,23,227,68,61,91,181,
  123. 159,41,241,75,43,92,73,62,105,151,213,240,248,190,109,255,206,140,127,50,223,113,249,59,233,135,249,52,250,65,86,255,120,15,75,
  124. 151,31,150,230,250,227,200,222,243,139,208,59,161,243,152,160,150,57,186,220,175,247,247,137,58,191,66,75,169,9,234,241,154,
  125. 69,11,85,126,141,206,175,161,5,90,10,21,67,133,254,231,164,209,179,132,212,190,145,57,67,216,186,123,228,155,180,196,232,142,
  126. 230,179,204,87,105,135,238,131,75,151,185,96,39,117,158,91,203,92,45,51,223,180,11,84,79,72,159,101,248,185,230,234,254,7,85,
  127. 254,92,237,183,115,71,122,106,215,159,167,229,124,93,79,232,243,23,203,124,125,127,214,11,71,202,11,85,255,164,182,200,60,95,
  128. 233,72,63,236,182,125,250,126,193,17,75,251,185,130,218,90,144,253,110,47,66,132,119,55,215,146,168,21,77,159,68,242,164,6,42,
  129. 89,17,239,75,196,45,211,74,111,50,205,100,107,212,28,172,221,17,25,136,144,88,77,114,117,35,137,70,146,141,51,1,212,181,36,215,
  130. 54,81,96,109,127,167,185,172,179,211,76,165,162,29,209,88,52,61,188,33,222,101,110,74,198,7,162,93,102,146,74,215,153,195,29,
  131. 241,72,178,107,101,52,213,23,77,165,154,162,169,180,105,161,64,52,145,108,66,107,77,104,166,169,137,140,38,36,112,89,203,151,
  132. 38,42,105,138,88,93,201,120,180,171,46,146,72,212,45,235,76,71,7,208,114,3,205,27,155,159,72,196,162,157,145,116,52,110,77,205,
  133. 216,52,69,187,205,206,225,206,152,185,34,18,139,117,68,58,119,166,26,104,194,177,106,101,23,117,198,45,244,44,93,183,130,229,
  134. 80,58,187,168,39,25,73,244,70,59,83,117,43,34,214,64,4,13,78,62,74,81,60,22,79,174,142,198,210,102,242,216,229,235,35,233,100,
  135. 116,168,129,102,254,195,242,49,77,149,29,105,186,41,18,181,208,191,210,35,75,54,155,157,40,40,30,41,136,167,234,150,247,91,93,
  136. 49,179,129,198,101,103,54,46,143,90,93,220,250,104,27,3,152,234,58,76,214,170,1,147,27,159,56,182,96,125,156,135,75,151,205,
  137. 28,91,198,78,50,117,163,181,58,222,217,159,90,209,27,177,122,204,204,36,103,119,101,196,52,251,145,70,50,79,73,198,251,19,13,
  138. 180,224,200,146,150,164,105,110,236,72,153,201,1,51,137,187,156,18,139,119,68,98,77,145,225,120,127,122,244,54,21,255,184,94,
  139. 3,213,143,53,136,100,251,107,221,24,239,93,31,177,34,61,92,101,206,63,93,133,29,190,209,234,142,31,209,255,227,212,201,44,146,
  140. 6,170,29,91,47,106,37,250,211,125,102,186,55,222,85,183,60,146,66,227,72,195,47,45,76,175,242,218,105,199,182,95,213,21,77,199,
  141. 147,118,119,170,143,109,118,68,147,53,199,177,93,175,244,145,209,57,185,169,51,222,87,151,236,75,197,234,118,32,0,212,29,17,54,
  142. 166,254,195,184,208,64,171,143,219,192,49,34,199,212,177,51,187,248,223,109,167,129,42,143,87,181,129,170,154,186,34,177,129,
  143. 232,206,186,136,101,197,211,42,102,212,173,178,58,99,241,84,212,234,89,17,139,164,84,48,56,210,166,17,3,155,212,229,149,71,41,
  144. 95,111,246,117,104,3,19,38,129,163,152,52,71,123,172,72,186,63,105,242,130,225,24,92,23,195,218,170,195,10,75,54,155,187,250,
  145. 77,171,19,37,69,217,37,246,237,170,178,178,26,99,49,179,39,18,179,167,97,213,80,167,153,176,39,123,234,81,108,146,61,253,125,
  146. 120,246,44,171,226,108,43,4,197,30,123,208,70,51,55,196,155,251,59,123,109,207,200,170,231,207,50,217,216,177,67,197,164,64,86,
  147. 94,179,217,217,159,132,67,28,163,74,51,98,160,213,195,30,57,154,151,52,187,99,104,7,221,24,136,219,161,187,37,146,236,49,179,
  148. 123,59,241,40,230,118,215,26,104,188,93,214,159,142,198,234,150,37,147,145,97,118,130,6,42,204,202,230,28,242,29,150,129,119,
  149. 220,150,173,155,86,145,55,219,231,72,180,146,108,109,36,103,107,35,126,160,174,37,87,235,218,198,213,171,215,146,3,178,145,175,
  150. 188,163,181,174,109,67,33,43,188,171,181,170,172,166,54,148,54,181,97,207,107,109,67,173,54,213,130,104,35,163,141,235,225,
  151. 210,196,106,19,57,219,214,178,238,128,192,62,217,198,185,216,31,93,109,77,42,219,201,18,249,237,216,148,219,27,201,223,126,164,
  152. 23,20,183,31,101,18,60,118,64,154,26,14,135,71,244,250,44,125,78,150,62,55,75,159,151,165,207,207,210,23,100,233,11,179,244,
  153. 69,208,243,108,125,117,44,210,147,162,252,49,145,144,198,69,142,18,113,201,21,81,161,136,107,178,108,138,116,152,49,202,137,232,
  154. 125,157,38,68,186,186,142,30,255,41,55,162,157,55,69,162,131,138,120,215,95,222,159,78,199,173,77,73,220,198,236,34,87,71,
  155. 28,201,62,72,181,27,146,171,83,109,228,228,238,84,251,85,23,57,113,96,136,36,41,175,147,99,84,28,219,235,178,52,39,70,182,100,
  156. 42,80,137,150,100,196,74,117,199,147,125,148,207,199,5,236,195,41,101,141,134,236,83,3,26,138,247,35,61,169,51,105,70,210,71,
  157. 198,63,142,203,228,232,138,118,119,147,48,201,105,242,134,74,193,110,236,198,71,53,77,45,31,110,225,86,115,217,66,109,176,228,
  158. 236,86,194,219,61,186,221,118,81,158,74,113,200,106,236,162,73,88,23,99,90,91,157,85,88,126,120,225,152,211,90,174,42,85,179,
  159. 48,158,213,209,147,146,62,21,81,62,178,57,4,97,90,204,36,94,144,56,201,30,71,30,214,180,145,151,87,38,63,90,75,180,207,84,141,
  160. 174,49,163,61,189,105,42,134,170,118,147,236,46,113,102,147,94,213,27,173,102,140,156,105,169,74,246,234,165,66,168,106,148,
  161. 17,48,213,224,122,71,51,80,221,141,212,230,200,224,233,25,101,43,229,177,18,143,167,185,125,242,33,209,60,12,71,233,107,198,234,
  162. 141,118,154,84,128,156,45,86,148,167,154,159,68,221,255,240,19,131,122,206,214,232,136,199,114,157,211,48,7,241,193,150,248,
  163. 78,116,175,124,36,173,140,98,38,54,151,68,44,50,188,58,25,193,19,59,80,122,186,186,110,37,209,75,133,152,37,120,29,70,115,83,
  164. 164,159,221,209,55,146,177,217,76,193,113,71,114,150,143,120,46,229,219,57,216,188,86,198,7,177,40,70,146,91,18,52,110,36,161,
  165. 54,182,53,209,174,46,244,73,223,102,125,28,247,80,117,198,100,36,35,61,153,54,85,6,154,209,109,170,227,36,21,235,132,153,100,
  166. 255,214,78,144,211,27,73,217,110,87,218,11,7,105,142,119,235,233,75,198,251,236,199,135,9,106,43,39,117,244,198,17,66,69,148,
  167. 60,152,245,141,42,42,167,200,136,246,245,81,33,191,95,68,35,177,21,145,68,106,61,134,157,242,117,70,179,25,91,101,117,141,148,
  168. 35,217,156,142,36,225,239,234,248,209,50,156,48,201,171,212,207,217,71,17,202,193,205,90,35,177,126,44,225,40,182,130,157,38,
  169. 110,150,106,180,82,233,8,182,67,148,166,54,38,34,216,27,105,66,52,213,18,199,222,180,106,40,129,101,171,92,107,149,21,193,60,
  170. 117,161,237,148,158,51,114,239,52,135,87,112,127,74,119,30,227,45,37,63,83,208,220,203,35,234,140,169,160,148,143,153,54,147,
  171. 220,189,13,56,47,144,35,102,118,167,201,21,51,173,158,116,47,185,116,87,133,69,14,139,189,193,109,153,131,27,88,201,177,50,17,
  172. 192,107,101,175,58,87,188,131,67,9,57,226,177,174,94,117,29,164,162,184,149,121,163,89,161,66,9,214,201,104,214,74,51,149,78,
  173. 198,135,217,113,70,51,181,115,101,213,204,120,215,164,209,172,230,200,128,153,25,47,140,117,218,204,182,87,131,63,182,137,230,
  174. 116,60,145,64,86,41,66,128,234,199,97,7,71,116,222,130,111,13,82,126,60,251,13,128,10,226,99,66,53,121,227,214,154,56,22,150,
  175. 10,11,148,27,183,50,142,157,175,212,245,253,177,116,52,193,83,162,146,112,206,28,222,1,84,85,88,52,71,207,48,51,177,14,45,217,
  176. 83,171,90,114,197,237,9,119,219,242,115,168,215,143,224,157,70,108,114,38,148,99,123,18,145,36,44,85,48,200,79,140,113,111,103,
  177. 66,5,239,64,34,158,232,143,29,51,92,139,36,185,147,246,59,37,85,37,205,30,246,141,228,177,95,55,169,60,105,246,225,81,237,199,
  178. 223,104,29,182,87,57,147,42,18,26,41,51,77,5,41,142,153,35,47,123,228,69,90,13,34,123,42,149,102,167,26,237,135,86,171,135,171,
  179. 101,157,201,85,181,166,140,71,82,25,82,71,125,27,163,241,169,76,40,220,18,205,138,109,147,142,154,205,135,225,8,54,193,148,29,
  180. 28,149,3,231,167,198,4,69,79,38,25,179,251,116,90,52,22,219,16,79,43,119,240,166,176,96,50,1,10,21,145,26,137,30,48,102,71,179,
  181. 251,133,163,30,138,225,101,163,201,178,148,221,155,198,209,123,233,39,117,168,237,197,145,238,141,166,200,197,215,169,97,45,235,
  182. 145,203,155,141,129,150,160,242,64,228,244,167,187,23,169,8,47,6,200,57,160,162,134,91,137,141,221,228,224,183,28,42,228,107,
  183. 182,115,229,114,70,75,124,75,202,36,223,192,17,123,194,64,52,153,238,143,196,244,190,229,25,24,29,10,49,72,98,136,228,80,24,212,
  184. 131,57,96,46,152,71,98,152,110,119,72,186,92,186,11,218,106,232,94,135,216,39,221,1,153,247,180,28,10,236,48,232,23,162,236,
  185. 15,235,232,167,14,249,69,137,252,2,122,194,33,46,20,238,192,99,242,140,192,219,6,93,44,170,107,46,119,18,189,224,48,246,201,228,
  186. 128,187,224,39,21,244,103,41,8,77,45,161,119,37,185,103,183,27,242,45,145,127,129,33,94,23,197,181,67,31,24,244,69,33,119,
  187. 44,17,69,69,209,37,50,21,112,210,18,145,231,66,125,105,119,64,46,216,42,215,13,214,208,175,165,184,134,239,118,184,252,3,154,
  188. 44,184,155,94,181,197,18,227,108,241,170,184,71,184,103,203,167,169,65,238,149,131,242,41,49,56,36,159,223,253,210,94,33,157,
  189. 158,101,53,75,106,151,44,57,169,221,160,179,60,103,26,98,143,152,191,228,150,74,195,120,76,132,69,233,248,240,100,67,62,42,164,
  190. 40,42,117,74,121,42,122,226,20,78,195,229,145,179,14,56,61,46,114,9,151,116,25,213,213,114,96,182,83,86,203,212,108,90,104,
  191. 247,96,161,188,70,94,171,20,7,43,215,201,235,199,230,142,40,206,76,241,126,78,238,231,30,95,88,78,3,16,235,232,45,67,94,45,111,
  192. 224,252,55,28,200,160,189,60,98,244,138,193,215,125,14,153,62,3,242,18,135,72,67,124,104,176,64,205,27,85,250,162,114,218,171,
  193. 13,174,179,13,206,182,197,245,134,56,136,121,89,183,174,166,109,93,91,45,157,37,118,171,90,247,27,242,75,242,187,2,21,39,213,
  194. 208,159,132,56,159,7,171,236,19,185,51,176,206,200,73,202,38,195,117,129,52,100,94,175,40,46,148,131,1,92,131,172,13,5,232,235,
  195. 82,62,196,214,129,243,165,63,32,19,1,89,216,32,251,15,108,147,195,107,233,81,105,60,36,206,81,133,50,255,60,57,16,184,170,125,
  196. 199,249,240,5,41,219,232,65,93,173,224,252,96,249,85,116,151,225,60,243,103,226,66,249,182,24,70,23,191,109,56,174,146,183,136,
  197. 95,137,95,162,252,196,243,219,232,106,97,155,202,71,41,32,239,63,11,93,202,229,46,185,185,75,63,161,173,114,233,108,116,38,108,
  198. 227,107,50,242,30,23,242,196,37,134,247,77,177,224,68,33,12,207,189,66,214,136,242,252,147,157,30,167,183,222,153,183,195,229,
  199. 169,21,197,37,114,119,195,18,151,247,68,17,24,207,249,99,51,229,106,17,40,160,159,25,226,74,140,125,208,16,231,202,176,240,151,
  200. 72,239,108,217,23,168,48,232,60,81,51,217,73,74,153,53,197,73,47,135,171,233,97,67,60,137,46,210,107,134,24,116,23,68,203,233,
  201. 2,41,46,66,229,135,12,186,79,4,106,119,172,27,218,62,225,124,146,149,226,75,178,44,40,171,164,229,240,63,46,74,243,229,84,100,
  202. 148,187,75,69,233,210,210,220,210,149,165,178,180,186,212,97,91,85,40,43,9,171,83,70,236,11,228,20,182,23,101,147,109,69,150,
  203. 5,202,42,72,10,135,231,210,160,240,79,253,194,30,199,129,242,105,226,161,114,33,14,4,132,248,33,120,96,50,138,133,87,138,75,131,
  204. 51,247,236,113,236,173,168,22,183,86,144,225,162,2,174,33,252,179,80,231,80,80,236,13,222,84,137,203,125,124,121,170,82,200,
  205. 131,224,210,42,114,149,78,42,242,195,247,253,246,191,122,24,223,87,5,147,115,167,227,178,159,47,119,243,229,41,190,188,201,151,
  206. 189,51,28,103,75,18,128,165,91,235,255,12,227,128,7,44,18,7,102,8,241,12,56,52,3,3,31,26,47,246,135,132,184,27,60,15,222,4,
  207. 123,102,10,113,7,120,9,188,11,246,86,11,177,31,28,2,7,102,193,14,60,80,35,196,173,181,66,92,83,39,28,207,128,131,117,176,9,59,
  208. 197,43,243,96,55,95,138,115,23,72,241,205,5,250,251,114,246,239,10,88,102,254,78,135,191,67,103,254,86,135,191,79,103,254,94,
  209. 39,243,187,78,254,155,29,254,54,157,249,187,29,23,141,254,237,142,225,179,203,248,119,17,34,104,255,142,103,106,1,108,130,182,
  210. 13,255,31,54,225,179,127,183,195,255,111,77,6,237,251,242,223,250,24,218,158,255,239,152,35,104,255,142,225,132,57,246,47,29,
  211. 184,174,250,191,111,62,187,175,252,119,69,255,7,207,224,91,10,144,52,0,0,0,0};
  212. //==============================================================================
  213. #if JUCE_PUSH_NOTIFICATIONS && JUCE_MODULE_AVAILABLE_juce_gui_extra
  214. extern bool juce_handleNotificationIntent (void*);
  215. extern void juce_firebaseDeviceNotificationsTokenRefreshed (void*);
  216. extern void juce_firebaseRemoteNotificationReceived (void*);
  217. extern void juce_firebaseRemoteMessagesDeleted();
  218. extern void juce_firebaseRemoteMessageSent(void*);
  219. extern void juce_firebaseRemoteMessageSendError (void*, void*);
  220. #endif
  221. //==============================================================================
  222. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  223. METHOD (create, "<init>", "(II)V")
  224. DECLARE_JNI_CLASS (AndroidLayoutParams, "android/view/ViewGroup$LayoutParams")
  225. #undef JNI_CLASS_MEMBERS
  226. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  227. METHOD (addView, "addView", "(Landroid/view/View;Landroid/view/ViewGroup$LayoutParams;)V") \
  228. METHOD (removeView, "removeView", "(Landroid/view/View;)V") \
  229. METHOD (updateViewLayout, "updateViewLayout", "(Landroid/view/View;Landroid/view/ViewGroup$LayoutParams;)V")
  230. DECLARE_JNI_CLASS (AndroidViewManager, "android/view/ViewManager")
  231. #undef JNI_CLASS_MEMBERS
  232. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  233. METHOD (create, "<init>", "(IIIIIII)V") \
  234. FIELD (gravity, "gravity", "I") \
  235. FIELD (windowAnimations, "windowAnimations", "I")
  236. DECLARE_JNI_CLASS (AndroidWindowManagerLayoutParams, "android/view/WindowManager$LayoutParams")
  237. #undef JNI_CLASS_MEMBERS
  238. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  239. METHOD (getDisplayCutout, "getDisplayCutout", "()Landroid/view/DisplayCutout;")
  240. DECLARE_JNI_CLASS_WITH_MIN_SDK (AndroidWindowInsets, "android/view/WindowInsets", 28)
  241. #undef JNI_CLASS_MEMBERS
  242. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  243. METHOD (getSafeInsetBottom, "getSafeInsetBottom", "()I") \
  244. METHOD (getSafeInsetLeft, "getSafeInsetLeft", "()I") \
  245. METHOD (getSafeInsetRight, "getSafeInsetRight", "()I") \
  246. METHOD (getSafeInsetTop, "getSafeInsetTop", "()I")
  247. DECLARE_JNI_CLASS_WITH_MIN_SDK (AndroidDisplayCutout, "android/view/DisplayCutout", 28)
  248. #undef JNI_CLASS_MEMBERS
  249. //==============================================================================
  250. namespace
  251. {
  252. enum
  253. {
  254. SYSTEM_UI_FLAG_VISIBLE = 0,
  255. SYSTEM_UI_FLAG_LOW_PROFILE = 1,
  256. SYSTEM_UI_FLAG_HIDE_NAVIGATION = 2,
  257. SYSTEM_UI_FLAG_FULLSCREEN = 4,
  258. SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 512,
  259. SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 1024,
  260. SYSTEM_UI_FLAG_IMMERSIVE = 2048,
  261. SYSTEM_UI_FLAG_IMMERSIVE_STICKY = 4096
  262. };
  263. constexpr int fullScreenFlags = SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
  264. constexpr int FLAG_NOT_FOCUSABLE = 0x8;
  265. }
  266. //==============================================================================
  267. static bool supportsDisplayCutout()
  268. {
  269. return getAndroidSDKVersion() >= 28;
  270. }
  271. static BorderSize<int> androidDisplayCutoutToBorderSize (LocalRef<jobject> displayCutout, double displayScale)
  272. {
  273. if (displayCutout.get() == nullptr)
  274. return {};
  275. auto* env = getEnv();
  276. auto getInset = [&] (jmethodID methodID)
  277. {
  278. return roundToInt (env->CallIntMethod (displayCutout.get(), methodID) / displayScale);
  279. };
  280. return { getInset (AndroidDisplayCutout.getSafeInsetTop),
  281. getInset (AndroidDisplayCutout.getSafeInsetLeft),
  282. getInset (AndroidDisplayCutout.getSafeInsetBottom),
  283. getInset (AndroidDisplayCutout.getSafeInsetRight) };
  284. }
  285. //==============================================================================
  286. class AndroidComponentPeer : public ComponentPeer,
  287. private Timer
  288. {
  289. public:
  290. AndroidComponentPeer (Component& comp, int windowStyleFlags, void* nativeViewHandle)
  291. : ComponentPeer (comp, windowStyleFlags)
  292. {
  293. auto* env = getEnv();
  294. // NB: must not put this in the initialiser list, as it invokes a callback,
  295. // which will fail if the peer is only half-constructed.
  296. view = GlobalRef (LocalRef<jobject> (env->NewObject (ComponentPeerView, ComponentPeerView.create,
  297. getAppContext().get(), (jboolean) component.isOpaque(),
  298. (jlong) this)));
  299. if (nativeViewHandle != nullptr)
  300. {
  301. viewGroupIsWindow = false;
  302. // we don't know if the user is holding on to a local ref to this, so
  303. // explicitly create a new one
  304. auto nativeView = LocalRef<jobject> (env->NewLocalRef (static_cast<jobject> (nativeViewHandle)));
  305. if (env->IsInstanceOf (nativeView.get(), AndroidActivity))
  306. {
  307. viewGroup = GlobalRef (nativeView);
  308. env->CallVoidMethod (viewGroup.get(), AndroidActivity.setContentView, view.get());
  309. }
  310. else if (env->IsInstanceOf (nativeView.get(), AndroidViewGroup))
  311. {
  312. viewGroup = GlobalRef (nativeView);
  313. LocalRef<jobject> layoutParams (env->NewObject (AndroidLayoutParams, AndroidLayoutParams.create, -2, -2));
  314. env->CallVoidMethod (view.get(), AndroidView.setLayoutParams, layoutParams.get());
  315. env->CallVoidMethod ((jobject) viewGroup.get(), AndroidViewGroup.addView, view.get());
  316. }
  317. else
  318. {
  319. // the native handle you passed as a second argument to Component::addToDesktop must
  320. // either be an Activity or a ViewGroup
  321. jassertfalse;
  322. }
  323. }
  324. else
  325. {
  326. viewGroupIsWindow = true;
  327. LocalRef<jobject> viewLayoutParams (env->NewObject (AndroidLayoutParams, AndroidLayoutParams.create, -2, -2));
  328. env->CallVoidMethod (view.get(), AndroidView.setLayoutParams, viewLayoutParams.get());
  329. auto physicalBounds = (comp.getBoundsInParent().toFloat() * scale).toNearestInt();
  330. view.callVoidMethod (AndroidView.layout,
  331. physicalBounds.getX(), physicalBounds.getY(), physicalBounds.getRight(), physicalBounds.getBottom());
  332. LocalRef<jobject> windowLayoutParams (env->NewObject (AndroidWindowManagerLayoutParams, AndroidWindowManagerLayoutParams.create,
  333. physicalBounds.getWidth(), physicalBounds.getHeight(),
  334. physicalBounds.getX(), physicalBounds.getY(),
  335. TYPE_APPLICATION, FLAG_NOT_TOUCH_MODAL | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_NO_LIMITS | FLAG_NOT_FOCUSABLE,
  336. component.isOpaque() ? PIXEL_FORMAT_OPAQUE : PIXEL_FORMAT_TRANSPARENT));
  337. env->SetIntField (windowLayoutParams.get(), AndroidWindowManagerLayoutParams.gravity, GRAVITY_LEFT | GRAVITY_TOP);
  338. env->SetIntField (windowLayoutParams.get(), AndroidWindowManagerLayoutParams.windowAnimations, 0x01030000 /* android.R.style.Animation */);
  339. if (supportsDisplayCutout())
  340. {
  341. jfieldID layoutInDisplayCutoutModeFieldId = env->GetFieldID (AndroidWindowManagerLayoutParams,
  342. "layoutInDisplayCutoutMode",
  343. "I");
  344. if (layoutInDisplayCutoutModeFieldId != nullptr)
  345. env->SetIntField (windowLayoutParams.get(),
  346. layoutInDisplayCutoutModeFieldId,
  347. LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS);
  348. }
  349. if (Desktop::getInstance().getKioskModeComponent() != nullptr)
  350. setNavBarsHidden (true);
  351. LocalRef<jobject> activity (getCurrentActivity());
  352. if (activity == nullptr)
  353. activity = getMainActivity();
  354. viewGroup = GlobalRef (LocalRef<jobject> (env->CallObjectMethod (activity.get(), AndroidContext.getSystemService, javaString ("window").get())));
  355. env->CallVoidMethod (viewGroup.get(), AndroidViewManager.addView, view.get(), windowLayoutParams.get());
  356. }
  357. if (supportsDisplayCutout())
  358. {
  359. jmethodID setOnApplyWindowInsetsListenerMethodId = env->GetMethodID (AndroidView,
  360. "setOnApplyWindowInsetsListener",
  361. "(Landroid/view/View$OnApplyWindowInsetsListener;)V");
  362. if (setOnApplyWindowInsetsListenerMethodId != nullptr)
  363. env->CallVoidMethod (view.get(), setOnApplyWindowInsetsListenerMethodId,
  364. CreateJavaInterface (new ViewWindowInsetsListener,
  365. "android/view/View$OnApplyWindowInsetsListener").get());
  366. }
  367. if (isFocused())
  368. handleFocusGain();
  369. }
  370. ~AndroidComponentPeer() override
  371. {
  372. stopTimer();
  373. auto* env = getEnv();
  374. env->CallVoidMethod (view, ComponentPeerView.clear);
  375. frontWindow = nullptr;
  376. GlobalRef localView (view);
  377. GlobalRef localViewGroup (viewGroup);
  378. callOnMessageThread ([env, localView, localViewGroup]
  379. {
  380. if (env->IsInstanceOf (localViewGroup.get(), AndroidActivity))
  381. env->CallVoidMethod (localViewGroup.get(), AndroidActivity.setContentView, nullptr);
  382. else
  383. env->CallVoidMethod (localViewGroup.get(), AndroidViewManager.removeView, localView.get());
  384. });
  385. }
  386. void* getNativeHandle() const override
  387. {
  388. return (void*) view.get();
  389. }
  390. void setVisible (bool shouldBeVisible) override
  391. {
  392. GlobalRef localView (view);
  393. callOnMessageThread ([localView, shouldBeVisible]
  394. {
  395. localView.callVoidMethod (ComponentPeerView.setVisible, shouldBeVisible);
  396. });
  397. }
  398. void setTitle (const String& title) override
  399. {
  400. view.callVoidMethod (ComponentPeerView.setViewName, javaString (title).get());
  401. }
  402. void setBounds (const Rectangle<int>& userRect, bool isNowFullScreen) override
  403. {
  404. auto bounds = (userRect.toFloat() * scale).toNearestInt();
  405. if (MessageManager::getInstance()->isThisTheMessageThread())
  406. {
  407. fullScreen = isNowFullScreen;
  408. view.callVoidMethod (AndroidView.layout,
  409. bounds.getX(), bounds.getY(), bounds.getRight(), bounds.getBottom());
  410. if (viewGroup != nullptr && viewGroupIsWindow)
  411. {
  412. auto* env = getEnv();
  413. LocalRef<jobject> windowLayoutParams (env->NewObject (AndroidWindowManagerLayoutParams, AndroidWindowManagerLayoutParams.create,
  414. bounds.getWidth(), bounds.getHeight(), bounds.getX(), bounds.getY(),
  415. TYPE_APPLICATION, FLAG_NOT_TOUCH_MODAL | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_NO_LIMITS,
  416. component.isOpaque() ? PIXEL_FORMAT_OPAQUE : PIXEL_FORMAT_TRANSPARENT));
  417. env->SetIntField (windowLayoutParams.get(), AndroidWindowManagerLayoutParams.gravity, GRAVITY_LEFT | GRAVITY_TOP);
  418. env->CallVoidMethod (viewGroup.get(), AndroidViewManager.updateViewLayout, view.get(), windowLayoutParams.get());
  419. }
  420. }
  421. else
  422. {
  423. GlobalRef localView (view);
  424. MessageManager::callAsync ([localView, bounds]
  425. {
  426. localView.callVoidMethod (AndroidView.layout,
  427. bounds.getX(), bounds.getY(), bounds.getRight(), bounds.getBottom());
  428. });
  429. }
  430. }
  431. Rectangle<int> getBounds() const override
  432. {
  433. Rectangle<int> bounds (view.callIntMethod (AndroidView.getLeft),
  434. view.callIntMethod (AndroidView.getTop),
  435. view.callIntMethod (AndroidView.getWidth),
  436. view.callIntMethod (AndroidView.getHeight));
  437. return (bounds.toFloat() / scale).toNearestInt();
  438. }
  439. void handleScreenSizeChange() override
  440. {
  441. ComponentPeer::handleScreenSizeChange();
  442. if (isFullScreen())
  443. setFullScreen (true);
  444. }
  445. Point<int> getScreenPosition() const
  446. {
  447. auto* env = getEnv();
  448. LocalRef<jintArray> position (env->NewIntArray (2));
  449. env->CallVoidMethod (view.get(), AndroidView.getLocationOnScreen, position.get());
  450. jint* const screenPosition = env->GetIntArrayElements (position.get(), nullptr);
  451. Point<int> pos (screenPosition[0], screenPosition[1]);
  452. env->ReleaseIntArrayElements (position.get(), screenPosition, 0);
  453. return pos;
  454. }
  455. Point<float> localToGlobal (Point<float> relativePosition) override
  456. {
  457. return relativePosition + (getScreenPosition().toFloat() / scale);
  458. }
  459. using ComponentPeer::localToGlobal;
  460. Point<float> globalToLocal (Point<float> screenPosition) override
  461. {
  462. return screenPosition - (getScreenPosition().toFloat() / scale);
  463. }
  464. using ComponentPeer::globalToLocal;
  465. void setMinimised (bool /*shouldBeMinimised*/) override
  466. {
  467. // n/a
  468. }
  469. bool isMinimised() const override
  470. {
  471. return false;
  472. }
  473. void setFullScreen (bool shouldBeFullScreen) override
  474. {
  475. if (shouldNavBarsBeHidden (shouldBeFullScreen))
  476. {
  477. if (isTimerRunning())
  478. return;
  479. startTimer (500);
  480. }
  481. else
  482. {
  483. setNavBarsHidden (false);
  484. }
  485. auto newBounds = [&]
  486. {
  487. if (navBarsHidden || shouldBeFullScreen)
  488. if (auto* display = Desktop::getInstance().getDisplays().getPrimaryDisplay())
  489. return navBarsHidden ? display->totalArea
  490. : display->userArea;
  491. return lastNonFullscreenBounds.isEmpty() ? getBounds() : lastNonFullscreenBounds;
  492. }();
  493. if (! newBounds.isEmpty())
  494. setBounds (newBounds, shouldBeFullScreen);
  495. component.repaint();
  496. }
  497. bool isFullScreen() const override
  498. {
  499. return fullScreen;
  500. }
  501. void setIcon (const Image& /*newIcon*/) override
  502. {
  503. // n/a
  504. }
  505. bool contains (Point<int> localPos, bool trueIfInAChildWindow) const override
  506. {
  507. return isPositiveAndBelow (localPos.x, component.getWidth())
  508. && isPositiveAndBelow (localPos.y, component.getHeight())
  509. && ((! trueIfInAChildWindow) || view.callBooleanMethod (ComponentPeerView.containsPoint,
  510. (float) localPos.x * scale,
  511. (float) localPos.y * scale));
  512. }
  513. BorderSize<int> getFrameSize() const override
  514. {
  515. // TODO
  516. return {};
  517. }
  518. bool setAlwaysOnTop (bool /*alwaysOnTop*/) override
  519. {
  520. // TODO
  521. return false;
  522. }
  523. void toFront (bool makeActive) override
  524. {
  525. // Avoid calling bringToFront excessively: it's very slow
  526. if (frontWindow != this)
  527. {
  528. view.callVoidMethod (AndroidView.bringToFront);
  529. frontWindow = this;
  530. }
  531. if (makeActive)
  532. grabFocus();
  533. handleBroughtToFront();
  534. }
  535. void toBehind (ComponentPeer*) override
  536. {
  537. // TODO
  538. }
  539. //==============================================================================
  540. void handleMouseDownCallback (int index, Point<float> sysPos, int64 time)
  541. {
  542. lastMousePos = sysPos / scale;
  543. auto pos = globalToLocal (lastMousePos);
  544. // this forces a mouse-enter/up event, in case for some reason we didn't get a mouse-up before.
  545. handleMouseEvent (MouseInputSource::InputSourceType::touch,
  546. pos,
  547. ModifierKeys::currentModifiers.withoutMouseButtons(),
  548. MouseInputSource::invalidPressure,
  549. MouseInputSource::invalidOrientation,
  550. time,
  551. {},
  552. index);
  553. if (isValidPeer (this))
  554. handleMouseDragCallback (index, sysPos, time);
  555. }
  556. void handleMouseDragCallback (int index, Point<float> sysPos, int64 time)
  557. {
  558. lastMousePos = sysPos / scale;
  559. auto pos = globalToLocal (lastMousePos);
  560. jassert (index < 64);
  561. touchesDown = (touchesDown | (1 << (index & 63)));
  562. ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
  563. handleMouseEvent (MouseInputSource::InputSourceType::touch,
  564. pos,
  565. ModifierKeys::currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier),
  566. MouseInputSource::invalidPressure,
  567. MouseInputSource::invalidOrientation,
  568. time,
  569. {},
  570. index);
  571. }
  572. void handleMouseUpCallback (int index, Point<float> sysPos, int64 time)
  573. {
  574. lastMousePos = sysPos / scale;
  575. auto pos = globalToLocal (lastMousePos);
  576. jassert (index < 64);
  577. touchesDown = (touchesDown & ~(1 << (index & 63)));
  578. if (touchesDown == 0)
  579. ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withoutMouseButtons();
  580. handleMouseEvent (MouseInputSource::InputSourceType::touch,
  581. pos,
  582. ModifierKeys::currentModifiers.withoutMouseButtons(),
  583. MouseInputSource::invalidPressure,
  584. MouseInputSource::invalidOrientation,
  585. time,
  586. {},
  587. index);
  588. }
  589. void handleKeyDownCallback (int k, int kc)
  590. {
  591. handleKeyPress (k, static_cast<juce_wchar> (kc));
  592. }
  593. void handleKeyUpCallback (int /*k*/, int /*kc*/)
  594. {
  595. }
  596. void handleBackButtonCallback()
  597. {
  598. bool handled = false;
  599. if (auto* app = JUCEApplicationBase::getInstance())
  600. handled = app->backButtonPressed();
  601. if (isKioskModeComponent())
  602. setNavBarsHidden (navBarsHidden);
  603. if (! handled)
  604. {
  605. auto* env = getEnv();
  606. LocalRef<jobject> activity (getCurrentActivity());
  607. if (activity != nullptr)
  608. {
  609. jmethodID finishMethod = env->GetMethodID (AndroidActivity, "finish", "()V");
  610. if (finishMethod != nullptr)
  611. env->CallVoidMethod (activity.get(), finishMethod);
  612. }
  613. }
  614. }
  615. void handleKeyboardHiddenCallback()
  616. {
  617. Component::unfocusAllComponents();
  618. }
  619. void handleAppPausedCallback() {}
  620. void handleAppResumedCallback()
  621. {
  622. if (isKioskModeComponent())
  623. setNavBarsHidden (navBarsHidden);
  624. }
  625. //==============================================================================
  626. AccessibilityNativeHandle* getNativeHandleForViewId (jint virtualViewId) const
  627. {
  628. if (auto* handler = (virtualViewId == HOST_VIEW_ID
  629. ? component.getAccessibilityHandler()
  630. : AccessibilityNativeHandle::getAccessibilityHandlerForVirtualViewId (virtualViewId)))
  631. {
  632. return handler->getNativeImplementation();
  633. }
  634. return nullptr;
  635. }
  636. jboolean populateAccessibilityNodeInfoCallback (jint virtualViewId, jobject info) const
  637. {
  638. if (auto* handle = getNativeHandleForViewId (virtualViewId))
  639. {
  640. handle->populateNodeInfo (info);
  641. return true;
  642. }
  643. return false;
  644. }
  645. jboolean handlePerformActionCallback (jint virtualViewId, jint action, jobject arguments) const
  646. {
  647. if (auto* handle = getNativeHandleForViewId (virtualViewId))
  648. return handle->performAction (action, arguments);
  649. return false;
  650. }
  651. static jobject getFocusViewIdForHandler (const AccessibilityHandler* handler)
  652. {
  653. if (handler != nullptr)
  654. return getEnv()->NewObject (JavaInteger,
  655. JavaInteger.constructor,
  656. handler->getNativeImplementation()->getVirtualViewId());
  657. return nullptr;
  658. }
  659. jobject getInputFocusViewIdCallback()
  660. {
  661. if (auto* comp = dynamic_cast<Component*> (findCurrentTextInputTarget()))
  662. return getFocusViewIdForHandler (comp->getAccessibilityHandler());
  663. return nullptr;
  664. }
  665. jobject getAccessibilityFocusViewIdCallback() const
  666. {
  667. if (auto* handler = component.getAccessibilityHandler())
  668. {
  669. if (auto* modal = Component::getCurrentlyModalComponent())
  670. {
  671. if (! component.isParentOf (modal)
  672. && component.isCurrentlyBlockedByAnotherModalComponent())
  673. {
  674. if (auto* modalHandler = modal->getAccessibilityHandler())
  675. {
  676. if (auto* focusChild = modalHandler->getChildFocus())
  677. return getFocusViewIdForHandler (focusChild);
  678. return getFocusViewIdForHandler (modalHandler);
  679. }
  680. }
  681. }
  682. if (auto* focusChild = handler->getChildFocus())
  683. return getFocusViewIdForHandler (focusChild);
  684. }
  685. return nullptr;
  686. }
  687. //==============================================================================
  688. bool isFocused() const override
  689. {
  690. if (view != nullptr)
  691. return view.callBooleanMethod (AndroidView.hasFocus);
  692. return false;
  693. }
  694. void grabFocus() override
  695. {
  696. if (view != nullptr)
  697. view.callBooleanMethod (AndroidView.requestFocus);
  698. }
  699. void handleFocusChangeCallback (bool hasFocus)
  700. {
  701. if (isFullScreen())
  702. setFullScreen (true);
  703. if (hasFocus)
  704. handleFocusGain();
  705. else
  706. handleFocusLoss();
  707. }
  708. static const char* getVirtualKeyboardType (TextInputTarget::VirtualKeyboardType type) noexcept
  709. {
  710. switch (type)
  711. {
  712. case TextInputTarget::textKeyboard: return "text";
  713. case TextInputTarget::numericKeyboard: return "number";
  714. case TextInputTarget::decimalKeyboard: return "numberDecimal";
  715. case TextInputTarget::urlKeyboard: return "textUri";
  716. case TextInputTarget::emailAddressKeyboard: return "textEmailAddress";
  717. case TextInputTarget::phoneNumberKeyboard: return "phone";
  718. default: jassertfalse; break;
  719. }
  720. return "text";
  721. }
  722. void textInputRequired (Point<int>, TextInputTarget& target) override
  723. {
  724. view.callVoidMethod (ComponentPeerView.showKeyboard,
  725. javaString (getVirtualKeyboardType (target.getKeyboardType())).get());
  726. }
  727. void dismissPendingTextInput() override
  728. {
  729. view.callVoidMethod (ComponentPeerView.showKeyboard, javaString ("").get());
  730. if (! isTimerRunning())
  731. startTimer (500);
  732. }
  733. //==============================================================================
  734. void handlePaintCallback (jobject canvas, jobject paint)
  735. {
  736. auto* env = getEnv();
  737. jobject rect = env->CallObjectMethod (canvas, AndroidCanvas.getClipBounds);
  738. auto left = env->GetIntField (rect, AndroidRect.left);
  739. auto top = env->GetIntField (rect, AndroidRect.top);
  740. auto right = env->GetIntField (rect, AndroidRect.right);
  741. auto bottom = env->GetIntField (rect, AndroidRect.bottom);
  742. env->DeleteLocalRef (rect);
  743. auto clip = Rectangle<int>::leftTopRightBottom (left, top, right, bottom);
  744. if (clip.isEmpty())
  745. return;
  746. auto sizeNeeded = clip.getWidth() * clip.getHeight();
  747. if (sizeAllocated < sizeNeeded)
  748. {
  749. buffer.clear();
  750. sizeAllocated = sizeNeeded;
  751. buffer = GlobalRef (LocalRef<jobject> ((jobject) env->NewIntArray (sizeNeeded)));
  752. }
  753. if (jint* dest = env->GetIntArrayElements ((jintArray) buffer.get(), nullptr))
  754. {
  755. {
  756. Image temp (new PreallocatedImage (clip.getWidth(), clip.getHeight(),
  757. dest, ! component.isOpaque()));
  758. {
  759. LowLevelGraphicsSoftwareRenderer g (temp);
  760. g.setOrigin (-clip.getPosition());
  761. g.addTransform (AffineTransform::scale (scale));
  762. handlePaint (g);
  763. }
  764. }
  765. env->ReleaseIntArrayElements ((jintArray) buffer.get(), dest, 0);
  766. env->CallVoidMethod (canvas, AndroidCanvas.drawBitmap, (jintArray) buffer.get(), 0, clip.getWidth(),
  767. (jfloat) clip.getX(), (jfloat) clip.getY(),
  768. clip.getWidth(), clip.getHeight(), true, paint);
  769. }
  770. }
  771. void repaint (const Rectangle<int>& userArea) override
  772. {
  773. auto area = (userArea.toFloat() * scale).toNearestInt();
  774. GlobalRef localView (view);
  775. callOnMessageThread ([area, localView]
  776. {
  777. localView.callVoidMethod (AndroidView.invalidate,
  778. area.getX(), area.getY(), area.getRight(), area.getBottom());
  779. });
  780. }
  781. void performAnyPendingRepaintsNow() override
  782. {
  783. // TODO
  784. }
  785. void setAlpha (float /*newAlpha*/) override
  786. {
  787. // TODO
  788. }
  789. StringArray getAvailableRenderingEngines() override
  790. {
  791. return StringArray ("Software Renderer");
  792. }
  793. //==============================================================================
  794. static Point<float> lastMousePos;
  795. static int64 touchesDown;
  796. //==============================================================================
  797. struct StartupActivityCallbackListener : public ActivityLifecycleCallbacks
  798. {
  799. void onActivityStarted (jobject /*activity*/) override
  800. {
  801. auto* env = getEnv();
  802. LocalRef<jobject> appContext (getAppContext());
  803. if (appContext.get() != nullptr)
  804. {
  805. env->CallVoidMethod (appContext.get(),
  806. AndroidApplication.unregisterActivityLifecycleCallbacks,
  807. activityCallbackListener.get());
  808. clear();
  809. activityCallbackListener.clear();
  810. forceDisplayUpdate();
  811. }
  812. }
  813. };
  814. private:
  815. //==============================================================================
  816. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  817. METHOD (create, "<init>", "(Landroid/content/Context;ZJ)V") \
  818. METHOD (clear, "clear", "()V") \
  819. METHOD (setViewName, "setViewName", "(Ljava/lang/String;)V") \
  820. METHOD (setVisible, "setVisible", "(Z)V") \
  821. METHOD (isVisible, "isVisible", "()Z") \
  822. METHOD (containsPoint, "containsPoint", "(II)Z") \
  823. METHOD (showKeyboard, "showKeyboard", "(Ljava/lang/String;)V") \
  824. METHOD (setSystemUiVisibilityCompat, "setSystemUiVisibilityCompat", "(I)V") \
  825. CALLBACK (handlePaintJni, "handlePaint", "(JLandroid/graphics/Canvas;Landroid/graphics/Paint;)V") \
  826. CALLBACK (handleMouseDownJni, "handleMouseDown", "(JIFFJ)V") \
  827. CALLBACK (handleMouseDragJni, "handleMouseDrag", "(JIFFJ)V") \
  828. CALLBACK (handleMouseUpJni, "handleMouseUp", "(JIFFJ)V") \
  829. CALLBACK (handleKeyDownJni, "handleKeyDown", "(JII)V") \
  830. CALLBACK (handleKeyUpJni, "handleKeyUp", "(JII)V") \
  831. CALLBACK (handleBackButtonJni, "handleBackButton", "(J)V") \
  832. CALLBACK (handleKeyboardHiddenJni, "handleKeyboardHidden", "(J)V") \
  833. CALLBACK (viewSizeChangedJni, "viewSizeChanged", "(J)V") \
  834. CALLBACK (focusChangedJni, "focusChanged", "(JZ)V") \
  835. CALLBACK (handleAppPausedJni, "handleAppPaused", "(J)V") \
  836. CALLBACK (handleAppResumedJni, "handleAppResumed", "(J)V") \
  837. CALLBACK (populateAccessibilityNodeInfoJni, "populateAccessibilityNodeInfo", "(JILandroid/view/accessibility/AccessibilityNodeInfo;)Z") \
  838. CALLBACK (handlePerformActionJni, "handlePerformAction", "(JIILandroid/os/Bundle;)Z") \
  839. CALLBACK (getInputFocusViewIdJni, "getInputFocusViewId", "(J)Ljava/lang/Integer;") \
  840. CALLBACK (getAccessibilityFocusViewIdJni, "getAccessibilityFocusViewId", "(J)Ljava/lang/Integer;") \
  841. DECLARE_JNI_CLASS_WITH_BYTECODE (ComponentPeerView, "com/rmsl/juce/ComponentPeerView", 16, javaComponentPeerView, sizeof (javaComponentPeerView))
  842. #undef JNI_CLASS_MEMBERS
  843. static void JNICALL handlePaintJni (JNIEnv*, jobject /*view*/, jlong host, jobject canvas, jobject paint) { if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host)) myself->handlePaintCallback (canvas, paint); }
  844. static void JNICALL handleMouseDownJni (JNIEnv*, jobject /*view*/, jlong host, jint i, jfloat x, jfloat y, jlong time) { if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host)) myself->handleMouseDownCallback (i, Point<float> ((float) x, (float) y), (int64) time); }
  845. static void JNICALL handleMouseDragJni (JNIEnv*, jobject /*view*/, jlong host, jint i, jfloat x, jfloat y, jlong time) { if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host)) myself->handleMouseDragCallback (i, Point<float> ((float) x, (float) y), (int64) time); }
  846. static void JNICALL handleMouseUpJni (JNIEnv*, jobject /*view*/, jlong host, jint i, jfloat x, jfloat y, jlong time) { if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host)) myself->handleMouseUpCallback (i, Point<float> ((float) x, (float) y), (int64) time); }
  847. static void JNICALL viewSizeChangedJni (JNIEnv*, jobject /*view*/, jlong host) { if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host)) myself->handleMovedOrResized(); }
  848. static void JNICALL focusChangedJni (JNIEnv*, jobject /*view*/, jlong host, jboolean hasFocus) { if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host)) myself->handleFocusChangeCallback (hasFocus); }
  849. static void JNICALL handleKeyDownJni (JNIEnv*, jobject /*view*/, jlong host, jint k, jint kc) { if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host)) myself->handleKeyDownCallback ((int) k, (int) kc); }
  850. static void JNICALL handleKeyUpJni (JNIEnv*, jobject /*view*/, jlong host, jint k, jint kc) { if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host)) myself->handleKeyUpCallback ((int) k, (int) kc); }
  851. static void JNICALL handleBackButtonJni (JNIEnv*, jobject /*view*/, jlong host) { if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host)) myself->handleBackButtonCallback(); }
  852. static void JNICALL handleKeyboardHiddenJni (JNIEnv*, jobject /*view*/, jlong host) { if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host)) myself->handleKeyboardHiddenCallback(); }
  853. static void JNICALL handleAppPausedJni (JNIEnv*, jobject /*view*/, jlong host) { if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host)) myself->handleAppPausedCallback(); }
  854. static void JNICALL handleAppResumedJni (JNIEnv*, jobject /*view*/, jlong host) { if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host)) myself->handleAppResumedCallback(); }
  855. static jboolean JNICALL populateAccessibilityNodeInfoJni (JNIEnv*, jobject /*view*/, jlong host, jint virtualViewId, jobject info)
  856. {
  857. if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host))
  858. return myself->populateAccessibilityNodeInfoCallback (virtualViewId, info);
  859. return false;
  860. }
  861. static jboolean JNICALL handlePerformActionJni (JNIEnv*, jobject /*view*/, jlong host, jint virtualViewId, jint action, jobject arguments)
  862. {
  863. if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host))
  864. return myself->handlePerformActionCallback (virtualViewId, action, arguments);
  865. return false;
  866. }
  867. static jobject JNICALL getInputFocusViewIdJni (JNIEnv*, jobject /*view*/, jlong host)
  868. {
  869. if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host))
  870. return myself->getInputFocusViewIdCallback();
  871. return nullptr;
  872. }
  873. static jobject JNICALL getAccessibilityFocusViewIdJni (JNIEnv*, jobject /*view*/, jlong host)
  874. {
  875. if (auto* myself = reinterpret_cast<AndroidComponentPeer*> (host))
  876. return myself->getAccessibilityFocusViewIdCallback();
  877. return nullptr;
  878. }
  879. //==============================================================================
  880. struct ViewWindowInsetsListener : public juce::AndroidInterfaceImplementer
  881. {
  882. jobject onApplyWindowInsets (LocalRef<jobject> v, LocalRef<jobject> insets)
  883. {
  884. auto* env = getEnv();
  885. LocalRef<jobject> displayCutout (env->CallObjectMethod (insets.get(), AndroidWindowInsets.getDisplayCutout));
  886. if (displayCutout != nullptr)
  887. {
  888. const auto& mainDisplay = *Desktop::getInstance().getDisplays().getPrimaryDisplay();
  889. auto newSafeAreaInsets = androidDisplayCutoutToBorderSize (displayCutout, mainDisplay.scale);
  890. if (newSafeAreaInsets != mainDisplay.safeAreaInsets)
  891. forceDisplayUpdate();
  892. auto* fieldId = env->GetStaticFieldID (AndroidWindowInsets, "CONSUMED", "Landroid/view/WindowInsets");
  893. jassert (fieldId != nullptr);
  894. return env->GetStaticObjectField (AndroidWindowInsets, fieldId);
  895. }
  896. jmethodID onApplyWindowInsetsMethodId = env->GetMethodID (AndroidView,
  897. "onApplyWindowInsets",
  898. "(Landroid/view/WindowInsets;)Landroid/view/WindowInsets;");
  899. jassert (onApplyWindowInsetsMethodId != nullptr);
  900. return env->CallObjectMethod (v.get(), onApplyWindowInsetsMethodId, insets.get());
  901. }
  902. private:
  903. jobject invoke (jobject proxy, jobject method, jobjectArray args) override
  904. {
  905. auto* env = getEnv();
  906. auto methodName = juce::juceString ((jstring) env->CallObjectMethod (method, JavaMethod.getName));
  907. if (methodName == "onApplyWindowInsets")
  908. {
  909. jassert (env->GetArrayLength (args) == 2);
  910. LocalRef<jobject> windowView (env->GetObjectArrayElement (args, 0));
  911. LocalRef<jobject> insets (env->GetObjectArrayElement (args, 1));
  912. return onApplyWindowInsets (std::move (windowView), std::move (insets));
  913. }
  914. // invoke base class
  915. return AndroidInterfaceImplementer::invoke (proxy, method, args);
  916. }
  917. };
  918. //==============================================================================
  919. struct PreallocatedImage : public ImagePixelData
  920. {
  921. PreallocatedImage (int width_, int height_, jint* data_, bool hasAlpha_)
  922. : ImagePixelData (Image::ARGB, width_, height_), data (data_), hasAlpha (hasAlpha_)
  923. {
  924. if (hasAlpha_)
  925. zeromem (data_, static_cast<size_t> (width * height) * sizeof (jint));
  926. }
  927. ~PreallocatedImage() override
  928. {
  929. if (hasAlpha)
  930. {
  931. auto pix = (PixelARGB*) data;
  932. for (int i = width * height; --i >= 0;)
  933. {
  934. pix->unpremultiply();
  935. ++pix;
  936. }
  937. }
  938. }
  939. std::unique_ptr<ImageType> createType() const override
  940. {
  941. return std::make_unique<SoftwareImageType>();
  942. }
  943. std::unique_ptr<LowLevelGraphicsContext> createLowLevelContext() override
  944. {
  945. return std::make_unique<LowLevelGraphicsSoftwareRenderer> (Image (this));
  946. }
  947. void initialiseBitmapData (Image::BitmapData& bm, int x, int y, Image::BitmapData::ReadWriteMode /*mode*/) override
  948. {
  949. bm.lineStride = width * static_cast<int> (sizeof (jint));
  950. bm.pixelStride = static_cast<int> (sizeof (jint));
  951. bm.pixelFormat = Image::ARGB;
  952. bm.data = (uint8*) (data + x + y * width);
  953. }
  954. ImagePixelData::Ptr clone() override
  955. {
  956. auto s = new PreallocatedImage (width, height, nullptr, hasAlpha);
  957. s->allocatedData.malloc (sizeof (jint) * static_cast<size_t> (width * height));
  958. s->data = s->allocatedData;
  959. memcpy (s->data, data, sizeof (jint) * static_cast<size_t> (width * height));
  960. return s;
  961. }
  962. private:
  963. jint* data;
  964. HeapBlock<jint> allocatedData;
  965. bool hasAlpha;
  966. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PreallocatedImage)
  967. };
  968. //==============================================================================
  969. void timerCallback() override
  970. {
  971. setNavBarsHidden (shouldNavBarsBeHidden (fullScreen));
  972. setFullScreen (fullScreen);
  973. stopTimer();
  974. }
  975. bool isKioskModeComponent() const
  976. {
  977. if (auto* kiosk = Desktop::getInstance().getKioskModeComponent())
  978. return kiosk->getPeer() == this;
  979. return false;
  980. }
  981. bool shouldNavBarsBeHidden (bool shouldBeFullScreen) const
  982. {
  983. return (shouldBeFullScreen && isKioskModeComponent());
  984. }
  985. void setNavBarsHidden (bool hidden)
  986. {
  987. if (navBarsHidden != hidden)
  988. {
  989. navBarsHidden = hidden;
  990. view.callVoidMethod (ComponentPeerView.setSystemUiVisibilityCompat,
  991. (navBarsHidden ? (jint) (fullScreenFlags) : (jint) (SYSTEM_UI_FLAG_VISIBLE)));
  992. }
  993. }
  994. template <typename Callback>
  995. static void callOnMessageThread (Callback&& callback)
  996. {
  997. if (MessageManager::getInstance()->isThisTheMessageThread())
  998. callback();
  999. else
  1000. MessageManager::callAsync (std::forward<Callback> (callback));
  1001. }
  1002. //==============================================================================
  1003. friend class Displays;
  1004. static AndroidComponentPeer* frontWindow;
  1005. static GlobalRef activityCallbackListener;
  1006. static constexpr int GRAVITY_LEFT = 0x3, GRAVITY_TOP = 0x30;
  1007. static constexpr int TYPE_APPLICATION = 0x2;
  1008. static constexpr int FLAG_NOT_TOUCH_MODAL = 0x20, FLAG_LAYOUT_IN_SCREEN = 0x100, FLAG_LAYOUT_NO_LIMITS = 0x200;
  1009. static constexpr int PIXEL_FORMAT_OPAQUE = -1, PIXEL_FORMAT_TRANSPARENT = -2;
  1010. static constexpr int LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS = 0x3;
  1011. GlobalRef view, viewGroup, buffer;
  1012. bool viewGroupIsWindow = false, fullScreen = false, navBarsHidden = false;
  1013. int sizeAllocated = 0;
  1014. float scale = (float) Desktop::getInstance().getDisplays().getPrimaryDisplay()->scale;
  1015. //==============================================================================
  1016. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AndroidComponentPeer)
  1017. };
  1018. Point<float> AndroidComponentPeer::lastMousePos;
  1019. int64 AndroidComponentPeer::touchesDown = 0;
  1020. AndroidComponentPeer* AndroidComponentPeer::frontWindow = nullptr;
  1021. GlobalRef AndroidComponentPeer::activityCallbackListener;
  1022. AndroidComponentPeer::ComponentPeerView_Class AndroidComponentPeer::ComponentPeerView;
  1023. //==============================================================================
  1024. ComponentPeer* Component::createNewPeer (int styleFlags, void* nativeWindow)
  1025. {
  1026. return new AndroidComponentPeer (*this, styleFlags, nativeWindow);
  1027. }
  1028. //==============================================================================
  1029. bool Desktop::canUseSemiTransparentWindows() noexcept
  1030. {
  1031. return true;
  1032. }
  1033. class Desktop::NativeDarkModeChangeDetectorImpl : public ActivityLifecycleCallbacks
  1034. {
  1035. public:
  1036. NativeDarkModeChangeDetectorImpl()
  1037. {
  1038. LocalRef<jobject> appContext (getAppContext());
  1039. if (appContext != nullptr)
  1040. {
  1041. auto* env = getEnv();
  1042. myself = GlobalRef (CreateJavaInterface (this, "android/app/Application$ActivityLifecycleCallbacks"));
  1043. env->CallVoidMethod (appContext.get(), AndroidApplication.registerActivityLifecycleCallbacks, myself.get());
  1044. }
  1045. }
  1046. ~NativeDarkModeChangeDetectorImpl() override
  1047. {
  1048. LocalRef<jobject> appContext (getAppContext());
  1049. if (appContext != nullptr && myself != nullptr)
  1050. {
  1051. auto* env = getEnv();
  1052. env->CallVoidMethod (appContext.get(),
  1053. AndroidApplication.unregisterActivityLifecycleCallbacks,
  1054. myself.get());
  1055. clear();
  1056. myself.clear();
  1057. }
  1058. }
  1059. bool isDarkModeEnabled() const noexcept { return darkModeEnabled; }
  1060. void onActivityStarted (jobject /*activity*/) override
  1061. {
  1062. const auto isEnabled = getDarkModeSetting();
  1063. if (darkModeEnabled != isEnabled)
  1064. {
  1065. darkModeEnabled = isEnabled;
  1066. Desktop::getInstance().darkModeChanged();
  1067. }
  1068. }
  1069. private:
  1070. static bool getDarkModeSetting()
  1071. {
  1072. auto* env = getEnv();
  1073. const LocalRef<jobject> resources (env->CallObjectMethod (getAppContext().get(), AndroidContext.getResources));
  1074. const LocalRef<jobject> configuration (env->CallObjectMethod (resources, AndroidResources.getConfiguration));
  1075. const auto uiMode = env->GetIntField (configuration, AndroidConfiguration.uiMode);
  1076. return ((uiMode & UI_MODE_NIGHT_MASK) == UI_MODE_NIGHT_YES);
  1077. }
  1078. static constexpr int UI_MODE_NIGHT_MASK = 0x00000030,
  1079. UI_MODE_NIGHT_NO = 0x00000010,
  1080. UI_MODE_NIGHT_UNDEFINED = 0x00000000,
  1081. UI_MODE_NIGHT_YES = 0x00000020;
  1082. GlobalRef myself;
  1083. bool darkModeEnabled = getDarkModeSetting();
  1084. //==============================================================================
  1085. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeDarkModeChangeDetectorImpl)
  1086. };
  1087. std::unique_ptr<Desktop::NativeDarkModeChangeDetectorImpl> Desktop::createNativeDarkModeChangeDetectorImpl()
  1088. {
  1089. return std::make_unique<NativeDarkModeChangeDetectorImpl>();
  1090. }
  1091. bool Desktop::isDarkModeActive() const
  1092. {
  1093. return nativeDarkModeChangeDetectorImpl->isDarkModeEnabled();
  1094. }
  1095. double Desktop::getDefaultMasterScale()
  1096. {
  1097. return 1.0;
  1098. }
  1099. Desktop::DisplayOrientation Desktop::getCurrentOrientation() const
  1100. {
  1101. enum
  1102. {
  1103. ROTATION_0 = 0,
  1104. ROTATION_90 = 1,
  1105. ROTATION_180 = 2,
  1106. ROTATION_270 = 3
  1107. };
  1108. JNIEnv* env = getEnv();
  1109. LocalRef<jstring> windowServiceString (javaString ("window"));
  1110. LocalRef<jobject> windowManager = LocalRef<jobject> (env->CallObjectMethod (getAppContext().get(), AndroidContext.getSystemService, windowServiceString.get()));
  1111. if (windowManager.get() != nullptr)
  1112. {
  1113. LocalRef<jobject> display = LocalRef<jobject> (env->CallObjectMethod (windowManager, AndroidWindowManager.getDefaultDisplay));
  1114. if (display.get() != nullptr)
  1115. {
  1116. int rotation = env->CallIntMethod (display, AndroidDisplay.getRotation);
  1117. switch (rotation)
  1118. {
  1119. case ROTATION_0: return upright;
  1120. case ROTATION_90: return rotatedAntiClockwise;
  1121. case ROTATION_180: return upsideDown;
  1122. case ROTATION_270: return rotatedClockwise;
  1123. }
  1124. }
  1125. }
  1126. jassertfalse;
  1127. return upright;
  1128. }
  1129. bool MouseInputSource::SourceList::addSource()
  1130. {
  1131. addSource (sources.size(), MouseInputSource::InputSourceType::touch);
  1132. return true;
  1133. }
  1134. bool MouseInputSource::SourceList::canUseTouch()
  1135. {
  1136. return true;
  1137. }
  1138. Point<float> MouseInputSource::getCurrentRawMousePosition()
  1139. {
  1140. return AndroidComponentPeer::lastMousePos;
  1141. }
  1142. void MouseInputSource::setRawMousePosition (Point<float>)
  1143. {
  1144. // not needed
  1145. }
  1146. //==============================================================================
  1147. bool KeyPress::isKeyCurrentlyDown (int /*keyCode*/)
  1148. {
  1149. // TODO
  1150. return false;
  1151. }
  1152. JUCE_API void JUCE_CALLTYPE Process::hide()
  1153. {
  1154. auto* env = getEnv();
  1155. LocalRef<jobject> currentActivity (getCurrentActivity().get());
  1156. if (env->CallBooleanMethod (currentActivity.get(), AndroidActivity.moveTaskToBack, true) == 0)
  1157. {
  1158. GlobalRef intent (LocalRef<jobject> (env->NewObject (AndroidIntent, AndroidIntent.constructor)));
  1159. env->CallObjectMethod (intent, AndroidIntent.setAction, javaString ("android.intent.action.MAIN") .get());
  1160. env->CallObjectMethod (intent, AndroidIntent.addCategory, javaString ("android.intent.category.HOME").get());
  1161. env->CallVoidMethod (currentActivity.get(), AndroidContext.startActivity, intent.get());
  1162. }
  1163. }
  1164. //==============================================================================
  1165. // TODO
  1166. JUCE_API bool JUCE_CALLTYPE Process::isForegroundProcess() { return true; }
  1167. JUCE_API void JUCE_CALLTYPE Process::makeForegroundProcess() {}
  1168. //==============================================================================
  1169. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  1170. METHOD (show, "show", "()V") \
  1171. METHOD (getWindow, "getWindow", "()Landroid/view/Window;")
  1172. DECLARE_JNI_CLASS (AndroidDialog, "android/app/Dialog")
  1173. #undef JNI_CLASS_MEMBERS
  1174. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  1175. METHOD (construct, "<init>", "(Landroid/content/Context;)V") \
  1176. METHOD (create, "create", "()Landroid/app/AlertDialog;") \
  1177. METHOD (setTitle, "setTitle", "(Ljava/lang/CharSequence;)Landroid/app/AlertDialog$Builder;") \
  1178. METHOD (setMessage, "setMessage", "(Ljava/lang/CharSequence;)Landroid/app/AlertDialog$Builder;") \
  1179. METHOD (setCancelable, "setCancelable", "(Z)Landroid/app/AlertDialog$Builder;") \
  1180. METHOD (setOnCancelListener, "setOnCancelListener", "(Landroid/content/DialogInterface$OnCancelListener;)Landroid/app/AlertDialog$Builder;") \
  1181. METHOD (setPositiveButton, "setPositiveButton", "(Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;") \
  1182. METHOD (setNegativeButton, "setNegativeButton", "(Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;") \
  1183. METHOD (setNeutralButton, "setNeutralButton", "(Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;")
  1184. DECLARE_JNI_CLASS (AndroidAlertDialogBuilder, "android/app/AlertDialog$Builder")
  1185. #undef JNI_CLASS_MEMBERS
  1186. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  1187. METHOD (dismiss, "dismiss", "()V")
  1188. DECLARE_JNI_CLASS (AndroidDialogInterface, "android/content/DialogInterface")
  1189. #undef JNI_CLASS_MEMBERS
  1190. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  1191. DECLARE_JNI_CLASS (AndroidDialogOnClickListener, "android/content/DialogInterface$OnClickListener")
  1192. #undef JNI_CLASS_MEMBERS
  1193. //==============================================================================
  1194. class DialogListener : public juce::AndroidInterfaceImplementer
  1195. {
  1196. public:
  1197. DialogListener (std::shared_ptr<ModalComponentManager::Callback> callbackToUse, int resultToUse)
  1198. : callback (std::move (callbackToUse)), result (resultToUse)
  1199. {}
  1200. void onResult (jobject dialog)
  1201. {
  1202. auto* env = getEnv();
  1203. env->CallVoidMethod (dialog, AndroidDialogInterface.dismiss);
  1204. if (callback != nullptr)
  1205. callback->modalStateFinished (result);
  1206. callback = nullptr;
  1207. }
  1208. private:
  1209. jobject invoke (jobject proxy, jobject method, jobjectArray args) override
  1210. {
  1211. auto* env = getEnv();
  1212. auto methodName = juce::juceString ((jstring) env->CallObjectMethod (method, JavaMethod.getName));
  1213. if (methodName == "onCancel" || methodName == "onClick")
  1214. {
  1215. onResult (env->GetObjectArrayElement (args, 0));
  1216. return nullptr;
  1217. }
  1218. // invoke base class
  1219. return AndroidInterfaceImplementer::invoke (proxy, method, args);
  1220. }
  1221. std::shared_ptr<ModalComponentManager::Callback> callback;
  1222. int result;
  1223. };
  1224. //==============================================================================
  1225. static void createAndroidDialog (const MessageBoxOptions& opts,
  1226. ModalComponentManager::Callback* callbackIn,
  1227. AlertWindowMappings::MapFn mapFn)
  1228. {
  1229. auto* env = getEnv();
  1230. LocalRef<jobject> builder (env->NewObject (AndroidAlertDialogBuilder, AndroidAlertDialogBuilder.construct, getMainActivity().get()));
  1231. builder = LocalRef<jobject> (env->CallObjectMethod (builder.get(), AndroidAlertDialogBuilder.setTitle, javaString (opts.getTitle()).get()));
  1232. builder = LocalRef<jobject> (env->CallObjectMethod (builder.get(), AndroidAlertDialogBuilder.setMessage, javaString (opts.getMessage()).get()));
  1233. builder = LocalRef<jobject> (env->CallObjectMethod (builder.get(), AndroidAlertDialogBuilder.setCancelable, true));
  1234. std::shared_ptr<ModalComponentManager::Callback> sharedCallback (AlertWindowMappings::getWrappedCallback (callbackIn, mapFn));
  1235. builder = LocalRef<jobject> (env->CallObjectMethod (builder.get(), AndroidAlertDialogBuilder.setOnCancelListener,
  1236. CreateJavaInterface (new DialogListener (sharedCallback, 0),
  1237. "android/content/DialogInterface$OnCancelListener").get()));
  1238. builder = LocalRef<jobject> (env->CallObjectMethod (builder.get(), AndroidAlertDialogBuilder.setPositiveButton,
  1239. javaString (opts.getButtonText (0)).get(),
  1240. CreateJavaInterface (new DialogListener (sharedCallback, 0),
  1241. "android/content/DialogInterface$OnClickListener").get()));
  1242. if (opts.getButtonText (1).isNotEmpty())
  1243. builder = LocalRef<jobject> (env->CallObjectMethod (builder.get(), AndroidAlertDialogBuilder.setNegativeButton,
  1244. javaString (opts.getButtonText (1)).get(),
  1245. CreateJavaInterface (new DialogListener (sharedCallback, 1),
  1246. "android/content/DialogInterface$OnClickListener").get()));
  1247. if (opts.getButtonText (2).isNotEmpty())
  1248. builder = LocalRef<jobject> (env->CallObjectMethod (builder.get(), AndroidAlertDialogBuilder.setNeutralButton,
  1249. javaString (opts.getButtonText (2)).get(),
  1250. CreateJavaInterface (new DialogListener (sharedCallback, 2),
  1251. "android/content/DialogInterface$OnClickListener").get()));
  1252. LocalRef<jobject> dialog (env->CallObjectMethod (builder.get(), AndroidAlertDialogBuilder.create));
  1253. LocalRef<jobject> window (env->CallObjectMethod (dialog.get(), AndroidDialog.getWindow));
  1254. if (Desktop::getInstance().getKioskModeComponent() != nullptr)
  1255. {
  1256. env->CallVoidMethod (window.get(), AndroidWindow.setFlags, FLAG_NOT_FOCUSABLE, FLAG_NOT_FOCUSABLE);
  1257. LocalRef<jobject> decorView (env->CallObjectMethod (window.get(), AndroidWindow.getDecorView));
  1258. env->CallVoidMethod (decorView.get(), AndroidView.setSystemUiVisibility, fullScreenFlags);
  1259. }
  1260. env->CallVoidMethod (dialog.get(), AndroidDialog.show);
  1261. if (Desktop::getInstance().getKioskModeComponent() != nullptr)
  1262. env->CallVoidMethod (window.get(), AndroidWindow.clearFlags, FLAG_NOT_FOCUSABLE);
  1263. }
  1264. void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (MessageBoxIconType /*iconType*/,
  1265. const String& title, const String& message,
  1266. Component* /*associatedComponent*/,
  1267. ModalComponentManager::Callback* callback)
  1268. {
  1269. createAndroidDialog (MessageBoxOptions()
  1270. .withTitle (title)
  1271. .withMessage (message)
  1272. .withButton (TRANS("OK")),
  1273. callback, AlertWindowMappings::messageBox);
  1274. }
  1275. bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (MessageBoxIconType /*iconType*/,
  1276. const String& title, const String& message,
  1277. Component* /*associatedComponent*/,
  1278. ModalComponentManager::Callback* callback)
  1279. {
  1280. createAndroidDialog (MessageBoxOptions()
  1281. .withTitle (title)
  1282. .withMessage (message)
  1283. .withButton (TRANS("OK"))
  1284. .withButton (TRANS("Cancel")),
  1285. callback, AlertWindowMappings::okCancel);
  1286. return false;
  1287. }
  1288. int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (MessageBoxIconType /*iconType*/,
  1289. const String& title, const String& message,
  1290. Component* /*associatedComponent*/,
  1291. ModalComponentManager::Callback* callback)
  1292. {
  1293. createAndroidDialog (MessageBoxOptions()
  1294. .withTitle (title)
  1295. .withMessage (message)
  1296. .withButton (TRANS("Yes"))
  1297. .withButton (TRANS("No"))
  1298. .withButton (TRANS("Cancel")),
  1299. callback, AlertWindowMappings::yesNoCancel);
  1300. return 0;
  1301. }
  1302. int JUCE_CALLTYPE NativeMessageBox::showYesNoBox (MessageBoxIconType /*iconType*/,
  1303. const String& title, const String& message,
  1304. Component* /*associatedComponent*/,
  1305. ModalComponentManager::Callback* callback)
  1306. {
  1307. createAndroidDialog (MessageBoxOptions()
  1308. .withTitle (title)
  1309. .withMessage (message)
  1310. .withButton (TRANS("Yes"))
  1311. .withButton (TRANS("No")),
  1312. callback, AlertWindowMappings::okCancel);
  1313. return 0;
  1314. }
  1315. void JUCE_CALLTYPE NativeMessageBox::showAsync (const MessageBoxOptions& options,
  1316. ModalComponentManager::Callback* callback)
  1317. {
  1318. createAndroidDialog (options, callback, AlertWindowMappings::noMapping);
  1319. }
  1320. void JUCE_CALLTYPE NativeMessageBox::showAsync (const MessageBoxOptions& options,
  1321. std::function<void (int)> callback)
  1322. {
  1323. showAsync (options, ModalCallbackFunction::create (callback));
  1324. }
  1325. //==============================================================================
  1326. static bool androidScreenSaverEnabled = true;
  1327. void Desktop::setScreenSaverEnabled (bool shouldEnable)
  1328. {
  1329. constexpr auto FLAG_KEEP_SCREEN_ON = 0x80;
  1330. if (shouldEnable != androidScreenSaverEnabled)
  1331. {
  1332. LocalRef<jobject> activity (getMainActivity());
  1333. if (activity != nullptr)
  1334. {
  1335. auto* env = getEnv();
  1336. LocalRef<jobject> mainWindow (env->CallObjectMethod (activity.get(), AndroidActivity.getWindow));
  1337. env->CallVoidMethod (mainWindow.get(), AndroidWindow.setFlags, shouldEnable ? 0 : FLAG_KEEP_SCREEN_ON, FLAG_KEEP_SCREEN_ON);
  1338. }
  1339. androidScreenSaverEnabled = shouldEnable;
  1340. }
  1341. }
  1342. bool Desktop::isScreenSaverEnabled()
  1343. {
  1344. return androidScreenSaverEnabled;
  1345. }
  1346. //==============================================================================
  1347. void Desktop::setKioskComponent (Component* kioskComp, bool enableOrDisable, bool allowMenusAndBars)
  1348. {
  1349. ignoreUnused (allowMenusAndBars);
  1350. if (AndroidComponentPeer* peer = dynamic_cast<AndroidComponentPeer*> (kioskComp->getPeer()))
  1351. peer->setFullScreen (enableOrDisable);
  1352. else
  1353. jassertfalse; // (this should have been checked by the caller)
  1354. }
  1355. //==============================================================================
  1356. static jint getAndroidOrientationFlag (int orientations) noexcept
  1357. {
  1358. enum
  1359. {
  1360. SCREEN_ORIENTATION_LANDSCAPE = 0,
  1361. SCREEN_ORIENTATION_PORTRAIT = 1,
  1362. SCREEN_ORIENTATION_USER = 2,
  1363. SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 8,
  1364. SCREEN_ORIENTATION_REVERSE_PORTRAIT = 9,
  1365. SCREEN_ORIENTATION_USER_LANDSCAPE = 11,
  1366. SCREEN_ORIENTATION_USER_PORTRAIT = 12,
  1367. };
  1368. switch (orientations)
  1369. {
  1370. case Desktop::upright: return (jint) SCREEN_ORIENTATION_PORTRAIT;
  1371. case Desktop::upsideDown: return (jint) SCREEN_ORIENTATION_REVERSE_PORTRAIT;
  1372. case Desktop::upright + Desktop::upsideDown: return (jint) SCREEN_ORIENTATION_USER_PORTRAIT;
  1373. case Desktop::rotatedAntiClockwise: return (jint) SCREEN_ORIENTATION_LANDSCAPE;
  1374. case Desktop::rotatedClockwise: return (jint) SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
  1375. case Desktop::rotatedClockwise + Desktop::rotatedAntiClockwise: return (jint) SCREEN_ORIENTATION_USER_LANDSCAPE;
  1376. default: return (jint) SCREEN_ORIENTATION_USER;
  1377. }
  1378. }
  1379. void Desktop::allowedOrientationsChanged()
  1380. {
  1381. LocalRef<jobject> activity (getMainActivity());
  1382. if (activity != nullptr)
  1383. getEnv()->CallVoidMethod (activity.get(), AndroidActivity.setRequestedOrientation, getAndroidOrientationFlag (allowedOrientations));
  1384. }
  1385. //==============================================================================
  1386. bool juce_areThereAnyAlwaysOnTopWindows()
  1387. {
  1388. return false;
  1389. }
  1390. //==============================================================================
  1391. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  1392. METHOD (create, "<init>", "()V") \
  1393. FIELD (density, "density", "F") \
  1394. FIELD (widthPixels, "widthPixels", "I") \
  1395. FIELD (heightPixels, "heightPixels", "I")
  1396. DECLARE_JNI_CLASS (AndroidDisplayMetrics, "android/util/DisplayMetrics")
  1397. #undef JNI_CLASS_MEMBERS
  1398. //==============================================================================
  1399. class LayoutChangeListener : public juce::AndroidInterfaceImplementer
  1400. {
  1401. public:
  1402. virtual void onLayoutChange (LocalRef<jobject> view, int left, int top, int right, int bottom,
  1403. int oldLeft, int oldTop, int oldRight, int oldBottom) = 0;
  1404. private:
  1405. jobject invoke (jobject proxy, jobject method, jobjectArray args) override
  1406. {
  1407. auto* env = getEnv();
  1408. auto methodName = juce::juceString ((jstring) env->CallObjectMethod (method, JavaMethod.getName));
  1409. if (methodName == "onLayoutChange")
  1410. {
  1411. jassert (env->GetArrayLength (args) == 9);
  1412. LocalRef<jobject> view (env->GetObjectArrayElement (args, 0));
  1413. int dims[8];
  1414. for (int i = 1; i < 9; ++i)
  1415. {
  1416. LocalRef<jobject> integer (env->GetObjectArrayElement (args, i));
  1417. dims[i - 1] = env->CallIntMethod (integer.get(), JavaInteger.intValue);
  1418. }
  1419. onLayoutChange (std::move (view), dims[0], dims[1], dims[2], dims[3],
  1420. dims[4], dims[5], dims[6], dims[7]);
  1421. return nullptr;
  1422. }
  1423. // invoke base class
  1424. return AndroidInterfaceImplementer::invoke (proxy, method, args);
  1425. }
  1426. std::unique_ptr<ModalComponentManager::Callback> callback;
  1427. };
  1428. //==============================================================================
  1429. struct MainActivityWindowLayoutListener : public LayoutChangeListener
  1430. {
  1431. MainActivityWindowLayoutListener (std::function<void()>&& updateDisplaysCb)
  1432. : forceDisplayUpdate (std::move (updateDisplaysCb))
  1433. {
  1434. }
  1435. void onLayoutChange (LocalRef<jobject> /*view*/, int left, int top, int right, int bottom,
  1436. int oldLeft, int oldTop, int oldRight, int oldBottom) override
  1437. {
  1438. auto newBounds = Rectangle<int>::leftTopRightBottom (left, top, right, bottom);
  1439. auto oldBounds = Rectangle<int>::leftTopRightBottom (oldLeft, oldTop, oldRight, oldBottom);
  1440. if (newBounds != oldBounds)
  1441. {
  1442. const auto& mainDisplay = *Desktop::getInstance().getDisplays().getPrimaryDisplay();
  1443. auto userArea = (newBounds.toFloat() / mainDisplay.scale).toNearestInt();
  1444. if (userArea != mainDisplay.userArea)
  1445. forceDisplayUpdate();
  1446. }
  1447. }
  1448. std::function<void()> forceDisplayUpdate;
  1449. };
  1450. //==============================================================================
  1451. void Displays::findDisplays (float masterScale)
  1452. {
  1453. auto* env = getEnv();
  1454. LocalRef<jobject> usableSize (env->NewObject (AndroidPoint, AndroidPoint.create, 0, 0));
  1455. LocalRef<jstring> windowServiceString (javaString ("window"));
  1456. LocalRef<jobject> displayMetrics (env->NewObject (AndroidDisplayMetrics, AndroidDisplayMetrics.create));
  1457. LocalRef<jobject> windowManager (env->CallObjectMethod (getAppContext().get(), AndroidContext.getSystemService, windowServiceString.get()));
  1458. LocalRef <jobject> display (env->CallObjectMethod (windowManager, AndroidWindowManager.getDefaultDisplay));
  1459. jmethodID getRealMetricsMethod = env->GetMethodID (AndroidDisplay, "getRealMetrics", "(Landroid/util/DisplayMetrics;)V");
  1460. if (getRealMetricsMethod != nullptr)
  1461. env->CallVoidMethod (display.get(), getRealMetricsMethod, displayMetrics.get());
  1462. else
  1463. env->CallVoidMethod (display.get(), AndroidDisplay.getMetrics, displayMetrics.get());
  1464. env->CallVoidMethod (display.get(), AndroidDisplay.getSize, usableSize.get());
  1465. Display d;
  1466. d.isMain = true;
  1467. d.scale = env->GetFloatField (displayMetrics.get(), AndroidDisplayMetrics.density);
  1468. d.dpi = (d.scale * 160.f);
  1469. d.scale *= masterScale;
  1470. d.totalArea = Rectangle<int> (env->GetIntField (displayMetrics.get(), AndroidDisplayMetrics.widthPixels),
  1471. env->GetIntField (displayMetrics.get(), AndroidDisplayMetrics.heightPixels)) / d.scale;
  1472. d.userArea = Rectangle<int> (env->GetIntField (usableSize.get(), AndroidPoint.x),
  1473. env->GetIntField (usableSize.get(), AndroidPoint.y)) / d.scale;
  1474. // unfortunately usableSize still contains the nav bar
  1475. // the best workaround is to try to get the size of the top-level view of
  1476. // the main activity
  1477. LocalRef<jobject> activity (getMainActivity());
  1478. if (activity != nullptr)
  1479. {
  1480. LocalRef<jobject> mainWindow (env->CallObjectMethod (activity.get(), AndroidActivity.getWindow));
  1481. LocalRef<jobject> decorView (env->CallObjectMethod (mainWindow.get(), AndroidWindow.getDecorView));
  1482. LocalRef<jobject> contentView (env->CallObjectMethod (decorView.get(), AndroidView.findViewById, 0x01020002 /* android.R.id.content */));
  1483. if (contentView != nullptr)
  1484. {
  1485. Rectangle<int> activityArea (env->CallIntMethod (contentView.get(), AndroidView.getLeft),
  1486. env->CallIntMethod (contentView.get(), AndroidView.getTop),
  1487. env->CallIntMethod (contentView.get(), AndroidView.getWidth),
  1488. env->CallIntMethod (contentView.get(), AndroidView.getHeight));
  1489. if (! activityArea.isEmpty())
  1490. d.userArea = activityArea / d.scale;
  1491. if (supportsDisplayCutout())
  1492. {
  1493. jmethodID getRootWindowInsetsMethodId = env->GetMethodID (AndroidView,
  1494. "getRootWindowInsets",
  1495. "()Landroid/view/WindowInsets;");
  1496. if (getRootWindowInsetsMethodId != nullptr)
  1497. {
  1498. LocalRef<jobject> insets (env->CallObjectMethod (contentView.get(), getRootWindowInsetsMethodId));
  1499. if (insets != nullptr)
  1500. {
  1501. LocalRef<jobject> displayCutout (env->CallObjectMethod (insets.get(), AndroidWindowInsets.getDisplayCutout));
  1502. if (displayCutout.get() != nullptr)
  1503. d.safeAreaInsets = androidDisplayCutoutToBorderSize (displayCutout, d.scale);
  1504. }
  1505. }
  1506. }
  1507. static bool hasAddedMainActivityListener = false;
  1508. if (! hasAddedMainActivityListener)
  1509. {
  1510. hasAddedMainActivityListener = true;
  1511. env->CallVoidMethod (contentView.get(), AndroidView.addOnLayoutChangeListener,
  1512. CreateJavaInterface (new MainActivityWindowLayoutListener ([this] { refresh(); }),
  1513. "android/view/View$OnLayoutChangeListener").get());
  1514. }
  1515. }
  1516. }
  1517. else
  1518. {
  1519. // the main activity may have not started yet so add an activity listener
  1520. if (AndroidComponentPeer::activityCallbackListener == nullptr)
  1521. {
  1522. LocalRef<jobject> appContext (getAppContext());
  1523. if (appContext.get() != nullptr)
  1524. {
  1525. AndroidComponentPeer::activityCallbackListener = GlobalRef (CreateJavaInterface (
  1526. new AndroidComponentPeer::StartupActivityCallbackListener,
  1527. "android/app/Application$ActivityLifecycleCallbacks"));
  1528. env->CallVoidMethod (appContext.get(),
  1529. AndroidApplication.registerActivityLifecycleCallbacks,
  1530. AndroidComponentPeer::activityCallbackListener.get());
  1531. }
  1532. }
  1533. }
  1534. displays.add (d);
  1535. }
  1536. //==============================================================================
  1537. Image juce_createIconForFile (const File& /*file*/)
  1538. {
  1539. return Image();
  1540. }
  1541. //==============================================================================
  1542. void* CustomMouseCursorInfo::create() const { return nullptr; }
  1543. void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType) { return nullptr; }
  1544. void MouseCursor::deleteMouseCursor (void* /*cursorHandle*/, bool /*isStandard*/) {}
  1545. //==============================================================================
  1546. void MouseCursor::showInWindow (ComponentPeer*) const {}
  1547. //==============================================================================
  1548. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& /*files*/, bool /*canMove*/,
  1549. Component* /*srcComp*/, std::function<void()> /*callback*/)
  1550. {
  1551. jassertfalse; // no such thing on Android!
  1552. return false;
  1553. }
  1554. bool DragAndDropContainer::performExternalDragDropOfText (const String& /*text*/, Component* /*srcComp*/,
  1555. std::function<void()> /*callback*/)
  1556. {
  1557. jassertfalse; // no such thing on Android!
  1558. return false;
  1559. }
  1560. //==============================================================================
  1561. void LookAndFeel::playAlertSound()
  1562. {
  1563. }
  1564. //==============================================================================
  1565. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  1566. METHOD (getText, "getText", "()Ljava/lang/CharSequence;") \
  1567. METHOD (setText, "setText", "(Ljava/lang/CharSequence;)V")
  1568. DECLARE_JNI_CLASS (AndroidClipboardManager, "android/content/ClipboardManager")
  1569. #undef JNI_CLASS_MEMBERS
  1570. //==============================================================================
  1571. void SystemClipboard::copyTextToClipboard (const String& text)
  1572. {
  1573. auto* env = getEnv();
  1574. LocalRef<jobject> clipboardManager (env->CallObjectMethod (getAppContext().get(), AndroidContext.getSystemService, javaString ("clipboard").get()));
  1575. env->CallVoidMethod (clipboardManager.get(), AndroidClipboardManager.setText, javaString(text).get());
  1576. }
  1577. String SystemClipboard::getTextFromClipboard()
  1578. {
  1579. auto* env = getEnv();
  1580. LocalRef<jobject> clipboardManager (env->CallObjectMethod (getAppContext().get(), AndroidContext.getSystemService, javaString ("clipboard").get()));
  1581. LocalRef<jobject> charSequence (env->CallObjectMethod (clipboardManager.get(), AndroidClipboardManager.getText));
  1582. if (charSequence == nullptr)
  1583. return {};
  1584. return juceString(LocalRef<jstring> ((jstring) env->CallObjectMethod(charSequence.get(), JavaCharSequence.toString)));
  1585. }
  1586. //==============================================================================
  1587. const int extendedKeyModifier = 0x10000;
  1588. const int KeyPress::spaceKey = ' ';
  1589. const int KeyPress::returnKey = 66;
  1590. const int KeyPress::escapeKey = 4;
  1591. const int KeyPress::backspaceKey = 67;
  1592. const int KeyPress::leftKey = extendedKeyModifier + 1;
  1593. const int KeyPress::rightKey = extendedKeyModifier + 2;
  1594. const int KeyPress::upKey = extendedKeyModifier + 3;
  1595. const int KeyPress::downKey = extendedKeyModifier + 4;
  1596. const int KeyPress::pageUpKey = extendedKeyModifier + 5;
  1597. const int KeyPress::pageDownKey = extendedKeyModifier + 6;
  1598. const int KeyPress::endKey = extendedKeyModifier + 7;
  1599. const int KeyPress::homeKey = extendedKeyModifier + 8;
  1600. const int KeyPress::deleteKey = extendedKeyModifier + 9;
  1601. const int KeyPress::insertKey = -1;
  1602. const int KeyPress::tabKey = 61;
  1603. const int KeyPress::F1Key = extendedKeyModifier + 10;
  1604. const int KeyPress::F2Key = extendedKeyModifier + 11;
  1605. const int KeyPress::F3Key = extendedKeyModifier + 12;
  1606. const int KeyPress::F4Key = extendedKeyModifier + 13;
  1607. const int KeyPress::F5Key = extendedKeyModifier + 14;
  1608. const int KeyPress::F6Key = extendedKeyModifier + 16;
  1609. const int KeyPress::F7Key = extendedKeyModifier + 17;
  1610. const int KeyPress::F8Key = extendedKeyModifier + 18;
  1611. const int KeyPress::F9Key = extendedKeyModifier + 19;
  1612. const int KeyPress::F10Key = extendedKeyModifier + 20;
  1613. const int KeyPress::F11Key = extendedKeyModifier + 21;
  1614. const int KeyPress::F12Key = extendedKeyModifier + 22;
  1615. const int KeyPress::F13Key = extendedKeyModifier + 23;
  1616. const int KeyPress::F14Key = extendedKeyModifier + 24;
  1617. const int KeyPress::F15Key = extendedKeyModifier + 25;
  1618. const int KeyPress::F16Key = extendedKeyModifier + 26;
  1619. const int KeyPress::F17Key = extendedKeyModifier + 50;
  1620. const int KeyPress::F18Key = extendedKeyModifier + 51;
  1621. const int KeyPress::F19Key = extendedKeyModifier + 52;
  1622. const int KeyPress::F20Key = extendedKeyModifier + 53;
  1623. const int KeyPress::F21Key = extendedKeyModifier + 54;
  1624. const int KeyPress::F22Key = extendedKeyModifier + 55;
  1625. const int KeyPress::F23Key = extendedKeyModifier + 56;
  1626. const int KeyPress::F24Key = extendedKeyModifier + 57;
  1627. const int KeyPress::F25Key = extendedKeyModifier + 58;
  1628. const int KeyPress::F26Key = extendedKeyModifier + 59;
  1629. const int KeyPress::F27Key = extendedKeyModifier + 60;
  1630. const int KeyPress::F28Key = extendedKeyModifier + 61;
  1631. const int KeyPress::F29Key = extendedKeyModifier + 62;
  1632. const int KeyPress::F30Key = extendedKeyModifier + 63;
  1633. const int KeyPress::F31Key = extendedKeyModifier + 64;
  1634. const int KeyPress::F32Key = extendedKeyModifier + 65;
  1635. const int KeyPress::F33Key = extendedKeyModifier + 66;
  1636. const int KeyPress::F34Key = extendedKeyModifier + 67;
  1637. const int KeyPress::F35Key = extendedKeyModifier + 68;
  1638. const int KeyPress::numberPad0 = extendedKeyModifier + 27;
  1639. const int KeyPress::numberPad1 = extendedKeyModifier + 28;
  1640. const int KeyPress::numberPad2 = extendedKeyModifier + 29;
  1641. const int KeyPress::numberPad3 = extendedKeyModifier + 30;
  1642. const int KeyPress::numberPad4 = extendedKeyModifier + 31;
  1643. const int KeyPress::numberPad5 = extendedKeyModifier + 32;
  1644. const int KeyPress::numberPad6 = extendedKeyModifier + 33;
  1645. const int KeyPress::numberPad7 = extendedKeyModifier + 34;
  1646. const int KeyPress::numberPad8 = extendedKeyModifier + 35;
  1647. const int KeyPress::numberPad9 = extendedKeyModifier + 36;
  1648. const int KeyPress::numberPadAdd = extendedKeyModifier + 37;
  1649. const int KeyPress::numberPadSubtract = extendedKeyModifier + 38;
  1650. const int KeyPress::numberPadMultiply = extendedKeyModifier + 39;
  1651. const int KeyPress::numberPadDivide = extendedKeyModifier + 40;
  1652. const int KeyPress::numberPadSeparator = extendedKeyModifier + 41;
  1653. const int KeyPress::numberPadDecimalPoint = extendedKeyModifier + 42;
  1654. const int KeyPress::numberPadEquals = extendedKeyModifier + 43;
  1655. const int KeyPress::numberPadDelete = extendedKeyModifier + 44;
  1656. const int KeyPress::playKey = extendedKeyModifier + 45;
  1657. const int KeyPress::stopKey = extendedKeyModifier + 46;
  1658. const int KeyPress::fastForwardKey = extendedKeyModifier + 47;
  1659. const int KeyPress::rewindKey = extendedKeyModifier + 48;
  1660. //==============================================================================
  1661. #ifdef JUCE_PUSH_NOTIFICATIONS_ACTIVITY
  1662. struct JuceActivityNewIntentListener
  1663. {
  1664. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
  1665. CALLBACK (appNewIntent, "appNewIntent", "(Landroid/content/Intent;)V")
  1666. DECLARE_JNI_CLASS (JavaActivity, JUCE_PUSH_NOTIFICATIONS_ACTIVITY)
  1667. #undef JNI_CLASS_MEMBERS
  1668. static void JNICALL appNewIntent (JNIEnv*, jobject /*activity*/, jobject intentData)
  1669. {
  1670. juce_handleNotificationIntent (static_cast<void*> (intentData));
  1671. }
  1672. };
  1673. JuceActivityNewIntentListener::JavaActivity_Class JuceActivityNewIntentListener::JavaActivity;
  1674. #endif
  1675. } // namespace juce