Log in or register to post comments

adding view on top of camera inplugin activity

June 25, 2013 - 3:30am #1

I am using an android project as a plugin in unity. 

The plugin Activity extends the QCARPlayerActivity.

What i want the a button should be displayed on top of it.

I followed the link

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

to add custom view. it works fine when we use unity project as plugin in eclipse.

But in my case. the application crashes as soon as i starts.

adding view on top of camera inplugin activity

June 25, 2013 - 11:39am #6

OK. So, I thought you were following the approach described in the ilnk that you originally mentioned:

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

The link above would allow you to work directly in Java in Eclipse.

However, if you want to follow the other approach mentioned here:

https://developer.vuforia.com/resources/dev-guide/unity-android-plugins

then you will be able to work from within Unity; if you want to know how to handle Android/Java plugins from within Unity,

you may want to have a look at the Unity website, where these things are explained in more detail:

http://docs.unity3d.com/Documentation/Manual/PluginsForAndroid.html

That's really about Unity + Android (there is nothing specific to Vuforia per se, except what is described in the link above).

 

adding view on top of camera inplugin activity

June 25, 2013 - 9:40am #5

sorry this is just typo mistake. I made this change after testing the code exactly i copied from the website link i mentioned.

and as i told it works.

But you are not getting my point.

It is that how should i add such view when i transfer the java as a plugin to unity. like this link.

https://developer.vuforia.com/resources/dev-guide/unity-android-plugins

adding view on top of camera inplugin activity

June 25, 2013 - 6:10am #4

I see in your code you have removed these two lines:

//private QCARUnityPlayer mQCARView = null;
   // private Timer mViewFinderTimer = null;
 
and all the code related to that Timer etc.... that's a fundamental part of the tutorial code;
if you don't follow that approach, obviously your custom view will disappear after the initial splash screen.
 
My recommendation: first implement the tutorial steps exactly as described, then make your changes on top of that.
 

adding view on top of camera inplugin activity

June 25, 2013 - 5:17am #3

the application runs fine when i use unity project as a plugin in eclipse.

Now i succesfully added the layout in plugin activity programmatically. But the issue is it just show up for a moment before splash screen. and disappears when the camera starts.

The Plugin Activity is here.

public class MainActivity extends QCARPlayerActivity {
 
private static MainActivity inst = null;
//////////////////////////////////////////////////////////////////////////
//private QCARUnityPlayer mQCARView = null;
   // private Timer mViewFinderTimer = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        inst = this;
        final Context context = getApplication();
        
        // Creating a new LinearLayout
        LinearLayout linearLayout = new LinearLayout(this);
         
        // Setting the orientation to vertical
        linearLayout.setOrientation(LinearLayout.VERTICAL);
         
        // Defining the LinearLayout layout parameters to fill the parent.
        LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.FILL_PARENT);
         
        // Creating a new TextView
        final TextView tv = new TextView(this);
        tv.setBackgroundColor(0xFFFF00FF);
        tv.setTextColor(0xFF000000);
        tv.setTypeface(null, Typeface.BOLD);
        tv.setText("Where is Fred?");
        tv.setGravity(Gravity.CENTER_HORIZONTAL);
         
        // Defining the layout parameters of the TextView
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
         
        // Setting the parameters on the TextView
        tv.setLayoutParams(lp);
         
        // Adding the TextView to the LinearLayout as a child
        linearLayout.addView(tv);
         
        // Creating Fred
       
         
        // Defining the layout parameters of Fred
        lp = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
         
        
         
        // Creating a new Button
        Button btn = new Button(this);
        btn.setText("Call Fred!");
         
        // Setting the Buttons OnClickListener
        btn.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
     
                
                    
            }
        });
         
        // Defining the layout parameters of the Button
        lp = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
         
        // Setting the parameters on the Button
        btn.setLayoutParams(lp);
         
        // Adding the Button to the LinearLayout as a child
        linearLayout.addView(btn);
         
        // Setting the LinearLayout as our content view
        setContentView(linearLayout, llp);
    }
   
   
    public void returnData() {
UnityPlayer.UnitySendMessage("GameObject", "loadModel", "file:///sdcard/Chair.obj");
}
}

adding view on top of camera inplugin activity

June 25, 2013 - 4:57am #2

Have you tried implementing the steps of that link for the ImageTargets sample ? does it crash for the sample too ?

 

Log in or register to post comments