Skip to content

Commit c2caf72

Browse files
committed
Android: fixed assortment of issues in the Demo + various APIs.
1 parent ee7f989 commit c2caf72

File tree

8 files changed

+81
-64
lines changed

8 files changed

+81
-64
lines changed

demo/SquarePineDemo.jucer

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,12 @@
9494
<EXPORTFORMATS>
9595
<ANDROIDSTUDIO targetFolder="builds/android" smallIcon="jqPxuh" bigIcon="jqPxuh"
9696
androidAdditionalResourceFolders="assets/Android/res" androidTheme="@style/ActivityTheme"
97-
microphonePermissionNeeded="1" cameraPermissionNeeded="1" androidInAppBilling="1"
98-
androidVibratePermissionNeeded="1" androidEnableContentSharing="1"
97+
cameraPermissionNeeded="1" androidVibratePermissionNeeded="1"
9998
androidCustomAppBuildGradleContent=" buildTypes&#10; {&#10; release&#10; {&#10; minifyEnabled true&#10; shrinkResources true&#10; proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'&#10; }&#10; }"
100-
androidMinimumSDK="24">
99+
androidMinimumSDK="24" microphonePermissionNeeded="1" androidTargetSDK="36">
101100
<CONFIGURATIONS>
102-
<CONFIGURATION isDebug="1" name="Debug" targetName="SquarePine Demo" recommendedWarnings="LLVM"/>
103-
<CONFIGURATION isDebug="0" name="Release" targetName="SquarePine Demo" recommendedWarnings="LLVM"
104-
linkTimeOptimisation="1"/>
101+
<CONFIGURATION isDebug="1" name="Debug" recommendedWarnings="LLVM"/>
102+
<CONFIGURATION isDebug="0" name="Release" recommendedWarnings="LLVM" linkTimeOptimisation="1"/>
105103
</CONFIGURATIONS>
106104
<MODULEPATHS>
107105
<MODULEPATH id="juce_analytics" path="../../JUCE/modules"/>

demo/source/demos/EffectChainDemo.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ EffectChainDemo::EffectChainDemo (SharedObjects& sharedObjs) :
371371
applyEffects.setToggleState (! effectChain->isBypassed(), sendNotificationSync);
372372

373373
loop.onClick = [this]() { updateLoopState(); };
374-
load.onClick = [this]() { loadAudioFile(); };
374+
load.onClick = [this]() { loadAudioFile (true); };
375375
goToStart.onClick = [this]() { rewindAndStop(); };
376376

377377
loop.setClickingTogglesState (true);
@@ -660,21 +660,36 @@ void EffectChainDemo::setFile (const File& file, AudioFormatManager* audioFormat
660660
}
661661
}
662662

663-
void EffectChainDemo::loadAudioFile()
663+
void EffectChainDemo::loadAudioFile (bool checkPermissions)
664664
{
665-
if (chooser != nullptr)
665+
if (fileChooser != nullptr)
666666
return;
667667

668668
stop();
669669

670-
chooser.reset (new FileChooser (TRANS ("Load an audio file to process."), {},
671-
sharedObjects.audioFormatManager.getWildcardForAllFormats()));
670+
if (checkPermissions)
671+
{
672+
SafePointer sp (this);
673+
674+
RuntimePermissions::request (RuntimePermissions::readMediaAudio,
675+
[this, sp] (bool wasGranted)
676+
{
677+
if (sp != nullptr && wasGranted)
678+
loadAudioFile (false);
679+
}
680+
);
681+
682+
return;
683+
}
672684

673-
const auto folderChooserFlags = FileBrowserComponent::openMode | FileBrowserComponent::canSelectFiles;
685+
fileChooser = std::make_unique<FileChooser> (TRANS ("Find an audio file to load."),
686+
File::getSpecialLocation (File::userMusicDirectory),
687+
sharedObjects.audioFormatManager.getWildcardForAllFormats());
674688

675-
chooser->launchAsync (folderChooserFlags, [this] (const FileChooser& fc)
689+
fileChooser->launchAsync (FileBrowserComponent::openMode | FileBrowserComponent::canSelectFiles,
690+
[this] (const FileChooser& fc)
676691
{
677-
auto c = std::move (chooser);
692+
auto c = std::move (fileChooser);
678693
ignoreUnused (c);
679694

680695
const auto newFileURL = fc.getURLResult();

demo/source/demos/EffectChainDemo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class EffectChainDemo final : public DemoBase,
260260
EffectChainComponent effectChainComponent;
261261
ToggleButton applyEffects;
262262

263-
std::unique_ptr<FileChooser> chooser;
263+
std::unique_ptr<FileChooser> fileChooser;
264264

265265
File lastLoadedFile;
266266
std::unique_ptr<AudioThumbnail> audioThumbnail;
@@ -287,7 +287,7 @@ class EffectChainDemo final : public DemoBase,
287287
void clear();
288288
void movePlayhead (const MouseEvent& e);
289289
void setFile (const File&, AudioFormatManager* afm = nullptr);
290-
void loadAudioFile();
290+
void loadAudioFile(bool checkPermissions);
291291

292292
//==============================================================================
293293
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EffectChainDemo)

demo/source/demos/ImageDemo.h

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,35 @@ class ImageDemo final : public DemoBase,
1414

1515
open.onClick = [this, sp]()
1616
{
17-
if (sp == nullptr)
17+
if (sp == nullptr || fileChooser != nullptr)
1818
return;
1919

20-
if (fileChooser != nullptr)
21-
{
22-
return;
23-
}
20+
RuntimePermissions::request (RuntimePermissions::readMediaImages,
21+
[this, sp] (bool wasGranted)
22+
{
23+
if (! wasGranted)
24+
return;
2425

25-
fileChooser = std::make_unique<FileChooser> (TRANS ("Find an image to load."),
26-
File::getSpecialLocation (File::userPicturesDirectory),
27-
imageFormatManager.getWildcardForAllFormats());
26+
fileChooser = std::make_unique<FileChooser> (TRANS ("Find an image to load."),
27+
File::getSpecialLocation (File::userPicturesDirectory),
28+
imageFormatManager.getWildcardForAllFormats());
2829

29-
fileChooser->launchAsync (FileBrowserComponent::openMode, [sp] (const FileChooser& chooser)
30-
{
31-
if (sp == nullptr)
32-
return;
30+
fileChooser->launchAsync (FileBrowserComponent::openMode | FileBrowserComponent::canSelectFiles,
31+
[sp] (const FileChooser& chooser)
32+
{
33+
auto c = std::move (sp->fileChooser);
34+
ignoreUnused (c);
35+
36+
const auto newFileURL = chooser.getURLResult();
37+
if (sp == nullptr || newFileURL.isEmpty())
38+
return; // User cancelled.
39+
40+
jassert (newFileURL.isLocalFile());
3341

34-
sp->setImage (chooser.getURLResult());
35-
sp->fileChooser.reset();
36-
});
42+
sp->setImage (newFileURL);
43+
});
44+
}
45+
);
3746
};
3847

3948
addAndMakeVisible (imageComponent);

demo/source/main/MainComponent.cpp

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
#if SQUAREPINE_IS_MOBILE
2-
3-
inline Rectangle<int> getBoundsAccountingForKeyboard()
4-
{
5-
if (auto* display = Desktop::getInstance().getDisplays().getPrimaryDisplay())
6-
{
7-
auto bounds = display->userArea;
8-
9-
// display->safeAreaInsets.subtractFrom (bounds);
10-
// display->keyboardInsets.subtractFrom (bounds);
11-
12-
return bounds;
13-
}
14-
15-
return {};
16-
}
17-
18-
#endif
19-
201
MainComponent::MainComponent (SharedObjects& sharedObjs)
212
{
223
SQUAREPINE_CRASH_TRACER
@@ -82,11 +63,7 @@ MainComponent::MainComponent (SharedObjects& sharedObjs)
8263
addAndMakeVisible (popupButton);
8364
menuItemSelected (1, 0);
8465

85-
#if SQUAREPINE_IS_DESKTOP
8666
setSize (1024, 768);
87-
#else
88-
setBounds (getBoundsAccountingForKeyboard());
89-
#endif
9067
}
9168

9269
MainComponent::~MainComponent()
@@ -150,13 +127,17 @@ void MainComponent::resized()
150127
{
151128
SQUAREPINE_CRASH_TRACER
152129

153-
auto b = getLocalBounds();
130+
auto b = [this]()
131+
{
132+
auto bounds = getLocalBounds();
154133

155-
#if SQUAREPINE_IS_MOBILE
156-
b = getBoundsAccountingForKeyboard();
157-
if (b.isEmpty())
158-
b = getLocalBounds();
159-
#endif
134+
#if SQUAREPINE_IS_MOBILE
135+
if (auto* display = Desktop::getInstance().getDisplays().getDisplayForRect (getScreenBounds()))
136+
return display->safeAreaInsets.subtractedFrom (display->keyboardInsets.subtractedFrom (bounds));
137+
#endif
138+
139+
return bounds;
140+
}();
160141

161142
b = b.reduced (DemoBase::marginPx);
162143

modules/squarepine_graphics/components/HighPerformanceRendererConfigurator.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ void configureContextWithModernGL (OpenGLContext& context, bool shouldEnableMult
2525
gl::loadExtensions();
2626

2727
// NB: On failure, JUCE will backtrack to an earlier version of OpenGL.
28-
context.setOpenGLVersionRequired (OpenGLContext::OpenGLVersion::openGL4_3);
28+
const auto openGLVersion =
29+
#if JUCE_ANDROID
30+
OpenGLContext::OpenGLVersion::defaultGLVersion;
31+
shouldEnableMultisampling = false; // Android's OpenGL ES struggles with configuring multisampling.
32+
#else
33+
OpenGLContext::OpenGLVersion::openGL4_3;
34+
#endif
35+
36+
context.setOpenGLVersionRequired (openGLVersion);
2937
context.setTextureMagnificationFilter (OpenGLContext::linear);
3038

3139
if (shouldEnableMultisampling)

modules/squarepine_graphics/images/ImageFormatManager.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ Image ImageFormatManager::loadFrom (const File& file)
134134

135135
Image ImageFormatManager::loadFrom (const URL& url)
136136
{
137-
return loadFrom (url.getLocalFile());
137+
if (url.isLocalFile())
138+
return loadFrom (url.getLocalFile());
139+
140+
return {};
138141
}
139142

140143
Image ImageFormatManager::loadFrom (const AndroidDocument& androidDocument)
@@ -150,7 +153,6 @@ Image ImageFormatManager::loadFrom (const AndroidDocument& androidDocument)
150153
return loadFrom (androidDocument.getUrl());
151154
}
152155

153-
jassertfalse;
154156
return {};
155157
}
156158

modules/squarepine_graphics/images/Resizer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
4457 4459 6297 6011 6001 6308 6255 6386
77
6385 6246 6387 6263 6262 28182)
88

9-
JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wconversion",
9+
JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wall",
10+
"-Wextra-semi",
11+
"-Wconversion",
1012
"-Wshadow",
13+
"-Wunused-parameter",
1114
"-Wfloat-conversion",
15+
"-Wfloat-equal",
1216
"-Wdeprecated-register",
1317
"-Wdeprecated-declarations",
1418
"-Wswitch-enum",

0 commit comments

Comments
 (0)