RICOH THETA Plug-in: How To Get Last Picture Taken with HTTP


#1

This example shows the following:

  1. get URI of last picture taken from plug-in using the library theta4j
  2. show URI on logs

For people who want to go further this example also shows:

  1. display last image take in Vysor using the Glide library to help with testing
  2. control image display with Wi-Fi button press
  3. convert URI to image file path to directly access image file on ExternalStorage sdcard

Prerequisite

  • You can use theta4j to take a picture
  • You’re able to use the pluginlibrary for button presses
  • You can edit the Gradle files to implement the libraries above
  • You can edit AndroidManifest.xml to adjust properties

If you have problems with the two points above, you can either go through these drills from @jcasman or copy and paste the starter code below or clone the entire repo, master branch.

I am using Glide and ImageView to help with testing. For your plug-in development, you should take the URI and feed it into your application. If you prefer, you can also parse the URI and use the last portion to access ExternalStorage directly.

Steps

  1. Under MainActivity, create variable of type URL.

     URL url;
    
  2. under executor.submit and above the try statement to take a picture, add

    CommandResponse<TakePicture.Result> response = null;
    
  3. assign response to `theta.takePicture();

     response = theta.takePicture();
    
  4. implement while loop to wait for takePicture() to finish

Place below the last catch for takePicture()

image

                while (response.getState() != CommandState.DONE) {
                    try {
                        response = theta.commandStatus(response);

                        Thread.sleep(100);


                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
  1. assign url to the result of the response. Put this at the end of the while loop (outside of the loop)

     url = response.getResult().getFileUrl();
    
  2. Print the url out to your log

    Log.d("THETADEBUG", "fileUrl: " + url);
    

Congratulations, you’re done


Optional – Display Image to Vysor Screen

For testing purposes, you can display the image and URI to the virtual THETA screen using Vysor.

  1. Create ImageView to activity_main.xml

Click on the text ImageView in the left panel. Drag it onto the graphical screen on the right. If ImageView is not visible, search for it.

  1. Assign id of ImageViewId

image

  1. Create ImageView variable in MainActivity.java

  1. Add Glide to Gradle and sync

     implementation 'com.github.bumptech.glide:glide:4.9.0'
     annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    
  2. Create method showImage

image

  1. attach imageView to resource ID in layout file

image

  1. Show Image on Key Up

image

  1. display URL on screen with Toast

image

Get Image File Path

  1. create new method for getImagePath()

25%20PM

  1. call method from onKeyUp

image

  1. Test
    Take picture and check logcat

  1. Add Toast

     Toast.makeText(MainActivity.this,filepath,Toast.LENGTH_LONG).show();
     return filepath;
    


Code Listing

The code is in the response-vysor branch