1 /* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * xscreensaver, Copyright (c) 2016-2018 Jamie Zawinski <jwz@jwz.org>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
12 * The superclass of every saver's Wallpaper.
14 * Each Wallpaper needs a distinct subclass in order to show up in the list.
15 * We know which saver we are running by the subclass name; we know which
16 * API to use by how the subclass calls super().
19 package org.jwz.xscreensaver;
21 import android.content.res.Configuration;
22 import android.service.wallpaper.WallpaperService;
23 import android.view.GestureDetector;
24 import android.view.SurfaceHolder;
25 import android.util.Log;
26 import java.lang.RuntimeException;
27 import java.lang.Thread;
28 import org.jwz.xscreensaver.jwxyz;
29 import android.graphics.PixelFormat;
30 import android.view.WindowManager;
31 import android.view.Display;
32 import android.graphics.Point;
34 public class Wallpaper extends WallpaperService
35 /*implements GestureDetector.OnGestureListener,
36 GestureDetector.OnDoubleTapListener, */ {
39 private Engine engine;
42 public Engine onCreateEngine() {
43 // Log.d("xscreensaver", "tid = " + Thread.currentThread().getId());
44 engine = new XScreenSaverGLEngine();
49 public void onConfigurationChanged(Configuration config) {
50 super.onConfigurationChanged(config);
51 Log.d("xscreensaver", "wallpaper onConfigurationChanged");
53 WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
54 Display display = wm.getDefaultDisplay();
55 Point size = new Point();
56 display.getSize(size);
59 engine.onSurfaceChanged(engine.getSurfaceHolder(), PixelFormat.RGBA_8888, width, height);
64 class XScreenSaverGLEngine extends Engine {
66 private boolean initTried = false;
67 private jwxyz jwxyz_obj;
70 public void onSurfaceCreated (SurfaceHolder holder) {
71 super.onSurfaceCreated(holder);
76 if (jwxyz_obj != null) {
84 public void onVisibilityChanged(final boolean visible) {
85 if (jwxyz_obj != null) {
94 public void onSurfaceChanged (SurfaceHolder holder, int format,
95 int width, int height) {
97 super.onSurfaceChanged(holder, format, width, height);
99 if (width == 0 || height == 0) {
104 Log.d ("xscreensaver",
105 String.format("surfaceChanged: %dx%d", width, height));
107 if (jwxyz_obj == null) {
108 jwxyz_obj = new jwxyz (jwxyz.saverNameOf(Wallpaper.this),
109 Wallpaper.this, null, width, height,
110 holder.getSurface(), null);
112 jwxyz_obj.resize (width, height);
119 public void onSurfaceDestroyed (SurfaceHolder holder) {
120 super.onSurfaceDestroyed (holder);
122 if (jwxyz_obj != null) {