Recent

Author Topic: LAMW OpenGLWallpaperService  (Read 3960 times)

drugsound

  • Newbie
  • Posts: 3
LAMW OpenGLWallpaperService
« on: June 25, 2020, 04:25:51 pm »
Hello to all! I need to use OpenGL live wallpapers in my project.

I found an implementation of this in Java.
https://github.com/learnopengles/Learn-OpenGLES-Tutorials/blob/master/android/AndroidOpenGLESLessons/app/src/main/java/com/learnopengles/android/livewallpaper/GLWallpaperService.java
Code: Java  [Select][+][-]
  1. import android.content.Context;
  2. import android.opengl.GLSurfaceView;
  3. import android.opengl.GLSurfaceView.Renderer;
  4. import android.os.Build;
  5. import android.service.wallpaper.WallpaperService;
  6. import android.util.Log;
  7. import android.view.SurfaceHolder;
  8.  
  9. import com.learnopengles.android.util.LoggerConfig;
  10.  
  11. public abstract class GLWallpaperService extends WallpaperService {
  12.  
  13.         public class GLEngine extends Engine {
  14.                 class WallpaperGLSurfaceView extends GLSurfaceView {
  15.                         private static final String TAG = "WallpaperGLSurfaceView";
  16.  
  17.                         WallpaperGLSurfaceView(Context context) {
  18.                                 super(context);
  19.  
  20.                                 if (LoggerConfig.ON) {
  21.                                         Log.d(TAG, "WallpaperGLSurfaceView(" + context + ")");
  22.                                 }
  23.                         }
  24.  
  25.                         @Override
  26.                         public SurfaceHolder getHolder() {
  27.                                 if (LoggerConfig.ON) {
  28.                                         Log.d(TAG, "getHolder(): returning " + getSurfaceHolder());
  29.                                 }
  30.  
  31.                                 return getSurfaceHolder();
  32.                         }
  33.  
  34.                         public void onDestroy() {
  35.                                 if (LoggerConfig.ON) {
  36.                                         Log.d(TAG, "onDestroy()");
  37.                                 }
  38.  
  39.                                 super.onDetachedFromWindow();
  40.                         }
  41.                 }
  42.  
  43.                 private static final String TAG = "GLEngine";
  44.  
  45.                 private WallpaperGLSurfaceView glSurfaceView;
  46.                 private boolean rendererHasBeenSet;            
  47.  
  48.                 @Override
  49.                 public void onCreate(SurfaceHolder surfaceHolder) {
  50.                         if (LoggerConfig.ON) {
  51.                                 Log.d(TAG, "onCreate(" + surfaceHolder + ")");
  52.                         }
  53.  
  54.                         super.onCreate(surfaceHolder);
  55.  
  56.                         glSurfaceView = new WallpaperGLSurfaceView(GLWallpaperService.this);
  57.                 }
  58.  
  59.                 @Override
  60.                 public void onVisibilityChanged(boolean visible) {
  61.                         if (LoggerConfig.ON) {
  62.                                 Log.d(TAG, "onVisibilityChanged(" + visible + ")");
  63.                         }
  64.  
  65.                         super.onVisibilityChanged(visible);
  66.  
  67.                         if (rendererHasBeenSet) {
  68.                                 if (visible) {
  69.                                         glSurfaceView.onResume();
  70.                                 } else {                                       
  71.                                         glSurfaceView.onPause();                                                                                                               
  72.                                 }
  73.                         }
  74.                 }              
  75.  
  76.                 @Override
  77.                 public void onDestroy() {
  78.                         if (LoggerConfig.ON) {
  79.                                 Log.d(TAG, "onDestroy()");
  80.                         }
  81.  
  82.                         super.onDestroy();
  83.                         glSurfaceView.onDestroy();
  84.                 }
  85.                
  86.                 protected void setRenderer(Renderer renderer) {
  87.                         if (LoggerConfig.ON) {
  88.                                 Log.d(TAG, "setRenderer(" + renderer + ")");
  89.                         }
  90.  
  91.                         glSurfaceView.setRenderer(renderer);
  92.                         rendererHasBeenSet = true;
  93.                 }
  94.                
  95.                 protected void setPreserveEGLContextOnPause(boolean preserve) {
  96.                         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
  97.                                 if (LoggerConfig.ON) {
  98.                                         Log.d(TAG, "setPreserveEGLContextOnPause(" + preserve + ")");
  99.                                 }
  100.        
  101.                                 glSurfaceView.setPreserveEGLContextOnPause(preserve);
  102.                         }
  103.                 }              
  104.  
  105.                 protected void setEGLContextClientVersion(int version) {
  106.                         if (LoggerConfig.ON) {
  107.                                 Log.d(TAG, "setEGLContextClientVersion(" + version + ")");
  108.                         }
  109.  
  110.                         glSurfaceView.setEGLContextClientVersion(version);
  111.                 }
  112.         }
  113. }

and OpenGLES2
https://github.com/learnopengles/Learn-OpenGLES-Tutorials/blob/master/android/AndroidOpenGLESLessons/app/src/main/java/com/learnopengles/android/livewallpaper/OpenGLES2WallpaperService.java
Code: Java  [Select][+][-]
  1. import android.app.ActivityManager;
  2. import android.content.Context;
  3. import android.content.pm.ConfigurationInfo;
  4. import android.opengl.GLSurfaceView.Renderer;
  5. import android.view.SurfaceHolder;
  6.  
  7. public abstract class OpenGLES2WallpaperService extends GLWallpaperService {
  8.         @Override
  9.         public Engine onCreateEngine() {
  10.                 return new OpenGLES2Engine();
  11.         }
  12.        
  13.         class OpenGLES2Engine extends GLWallpaperService.GLEngine {
  14.  
  15.                 @Override
  16.                 public void onCreate(SurfaceHolder surfaceHolder) {
  17.                         super.onCreate(surfaceHolder);
  18.                        
  19.                         // Check if the system supports OpenGL ES 2.0.
  20.                         final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
  21.                         final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
  22.                         final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
  23.                        
  24.                         if (supportsEs2)
  25.                         {
  26.                                 // Request an OpenGL ES 2.0 compatible context.
  27.                                 setEGLContextClientVersion(2);
  28.                                
  29.                                 // On Honeycomb+ devices, this improves the performance when
  30.                                 // leaving and resuming the live wallpaper.
  31.                                 setPreserveEGLContextOnPause(true);
  32.  
  33.                                 // Set the renderer to our user-defined renderer.
  34.                                 setRenderer(getNewRenderer());
  35.                         }
  36.                         else
  37.                         {
  38.                                 // This is where you could create an OpenGL ES 1.x compatible
  39.                                 // renderer if you wanted to support both ES 1 and ES 2.
  40.                                 return;
  41.                         }                      
  42.                 }
  43.         }      
  44.        
  45.         abstract Renderer getNewRenderer();
  46. }

Is it possible to create a LAMW component from this?
Are there any tutorials on creating "jComponent"?
thank!

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: LAMW OpenGLWallpaperService
« Reply #1 on: June 25, 2020, 08:07:47 pm »
Quote
Is it possible to create a LAMW component from this?
Are there any tutorials on creating "jComponent"?

Yes!

Go to Lazarus IDE:

"Tools"  ---> "[LAMW] ......."   --->  "New jComponent...."   --->  [HELP]
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

drugsound

  • Newbie
  • Posts: 3
Re: LAMW OpenGLWallpaperService
« Reply #2 on: December 28, 2021, 01:39:55 pm »
I figured out how to create components. But what about WallpaperService?
It is not launched from an application. And it doesn't start MainActivity (App.java and Controls.java).

Or am I wrong?

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: LAMW OpenGLWallpaperService
« Reply #3 on: December 28, 2021, 10:38:41 pm »
Quote
Or am I wrong?

No. 

Here are some complete examples (and you can point up to others....)

https://saltesta.com/android/android-live-wallpaper/

https://www.vogella.com/tutorials/AndroidLiveWallpaper/article.html

https://www.pushing-pixels.org/2010/02/01/live-wallpapers-with-android-sdk-2-1.html


Can you point out which of these examples (or others....) is closest to your needs?
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

drugsound

  • Newbie
  • Posts: 3
Re: LAMW OpenGLWallpaperService
« Reply #4 on: January 02, 2022, 01:15:06 pm »
Quote
Can you point out which of these examples (or others....) is closest to your needs?

I think this

https://www.vogella.com/tutorials/AndroidLiveWallpaper/article.html

 

TinyPortal © 2005-2018