Log in or register to post comments

Show a dialog instead a toast

June 27, 2012 - 4:23pm #1

Hello

 

I'm newbie to programing in android, i'm programming an app for my final proyect with AR, it's a simple app that must show a dialog with some information, well, i think it's simple.

I already made the change to show a toast explained by Kim (ksiva) on ImageTargets. I've been reading but i don't know how to make this change, could someone please explain me? 

 

By the way, i used this topic to show the toast:
https://ar.qualcomm.at/content/overlaying-android-interface-objects  

Show a dialog instead a toast

June 28, 2012 - 8:35am #3

Hello David

 

Thank you for reply.

Actually i already bulid and test the app showing a toast on my device, and works fine, i've been reading the code trying to understand, but i can't understand it fully, here's the code i use to make this changes:

added code within ImageTargetsRenderer.java

//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);

}

 

Changed code within ImageTargets.java

 /** Called when the activity will start interacting with the user.*/

    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;

            int duration = Toast.LENGTH_LONG;

            Toast toast = Toast.makeText(context, text, duration);

            toast.show();

            }

        };

    }

 

 

Changed code within ImageTargets.cpp

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;

}

    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();

        }   

    }

}

 

according to my understanding would have to modify the code in onResume within ImageTarget.java, am i wrong?

Show a dialog instead a toast

June 27, 2012 - 4:59pm #2

I would recommend starting w/ the ImageTargets project and simply pasting the code in that thread into the respective methods. Be sure to compile it after each change using ndk-build from the command line.

Are you currently seeing errors, what's the problem?

Log in or register to post comments