Mental Jetsam

By Peter Finch

Changing Google cardboard IPD ( interpupillary distance)

Posted by pcfinch on June 17, 2015

I recently received a Google Cardboard viewer from Dodocase. It was fun to put together and worked really well with my Samsung S3 (even though the phone is a bit “dated” these days). However,  in some of the cardboard demos I was “seeing double” and I think this was due to the default setup of the viewer and my interpupillary distance (which is slightly different for everyone). There is no way to customize it on phone without having a QR code, but there was no QR code on the case.

I found that you can customize the cardboard viewer by generating you own QR code using the following link.

https://www.google.com/get/cardboard/viewerprofilegenerator/

I originally used the measurements that matched my case, but I found I had a “play” with the values a little to get them to work, but after a few tries it worked great! I found that using a “Inter-lens distance (mm)” or 55mm a little less that the actually measurement of 60mm and a “Tray to lens-center distance (mm)” of 35mm (1/2 my phone height width) worked well.

Good luck and I hope it works for your!

Posted in Google Cardboard | Leave a Comment »

Simple HTML5 Drag, Drop and upload JQuery plugin

Posted by pcfinch on January 21, 2013

The following code is based on an excellect description of working with HTML5’s ability to handle drag and drop and auto upload items to a server, found at HTML5 Drag and Drop Upload and File API Tutorial. The code below implements this as a very simple JQuery plugin and current this only works on Chrome and Firefox.

(function ($) {
    $.fn.html5Upload = function (options) {
        var settings = $.extend({
            'start': function () { },
            'preview': function () { },
            'url': null,
            'data': 'data',
            'filename': 'filename'
        }, options);
        this.each(function () {
            function noopHandler(evt) {
                evt.stopPropagation();
                evt.preventDefault();
            };
            $(this).bind("dragenter", noopHandler);
            $(this).bind("dragexit", noopHandler);
            $(this).bind("dragover", noopHandler);
            $(this).bind("drop", function (devt) {
                noopHandler(devt);
                var files = devt.originalEvent.dataTransfer.files;
                if (settings.start) settings.start();
                $.each(files, function (index, file) {
                    var reader = new FileReader();
                    reader.onload = function (revt) {
                        var data64 = revt.target.result;
                        if (settings.preview) settings.preview(file, data64);
                        if (settings.url && settings.filename && settings.data) {
                            var postdata = {} ;
                            postdata[settings.filename] = file.name ;
                            postdata[settings.data] = data64 ;
                            $.ajax({
                                url : settings.url,
                                type : "POST",
                                data : postdata
                            }) ; 
                        }
                    };
                    reader.readAsDataURL(file);
                });
            });
        });
    }
})(jQuery);

You can use the following javascript to start the plugin. The “upload.aspx” script will be called and the filename and data will be passed to it in the “filename” and “data” post parameters.

$(document).ready(function () {
    $("#dropbox").html5Upload({
        start: function() {
            $("#preview").empty() ;
        },
        preview: function (file, data64) {
            $("#preview").append($("<img>").attr("src", data64));
        },
        url : "upload.ashx"
    });
});

Some example HTML, just for good measure…

<div id="dropbox">
<span id="droplabel">Drop file here...</span>
</div>
<div id="preview" ></div>

Posted in Uncategorized | Leave a Comment »

Android JSON WebService Example

Posted by pcfinch on September 27, 2012

The following code, for the Android OS, will make a HTTP request to a JSON webservice at “url” and convert the response into a JSONObject.

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(url) ;
ResponseHandler<String> responseHandler=new BasicResponseHandler();
String responseBody = httpClient.execute(request, responseHandler);
JSONObject jsonResponse = new JSONObject(responseBody) ;

Posted in Programming | Leave a Comment »

Calculating Android canvas device pixels sizes

Posted by pcfinch on July 26, 2012

When drawing on a Android Canvas, it’s important to take into consideration the different pixel densities when rendering lines and text. Using “pixels” can make things too small on high resolution screens. Using DIP instead of pixels is a good way to keep things a similar size physical size on the screen and the following code can be used to map DP values to pixel based values.

int dpSize = 5 ;
DisplayMetrics dm = getResources().getDisplayMetrics() ;
float inPixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpSize , dm);
...
paint.setStrokeWidth(inPixels) ;
...
paint.setTextSize(inPixels * 3);
...

Posted in Programming | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.