By dennisAC
on Tue, 02/26/2013 - 08:04
// 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; // Inflate the overlayView layout mOverlayView = View.inflate(context, R.layout.overlay, null); addContentView(mOverlayView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); if (text.equals("NO_MARKER_IN_THIS_FRAME")) { DebugLog.LOGD("NO_MARKER_IN_THIS_FRAME"); textView1.setVisibility(View.INVISIBLE); imageView1.setVisibility(View.INVISIBLE); imageView2.setVisibility(View.INVISIBLE); } else { DebugLog.LOGD("MARKER_IN_THIS_FRAME"); String fullText = null; // Set the layout's text. this is not the best way to do this but ok if(text.equals("chips")) { fullText = "Ini teko yang berada di texture chips."; imageView1.setImageResource(R.drawable.cloud1); imageView1.setVisibility(View.VISIBLE); } else if(text.equals("stones")) { fullText = "Ini teko yang berada di texture stones."; imageView2.setImageResource(R.drawable.cloud2); imageView2.setVisibility(View.VISIBLE); } textView1.setVisibility(View.VISIBLE); textView1.setText(fullText); } } };
i used the trackable->getName() to distinguish action between chips trackable or stones trackable for the UI. is it possible i use the ID of the trackables to distinguish the action? i know, i should use trackable->getID(), but i have a problem because it is integer, and will crash the code in _renderFrame() method here
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(); }
and in ImageTargetRenderer.java here
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); }
how can i solve this?
passing the trackable->getID() value to java
Hi, you could use trackable->getName() instead of trackable->getId(), if you like.
However, I'm not sure to follow on why the trackable ID would crash your program in this code:
passing the trackable->getID() value to java
no.. i mean i want to do something with the trackable->getID(), i want to pass that integer value to my ImageTarget.java, but i dont know how to do it because the code in _renderFrame() method is to pass the String, trackable->getName(), i haven't change these codes yet:
passing the trackable->getID() value to java
OK, if you want to pass the trackable ID as a string you can just use this simple C code:
and then you can build your js string like: