diff options
Diffstat (limited to 'src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseActivity.java')
-rw-r--r-- | src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseActivity.java | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseActivity.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseActivity.java new file mode 100644 index 0000000..6ea835c --- /dev/null +++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseActivity.java @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cyanogenmod.wallpapers.photophase; + +import android.app.Activity; +import android.content.Intent; +import android.opengl.GLSurfaceView; +import android.os.Bundle; +import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.Window; +import android.view.WindowManager; + +import org.cyanogenmod.wallpapers.photophase.preferences.PhotoPhasePreferences; +import org.cyanogenmod.wallpapers.photophase.preferences.PreferencesProvider; + +/** + * A testing activity to simulate the PhotoPhase Live Wallpaper inside an GLES activity. + */ +public class PhotoPhaseActivity extends Activity { + + private static final String TAG = "PhotoPhaseActivity"; + + private static final boolean DEBUG = true; + + private GLSurfaceView mGLSurfaceView; + private PhotoPhaseRenderer mRenderer; + + /** + * {@inheritDoc} + */ + @Override + protected void onCreate(Bundle savedInstanceState) { + if (DEBUG) Log.d(TAG, "onCreate"); + super.onCreate(savedInstanceState); + + boolean preserveEglCtx = getResources().getBoolean(R.bool.config_preserve_egl_context); + + // Instance the application + PreferencesProvider.reload(this); + Colors.register(this); + + requestWindowFeature(Window.FEATURE_NO_TITLE); + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + + // Configure the EGL context + mGLSurfaceView = new GLSurfaceView(getApplicationContext()); + mGLSurfaceView.setEGLContextClientVersion(2); + mGLSurfaceView.setEGLConfigChooser(false); + mRenderer = new PhotoPhaseRenderer(this, new GLESSurfaceDispatcher(mGLSurfaceView)); + mGLSurfaceView.setRenderer(mRenderer); + mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); + mGLSurfaceView.setPreserveEGLContextOnPause(preserveEglCtx); + setContentView(mGLSurfaceView); + + mRenderer.onCreate(); + } + + /** + * {@inheritDoc} + */ + @Override + public void onDestroy() { + if (DEBUG) Log.d(TAG, "onDestroy"); + super.onDestroy(); + mRenderer.onDestroy(); + } + + /** + * {@inheritDoc} + */ + @Override + protected void onResume() { + super.onResume(); + if (DEBUG) Log.d(TAG, "onResume"); + mGLSurfaceView.onResume(); + mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); + if (mRenderer != null) { + mRenderer.onResume(); + } + } + + /** + * {@inheritDoc} + */ + @Override + protected void onPause() { + super.onPause(); + if (DEBUG) Log.d(TAG, "onPause"); + mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); + mRenderer.onPause(); + mGLSurfaceView.onPause(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.main, menu); + return super.onCreateOptionsMenu(menu); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.mnu_settings: + Intent settings = new Intent(this, PhotoPhasePreferences.class); + startActivity(settings); + return true; + default: + return super.onOptionsItemSelected(item); + } + } +} |