Audio plugin host https://kx.studio/carla
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.

1671 lines
85KB

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