Posts mit dem Label Phonegap werden angezeigt. Alle Posts anzeigen
Posts mit dem Label Phonegap werden angezeigt. Alle Posts anzeigen

Sencha Touch Grind-Printer

Montag, 31. März 2014
Maybe someone of you already had the wish to print a grid easily from within a Sencha Touch application.

Requirements:

  • Cordova
  • Cordova printer plugin: https://github.com/FRD49/phonegap-print-plugin


Here is a short javascript source written by myself to archive this. Documentation is in the code itself. Columns without a dataindex will not be printed!

Read more ...

Part 3: Send file attachments by email

Montag, 3. Februar 2014
In this last part I want you to show how you can send an attachment by email. Generally you can add any file from the device you have in your sandbox. I will show you how to add the csv file which we created in Part 1 and Part 2

First we need a Phonegap / Cordova plugin. If you didnt know how to setup your project for use with phonegap, you would have to take a look at Part 2.

1. Add emailComposer Plugin
Open the terminal and cd to your Phonegap / Cordova folder and execute the following command:

cordova plugin add https://github.com/katzer/cordova-plugin-email-composer.git

This is the call structure from the developer website:

/*
 * Opens an email draft pre-filled with the passed properties.
 */
window.plugin.email.open({
    to:          Array, // contains all the email addresses for TO field
    cc:          Array, // contains all the email addresses for CC field
    bcc:         Array, // contains all the email addresses for BCC field
    attachments: Array, // contains all full paths to the files you want to attach
    subject:    String, // represents the subject of the email
    body:       String, // represents the email body (could be HTML code, in this case set isHtml to true)
    isHtml:    Boolean, // indicats if the body is HTML or plain text
});

For further informations about the plugin take a look to the developer website: https://github.com/katzer/cordova-plugin-email-composer

2. Send the email

The function should be self explaining. You can either pass the recipient, cc, bbc as string or as Array. Of course you can send any kind of attachments using this function. If an example is needed how to read file from LocalFileSystem and send them please ask for it and I'm willing to prove an example.

FILE2MAIL: function(recipient, cc, bcc, subject, body, attachementURL) {
    if (!Ext.isArray(recipient)) {
        recipient = new Array(recipient);
    }

    if (!Ext.isArray(cc)) {
        cc = new Array(cc);
    }

    if (!Ext.isArray(bcc)) {
        bcc = new Array(bcc);
    }

    if (!Ext.isArray(attachementURL)) {
        attachementURL = new Array(attachementURL);
    }

    window.plugin.email.open({
        to:          recipient, // contains all the email addresses for TO field
        cc:          cc, // contains all the email addresses for CC field
        bcc:         bcc, // contains all the email addresses for BCC field
        attachments: attachementURL, // contains all full paths to the files you want to attach
        subject:    subject, // represents the subject of the email
        body:       body, // represents the email body (could be HTML code, in this case set isHtml to true)
        isHtml:    true // indicats if the body is HTML or plain text
   });
}

3. Combining Part 1 & Part 2 & Part 3

var dummyStore = Ext.getStore('dummyStore');

STORE2CSV(dummyStore,null, stringSuccess);

function stringSuccess(csv){
    DATA2FILE('export.csv',csv,fileSavedSuccess)
}

function fileSavedSuccess(file){
    FILE2MAIL('dummyEmail@gmail.com','','','hallo test file','Test Attachement',file.fileName);
}


If you have any kind of questions or improvements please leave a comment or contact me. I appreciate any help or hints!


Read more ...

Part 2: Sencha Store to local CSV file

Sonntag, 2. Februar 2014
Hey guys,

This is Part 2 of 3 How to send a Sencha Store as CSV file by email. If you missed the first part, you would like to take a look here http://abitofcoding.blogspot.com/2014/01/part-1-sencha-touch-store-to-csv-string.html

1. Get Phonegap / Cordova ready
Firstly we will need our app wrapped with Phonegap / Cordova. There are several ways to do, since Touch 2.3.0 Sencha offers a pretty nice integration for Phonegap and Cordova. Since the you can setup your project with a single Sencha CMD command:



// FOR PHONEGAP
// sencha phonegap init [APP IDENTIFIER] [APP NAME]
sencha phonegap init com.mycompany.MyApp MyApp

// FOR CORDOVA
// sencha cordova init [APP IDENTIFIER] [APP NAME]
sencha cordova init com.mycompant.MyApp MyApp


Take a look at the Sencha Docs for more options and information: http://www.sencha.com/blog/leveraging-phonegap-within-sencha-touch/

2. Install requirements
As we need access to the device filesystem we need to install the file plugin for Phonegap / Cordova.
If you use Phonegap / Cordova 3.* it's pretty simple:

// FOR CORDOVA
//same for phonegap as for cordova
cordova plugin add org.apache.cordova.file
// the transfer plugin is not really needed but nice to avoid errors :)
cordova plugin add org.apache.cordova.file-transfer


That's it :D

3. Building and saving

As mentioned Part 1 is about building the CSV string. This one we will use now to safe on file.
You can create and add any content to any kind of file you want.
Take the CSV string from Part 1 as data and take a filename which is something like *.csv and you will have a CSV file created on your device!
Questions or improvements are welcome!

// FOR CORDOVA
DATA2FILE: function(filename, data, callback) {
        // default filename
        var defaultFileName =  'export-file.txt';

        if (filename === undefined || filename === null) {
            filename = defaultFileName;
        }

        // Request the file system
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);

        // Access to filesystem is OK
        function gotFS(fileSystem) {
            fileSystem.root.getFile(filename, {create: true}, gotFileEntry, fail);
        }

        // File is ready
        function gotFileEntry(fileEntry) {
            fileEntry.createWriter(gotFileWriter, fail);
        }

        // Write file content
        function gotFileWriter(writer) {
            writer.onwriteend = function(evt) {
                console.log('finished writing');
                if (callback !== undefined) {
                    callback(writer);
                }
            };
            writer.write(data);
        }

        function fail(error) {
            console.log('Error: ', error.code);
        }
    }

To combine the CSV string from Part 1 and this method something like this is possible:

var duSto = Ext.getStore('dummyStore');
STORE2CSV(duSto,null,
 function(csvData){
  DATA2FILE('export.csv',csvData, function( // PART 3 HOW TO SEND COMING SOON){}
        }
) 



Read more ...

iOS7 Phonegap / Cordova statusbar fix

Freitag, 31. Januar 2014


Since Apple has release the complete new iOS7 to public you may have some trouble with your phonegap apps. The reason is simple: the statusbar is not a reserved area anymore. It got a transparent bar with a 20px height.

It seems a simple thing but it is going to annoy you and especially your users!
Here is a simple trick to fix your application again, there might be other solutions to solve it in javascript within your application but I prefer the Objective-C way. If you had the app running as a website you wouldn't have to apply any changes.

Just replace the existing viewWillAppear function in your MainViewController.m, rebuild and you're done.

// Fix for shrinking screen on Camera, Camera-Roll, InAppBrowser and more...
bool sizeWasAdjusted = false;
- (void)viewWillAppear:(BOOL)animated
{
    // View defaults to full size.  If you want to customize the view's size, or its subviews (e.g. webView),
    // you can do so here.
    //Lower screen 20px on ios 7
    if (!sizeWasAdjusted && [[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        CGRect viewBounds = [self.webView bounds];
        viewBounds.origin.y = 20;
        viewBounds.size.height = viewBounds.size.height - 20;
        self.webView.frame = viewBounds;
        sizeWasAdjusted = true;
    }
    [super viewWillAppear:animated];
}
Read more ...