Log in or register to post comments

Virtual Button actions

November 2, 2013 - 6:21am #1

How can I change virtual button actions? In the sample it is used for changing teapot colours. What to do if I want to use a virtual button to go to a certain url?

Virtual Button actions

November 19, 2013 - 2:56am #7

Hello, 

I extactly got the same problem that you but in the case to play a sound.

Did you resolve your problem? 

Thanks you.

Virtual Button actions

November 4, 2013 - 4:32am #6

Thanks for your reply....NDK-build worked   :)

Compiler shows no error But when I touch the VB, the app crashes....

My codes look like this:

VirtualButtons.cpp

if (buttonResult->isPressed())
            {
                // Run through button name array to find texture index
                for (int j = 0; j < NUM_BUTTONS; ++j)
                {
                    if (strcmp(button.getName(), virtualButtonColors[j]) == 0)
                    {
                        textureIndex = j+1;
                        jclass javaClass = env->GetObjectClass(obj);
                        jmethodID method = env->GetMethodID(javaClass, "gotoUrl", "V");
                        env->CallVoidMethod(obj, method);
                        break;
                    }
                }
            }

 

VirtualButtonsRenderer.java

public static Handler mainActivityHandler;

    // Called from native to display a message
    public void gotoUrl()
    {
        Message message = new Message();

        //Should I add something here??

        mainActivityHandler.sendMessage(message);
    }

VirtualButtons.java

/**Calling gotoUrl*/
    protected void onResume1()
    {
        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
        VirtualButtonsRenderer.mainActivityHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                Context context = getApplicationContext();
                Intent intent = new Intent(context, gotoUrl.class);
                startActivity(intent);
            }
        }; 
        
    }

gotoUrl.java

public class gotoUrl extends Activity{
	 public void onCreate(Bundle savedInstanceState)
	    {
		 Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com"));
		 startActivity(myIntent);
	    }

}

I doubt may be the problem is in VirtualButtons.java and VirtualButtonsRenderer.java. Please give solution code. Thanks again.

Virtual Button actions

November 4, 2013 - 12:31am #5

You will simply need to add the env and obj variables in the argument list of your function.

 

Virtual Button actions

November 3, 2013 - 11:24am #4

I have modified  VirtualButtons.cpp to call gotoUrl.java activity class in this way:

 

 

 const QCAR::VirtualButtonResult* buttonResult = imageTargetResult->getVirtualButtonResult(i);
            const QCAR::VirtualButton& button = buttonResult->getVirtualButton();
 
            // If the button is pressed, than use this texture:
            if (buttonResult->isPressed())
            {
                // Run through button name array to find texture index
                for (int j = 0; j < NUM_BUTTONS; ++j)
                {
                    if (strcmp(button.getName(), virtualButtonColors[j]) == 0)
                    {
                        textureIndex = j+1;
                        jclass activityClass=env->GetObjectClass(obj);
                        jmethodID method=env->GetMethodID(activityClass, "gotoUrl","()V");
                        env->CallVoidMethod(obj, method);
                        break;
                    }
 
 
But it shows error while I ndk-build. Shows that 'env' and 'obj' was not declared in this scope. Please help.

Virtual Button actions

November 3, 2013 - 10:00am #3

Hello

If I want to create an event for a virtual button which will start an android activity (i.e an activity go to a url) then where I should make the changes or add something in native code?
I want to discard the texture change events of the teapot in the VB sample and use the buttons only to switch to an activity.
 

Virtual Button actions

November 2, 2013 - 8:51am #2

You can open a URL in a new view by starting a new Activity or using other Android techniques; however, this is about Application programming and Android.

 

Log in or register to post comments