Log in or register to post comments

PROBLEMA

July 9, 2012 - 4:34pm #1

 

i am new programming in android and I have a problem with the application, I'm developing not know if I can help

 

the problem is how could I create a function that performs dismiss when trackable not be detected.

 

the code is this

 


[CODE]protected void onResume()

{
super.onResume();
// 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;
AlertDialog.Builder dialog = new AlertDialog.Builder(ImageTargets.this);
dialog.setTitle(text);
dialog.setMessage("esta es una prueba");
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
public void onClick(DialogInterface dialog, int id) { 
dialog.dismiss(); 
}
});
dialog.show();


}

@Override
public void Dismiss(DialogInterface dialog, int id){
dialog.dismiss();
}

};
}[/CODE]

I hope you can help me, thanks 

PROBLEMA

March 6, 2013 - 11:35am #17

Hello, 

I've had the same problem myself.

Thus far, I have managed to show a View's layout, in front of the camera, but I want it to appear only after the trackable is detected.

So I 've originally set the visibilty of the View to INVISIBLE and I want to change it to VISIBLE inside the Handler, but nothing happens.

What I really want my app to do is to pop-up a picture with a message on top, when it's corresponding trackable is detected.

Could you please help me?

PROBLEMA

November 8, 2012 - 11:05pm #16

can u post ur code where i must change the code in imagetarget?i want to show text with dialog but i can't make button and view and how to call the function.thnks

PROBLEMA

July 27, 2012 - 11:25am #15

Ok, thanks, that works.

The view is launched at the beginning but crashes and close the app, i'm gonna check to make the changes to launch the view when trackable is detected.

I'm also checking how to change size, and color of the dialog, but i think this can wait, it's just presentation.

PROBLEMA

July 27, 2012 - 10:37am #14

Change 'overlay' to the name of your view.

PROBLEMA

July 27, 2012 - 10:35am #13

I have a doubt, i need 2 Views?, because i already added a View named "dialog" (dialog.xml), i need a second view?, or i need to change "overlay" for the name of my view?

PROBLEMA

July 27, 2012 - 10:23am #12

You need to define the View in XML and place it in /res/layout for that code to work. Try creating a new Android Layout XML file in the layout folder. Name this 'overlay', and you can use the Eclipse GUI editor to design your dialog.

PROBLEMA

July 26, 2012 - 7:08pm #11

Hi David

 

First of all, thank you for the example, let me tell you..
I've been reading about the custom dialog, i made an example to have a better understand, now i get the idea about the view and i tried to use the code you wrote but i have some errors, i tried to fix it but unfortunately not be succesful.

These are the errors:

line addContentView(dialog, new LayoutParams( 

LayoutParams.FILL_PARENT, 

LayoutParams.FILL_PARENT));

Show:

The metod addContentView(view, viewGroup.LayoutParams), in the type Activity is not applicable fot the arguments (Dialog.viewGroup.LayoutParams)

 

line dialog - inflater.inlate(R.layout.overlay, null);

Show:

overlay cannot be resolved or is not a field

 

I already added the dialog.xml in "res\layout", and a bgdialog.xml for color in "res\drawable".

There's something i'm doing wrong or forgetting?

 

PROBLEMA

July 16, 2012 - 11:01am #10

Does the text disappear if you send a blank message (i.e. "" ).

In any case, I think that you're going to need to use a UI View if you want to present a button and have this interact with the Java layer. Android Views are used to present controls in layers on the screen. So you would define a View (e.g. in Eclipse ) and then present it as such..

 

e.g. at line 592 in ImageTargets.java, you would add your view after adding mGLView so that it appears above the rendered view.

                            // Now add the GL surface view. It is important
                            // that the OpenGL ES surface view gets added
                            // BEFORE the camera is started and video
                            // background is configured.
                            addContentView(mGlView, new LayoutParams(
                                            LayoutParams.FILL_PARENT,
                                            LayoutParams.FILL_PARENT));
                           
                            addContentView(mOverlayView, new LayoutParams(
                                            LayoutParams.FILL_PARENT,
                                            LayoutParams.FILL_PARENT));

 

where mOverlayView is your inflated View..

LayoutInflater inflater = getLayoutInflater();
mOverlayView = inflater.inflate(R.layout.overlay, null);

* you can place that code in initApplication()

If you're using Eclipse, you can create this UI View by adding a new Android XML Layout File to /res/layout. When you open this file, it will by presented by a graphical layout editor through which you can add a text region and a button. Here is an example of a layout w/ a single textfield and a button..

 

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textMultiLine" >

            <requestFocus />
        </EditText>

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

    </LinearLayout>

</FrameLayout>

 

PROBLEMA

July 16, 2012 - 10:30am #9

Hi David

Any suggestions about this?

 

Thanks in advance

PROBLEMA

July 12, 2012 - 3:05pm #8

Hi David, i think it's better if i show you the actuall code, at this time, we can show the dialog when detecth the trackable, but the dialog stays on screen until we press de back button device:

ImageTarget.cpp wrote:

int lastTrackableId=-1;

JNIEXPORT void JNICALL

Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv* env, jobject obj)

{

// Get the state from QCAR and mark the beginning of a rendering section

    QCAR::State state = QCAR::Renderer::getInstance().begin();

        // Explicitly render the Video Background

    QCAR::Renderer::getInstance().drawVideoBackground();

    

    // Did we find any trackables this frame?

if (state.getNumActiveTrackables()==0)

{

lastTrackableId=-1;

}

else

{

for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)

{

   

// Get the trackable:

const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);

        

// Compare this trackable's id to a globally stored id

// If this is a new trackable, find the displayMessage java method and

// call it with the trackable's name

 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();

}   

  }

}

}

 

ImageTargets.java wrote:

protected void onResume()

    {

        super.onResume();

        // 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;

            AlertDialog dialog = new AlertDialog.Builder(ImageTargets.this).create();

            dialog.setTitle(text);

            dialog.setMessage("esta es una prueba");

            dialog.show();      

              }

        };

    }

 

ImageTargetsRenderer.java wrote:

//A handler object for sending messages to the main activity thread

public static Handler mainActivityHandler;

// Called from native to display a message

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);  

}

 

 

Sorry, i didn't understand the idea about button as a View, can you explain me please?

 

Thanks in advance

PROBLEMA

July 12, 2012 - 1:40pm #7

If you have the dialog with button as a View, then you can set the visibility of that view to hide the dialog (see: setVisibility() @ http://developer.android.com/reference/android/view/View.html )

Have you defined the JNI method that will call your dialog from C++ yet? - is that part in place?

If so, you can use the same to signal when no targets are detected and hide the dialog from the same method.

PROBLEMA

July 12, 2012 - 6:57am #6

Hi again David

 

First of all, thank you for the help.

malilla01 and i are a team for a university project, let me explain you the idea we have.

The app must detect the Trackable and then show a dialog with some buttons, the buttons would call a new screen with some information (i think this part it's easy), but we need to show the dialog with the buttons just when the app detect the trackable, when there's no trackable detected, then the dialog must close.

We are new to programming in android, but we want and like to learn, but there's somethings we can't understand yet.

malilla01 sent the code that already show the dialog on screen, but ppreuss told me we need to create maybe a function (actually i don't know if must be a function or what else :( ) to dismiss the dialog, that's why we put the button, to try to understand how it work dismiss.

We are using the base code from the example to show a toast, but we already changed the code to show the dialog instead the toast.

Let me know if i'm not very clear, or if you need something else, maybe we are in the wrong direction.

 

PROBLEMA

July 11, 2012 - 5:56pm #5

Let me see if I can provide you with a simple example of how to present, and remove, a Java UI View in response to Tracking states. We have some examples of this.

What is your button doing? Is it going to call any methods in C++ via JNI?

 

PROBLEMA

July 11, 2012 - 4:29pm #4

DavidBeard thanks for the help, I have an idea of how the code, but I have a question.

Does the code only works for 3D objects? that I am using only Handle dialog 

I had commented that used dismiss to hide the Handle dialog, but do not know how?

I hope you can help me

PROBLEMA

July 10, 2012 - 9:55am #3

what you want to do is create an application that displays box dialogs and they show a specific information of an object, the box dialog should aparaser when detecting the label and desapareser when not detect  the label.

 

the box dialog should also have buttons, that's what I want do

PROBLEMA

July 9, 2012 - 5:11pm #2

So you want to allow the Tracker to search for a Trackable for a given interval and then dismiss the dialog if no Trackable is found?

If so, take a look at how the splash screen handler is implemented in ImageTargets.java. This is doing something similar..

e.g.

// Request a callback function after a given timeout to dismiss
                // the splash screen:
                mSplashScreenHandler = new Handler();
                mSplashScreenRunnable =
                    new Runnable() {
                        public void run()
                        {
                            // Hide the splash screen
                            mSplashScreenView.setVisibility(View.INVISIBLE);
                           
                            // Activate the renderer
                            mRenderer.mIsActive = true;
   
                            // Now add the GL surface view. It is important
                            // that the OpenGL ES surface view gets added
                            // BEFORE the camera is started and video
                            // background is configured.
                            addContentView(mGlView, new LayoutParams(
                                            LayoutParams.FILL_PARENT,
                                            LayoutParams.FILL_PARENT));
                           
                            addContentView(mOverlayView, new LayoutParams(
                                            LayoutParams.FILL_PARENT,
                                            LayoutParams.FILL_PARENT));
                           
                            // Start the camera:
                            updateApplicationStatus(APPSTATUS_CAMERA_RUNNING);
                        }
                };

                mSplashScreenHandler.postDelayed(mSplashScreenRunnable,
                                                    newSplashScreenTime);

Log in or register to post comments