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

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