Thursday, October 30, 2014

Image convert to String using Javascript

I am working as phonegap developer past 1 year. I want to save the image in my database. so i want to convert image to string .

 Create a canvas, load your image into it and then use toDataURL() to get the base64 representation (actually, it's a data: URL but it contains the base64-encoded image)



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>File Transfer Example</title>
 <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
   </head>
<body>
  <input type="file" id="file" />
<div id="imgTest"></div>
<div id="testing"></div>
<script type='text/javascript'>
var _URL = window.URL || window.webkitURL;

$("#file").change(function(e) {
    var file, img;


    if ((file = this.files[0])) {
        img = new Image();
        img.onload = function() {
if(this.width > 150 && this.height > 150 )
            {
            alert("please upload image size 150 X 100");
            }
            else{
            var filesSelected = document.getElementById("file").files;
    if (filesSelected.length > 0)
    {
        var fileToLoad = filesSelected[0];

        var fileReader = new FileReader();

        fileReader.onload = function(fileLoadedEvent) {
            var srcData = fileLoadedEvent.target.result; // <--- data: base64

            var newImage = document.createElement('img');
            newImage.src = srcData;

            document.getElementById("imgTest").innerHTML = newImage.outerHTML;
            alert("Converted Base64 version is "+document.getElementById("imgTest").innerHTML);
            console.log("Converted Base64 version is "+document.getElementById("imgTest").innerHTML);
   document.getElementById("testing").innerHTML = srcData;
        }
        fileReader.readAsDataURL(fileToLoad);
    }
            }
        };
        img.onerror = function() {
            alert( "not a valid file: " + file.type);
        };
        img.src = _URL.createObjectURL(file);


    }

});
</script>
</body>
</html>

Jquery mobile datepicker for Phonegap

I am working us a phonegap developer past 1 year. i used pickerview for datepicker. when i update ios 8. the pickerview bug. so i changed the jquery mobile theme based date picker.

Its very easy to call the date picker popup using the jquery mobile theme base date picker without jquery theme cannot be work.

Some ios pickerview not working in ios 8 but this date picker work all the platform.


<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>jQueryMobile - DateBox Demos</title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.min.css" />
    <link rel="stylesheet" href="http://cdn.jtsage.com/datebox/1.4.4/jqm-datebox-1.4.4.min.css" />
    <link type="text/css" href="css/demos.css" rel="stylesheet" />
    <!-- NOTE: Script load order is significant! -->
    <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.min.js"></script>
    
    
    <script type="text/javascript" src="http://cdn.jtsage.com/datebox/1.4.4/jqm-datebox-1.4.4.core.min.js"></script>
    
    
    <script type="text/javascript" src="http://cdn.jtsage.com/datebox/1.4.4/jqm-datebox-1.4.4.mode.flipbox.min.js"></script>
    
    <script type="text/javascript">
    jQuery.extend(jQuery.mobile,
    {
      ajaxEnabled: false
    });
 
    </script> 
  </head>
  <body>
  
    <div data-role="page" id="main" align="center" style="width:100px;" >     
    
      <center>
          
            <label for="mode7">TimeFlipBox</label>
            <input name="mode7" id="mode7" type="text" data-role="datebox" data-options='{&quot;mode&quot;:&quot;flipbox&quot;}' readonly=true />
         </center>
       
    </div>
</html>

Jquery mobile Time Picker for Phonegap

I am working us a phonegap developer past 1 year. i used pickerview for timepicker. when i update ios 8. the pickerview bug. so i changed the jquery mobile theme based time picker.

Its very easy to call the time picker popup using the jquery mobile theme base time picker without jquery theme cannot be work.

Some ios pickerview not working in ios 8 but this time picker work all the platform.



<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>jQueryMobile - DateBox Demos</title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.min.css" />
    <link rel="stylesheet" href="http://cdn.jtsage.com/datebox/1.4.4/jqm-datebox-1.4.4.min.css" />
    <link type="text/css" href="css/demos.css" rel="stylesheet" />
    <!-- NOTE: Script load order is significant! -->
    <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.min.js"></script>
    
    
    <script type="text/javascript" src="http://cdn.jtsage.com/datebox/1.4.4/jqm-datebox-1.4.4.core.min.js"></script>
    
    
    <script type="text/javascript" src="http://cdn.jtsage.com/datebox/1.4.4/jqm-datebox-1.4.4.mode.flipbox.min.js"></script>
    
    <script type="text/javascript">
    jQuery.extend(jQuery.mobile,
    {
      ajaxEnabled: false
    });
 
    </script>
 <style>
 .ui-datebox-flipcenter{width:160px;}
 </style>
  </head>
  <body>
  
    <div data-role="page" id="main" align="center" style="width:100px;" >     
    
      <center>
          
            <label for="mode7">TimeFlipBox</label>
            <input name="mode7" id="mode7" type="text" data-role="datebox" data-options='{"mode": "timeflipbox", "useNewStyle":true,"overrideTimeFormat": 24}' />
         </center>
       
    </div>
</html>

Phonegap Installation Document in Mac

PhoneGap is a great tool for building cross-platform mobile apps using web technologies. Getting started with it seems pretty easy according to their install guide:

Install Phonegap Environment setup:

First i will tell you how to install Phonegap in mac System.

Step : 1

(a).Install x-code lastest version.
(b).Install Node.js.

To Install, ensure that you have NodeJS installed, then open your commandline and run the following:

(c).Install Cordova (or) Phonegap
Apples-MacBook-Pro:~ apple$ npm install -g cordova

(or)

Apples-MacBook-Pro:~ apple$ npm install -g phonegap

Once installation completes, just check the Path in command line using this command.
Apples-MacBook-Pro:~ apple$ cordova -version
3.5.0-0.2.7

(d).Install Apache-Ant. Run brew update & then install ant brew install ant
Step 2: For iOS development, Run to the App Store & Download the latest version of XCode. After the installation is completed, launch the application & accept the license, terms.
Step 3: For Android development, Navigate here & download the ADT bundle for MAC. After the download is completed, unzip the file. Navigate inside the eclipse folder and run Eclipse.app. Once eclipse loads up, You will see a menu bar on the top left hand corner

Click on the 3rd icon from right (in the above image). This will launch the Android SDK Manager. You can select the targeted Android version from the list.

Step 4: Configure Android SDK. We need to hook up the SDK path.
In your terminal, Run cd ~ Remember where you have downloaded the ADT Eclipse? We need to head back to the unzipped folder & then into SDK & then into tools folder. Right click & click Get Info.. You should see a path.
On my mac, this is how it will look
export 
PATH=/Users/me/Development/adt-bundle-mac-x86_64-20130917/sdk/tools:Users/me/Development/adt-bundle-mac-x86_64-20130917/sdk/platform-tools:$PATH

Next, lets edit the .bash_profile & add the SDK instance open -e .bash_profile & add the above line to the top of the file. Save and close .bash_profile
If you want to use the same code and functionality in android and ios application u can create local developer project.
If you want to develop android and ios app support Mac OS
just create a phonegap project in terminal.
Add Platforms:
$ cd hello

$ cordova platform add ios
$ cordova platform add android

next build the platforms using this command:
$ cordova build ios.
$ cordova build android.

Open your project folder hello/platforms/ios
double click ios "HelloWorld.xcodeproj".
this project file will open in x-code.
and develop your project pages in www folder.