nicolas2k / google-glass-api

Automatically exported from code.google.com/p/google-glass-api
1 stars 0 forks source link

GDK: TimelineManager.insert Card with non-resource image content #337

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. I have an app which uses the android Camera API to capture still images and 
video.  I would like to eventually add the captured item to the timeline, but 
it appears from the API documentation 
(https://developers.google.com/glass/develop/gdk/reference/com/google/android/gl
ass/app/Card#addImage(android.net.Uri)) that only resource images can be added 
to the timeline.

When the following code is invoked, the image data resides in the variable 
'mCapturedImageData', which is stored into a temporary file then sent to the 
gallery.  However, the card that appears in the timeline has no image.
                // Save the image to a temporary file
                    String timeStamp = new java.text.SimpleDateFormat("yyyyMMdd_HHmmss").format(new java.util.Date());
                    String imageFileName = "JPEG_" + timeStamp + "_";
                    java.io.File storageDir = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_PICTURES);
                    java.io.File imageFile = java.io.File.createTempFile(
                        imageFileName,  // prefix
                        ".jpg",         // suffix
                        storageDir );   // directory

                    (new java.io.FileOutputStream(imageFile)).write(mCapturedImageData, 0, mCapturedImageData.length);

                    // add the image to the device gallery
                    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                    java.io.File f = new java.io.File("file:" + imageFile.getAbsolutePath());
                    android.util.Log.d("preview service", "onReceive() -- saving image '" + f + "' to gallery");
                    android.net.Uri contentUri = android.net.Uri.fromFile(f);
                    mediaScanIntent.setData(contentUri);
                    sendBroadcast(mediaScanIntent);

                    com.google.android.glass.app.Card timelineCard = new com.google.android.glass.app.Card(PreviewService.this);
                    timelineCard.addImage(android.net.Uri.fromFile(imageFile));
                    timelineCard.setFootnote("You captured an image");
                    mTimelineManager.insert(timelineCard);

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
XE12, GDK Preview

Please provide any additional information below.

Original issue reported on code.google.com by josephba...@gmail.com on 3 Jan 2014 at 9:42

GoogleCodeExporter commented 8 years ago
Hello,

Setting an image file in a Card should just work as long as the URI has a 
"file://" scheme. One issue that might be occurring in your use-case would be 
that the full image taken by the Camera is too big to be loaded onto a Card 
(check the logs for warnings): make sure to resize the image to an appropriate 
size (640x360px should do it).

Best,
Alain

Original comment by ala...@google.com on 6 Jan 2014 at 9:27

GoogleCodeExporter commented 8 years ago
That was my problem -- I needed to scale the bitmap to 640x360 or less before 
adding it to a card.

Incidentally, one thing that threw me off was the fact that the API 
documentation for Card.addImage states:
  public Card addImage (Uri uri)
    Adds an image defined by an Uri to card. Supported schemes are: android.resource file
This in combination with the fact that my image didn't show up led me to the 
tentative conclusion that only resource files were allowed on timeline cards.  
For other developers, it might make sense to update the documentation 
(https://developers.google.com/glass/develop/gdk/reference/com/google/android/gl
ass/app/Card#addImage(android.net.Uri)) to reflect both the 640x360 limitation, 
and to remove the erroneous "Supported schemes are: android.resource file" 
statement.

Original comment by josephba...@gmail.com on 7 Jan 2014 at 3:36

GoogleCodeExporter commented 8 years ago
Oh, this seems to be an issue with how the Javadocs got generated into HTML, 
the doc should be read as: Suppored schemes are: "android.resource" and "file"; 
meaning that an URI that has a scheme of "android.resource://" or "file://" 
will work.

We will update the docs to remove the confusion.

Original comment by ala...@google.com on 7 Jan 2014 at 4:55