Hi David, i think it's better if i show you the actuall code, at this time, we can show the dialog when detecth the trackable, but the dialog stays on screen until we press de back button device:
ImageTarget.cpp wrote:
int lastTrackableId=-1;
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv* env, jobject obj)
{
// Get the state from QCAR and mark the beginning of a rendering section
QCAR::State state = QCAR::Renderer::getInstance().begin();
// Explicitly render the Video Background
QCAR::Renderer::getInstance().drawVideoBackground();
// Did we find any trackables this frame?
if (state.getNumActiveTrackables()==0)
{
lastTrackableId=-1;
}
else
{
for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
{
// Get the trackable:
const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);
// Compare this trackable's id to a globally stored id
// If this is a new trackable, find the displayMessage java method and
// call it with the trackable's name
if (trackable->getId() != lastTrackableId) {
jstring js = env->NewStringUTF(trackable->getName());
jclass javaClass = env->GetObjectClass(obj);
jmethodID method = env->GetMethodID(javaClass, "displayMessage", "(Ljava/lang/String;)V");
env->CallVoidMethod(obj, method, js);
lastTrackableId = trackable->getId();
}
}
}
}
ImageTargets.java wrote:
protected void onResume()
{
super.onResume();
// Create a new handler for the renderer thread to use
// This is necessary as only the main thread can make changes to the UI
ImageTargetsRenderer.mainActivityHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
//Context context = getApplicationContext();
String text = (String) msg.obj;
AlertDialog dialog = new AlertDialog.Builder(ImageTargets.this).create();
dialog.setTitle(text);
dialog.setMessage("esta es una prueba");
dialog.show();
}
};
}
ImageTargetsRenderer.java wrote:
//A handler object for sending messages to the main activity thread
public static Handler mainActivityHandler;
// Called from native to display a message
public void displayMessage(String text)
{
// We use a handler because this thread cannot change the UI
Message message = new Message();
message.obj = text;
mainActivityHandler.sendMessage(message);
}
Sorry, i didn't understand the idea about button as a View, can you explain me please?
Thanks in advance
Hello,
I've had the same problem myself.
Thus far, I have managed to show a View's layout, in front of the camera, but I want it to appear only after the trackable is detected.
So I 've originally set the visibilty of the View to INVISIBLE and I want to change it to VISIBLE inside the Handler, but nothing happens.
What I really want my app to do is to pop-up a picture with a message on top, when it's corresponding trackable is detected.
Could you please help me?