Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3.  
  4. http://www.cocos2d-x.org
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12.  
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. THE SOFTWARE.
  23. ****************************************************************************/
  24. package com.tmg.shivawallpaper;
  25.  
  26. import javax.microedition.khronos.egl.EGLConfig;
  27. import javax.microedition.khronos.opengles.GL10;
  28.  
  29. import org.cocos2dx.lib.Cocos2dxActivity;
  30. import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
  31. import org.cocos2dx.lib.Cocos2dxHelper;
  32. import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener;
  33. import org.cocos2dx.lib.Cocos2dxRenderer;
  34.  
  35. import android.content.Context;
  36. import android.opengl.GLSurfaceView.Renderer;
  37. import android.os.Bundle;
  38. import android.service.wallpaper.WallpaperService;
  39. import android.view.SurfaceHolder;
  40.  
  41. //public class shivalive extends Cocos2dxActivity{
  42. //
  43. // protected void onCreate(Bundle savedInstanceState){
  44. // super.onCreate(savedInstanceState);
  45. // }
  46. //
  47. // static {
  48. // System.loadLibrary("game");
  49. // }
  50. //}
  51. public class shivalive extends WallpaperService
  52. {
  53. static
  54. {
  55. System.loadLibrary("game");
  56. }
  57.  
  58. @Override
  59. public Engine onCreateEngine()
  60. {
  61. return new MyWallpaperEngine();
  62. }
  63.  
  64. // Based on: http://www.learnopengles.com/how-to-use-opengl-es-2-in-an-android-live-wallpaper/
  65. protected class MyWallpaperEngine extends Engine implements Cocos2dxHelperListener
  66. {
  67. protected class MyGLSurfaceView extends Cocos2dxGLSurfaceView
  68. {
  69. MyGLSurfaceView(Context context)
  70. {
  71. super(context);
  72. }
  73. @Override
  74. public SurfaceHolder getHolder()
  75. {
  76. return getSurfaceHolder();
  77. }
  78.  
  79. public void onDestroy()
  80. {
  81. super.onDetachedFromWindow();
  82. }
  83. }
  84.  
  85. protected class MyGLRenderer extends Cocos2dxRenderer
  86. {
  87. //prevent the cocos2dxRenderer from calling nativeInit
  88. @Override
  89. public void onSurfaceCreated(final GL10 pGL10, final EGLConfig pEGLConfig) {
  90. }
  91.  
  92. @Override
  93. public void onSurfaceChanged(final GL10 pGL10, final int pWidth, final int pHeight) {
  94. setScreenWidthAndHeight(pWidth, pHeight);
  95. super.onSurfaceCreated(null, null);
  96. }
  97.  
  98. }
  99.  
  100. private MyGLSurfaceView mGLSurfaceView;
  101. private boolean rendererHasBeenSet;
  102.  
  103. @Override
  104. public void onCreate(SurfaceHolder surfaceHolder)
  105. {
  106. super.onCreate(surfaceHolder);
  107.  
  108. mGLSurfaceView = new MyGLSurfaceView(shivalive.this);
  109. mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
  110. //mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());
  111. setRenderer(getNewRenderer());
  112. Cocos2dxHelper.init(shivalive.this, this);
  113. }
  114.  
  115. @Override
  116. public void onVisibilityChanged(boolean visible)
  117. {
  118. super.onVisibilityChanged(visible);
  119.  
  120. if (visible)
  121. {
  122. Cocos2dxHelper.onResume();
  123. mGLSurfaceView.onResume();
  124. }
  125. else
  126. {
  127. Cocos2dxHelper.onPause();
  128. mGLSurfaceView.onPause();
  129. }
  130. }
  131.  
  132. @Override
  133. public void onDestroy()
  134. {
  135. super.onDestroy();
  136.  
  137. Cocos2dxHelper.end();
  138.  
  139. mGLSurfaceView.onDestroy();
  140. }
  141.  
  142. protected void setRenderer(Renderer renderer) {
  143. mGLSurfaceView.setCocos2dxRenderer((Cocos2dxRenderer) renderer);
  144. rendererHasBeenSet = true;
  145. }
  146.  
  147. Renderer getNewRenderer(){
  148. Cocos2dxRenderer renderer = new MyGLRenderer();
  149. return renderer;
  150. }
  151.  
  152. @Override
  153. public void showDialog(String pTitle, String pMessage)
  154. {
  155. }
  156.  
  157. @Override
  158. public void showEditTextDialog(String pTitle, String pMessage, int pInputMode, int pInputFlag, int pReturnType, int pMaxLength)
  159. {
  160. }
  161.  
  162. @Override
  163. public void runOnGLThread(Runnable pRunnable)
  164. {
  165. mGLSurfaceView.queueEvent(pRunnable);
  166. }
  167. }
  168. }