I'm sorry to come up with this subject again but we're going to the
end of December and I'm still stuck in this..it's so demotivating.
I've tried to reach wikitude developers but they don't know how to
help me so if you have the patience or will to give me some
suggestions on this I would be really gratefull. I'll try to explain
with the code to make the things more clear.

I have an activity called BasicOpenARDemoActivity (wikitude activity
that initiates a wikitude camera view) with a method to happen when
the location is changed. If there's a certain proximity to a target a
trigger is called which opens a new intent:

public void onLocationChanged(Location newLocation) {

        double picLatitude = Double.parseDouble(picLatitudeString);
        double picLongitude = Double.parseDouble(picLongitudeString);
        double myLatitude  =  (newLocation.getLatitude());
        double myLongitude =  (newLocation.getLongitude());

        float R = 6371; // km
        float dLat = (float) Math.toRadians((picLatitude-myLatitude));
        float dLon = (float) Math.toRadians((picLongitude-myLongitude));
        float a = (float) (Math.sin(dLat/2) * Math.sin(dLat/2) +
                           Math.cos(Math.toRadians(myLatitude)) *
Math.cos(Math.toRadians(picLatitude)) *
                           Math.sin(dLon/2) * Math.sin(dLon/2));
        float c = (float) (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)));
        float distancia = R * c;

        // distancia in KM
        if(distancia<0.05 && ar.equals("1")){
        LogToSD.write("AR:", "PROXIMITY ALERT");

        Intent TNNIntent = new Intent(this.getBaseContext(),
thenNnowMode.class);
        Bundle w = new Bundle();
        activityName="finding";
        w.putString("code", activityName);
        w.putString("piclink", picLink);
        w.putString("sd", picSD);
        w.putString("id", picId);
        w.putString("ar", ar);
        w.putString("latitude", picLatitudeString);
        w.putString("longitude", picLongitudeString);
        w.putString("orientation", picOrientationString);
        TNNIntent.putExtras(w);
        startActivity(TNNIntent);
        finish();
}

The activity called after the trigger happens is called thenNnowMode
which initiates a surfaceview and the native camera of android:

        Bundle w = getIntent().getExtras();
    if (w!=null){
        activityName = w.getString("code");
         if(activityName.equals("finding")){
                picId = w.getString("id");
                picSD = w.getString("sd");
                picDate = w.getString("date");
                picKeywords = w.getString("keywords");
                picComment = w.getString("comment");
                picLink = w.getString("piclink");
                piclatitudeString = w.getString("latitude");
                piclongitudeString = w.getString("longitude");
                picorientationString = w.getString("orientation");
                ar = w.getString("ar");
                if (ar.equals("1")){
                        TNNPicture = BitmapFactory.decodeFile(picSD);
                        transparencyPreview = (ImageView) 
findViewById(R.id.picture);
                        transparencyPreview.setImageBitmap(TNNPicture);
                        transparencyPreview.setAlpha(150);

}
                }else{
                          picId = w.getString("id");
                          TNNPicturePath = w.getString("path");
                 }
        }

A SurfaceView is created  on the method onCreate() (I use it to be
able to TAP the screen and take a picture)

        tnnSurfaceView = (TappableSurfaceView)
findViewById(R.id.surface_camera);
        mSurfaceHolder = tnnSurfaceView.getHolder();
        mSurfaceHolder.addCallback(this);
        mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        tnnSurfaceView.addTapListener(onTap);

SurfaceView methods

        @Override
        // Create the Surface and Open the Camera
        public void surfaceCreated(SurfaceHolder holder) {
                tnnCamera = Camera.open();
        }

        @Override
        // Reacts for camera changes
        public void surfaceChanged(SurfaceHolder holder, int format, int
w,int h) {
                if (mPreviewRunning) {
                        tnnCamera.stopPreview();
                        }
                        Camera.Parameters p = tnnCamera.getParameters();
                        p.setPreviewSize(w, h);
                        tnnCamera.setParameters(p);
                        try {
                                tnnCamera.setPreviewDisplay(holder);
                        } catch (IOException e) {
                        e.printStackTrace();
                        }
                        tnnCamera.startPreview();
                        mPreviewRunning = true;
        }

        @Override
        // When the camera is closed
        public void surfaceDestroyed(SurfaceHolder holder) {
                mPreviewRunning = false;
                tnnCamera.setPreviewCallback(null);
                tnnCamera.stopPreview();
                tnnCamera.release();
        }

IMPORTANT NOTE/ISSUE:
This code works perfectly fine when I launch the
BasicOpenARDemoActivity and the condition "if(distancia<0.05 &&
ar.equals("1"))" is already TRUE (it follows the right procedure which
is:condition true-> run intent tnnintent -> go to activity
thennnowmode -> call native cam and a surfaceview).
The application only crashes if that same condition is FALSE and then
turns TRUE by changing the device position.

In lay man terms: If I'm already in the position (lat/long) where the
intent to call the activity happens (distance <0.05) everything works
correctly. If I'm far away (distance>0.05) and approach ... the
condition/trigger  "if(distancia<0.05 && ar.equals("1"))" turns true
and I get the error.

I hope I made myself clear, I guess this is as hard to understand as
it is to explain.

Thank you very much for your time and thanks in advance.

Pedro



On Dec 4, 3:29 pm, Pedro Teixeira <pedroteixeir...@gmail.com> wrote:
> Yes that's the only way I know how to do it. I'll try to contact them
> and hear what they have to say about it. Thank you
>
> On Dec 4, 3:20 pm, Mark Murphy <mmur...@commonsware.com> wrote:
>
>
>
> > On Sun, Dec 4, 2011 at 10:10 AM, Pedro Teixeira
>
> > <pedroteixeir...@gmail.com> wrote:
> > > I'm almost sure the problem is as you mentioned that thecamerais
> > > already in use.
>
> > > I'm going from an activity that uses thecamera(wikitudeapplicaiton)
> > > to an activity that still uses thecamera(my own).
>
> > > I'm not sure what are my options here:
> > > Am I able to continue without releasing thecameraor do I have to
> > > release thecameraand then start again?
>
> > Unless you want problems (technical or user), activities should
> > release theCamerain onPause(), or at the very latest onStop(). If
> >Wikitudeis not doing this, andWikitudeis starting your activity,
> > then you need to talk to the authors ofWikitude.
>
> > > Another issue that I'm having is that I can't seem to find any code on
> > >wikitudedemonstration example that starts thecameraso I'm not even
> > > sure how to stop it.
>
> > Presumably, they have a support board or email address or something.
>
> > > Is there any general or standard mode of doing this? I mean.. release
> > > thecameraindependently from which activity I'm on at the moment?
>
> > You can only release cameras that you open. If you open in (onStart()
> > or onResume()), you release it (onPause() or onStop()).
>
> > --
> > Mark Murphy (a Commons 
> > Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> > Android Training...At Your Office:http://commonsware.com/training

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to