Example usage for android.opengl GLSurfaceView RENDERMODE_CONTINUOUSLY

List of usage examples for android.opengl GLSurfaceView RENDERMODE_CONTINUOUSLY

Introduction

In this page you can find the example usage for android.opengl GLSurfaceView RENDERMODE_CONTINUOUSLY.

Prototype

int RENDERMODE_CONTINUOUSLY

To view the source code for android.opengl GLSurfaceView RENDERMODE_CONTINUOUSLY.

Click Source Link

Document

The renderer is called continuously to re-render the scene.

Usage

From source file:com.almalence.opencam.PluginManagerBase.java

public boolean handleApplicationMessage(Message msg) {
    long sessionID = 0;

    switch (msg.what) {
    case ApplicationInterface.MSG_NO_CAMERA:
        break;//ww  w . ja  va2  s  .co m

    case ApplicationInterface.MSG_CAPTURE_FINISHED:

        /*
         * Debug code for Galaxy S6 in Super mode. Look at Camera2 for more
         * details
         */
        // CameraController.onCaptureFinished();

        if (ApplicationScreen.instance.getFlashModePref(
                ApplicationScreen.sDefaultFlashValue) == CameraParameters.FLASH_MODE_CAPTURE_TORCH) {
            // If flashMode == FLASH_MODE_CAPTURE_TORCH, then turn off torch
            // after capturing completed.
            CameraController.setCameraFlashMode(CameraParameters.FLASH_MODE_OFF);
        }

        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onCaptureFinished();

        ApplicationScreen.getGUIManager().onCaptureFinished();
        ApplicationScreen.getGUIManager().startProcessingAnimation();

        int id = ApplicationScreen.getAppResources().getIdentifier(getActiveMode().modeName, "string",
                ApplicationScreen.instance.getPackageName());
        String modeName = ApplicationScreen.getAppResources().getString(id);
        addToSharedMem("mode_name" + (String) msg.obj, modeName);
        // start async task for further processing
        cntProcessing++;

        sessionID = Long.valueOf((String) msg.obj);

        // Map sessionID and processing plugin, because active plugin may be
        // changed before image processing will start.
        // We don't map export plugin, because it's the same for all modes.
        processingPluginList.put(sessionID, pluginList.get(activeProcessing));

        Intent mServiceIntent = new Intent(ApplicationScreen.instance, ProcessingService.class);

        // Pass to Service sessionID and some other parameters, that may be
        // required.
        mServiceIntent.putExtra("sessionID", sessionID);
        CameraController.Size imageSize = CameraController.getCameraImageSize();
        PluginManager.getInstance().addToSharedMem("imageWidth" + sessionID,
                String.valueOf(imageSize.getWidth()));
        PluginManager.getInstance().addToSharedMem("imageHeight" + sessionID,
                String.valueOf(imageSize.getHeight()));
        PluginManager.getInstance().addToSharedMem("wantLandscapePhoto" + sessionID,
                String.valueOf(ApplicationScreen.getWantLandscapePhoto()));
        PluginManager.getInstance().addToSharedMem("cameraMirrored" + sessionID,
                String.valueOf(CameraController.isFrontCamera()));

        // Start processing service with current sessionID.
        ApplicationScreen.instance.startService(mServiceIntent);

        ApplicationScreen.instance.muteShutter(false);

        break;

    case ApplicationInterface.MSG_CAPTURE_FINISHED_NORESULT:

        /*
         * Debug code for Galaxy S6 in Super mode. Look at Camera2 for more
         * details
         */
        // CameraController.onCaptureFinished();

        if (ApplicationScreen.instance.getFlashModePref(
                ApplicationScreen.sDefaultFlashValue) == CameraParameters.FLASH_MODE_CAPTURE_TORCH) {
            // If flashMode == FLASH_MODE_CAPTURE_TORCH, then turn off torch
            // after capturing completed.
            CameraController.setCameraFlashMode(CameraParameters.FLASH_MODE_OFF);
        }

        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onCaptureFinished();

        ApplicationScreen.getGUIManager().onCaptureFinished();
        ApplicationScreen.getGUIManager().startProcessingAnimation();

        ApplicationScreen.instance.muteShutter(false);

        ApplicationScreen.getGUIManager().lockControls = false;

        sendMessage(ApplicationInterface.MSG_BROADCAST, ApplicationInterface.MSG_CONTROL_UNLOCKED);

        ApplicationScreen.getGUIManager().onExportFinished();

        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onExportFinished();

        break;

    case ApplicationInterface.MSG_START_POSTPROCESSING:
        if (null != pluginList.get(activeProcessing)) {
            ApplicationScreen.getGUIManager().lockControls = true;
            sendMessage(ApplicationInterface.MSG_BROADCAST, ApplicationInterface.MSG_CONTROL_LOCKED);

            pluginList.get(activeProcessing).onStartPostProcessing();
            ApplicationScreen.getGUIManager().onPostProcessingStarted();
        }
        break;

    case ApplicationInterface.MSG_POSTPROCESSING_FINISHED:
        sessionID = 0;
        String sSessionID = getFromSharedMem("sessionID");
        if (sSessionID != null)
            sessionID = Long.parseLong(getFromSharedMem("sessionID"));

        // notify GUI about saved images
        ApplicationScreen.getGUIManager().lockControls = false;
        sendMessage(ApplicationInterface.MSG_BROADCAST, ApplicationInterface.MSG_CONTROL_UNLOCKED);

        ApplicationScreen.getGUIManager().onPostProcessingFinished();
        if (null != pluginList.get(activeExport) && 0 != sessionID) {
            pluginList.get(activeExport).onExportActive(sessionID);
        } else {
            ApplicationScreen.getMessageHandler().sendEmptyMessage(ApplicationInterface.MSG_EXPORT_FINISHED);
            clearSharedMemory(sessionID);
        }

        break;
    case ApplicationInterface.MSG_EXPORT_FINISHED:
        // event from plugin that saving finished and memory can be freed
        if (cntProcessing > 0)
            cntProcessing--;
        // free memory in processing
        if (null != pluginList.get(activeProcessing))
            pluginList.get(activeProcessing).freeMemory();

        // notify GUI about saved images
        ApplicationScreen.getGUIManager().onExportFinished();

        // notify capture plugins that saving finished
        if (null != pluginList.get(activeCapture))
            pluginList.get(activeCapture).onExportFinished();
        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onExportFinished();

        if (ApplicationScreen.instance.getIntent().getAction() != null) {
            if (ApplicationScreen.instance.getIntent().getAction().equals(MediaStore.ACTION_IMAGE_CAPTURE)) {
                ApplicationScreen.getMessageHandler()
                        .sendEmptyMessage(ApplicationInterface.MSG_RETURN_CAPTURED);
            }
        }

        ApplicationScreen.getGUIManager().lockControls = false;
        sendMessage(ApplicationInterface.MSG_BROADCAST, ApplicationInterface.MSG_CONTROL_UNLOCKED);

        break;

    case ApplicationInterface.MSG_EXPORT_FINISHED_IOEXCEPTION:
        // event from plugin that saving finished and memory can be freed
        if (cntProcessing > 0)
            cntProcessing--;
        // free memory in processing
        if (null != pluginList.get(activeProcessing))
            pluginList.get(activeProcessing).freeMemory();

        // notify GUI about saved images
        ApplicationScreen.getGUIManager().onExportFinished();

        // notify capture plugins that saving finished
        if (null != pluginList.get(activeCapture))
            pluginList.get(activeCapture).onExportFinished();
        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onExportFinished();

        Toast.makeText(ApplicationScreen.getMainContext(),
                "Can't save data - no free space left or problems while saving occurred.", Toast.LENGTH_LONG)
                .show();

        ApplicationScreen.getGUIManager().lockControls = false;
        sendMessage(ApplicationInterface.MSG_BROADCAST, ApplicationInterface.MSG_CONTROL_UNLOCKED);

        break;

    case ApplicationInterface.MSG_DELAYED_CAPTURE:
        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onShutterClick();
        if (null != pluginList.get(activeCapture))
            pluginList.get(activeCapture).onShutterClick();
        break;

    case ApplicationInterface.MSG_RETURN_CAPTURED:
        ApplicationScreen.instance.setResult(Activity.RESULT_OK);
        ApplicationScreen.instance.finish();
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_SHOW:
        ApplicationScreen.instance.showOpenGLLayer(1);
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_SHOW_V2:
        ApplicationScreen.instance.showOpenGLLayer(2);
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_HIDE:
        ApplicationScreen.instance.hideOpenGLLayer();
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_RENDERMODE_CONTINIOUS:
        ApplicationScreen.instance.glSetRenderingMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_RENDERMODE_WHEN_DIRTY:
        ApplicationScreen.instance.glSetRenderingMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
        break;

    case ApplicationInterface.MSG_PROCESSING_BLOCK_UI:
        ApplicationScreen.getGUIManager().processingBlockUI();
        break;

    case ApplicationInterface.MSG_BROADCAST:
        onBroadcast(msg.arg1, msg.arg2);
        break;
    default:
        break;
    }

    return true;
}

From source file:com.almalence.opencam.PluginManager.java

/******************************************************************************************************
 * Message handler//from ww w  .  jav  a 2s. c  o m
 ******************************************************************************************************/
@Override
public boolean handleApplicationMessage(Message msg) {
    long sessionID = 0;

    switch (msg.what) {
    case ApplicationInterface.MSG_NO_CAMERA:
        break;

    case ApplicationInterface.MSG_CAPTURE_FINISHED:
        shutterRelease = true;

        /*
         * Debug code for Galaxy S6 in Super mode. Look at Camera2 for more
         * details
         */
        // CameraController.onCaptureFinished();

        if (CameraController.getFocusMode() == CameraParameters.AF_MODE_CONTINUOUS_PICTURE) {
            CameraController.cancelAutoFocus();
        }

        if (ApplicationScreen.instance.getFlashModePref(
                ApplicationScreen.sDefaultFlashValue) == CameraParameters.FLASH_MODE_CAPTURE_TORCH) {
            // If flashMode == FLASH_MODE_CAPTURE_TORCH, then turn off torch
            // after capturing completed.
            CameraController.setCameraFlashMode(CameraParameters.FLASH_MODE_OFF);
        }

        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onCaptureFinished();

        ApplicationScreen.getGUIManager().onCaptureFinished();
        ApplicationScreen.getGUIManager().startProcessingAnimation();

        // Returns actual flash mode if it was changed during capturing.
        if (!CameraController.isUseCamera2()) {
            int flashMode = ApplicationScreen.instance.getFlashModePref(ApplicationScreen.sDefaultFlashValue);
            if (flashMode != CameraParameters.FLASH_MODE_CAPTURE_TORCH) {
                CameraController.setCameraFlashMode(flashMode);
            }
        }

        int id = ApplicationScreen.getAppResources().getIdentifier(getActiveMode().modeName, "string",
                ApplicationScreen.instance.getPackageName());
        String modeName = ApplicationScreen.getAppResources().getString(id);
        addToSharedMem("mode_name" + (String) msg.obj, modeName);
        // start async task for further processing
        cntProcessing++;

        sessionID = Long.valueOf((String) msg.obj);

        // Map sessionID and processing plugin, because active plugin may be
        // changed before image processing will start (Mode was switched).
        // We don't map export plugin, because it's the same for all modes.
        processingPluginList.put(sessionID, pluginList.get(activeProcessing));

        Intent mServiceIntent = new Intent(ApplicationScreen.instance, ProcessingService.class);

        // Pass to Service sessionID and some other parameters, that may be required.
        mServiceIntent.putExtra("sessionID", sessionID);
        CameraController.Size imageSize = CameraController.getCameraImageSize();
        PluginManager.getInstance().addToSharedMem("imageWidth" + sessionID,
                String.valueOf(imageSize.getWidth()));
        PluginManager.getInstance().addToSharedMem("imageHeight" + sessionID,
                String.valueOf(imageSize.getHeight()));
        PluginManager.getInstance().addToSharedMem("wantLandscapePhoto" + sessionID,
                String.valueOf(ApplicationScreen.getWantLandscapePhoto()));
        PluginManager.getInstance().addToSharedMem("cameraMirrored" + sessionID,
                String.valueOf(CameraController.isFrontCamera()));

        // Start processing service with current sessionID.
        ApplicationScreen.instance.startService(mServiceIntent);

        ApplicationScreen.instance.muteShutter(false);

        // <!-- -+-
        // if mode free
        controlPremiumContent();
        // -+- -->

        if (!PluginManager.getInstance().getActiveModeID().equals("video")) {
            ApplicationScreen.getGUIManager().lockControls = false;
            PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
                    ApplicationInterface.MSG_CONTROL_UNLOCKED);
        }

        break;

    case ApplicationInterface.MSG_CAPTURE_FINISHED_NORESULT:
        shutterRelease = true;

        /*
         * Debug code for Galaxy S6 in Super mode. Look at Camera2 for more
         * details
         */
        // CameraController.onCaptureFinished();

        if (CameraController.getFocusMode() == CameraParameters.AF_MODE_CONTINUOUS_PICTURE) {
            CameraController.cancelAutoFocus();
        }

        if (ApplicationScreen.instance.getFlashModePref(
                ApplicationScreen.sDefaultFlashValue) == CameraParameters.FLASH_MODE_CAPTURE_TORCH) {
            // If flashMode == FLASH_MODE_CAPTURE_TORCH, then turn off torch
            // after capturing completed.
            CameraController.setCameraFlashMode(CameraParameters.FLASH_MODE_OFF);
        }

        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onCaptureFinished();

        ApplicationScreen.getGUIManager().onCaptureFinished();
        ApplicationScreen.getGUIManager().startProcessingAnimation();

        ApplicationScreen.instance.muteShutter(false);

        ApplicationScreen.getGUIManager().lockControls = false;

        PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
                ApplicationInterface.MSG_CONTROL_UNLOCKED);

        ApplicationScreen.getGUIManager().onExportFinished();

        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onExportFinished();

        break;

    case ApplicationInterface.MSG_START_POSTPROCESSING:
        if (null != pluginList.get(activeProcessing)) {
            ApplicationScreen.getGUIManager().lockControls = true;
            PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
                    ApplicationInterface.MSG_CONTROL_LOCKED);

            pluginList.get(activeProcessing).onStartPostProcessing();
            ApplicationScreen.getGUIManager().onPostProcessingStarted();
        }
        break;

    case ApplicationInterface.MSG_POSTPROCESSING_FINISHED:
        sessionID = 0;
        String sSessionID = getFromSharedMem("sessionID");
        if (sSessionID != null)
            sessionID = Long.parseLong(getFromSharedMem("sessionID"));

        // notify GUI about saved images
        ApplicationScreen.getGUIManager().lockControls = false;
        PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
                ApplicationInterface.MSG_CONTROL_UNLOCKED);

        ApplicationScreen.getGUIManager().onPostProcessingFinished();
        if (null != pluginList.get(activeExport) && 0 != sessionID) {
            pluginList.get(activeExport).onExportActive(sessionID);
        } else {
            ApplicationScreen.getMessageHandler().sendEmptyMessage(ApplicationInterface.MSG_EXPORT_FINISHED);
            clearSharedMemory(sessionID);
        }
        break;
    case ApplicationInterface.MSG_EXPORT_FINISHED:
        getPrefs();

        // event from plugin that saving finished and memory can be freed
        if (cntProcessing > 0)
            cntProcessing--;
        // free memory in processing
        if (null != pluginList.get(activeProcessing))
            pluginList.get(activeProcessing).freeMemory();

        // notify GUI about saved images
        ApplicationScreen.getGUIManager().onExportFinished();

        // notify capture plugins that saving finished
        if (null != pluginList.get(activeCapture))
            pluginList.get(activeCapture).onExportFinished();
        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onExportFinished();

        if (ApplicationScreen.instance.getIntent().getAction() != null) {
            if (ApplicationScreen.instance.getIntent().getAction().equals(MediaStore.ACTION_IMAGE_CAPTURE)
                    && ApplicationScreen.getForceFilename() == null) {
                ApplicationScreen.getMessageHandler()
                        .sendEmptyMessage(ApplicationInterface.MSG_RETURN_CAPTURED);
            }
        }

        if (photoTimeLapseActive && photoTimeLapseIsRunning) {
            AlarmReceiver.getInstance().setNextAlarm(ApplicationScreen.instance.getApplicationContext());
            ApplicationScreen.instance.guiManager.showCaptureIndication();
        }
        break;

    case ApplicationInterface.MSG_EXPORT_FINISHED_IOEXCEPTION:
        getPrefs();

        // event from plugin that saving finished and memory can be freed
        if (cntProcessing > 0)
            cntProcessing--;
        // free memory in processing
        if (null != pluginList.get(activeProcessing))
            pluginList.get(activeProcessing).freeMemory();

        // notify GUI about saved images
        ApplicationScreen.getGUIManager().onExportFinished();

        // notify capture plugins that saving finished
        if (null != pluginList.get(activeCapture))
            pluginList.get(activeCapture).onExportFinished();
        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onExportFinished();

        Toast.makeText(ApplicationScreen.getMainContext(), "Can't save data - seems no free space left.",
                Toast.LENGTH_LONG).show();

        if (photoTimeLapseActive && photoTimeLapseIsRunning) {
            AlarmReceiver.getInstance().setNextAlarm(ApplicationScreen.instance.getApplicationContext());
            ApplicationScreen.instance.guiManager.showCaptureIndication();
        }
        break;

    case ApplicationInterface.MSG_DELAYED_CAPTURE:
        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onShutterClick();
        if (null != pluginList.get(activeCapture) && ApplicationScreen.instance
                .findViewById(R.id.postprocessingLayout).getVisibility() == View.GONE)
            pluginList.get(activeCapture).onShutterClick();
        break;

    case ApplicationInterface.MSG_RETURN_CAPTURED:
        ApplicationScreen.instance.setResult(Activity.RESULT_OK);
        ApplicationScreen.instance.finish();
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_SHOW:
        ApplicationScreen.instance.showOpenGLLayer(1);
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_SHOW_V2:
        ApplicationScreen.instance.showOpenGLLayer(2);
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_HIDE:
        ApplicationScreen.instance.hideOpenGLLayer();
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_RENDERMODE_CONTINIOUS:
        ApplicationScreen.instance.glSetRenderingMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_RENDERMODE_WHEN_DIRTY:
        ApplicationScreen.instance.glSetRenderingMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
        break;

    case ApplicationInterface.MSG_PROCESSING_BLOCK_UI:
        ApplicationScreen.getGUIManager().processingBlockUI();
        break;

    case ApplicationInterface.MSG_BROADCAST:
        pluginManager.onBroadcast(msg.arg1, msg.arg2);
        break;
    default:
        break;
    }

    return true;
}