Log in or register to post comments

Added Android sub view have no respond to touch

February 24, 2013 - 9:58pm #1

I just followed the instruction https://developer.vuforia.com/forum/faq/unity-how-can-i-extend-unitys-android-activity to integrate Unity with Eclipse and added a layout as sub view.

However, there are buttons and web view inside the layout, receive no input and thus it just can be "look" and no function at all.

Do I missed something important causing this problem?

 

 

Added Android sub view have no respond to touch

March 21, 2013 - 4:00am #15

Hi arlover,

looks like this is the same question you posted here:

https://developer.vuforia.com/forum/unity-3-extension-technical-discussion/custom-android-view-qcarplayer-activity-problem

Please follow up there.

Added Android sub view - facing some problem

March 21, 2013 - 3:23am #14

Hi Alessandro,

Am trying to inflate my Custom UI through the below code which I found out in the forum. I Am able to successfuly inflate a android widget through the code that you had given.  But when I inflate an Layout file (Which is having just one Hello World text view and an image) the app is getting closed. Below is the LOGCAT of the app. Can you help me on this ?
 
Thank you. 
 
class QCARViewFinderTask extends TimerTask {
   
  public void run() {
      Test.this.runOnUiThread(new Runnable() {
       public void run() {
          if (!QCAR.isInitialized()) return; //wait for QCAR init
                       
          if (mQCARView != null) return;//already found, no need to search
                              
          //else search
          View rootView = Test.this.findViewById(android.R.id.content);
          QCARUnityPlayer qcarView = findQCARView(rootView);
                        
          //if QCAR view has been found, add some android view/widget on top
          if (qcarView != null) {
              ViewGroup qcarParentView = (ViewGroup)(qcarView.getParent());
			  
              View myView = getLayoutInflater().inflate(R.layout.activity_test, null);
              qcarParentView.addView(myView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
              
              //qcarParentView.addView(button, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                        
              mQCARView = qcarView;
            }
          }
     });
}

 


LOG CAT results:
03-21 15:21:52.958: E/AndroidRuntime(13510): FATAL EXCEPTION: main
03-21 15:21:52.958: E/AndroidRuntime(13510): android.content.res.Resources$NotFoundException: Resource ID #0x7f030002
03-21 15:21:52.958: E/AndroidRuntime(13510):  at android.content.res.Resources.getValue(Resources.java:1019)
03-21 15:21:52.958: E/AndroidRuntime(13510):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:2107)
03-21 15:21:52.958: E/AndroidRuntime(13510):  at android.content.res.Resources.getLayout(Resources.java:858)
03-21 15:21:52.958: E/AndroidRuntime(13510):  at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
03-21 15:21:52.958: E/AndroidRuntime(13510):  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-21 15:21:52.958: E/AndroidRuntime(13510):  at insanelabs.devv1.Test$QCARViewFinderTask$1.run(Test.java:72)
03-21 15:21:52.958: E/AndroidRuntime(13510):  at android.os.Handler.handleCallback(Handler.java:605)
03-21 15:21:52.958: E/AndroidRuntime(13510):  at android.os.Handler.dispatchMessage(Handler.java:92)
03-21 15:21:52.958: E/AndroidRuntime(13510):  at android.os.Looper.loop(Looper.java:137)
03-21 15:21:52.958: E/AndroidRuntime(13510):  at android.app.ActivityThread.main(ActivityThread.java:4503)
03-21 15:21:52.958: E/AndroidRuntime(13510):  at java.lang.reflect.Method.invokeNative(Native Method)
03-21 15:21:52.958: E/AndroidRuntime(13510):  at java.lang.reflect.Method.invoke(Method.java:511)
03-21 15:21:52.958: E/AndroidRuntime(13510):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
03-21 15:21:52.958: E/AndroidRuntime(13510):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
03-21 15:21:52.958: E/AndroidRuntime(13510):  at dalvik.system.NativeStart.main(Native Method)

 

Added Android sub view have no respond to touch

March 21, 2013 - 3:21am #13
class QCARViewFinderTask extends TimerTask {
   
  public void run() {
      Test.this.runOnUiThread(new Runnable() {
       public void run() {
          if (!QCAR.isInitialized()) return; //wait for QCAR init
                       
          if (mQCARView != null) return;//already found, no need to search
                              
          //else search
          View rootView = Test.this.findViewById(android.R.id.content);
          QCARUnityPlayer qcarView = findQCARView(rootView);
                        
          //if QCAR view has been found, add some android view/widget on top
          if (qcarView != null) {
              ViewGroup qcarParentView = (ViewGroup)(qcarView.getParent());
			  
              View myView = getLayoutInflater().inflate(R.layout.activity_test, null);
              qcarParentView.addView(myView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
              
              //qcarParentView.addView(button, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                        
              mQCARView = qcarView;
            }
          }
     });
}

Here is the Code SNIPPET. . 

LOG CAT:

 

 
03-21 15:21:52.958: E/AndroidRuntime(13510): FATAL EXCEPTION: main
03-21 15:21:52.958: E/AndroidRuntime(13510): android.content.res.Resources$NotFoundException: Resource ID #0x7f030002
03-21 15:21:52.958: E/AndroidRuntime(13510): at android.content.res.Resources.getValue(Resources.java:1019)
03-21 15:21:52.958: E/AndroidRuntime(13510): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2107)
03-21 15:21:52.958: E/AndroidRuntime(13510): at android.content.res.Resources.getLayout(Resources.java:858)
03-21 15:21:52.958: E/AndroidRuntime(13510): at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
03-21 15:21:52.958: E/AndroidRuntime(13510): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-21 15:21:52.958: E/AndroidRuntime(13510): at insanelabs.devv1.Test$QCARViewFinderTask$1.run(Test.java:72)
03-21 15:21:52.958: E/AndroidRuntime(13510): at android.os.Handler.handleCallback(Handler.java:605)
03-21 15:21:52.958: E/AndroidRuntime(13510): at android.os.Handler.dispatchMessage(Handler.java:92)
03-21 15:21:52.958: E/AndroidRuntime(13510): at android.os.Looper.loop(Looper.java:137)
03-21 15:21:52.958: E/AndroidRuntime(13510): at android.app.ActivityThread.main(ActivityThread.java:4503)
03-21 15:21:52.958: E/AndroidRuntime(13510): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 15:21:52.958: E/AndroidRuntime(13510): at java.lang.reflect.Method.invoke(Method.java:511)
03-21 15:21:52.958: E/AndroidRuntime(13510): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
03-21 15:21:52.958: E/AndroidRuntime(13510): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
03-21 15:21:52.958: E/AndroidRuntime(13510): at dalvik.system.NativeStart.main(Native Method)
 
Can you figure out what the issue is ?

Added Android sub view have no respond to touch

February 26, 2013 - 12:30am #12

Great.

Added Android sub view have no respond to touch

February 26, 2013 - 12:25am #11

Thank you for your advise and I have changed to use non-native player, the layout work normally.

 

Added Android sub view have no respond to touch

February 25, 2013 - 11:54pm #10

Well, not sure that QCAR would perform (significantly) better with native player; anyway, all I am saying is that in order to make your application (with buttons) work properly, it would be best to perform all the steps exactly as they are described in the article you refer to:

https://developer.vuforia.com/forum/faq/unity-how-can-i-extend-unitys-android-activity

So, of course you are free to try with slightly different approaches, but as a general advice, if you make any deviations from the procedure described in that article(which has been tested extensively), then there is always a risk that something may not work properly ...

Added Android sub view have no respond to touch

February 25, 2013 - 7:18pm #9

Oh really? I have created the proxy player that choose to launch native player and player.

So I need to force proxy to launch player? It is said QCAR perform better with native player, so I just follow the instruction to create both native and normal player.

 

Added Android sub view have no respond to touch

February 25, 2013 - 8:39am #8

Hi, you should extend from QCARPlayerActivity and not QCARPlayerNativeActivity; that might explain the issue...

Added Android sub view have no respond to touch

February 25, 2013 - 8:38am #7

poor, it is not working still.

I am using Unity 3.5.6 and the activity extended from  QCARPlayerNativeActivity.

It is quite strange that it should be simple enough.

 

Added Android sub view have no respond to touch

February 25, 2013 - 8:22am #6

Hi, not sure what could be wrong in your Android application; 

I am pasting here below the code of the Activity in the Application that I've just tested (note: this only contains a Button which is programmatically created; in the past I have also tested with farily sophisticated Layouts and never observed the issue ou observe);

could you perhaps try this code and see if it works in your case ?

package com.ab.QCARUnity20;

import java.util.Timer;
import java.util.TimerTask;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.Toast;

import com.qualcomm.QCAR.QCAR;
import com.qualcomm.QCARUnityPlayer.QCARPlayerActivity;
import com.qualcomm.QCARUnityPlayer.QCARUnityPlayer;


public class MainActivity extends QCARPlayerActivity {
	   
    private QCARUnityPlayer mQCARView = null;
    private Timer mViewFinderTimer = null;
      
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
   
    @Override
    public void onResume() {
       super.onResume();
      
       if (mQCARView == null) {
              //search the QCAR view
              mViewFinderTimer = new Timer();
              mViewFinderTimer.scheduleAtFixedRate(new QCARViewFinderTask(), 1000, 1000);
       }
    }
   
    @Override
    public void onPause() {
       super.onPause();
      
       if (mViewFinderTimer != null) {
              mViewFinderTimer.cancel();
              mViewFinderTimer = null;
       }
    }
   
    class QCARViewFinderTask extends TimerTask {
      
      public void run() {
    	  MainActivity.this.runOnUiThread(new Runnable() {
           public void run() {
              if (!QCAR.isInitialized()) return; //wait for QCAR init
                          
              if (mQCARView != null) return;//already found, no need to search
                                 
              //else search
              View rootView = MainActivity.this.findViewById(android.R.id.content);
              QCARUnityPlayer qcarView = findQCARView(rootView);
                           
              //if QCAR view has been found, add some android view/widget on top
              if (qcarView != null) {
                  ViewGroup qcarParentView = (ViewGroup)(qcarView.getParent());
                                  
                  Button button = new Button(MainActivity.this);
                  button.setText("Press me");
                  button.setOnClickListener(new Button.OnClickListener() {
					@Override
					public void onClick(View v) {
						Toast.makeText(MainActivity.this, "Button was pressed!", Toast.LENGTH_SHORT).show();	
					}
				  });
                  
                  qcarParentView.addView(button, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                           
                  mQCARView = qcarView;
                }
              }
         });
       }
   
       private QCARUnityPlayer findQCARView(View view) {
              if (view instanceof QCARUnityPlayer) {
                 return (QCARUnityPlayer)view;
              }
             
              if (view instanceof ViewGroup) {
                     ViewGroup vg = (ViewGroup)view;
                     for (int i = 0; i < vg.getChildCount(); ++i) {
                           QCARUnityPlayer foundView = findQCARView(vg.getChildAt(i));
                           if (foundView != null)
                                  return foundView;
                     }
              }
             
              return null;
        }
    }
}

 

Added Android sub view have no respond to touch

February 25, 2013 - 8:03am #5

Actually I not handling it as I just saw the button doesn't "pressed" as normally should be.

However, after added the handling codes and a break point, but doesn't hit:

            Button arbt = (Button)findViewById(R.id.button1);
            arbt.setOnClickListener(new Button.OnClickListener() {
          	  public void onClick(View v)
          	  {
          		  mARButtonPressed = true;
          		  mLayoutShowing = false;
          		  mMyView.setVisibility(View.GONE);
          	  }
            });

 

Added Android sub view have no respond to touch

February 25, 2013 - 7:36am #4

Can you share the code which handles your button click ?

Added Android sub view have no respond to touch

February 25, 2013 - 7:27am #3

Hi,

I have tried to create another simple layout file such that just contains one button, and add to the view, however, the button still not working.

The following is the layout file:

 

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical" >

 

    <Button

        android:id="@+id/button1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Button" />

 

</LinearLayout>

 

What's wrong might be?

Added Android sub view have no respond to touch

February 25, 2013 - 12:12am #2

Hi, there might be several reasons why your widgets do not receive the inputs;

have you tried (just for testing) to replace your "complex" layout with just a single Button and verify that it responds to inputs (I know by expereince that this works) ?

Then the best approach would be to incrementally add more views / layouts and see what causes the issue.

 

 

Log in or register to post comments