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.

1634 lines
83KB

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