Topic locked

Custom Android View for QCARPlayer Activity - problem

March 21, 2013 - 3:28am #1

 

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. 
 
CODE SNIPPET:
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());
              /*                 
              Button button = new Button(Test.this);
              button.setText("Press me");
              button.setOnClickListener(new Button.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(Test.this, "Button was pressed!", Toast.LENGTH_SHORT).show();    
                }
              });
               */
              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:


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)

 

 

Custom Android View for QCARPlayer Activity - problem

December 22, 2014 - 6:24am #18

You're welcome.

Custom Android View for QCARPlayer Activity - problem

December 22, 2014 - 5:20am #17

Hey thanks for your reply, I solved my issue, thank you so much

Custom Android View for QCARPlayer Activity - problem

December 22, 2014 - 5:00am #16

If the button is visible but not "clickable", you probably need to simply set the ForwardNativeEventsToDalvik to true in your AndroidManifest.xml; see also:

https://developer.vuforia.com/resources/dev-guide/extending-unity-android-activity-and-adding-custom-views-eclipse

 

Custom Android View for QCARPlayer Activity - problem

December 22, 2014 - 4:18am #15

Hey bro did you get any solution?

I have same problem button is display but is not clikable.

Please help me.

 

 

 final long delay = 5000; // milliseconds
        
        Handler handler = new Handler();
        Runnable runnable = new Runnable() 
        {
            public void run() 
            {
                ViewGroup rootView = (ViewGroup)MainActivity.this.findViewById(android.R.id.content);
                 View topMostView = getLeafView(rootView);
                ViewGroup leafParent = (ViewGroup)topMostView.getParent();
                sampleButton = new Button(MainActivity.this);
                sampleButton.setText("Button");
                sampleButton.setOnClickListener(new OnClickListener() {
 
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "Button Clicked :", Toast.LENGTH_LONG).show();
}
});
              
                leafParent.addView(sampleButton, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                
            }
        };
 
        handler.postDelayed(runnable, delay);
    }
 
    private View getLeafView(View view) 
    {
        if (view instanceof ViewGroup) 
        {
            ViewGroup vg = (ViewGroup)view;
             
            for (int i = 0; i < vg.getChildCount(); ++i) 
            {
                View chview = vg.getChildAt(i);
                View result = getLeafView(chview);
                if (result != null) {
                return result;
                }
            }
           
            return null;
        }
        else
        {
        DebugLog.LOGE("Found leaf view");
            return view;
        }
    }
    

Custom Android View for QCARPlayer Activity - problem

June 5, 2013 - 6:56am #14

Nice, glad to hear it is solved.

Custom Android View for QCARPlayer Activity - problem

June 5, 2013 - 5:22am #13

Hi dude 

 

 i have used following line 

 
    LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    RelativeLayout progr = (RelativeLayout) layoutInflater.inflate(R.layout.activity_main, null);
 
 
on the place of 
 
View myView = getLayoutInflater().inflate(R.layout.activity_test, null);
 
Now its working for me .i was doing mistake .i am so sorry
   

Custom Android View for QCARPlayer Activity - problem

June 5, 2013 - 5:18am #12

have you tried using the bringToFront() method ?

i.e. myView.bringToFront() ?

If that does not work yet, then it is likely to be an issue with the Layout.

Custom Android View for QCARPlayer Activity - problem

June 5, 2013 - 5:11am #11

Hi 

 

  i am aslo getting same problem .

   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, "Waw its great !", Toast.LENGTH_SHORT).show();    
              }
            });
           // View myView = getLayoutInflater().inflate(R.layout.activity_main, null); .............................................................its not vissible on the screen 
         
            qcarParentView.addView(button, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            mQCARView = qcarView;
        
        }
        }
 
here , my button is vissible on the camerea view but , when i inflate a xml its not vissible.

Custom Android View for QCARPlayer Activity - problem

March 22, 2013 - 4:41am #10

Ok, did you put your layout xml next to mine ? (same dir?)

also, can you paste here your layout xml ?

 

Custom Android View for QCARPlayer Activity - problem

March 22, 2013 - 3:41am #9

I meant Unity Android Plugin Approach. Through the plugin I was able to populate the Android Widget on GUI.button Click in Unity Project. 

 

//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(Test.this);
              button.setText("Press me");
              button.setOnClickListener(new Button.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(Test.this, "Button was pressed!", Toast.LENGTH_SHORT).show();    
                }
              });
               */
              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;

If you note the Commented part, I used your way of inflating the Android widget. This gets triggered when I click on GUI Button in Unity. I tried to inflate my custom layout similar to the way you gave the code for android widget

Custom Android View for QCARPlayer Activity - problem

March 22, 2013 - 3:10am #8

Hey, when you say:

But I am able to inflate the android widgets that you had posted on the forum

Do you mean you can inlfate them using the "work from Eclipse" approach, or using the "Unity Android Plugin" approach ?

 

Custom Android View for QCARPlayer Activity - problem

March 22, 2013 - 2:56am #7

I tried the tutorial that you had sent me. I sucessfully integrated the Java Project and the Unity project. I was able to overlay some Image Views and Image Buttons on top of the AR view of unity.

So, what is the issue in making as an android plugin through which I inflate my XML layout objects ? But I am able to inflate the android widgets that you had posted on the forum. Please help me on this.

Thank you.

Custom Android View for QCARPlayer Activity - problem

March 21, 2013 - 11:47am #6

Hi, the tutorial I'm referring to shows how to do things from Eclipse (not using the "plugin" approach, which is slightly different).

I would try maybe that first (read the link that I have pasted below).

 

Custom Android View for QCARPlayer Activity - problem

March 21, 2013 - 7:04am #5

AlessandroB wrote:

So, if I understand correctlty, you have exported from Unity and are now using Eclipse, following this tutorial:

https://developer.vuforia.com/resources/dev-guide/extending-unity-android-activity-and-adding-custom-views-eclipse

correct ?

So, then you should just add those layouts (and layout directories) in your Eclipse project directory and build/run from there.

 

Yeah. I have used the above tutorial and exported the jar file from Java Project and Have put it in Assets/Plugins/Android folder of the Unity Project and updated the Androidmanifest file and working in the unity platform. 

For me everything is working in UNITY. I played a toast message on GUI.button click. But when I try to inflate an XML file from the Android plugin. It is shooting the earlier error that I had quoted. 

 

My requirement is:

1. I have an android layout XML file and a corresponding activity. 

2.  On GUI.button click from the unity screen, i should populate the activity with the UI (I dont want to programatically add layouts. Planning to use XML file)

Custom Android View for QCARPlayer Activity - problem

March 21, 2013 - 6:15am #4

So, if I understand correctlty, you have exported from Unity and are now using Eclipse, following this tutorial:

https://developer.vuforia.com/resources/dev-guide/extending-unity-android-activity-and-adding-custom-views-eclipse

correct ?

So, then you should just add those layouts (and layout directories) in your Eclipse project directory and build/run from there.

 

Custom Android View for QCARPlayer Activity - problem

March 21, 2013 - 5:53am #3

Hey,

I created the three folders with all the available layouts as mentioned by you.  (I created these folders in my java project from which I exported the jar. Should I create some layout file in the Unity Project too ? I suppose, that should be included in the JAR file itself. )

layout-large
layout-small
layout-xlarge
 
Am getting the same error. 
03-21 18:19:13.039: E/AndroidRuntime(15022): FATAL EXCEPTION: main
03-21 18:19:13.039: E/AndroidRuntime(15022): android.content.res.Resources$NotFoundException: Resource ID #0x7f030002
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at android.content.res.Resources.getValue(Resources.java:1019)
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at android.content.res.Resources.loadXmlResourceParser(Resources.java:2107)
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at android.content.res.Resources.getLayout(Resources.java:858)
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at insanelabs.devv1.Test$QCARViewFinderTask$1.run(Test.java:72)
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at android.os.Handler.handleCallback(Handler.java:605)
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at android.os.Handler.dispatchMessage(Handler.java:92)
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at android.os.Looper.loop(Looper.java:137)
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at android.app.ActivityThread.main(ActivityThread.java:4503)
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at java.lang.reflect.Method.invokeNative(Native Method)
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at java.lang.reflect.Method.invoke(Method.java:511)
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
03-21 18:19:13.039: E/AndroidRuntime(15022): 	at dalvik.system.NativeStart.main(Native Method)

 

 

Custom Android View for QCARPlayer Activity - problem

March 21, 2013 - 3:50am #2

Hi, this is a typical resource issue where Android cannot find your layout;

normally you should put your layout XML in the res/layout folder of your project, but you may also need to add the same layout in these three additional subdirectories:

  • res/layout-small/
  • res/layout-large/
  • res/layout-xlarge/

Have you tried that ?

 

Topic locked