Permalink
Browse files

Merge pull request #123 from divineprog/master

[MOSYNC-2021] Android: Implementation of maWakeLock
  • Loading branch information...
2 parents a9d546e + 1066bfe commit 840e8a626c024b7c1f5336b28ae3e83cf47cb0f9 Ali Sarrafi committed Mar 28, 2012
@@ -743,6 +743,20 @@ namespace Base
return (int)result;
}
+ int _maWakeLock(int flag, JNIEnv* jNIEnv, jobject jThis)
+ {
+ jclass cls = jNIEnv->GetObjectClass(jThis);
+ jmethodID methodID = jNIEnv->GetMethodID(
+ cls,
+ "maWakeLock",
+ "(I)I");
+ if (methodID == 0) return -2;
+ jint result = jNIEnv->CallIntMethod(jThis, methodID, flag);
+ jNIEnv->DeleteLocalRef(cls);
+
+ return (int)result;
+ }
+
int _maWidgetCreate(const char *widgetType, JNIEnv* jNIEnv, jobject jThis)
{
// Get the Java method
@@ -221,6 +221,8 @@ namespace Base
*/
int _maScreenStateEventsOnOff(int eventsOn, JNIEnv* jNIEnv, jobject jThis);
+ int _maWakeLock(int flag, JNIEnv* jNIEnv, jobject jThis);
+
int _maTextBox(const wchar* title, const wchar* inText, int outText,
int maxSize, int constraints, int memStart,
JNIEnv* jNIEnv, jobject jThis);
@@ -1891,6 +1891,10 @@ namespace Base
// 0 = events off
return _maScreenStateEventsOnOff(0, mJNIEnv, mJThis);
+ case maIOCtl_maWakeLock:
+ SYSLOG("maIOCtl_maWakeLock");
+ return _maWakeLock(a, mJNIEnv, mJThis);
+
case maIOCtl_maMessageBox:
SYSLOG("maIOCtl_maMessageBox");
return _maMessageBox(
@@ -110,6 +110,8 @@ public void Init(Syscalls syscalls, Core core, Runtime runtime)
* Discussion: this needs to be re-enabled for the backlight to work
* so an maStartBacklight should be needed for WP7;
* what about maToggleBacklight(bool)?
+ *
+ * We have maWakeLock instead on Windows Phone, Android, iOS.
*/
syscalls.maResetBacklight = delegate()
{
@@ -299,8 +301,24 @@ public void Init(Ioctls ioctls, Core core, Runtime runtime)
}
return value.Length + 1;
};
- }
+ ioctls.maWakeLock = delegate(int flag)
+ {
+ if (MoSync.Constants.MA_WAKE_LOCK_ON == flag)
+ {
+ Microsoft.Phone.Shell.PhoneApplicationService.Current.
+ UserIdleDetectionMode =
+ Microsoft.Phone.Shell.IdleDetectionMode.Enabled;
+ }
+ else
+ {
+ Microsoft.Phone.Shell.PhoneApplicationService.Current.
+ UserIdleDetectionMode =
+ Microsoft.Phone.Shell.IdleDetectionMode.Disabled;
+ }
+ return 1;
+ };
+ }
/**
* Retrieves the values of MoSync System Properties
@@ -50,12 +50,14 @@
import static com.mosync.internal.generated.MAAPI_consts.MA_RESOURCE_OPEN;
import static com.mosync.internal.generated.MAAPI_consts.MA_RESOURCE_CLOSE;
+import static com.mosync.internal.generated.MAAPI_consts.MA_WAKE_LOCK_ON;
+import static com.mosync.internal.generated.MAAPI_consts.MA_WAKE_LOCK_OFF;
+
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
@@ -100,7 +102,7 @@
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.util.Log;
-import android.view.View;
+import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
@@ -118,7 +120,6 @@
import com.mosync.java.android.TextBox;
import com.mosync.nativeui.ui.widgets.MoSyncCameraPreview;
import com.mosync.nativeui.ui.widgets.ScreenWidget;
-import com.mosync.nativeui.ui.widgets.Widget;
import com.mosync.nativeui.util.AsyncWait;
/**
@@ -3918,6 +3919,43 @@ int maHomeScreenEventsOnOff(int eventsOn)
return mMoSyncHomeScreen.maHomeScreenEventsOnOff(eventsOn);
}
+ /**
+ * Activate/deactivate wake lock.
+ * @param flag
+ */
+ int maWakeLock(final int flag)
+ {
+ getActivity().runOnUiThread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ if (MA_WAKE_LOCK_ON == flag)
+ {
+ Window w = mContext.getWindow();
+ w.setFlags(
+ WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
+ WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ }
+ else
+ {
+ Window w = mContext.getWindow();
+ w.setFlags(
+ 0,
+ WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ }
+ }
+ catch(Exception ex)
+ {
+ Log.i("MoSync", "maWakeLock: Could not set wake lock.");
+ ex.printStackTrace();
+ }
+ }
+ });
+ return 1;
+ }
+
/**
* Internal wrapper for maWidgetCreate that runs
* the call in the UI thread.
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?>
+
+<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+ <storageModule moduleId="org.eclipse.cdt.core.settings">
+ <cconfiguration id="org.eclipse.cdt.core.default.config.57093212">
+ <storageModule buildSystemId="org.eclipse.cdt.core.defaultConfigDataProvider" id="org.eclipse.cdt.core.default.config.57093212" moduleId="org.eclipse.cdt.core.settings" name="Configuration">
+ <externalSettings/>
+ <extensions/>
+ </storageModule>
+ <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+ </cconfiguration>
+ </storageModule>
+ <storageModule moduleId="org.eclipse.cdt.core.pathentry">
+ <pathentry kind="con" path="com.mobilesorcery.mosync.includepaths"/>
+ </storageModule>
+</cproject>
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project supports-build-configs="true" version="1.4">
+<build.cfg id="Debug" types="Debug"/>
+<build.cfg id="Release" types="Release"/>
+<criteria>
+<filter type="com.mobilesorcery.sdk.capabilities.devices.elementfactory">
+<capabilities optional="" required=""/>
+</filter>
+</criteria>
+<properties>
+<property key="build.prefs:additional.libraries" value="MAUtil.lib"/>
+<property key="build.prefs:additional.libraries/Debug" value="MAUtilD.lib"/>
+<property key="profile.mgr.type" value="0"/>
+<property key="template.id" value="project.moblet"/>
+<property key="winmobilecs:guid" value="7d8b60a0-5afa-102f-80c7-8b10f57efc89"/>
+</properties>
+</project>
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>WakeLock</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.mobilesorcery.sdk.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.mobilesorcery.sdk.core.nature</nature>
+ <nature>org.eclipse.cdt.core.cnature</nature>
+ <nature>org.eclipse.cdt.core.ccnature</nature>
+ </natures>
+ <filteredResources>
+ <filter>
+ <id>1332925411557</id>
+ <name></name>
+ <type>6</type>
+ <matcher>
+ <id>org.eclipse.ui.ide.multiFilter</id>
+ <arguments>1.0-name-matches-false-true-.*rebuild.build.cpp</arguments>
+ </matcher>
+ </filter>
+ </filteredResources>
+</projectDescription>
@@ -0,0 +1,3 @@
+#Wed Mar 28 11:03:31 CEST 2012
+eclipse.preferences.version=1
+encoding/<project>=UTF-8
@@ -0,0 +1,47 @@
+#include <MAUtil/Moblet.h>
+#include <conprint.h>
+
+using namespace MAUtil;
+
+class MyMoblet : public Moblet
+{
+public:
+ MyMoblet() : mWakeLockOn(false)
+ {
+ printf("Test wake lock\n");
+ printf("Touch screen to toggle wake lock on/off\n");
+ printf("Press zero or back to exit\n");
+ }
+
+ void keyPressEvent(int keyCode, int nativeCode)
+ {
+ if (MAK_BACK == keyCode || MAK_0 == keyCode)
+ {
+ // Call close to exit the application.
+ close();
+ }
+ }
+
+ void pointerReleaseEvent(MAPoint2d point)
+ {
+ if (mWakeLockOn)
+ {
+ maWakeLock(MA_WAKE_LOCK_OFF);
+ printf("Wake lock is OFF\n");
+ }
+ else
+ {
+ maWakeLock(MA_WAKE_LOCK_ON);
+ printf("Wake lock is ON\n");
+ }
+ mWakeLockOn = !mWakeLockOn;
+ }
+
+ bool mWakeLockOn;
+};
+
+extern "C" int MAMain()
+{
+ Moblet::run(new MyMoblet());
+ return 0;
+}
View
@@ -1,18 +1,19 @@
-/* Copyright (C) 2009 Mobile Sorcery AB
+/*
+Copyright (C) 2009 MoSync AB
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License, version 2, as published by
-the Free Software Foundation.
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License,
+version 2, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-or FITNESS FOR A PARTICULAR PURPOSE. ee the GNU General Public License
-for more details.
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with this program; see the file COPYING. If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+MA 02110-1301, USA.
*/
/** \file maapi.h
@@ -8450,6 +8451,21 @@ group CameraFunctions "Camera Functions" {
*/
int maScreenStateEventsOff();
+ /**
+ * Lock device to be "awake". This means that the device
+ * won't go to sleep while the app is running.
+ * @param flag MA_WAKE_LOCK_ON or MA_WAKE_LOCK_OFF
+ * @return \>0 on success, \< 0 on error (-1 if not available).
+ */
+ int maWakeLock(in int flag);
+
+ constset int MA_WAKE_LOCK_ {
+ /// Application will run with screen on (consumes power).
+ ON = 1;
+ /// Turn off the wake lock.
+ OFF = 2;
+ }
+
group OpenGLES "OpenGLES" {
#include "opengl_non_generated.idl"
#include "opengl_generated.idl"

0 comments on commit 840e8a6

Please sign in to comment.