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.

1674 lines
85KB

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