@Override
 public void onVisibilityChanged(boolean visible) {
   super.onVisibilityChanged(visible);
   if (mWallpaperRS != null) {
     if (visible) {
       mWallpaperRS.start();
     } else {
       mWallpaperRS.stop();
     }
   }
 }
    @Override
    public void onSurfaceChanged(SurfaceHolder surfaceHolder, int format, int width, int height) {
      super.onSurfaceChanged(surfaceHolder, format, width, height);

      if (mRenderScript != null) {
        mRenderScript.setSurface(surfaceHolder, width, height);
      }

      if (mWallpaperRS == null) {
        mWallpaperRS = new PhaseBeamRS();
        mWallpaperRS.init(mDensityDPI, mRenderScript, getResources(), width, height);
        mWallpaperRS.start();
      }

      mWallpaperRS.resize(width, height);
    }
    public void destroyRenderer() {
      if (mWallpaperRS != null) {
        mWallpaperRS.stop();
        mWallpaperRS = null;
      }

      if (mRenderScript != null) {
        mRenderScript.setSurface(null, 0, 0);
        mRenderScript.destroy();
        mRenderScript = null;
      }
    }