Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Removing added views
Started by richard11 Nov 24 2018 08:38 AM

1 reply to this topic
corona native java getoverlayview addview
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

The default LuaLoader class from the Android template includes a show() method that creates a webView and adds to the Corona activity, so I'm building my own plugin based on this same approach to get a camera surface view onto the activity. e.g:

public class start implements com.naef.jnlua.NamedJavaFunction {
    // This reports a class name back to Lua during the initiation phase.
    @Override
    public String getName() {
        return "start";
    }

    // This is what actually gets invoked by the Lua call
    @Override
    public int invoke(final LuaState luaState) {
        if(shared.status != "running") {
            shared.status = "running";

            CoronaActivity activity = CoronaEnvironment.getCoronaActivity();
            if (activity == null) {
                return 0;
            }

            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    CoronaActivity activity = CoronaEnvironment.getCoronaActivity();
                    if (activity == null) {
                        return;
                    }

                    cameraPreview mPreview = new cameraPreview(activity);
                    activity.getOverlayView().addView(mPreview);
                }
            });
        }

        return 1;
    }
}

(obviously cameraPreview is another class)

 

Seems to work perfectly, but I can't find how to remove the surface again? Or potentially better yet, to clear the OverlayView completely. Any pointers please?



[TOPIC: post.html]
#2

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

Aha, cracked it.

 

For anybody else who stumbles on to this, moving mPreview into a shared class:

public class shared {
    public static cameraPreview mPreview;
}

And changing the above to this:

shared.mPreview = new cameraPreview(activity);
activity.getOverlayView().addView(shared.mPreview);

Means that you can later kill it again, like this:

activity.getOverlayView().removeView(shared.mPreview);

Simples =).




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: corona native, java, getoverlayview, addview