changeset 4055:0e0747873240

iOS: adding memory warning handler
author Oldrich Maticka <oldrich.maticka@oracle.com>
date Tue, 25 Jun 2013 15:26:19 +0200
parents ee40f037a5e4
children e2faabf0c904
files glass/glass-lib-ios/src/GlassApplication.m glass/glass-lib-ios/src/GlassHelper.h glass/glass-lib-ios/src/GlassHelper.m glass/glass/src/com/sun/glass/ui/Application.java
diffstat 4 files changed, 43 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/glass/glass-lib-ios/src/GlassApplication.m	Tue Jun 25 14:43:56 2013 +0300
+++ b/glass/glass-lib-ios/src/GlassApplication.m	Tue Jun 25 15:26:19 2013 +0200
@@ -337,6 +337,18 @@
     GLASS_CHECK_EXCEPTION(env);
 }
 
+- (void)callDidReceiveMemoryWarning
+{
+    GET_MAIN_JENV;
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    {
+        (*env)->CallVoidMethod(env, self.jApplication, [GlassHelper ApplicationNotifyDidReceiveMemoryWarningMethod]);
+    }
+    [pool drain];
+    GLASS_CHECK_EXCEPTION(env);
+}
+
+
 - (void)callWillBecomeActive
 {
     GET_MAIN_JENV;
@@ -400,6 +412,10 @@
     [self applicationCallback:@selector(callDidResignActive)];
 }
 
+- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
+    GLASS_LOG("GlassApplication:applicationDidReceiveMemoryWarning");
+    [self applicationCallback:@selector(callDidReceiveMemoryWarning)];
+}
 
 - (void)applicationWillEnterForeground:(UIApplication *)application {
     /*
--- a/glass/glass-lib-ios/src/GlassHelper.h	Tue Jun 25 14:43:56 2013 +0300
+++ b/glass/glass-lib-ios/src/GlassHelper.h	Tue Jun 25 15:26:19 2013 +0200
@@ -47,5 +47,6 @@
 + (jmethodID)ApplicationNotifyWillResignActiveMethod;
 + (jmethodID)ApplicationNotifyDidResignActiveMethod;
 + (jmethodID)ApplicationNotifyQuitMethod;
++ (jmethodID)ApplicationNotifyDidReceiveMemoryWarningMethod;
 
 @end
--- a/glass/glass-lib-ios/src/GlassHelper.m	Tue Jun 25 14:43:56 2013 +0300
+++ b/glass/glass-lib-ios/src/GlassHelper.m	Tue Jun 25 15:26:19 2013 +0200
@@ -206,6 +206,22 @@
     return _ApplicationNotifyDidResignActiveMethod;
 }
 
++ (jmethodID)ApplicationNotifyDidReceiveMemoryWarningMethod
+{
+    static jmethodID _ApplicationNotifyDidReceiveMemoryWarningMethod = NULL;
+    if (_ApplicationNotifyDidReceiveMemoryWarningMethod == NULL)
+    {
+        GET_MAIN_JENV;
+        _ApplicationNotifyDidReceiveMemoryWarningMethod = (*env)->GetMethodID(env, [GlassHelper ApplicationClass], "notifyDidReceiveMemoryWarning", "()V");
+        GLASS_CHECK_EXCEPTION(env);
+    }
+    if (_ApplicationNotifyDidReceiveMemoryWarningMethod == NULL)
+    {
+        NSLog(@"GlassHelper error: _ApplicationNotifyDidReceiveMemoryWarningMethod == NULL");
+    }
+    return _ApplicationNotifyDidReceiveMemoryWarningMethod;
+}
+
 
 + (jmethodID)ApplicationNotifyQuitMethod
 {
--- a/glass/glass/src/com/sun/glass/ui/Application.java	Tue Jun 25 14:43:56 2013 +0300
+++ b/glass/glass/src/com/sun/glass/ui/Application.java	Tue Jun 25 15:26:19 2013 +0200
@@ -62,6 +62,9 @@
         // currently used only on Mac OS X
         public void handleDidResignActiveAction(Application app, long time) {
         }
+        // currently used only on iOS
+        public void handleDidReceiveMemoryWarning(Application app, long time) {
+        }
         // currently used only on Mac OS X
         public void handleWillHideAction(Application app, long time) {
         }
@@ -214,6 +217,13 @@
         }
     }
     
+    private void notifyDidReceiveMemoryWarning() {
+        EventHandler handler = getEventHandler();
+        if (handler != null) {
+            handler.handleDidReceiveMemoryWarning(this, System.nanoTime());
+        }
+    }
+    
     private void notifyWillHide() {
         EventHandler handler = getEventHandler();
         if (handler != null) {