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.

1664 lines
84KB

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