- Sort Posts
- 9 replies
- Last post
How to create new UI in camera screen in virtual button
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
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
How to create new UI in camera screen in virtual button
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
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
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.
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!