Log in or register to post comments

How to create new UI in camera screen in virtual button

April 9, 2013 - 11:43pm #1

Hi All,

how to create a new UI in virtual button when we showing target image then how to show the UI, when the model image is appearing on screen.

Thanks in advance.

How to create new UI in camera screen in virtual button

August 25, 2016 - 9:40am #10

Hello All,

would anybody know any repository or project online with the c++ file? I am trying to make me an idea but I am very new with Vuforia, I am having troubles trying to undertand it. In addition I would like to know if adding the imagetarget in a fragment is possible.

Thanks very much in advance!

How to create new UI in camera screen in virtual button

April 11, 2013 - 4:29am #9

Hi,

you are creating new layout inside the handleMessage() method; 

you should instead create it outside (for instance in the onCreate() of your main activity) and then use the handleMessage() method only to set the visibility of the layout.

 

How to create new UI in camera screen in virtual button

April 11, 2013 - 3:55am #8

AlessandroB,

As you said i change in virtualButtons.cpp; virtualButtons.java; virtualButtonsRender.java

in virtualButtons.cpp

int lastTrackableId = -1;
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_VirtualButtons_VirtualButtonsRenderer_renderFrame(JNIEnv* env, jobject obj)
{

--------

    // Did we find any trackables this frame?
    if (state.getNumTrackableResults())
    {
        // call it with the trackable's name
        jclass javaClass = env->GetObjectClass(obj);
        jmethodID method = env->GetMethodID(javaClass, "displayMessage", "(Ljava/lang/String;)V");
        env->CallVoidMethod(obj, method, "hello");

----

}

in virtualButtons.java

VirtualButtonsRenderer.mainActivityHandler = new Handler() {
            @Override
             public void handleMessage(Message msg) {
               String text = (String) msg.obj;
               System.out.println("Hello iiii"+text);
               // The Toast display the name of the detected trackable on the screen
               Context context = getApplicationContext();
               LinearLayout l1=new LinearLayout(getApplicationContext());
               l1.setLayoutParams(new LayoutParams(100, 100));
               l1.setBackgroundColor(Color.RED);
               addContentView(l1, new LayoutParams(100, 100));

}

in VirtualButtonsRender.java

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

i added as you said but when camera viewing target image it was hanging.

and it showing an error like below

Fatal Signal 11 (SIGSEGV) at 0x6c6c6580 (code = 1), thread 8203 (.virtualButtons)

How to create new UI in camera screen in virtual button

April 11, 2013 - 12:42am #7

I undrestand, but that is explained in the tutorial (see the link that I posted previously, on "how to display a Toast message when target is detected"):

https://developer.vuforia.com/resources/dev-guide/open-web-site-and-display-toast-target-detection

The only difference is that, instead of showing a Toast Message (see the method calld displayMessage() which is mentioned in the tutorial), you will need to make your UI layout visible when the target is detected; 

to make the layout visible, you can use some code like this:

 mUILayout.setVisibility(View.VISIBLE);

 

How to create new UI in camera screen in virtual button

April 11, 2013 - 12:36am #6

AlessandroB,

Layout creation is not problem to me.But when the 3d object is appearing then the ui also to display on screen when camera overlay on target image.

i have to show 3d object and UI both when camera overlay on target image.

Thanks

How to create new UI in camera screen in virtual button

April 11, 2013 - 12:24am #5

Hi, make sure to define the layout also in your /layout directory (as you are inflating it using the camera_overlay id);

see also http://developer.android.com/guide/topics/ui/declaring-layout.html

Also, make sure to read the tutorial that I was referring to (how to show a toast message when target is detected);

then, instead of showing a toast you will need to make your custom layout visible.

How to create new UI in camera screen in virtual button

April 10, 2013 - 11:47pm #4

AlessandroB,

Help me on this.

Thanks in Advance.

How to create new UI in camera screen in virtual button

April 10, 2013 - 1:46am #3

Hi,

i added mUILayout like wise imagetarget.java file but i am not getting any UI was showing. like below in virtualButtons.java file.

private LinearLayout mUILayout;

-----

/** Initializes AR application components. */
    private void initApplicationAR()
    {        
        // Do application initialization in native code (e.g. registering
        // callbacks, etc.):
        initApplicationNative(mScreenWidth, mScreenHeight);

        // Create OpenGL ES view:
        int depthSize = 16;
        int stencilSize = 0;
        boolean translucent = QCAR.requiresAlpha();
        
        mGlView = new QCARSampleGLView(this);
        mGlView.init(mQCARFlags, translucent, depthSize, stencilSize);
        
        mRenderer = new VirtualButtonsRenderer();
        mGlView.setRenderer(mRenderer);
        
        mGlView.setOnClickListener(new OnClickListener(){
            public void onClick(View v) {
                autofocus();
                
                // Autofocus action resets focus mode
                mFocusMode = FOCUS_MODE_NORMAL;
            }});
        
        LayoutInflater inflater = LayoutInflater.from(this);
        mUILayout = (LinearLayout) inflater.inflate(R.layout.camera_overlay,
                null, false);

        mUILayout.setVisibility(View.VISIBLE);
        //mUILayout.setBackgroundColor(Color.BLACK);
            mUILayout.setOrientation(LinearLayout.VERTICAL);
            
            LinearLayout lbottomLayoutu1=new LinearLayout(getApplicationContext());
           // lbottomLayoutu1.setBackgroundColor(Color.GRAY);
            lbottomLayoutu1.setGravity(Gravity.CENTER);
            LinearLayout.LayoutParams layoutParams1u1= new LinearLayout.LayoutParams(width,height/4);
            layoutParams1u1.weight=1.0f;    
            lbottomLayoutu1.setLayoutParams(layoutParams1u1);
            lbottomLayoutu1.setBackgroundColor(Color.RED);
            //lbottomLayoutu1.setBackgroundResource(R.drawable.image);
            mUILayout.addView(lbottomLayoutu1);
            
            addContentView(mUILayout, new LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.MATCH_PARENT));

    }
 

Actually what i doing is when we showing target image then the 3d object was appearing then i have to put left, right, up,down buttons on screen with 3d model object when ever camera overlay on the target image.

Help me,

Thanks in Advance.

How to create new UI in camera screen in virtual button

April 10, 2013 - 12:08am #2

Hi, in order to build a UI which overlays on top of the AR view, you can take inspiraion from the mUILayout variable in ImageTargets.java in the ImageTargets sample.

Concerning your second question, how to show the UI when the model appears, you can follow this tutorial:

https://developer.vuforia.com/resources/dev-guide/open-web-site-and-display-toast-target-detection

which explains how to show something on the UI (in this case just a simple message on screen, but you can easily adapt it to show your custom UI) when a target is detected.

 

Log in or register to post comments