Browse Source

Added callbacks JUCEApplication::suspended() and resumed() for iOS and Android.

tags/2021-05-28
jules 13 years ago
parent
commit
7ce0bf15d3
7 changed files with 86 additions and 7 deletions
  1. +16
    -0
      extras/JuceDemo/Builds/Android/src/com/juce/JuceDemo.java
  2. +16
    -0
      modules/juce_core/native/java/JuceAppActivity.java
  3. +10
    -0
      modules/juce_events/messages/juce_ApplicationBase.h
  4. +4
    -7
      modules/juce_gui_basics/application/juce_Application.cpp
  5. +10
    -0
      modules/juce_gui_basics/application/juce_Application.h
  6. +14
    -0
      modules/juce_gui_basics/native/juce_android_Windowing.cpp
  7. +16
    -0
      modules/juce_gui_basics/native/juce_ios_Windowing.mm

+ 16
- 0
extras/JuceDemo/Builds/Android/src/com/juce/JuceDemo.java View File

@@ -71,6 +71,20 @@ public final class JuceDemo extends Activity
super.onDestroy();
}
@Override
protected final void onPause()
{
suspendApp();
super.onPause();
}
@Override
protected final void onResume()
{
super.onResume();
resumeApp();
}
@Override
public void onConfigurationChanged (Configuration cfg)
{
@@ -87,6 +101,8 @@ public final class JuceDemo extends Activity
//==============================================================================
private native void launchApp (String appFile, String appDataDir);
private native void quitApp();
private native void suspendApp();
private native void resumeApp();
private native void setScreenSize (int screenWidth, int screenHeight);
//==============================================================================


+ 16
- 0
modules/juce_core/native/java/JuceAppActivity.java View File

@@ -71,6 +71,20 @@ public final class JuceAppActivity extends Activity
super.onDestroy();
}
@Override
protected final void onPause()
{
suspendApp();
super.onPause();
}
@Override
protected final void onResume()
{
super.onResume();
resumeApp();
}
@Override
public void onConfigurationChanged (Configuration cfg)
{
@@ -87,6 +101,8 @@ public final class JuceAppActivity extends Activity
//==============================================================================
private native void launchApp (String appFile, String appDataDir);
private native void quitApp();
private native void suspendApp();
private native void resumeApp();
private native void setScreenSize (int screenWidth, int screenHeight);
//==============================================================================


+ 10
- 0
modules/juce_events/messages/juce_ApplicationBase.h View File

@@ -127,6 +127,16 @@ public:
*/
virtual void systemRequestedQuit() = 0;
/** This method is called when the application is being put into background mode
by the operating system.
*/
virtual void suspended() = 0;
/** This method is called when the application is being woken from background mode
by the operating system.
*/
virtual void resumed() = 0;
/** If any unhandled exceptions make it through to the message dispatch loop, this
callback will be triggered, in case you want to log them or do some other
type of error-handling.


+ 4
- 7
modules/juce_gui_basics/application/juce_Application.cpp View File

@@ -60,14 +60,11 @@ JUCEApplication::~JUCEApplication()
}
//==============================================================================
bool JUCEApplication::moreThanOneInstanceAllowed()
{
return true;
}
bool JUCEApplication::moreThanOneInstanceAllowed() { return true; }
void JUCEApplication::anotherInstanceStarted (const String&) {}
void JUCEApplication::anotherInstanceStarted (const String&)
{
}
void JUCEApplication::suspended() {}
void JUCEApplication::resumed() {}
void JUCEApplication::systemRequestedQuit()
{


+ 10
- 0
modules/juce_gui_basics/application/juce_Application.h View File

@@ -161,6 +161,16 @@ public:
*/
virtual void systemRequestedQuit();
/** This method is called when the application is being put into background mode
by the operating system.
*/
virtual void suspended();
/** This method is called when the application is being woken from background mode
by the operating system.
*/
virtual void resumed();
/** If any unhandled exceptions make it through to the message dispatch loop, this
callback will be triggered, in case you want to log them or do some other
type of error-handling.


+ 14
- 0
modules/juce_gui_basics/native/juce_android_Windowing.cpp View File

@@ -49,6 +49,20 @@ JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, launchApp, void, (JNIEnv* en
jassert (MessageManager::getInstance()->isThisTheMessageThread());
}
JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, suspendApp, void, (JNIEnv* env, jobject activity))
{
JUCEApplicationBase* const app = JUCEApplicationBase::getInstance();
if (app != nullptr)
app->suspended();
}
JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, resumeApp, void, (JNIEnv* env, jobject activity))
{
JUCEApplicationBase* const app = JUCEApplicationBase::getInstance();
if (app != nullptr)
app->resumed();
}
JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, quitApp, void, (JNIEnv* env, jobject activity))
{
JUCEApplicationBase::appWillTerminateByForce();


+ 16
- 0
modules/juce_gui_basics/native/juce_ios_Windowing.mm View File

@@ -31,6 +31,8 @@
- (void) applicationDidFinishLaunching: (UIApplication*) application;
- (void) applicationWillTerminate: (UIApplication*) application;
- (void) applicationDidEnterBackground: (UIApplication*) application;
- (void) applicationWillEnterForeground: (UIApplication*) application;
@end
@@ -50,6 +52,20 @@
JUCEApplicationBase::appWillTerminateByForce();
}
- (void) applicationDidEnterBackground: (UIApplication*) application
{
JUCEApplicationBase* const app = JUCEApplicationBase::getInstance();
if (app != nullptr)
app->suspended();
}
- (void) applicationWillEnterForeground: (UIApplication*) application
{
JUCEApplicationBase* const app = JUCEApplicationBase::getInstance();
if (app != nullptr)
app->resumed();
}
@end
namespace juce


Loading…
Cancel
Save