Friday, 19 February 2016

Device Calendar In Ionic Framework

Hi,

Here is a way by which, we can the device calendar in ionic framework.

ionic start IonicCalendar blank
cd IonicCalendar
ionic platform add android


The next step is to install the Cordova plugin for Calendar.  Using your Terminal or command prompt, run the following command:

cordova plugin add https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin.git


At this point you can use the native calendar in your application, but we are going to make easier by using ngCordova.  Download the latest ngCordova release and extract ng-cordova.min.js into your project’s www/js directory.
With the file included in your project you now need to include it in your www/index.html file:

<script src="js/ng-cordova.min.js"></script>

It is very important that the above line be included before cordova.js, otherwise we can't use the cordova plugin in our project.
Now we must include it into our angular.module directives list like the following in our www/js/app.js file:

var ionicApp = angular.module("starter", ["ionic", "ngCordova"]);

Open your www/js/app.js file and make it look like the following:

var ionicApp = angular.module('starter', ['ionic', 'ngCordova']);
 
ionicApp.run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {
        if(window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        }
        if(window.StatusBar) {
            StatusBar.styleDefault();
        }
    });
});
 
ionicApp.controller("CalendarController", function($scope, $cordovaCalendar) {
 
    $scope.createEvent = function() {
        $cordovaCalendar.createEvent({
            title: 'Hello world',
            location: 'Home',
            notes: 'Bring sandwiches',
            startDate: new Date(2015, 0, 15, 18, 30, 0, 0, 0),
            endDate: new Date(2015, 1, 17, 12, 0, 0, 0, 0)
        }).then(function (result) {
            alert("Event created successfully");
        }, function (err) {
            alert("There was an error: " );
        });
    }
 
});

To use the createEvent() method above, open your www/index.html file and add the following code:

<ion-content ng-controller="CalendarController">
  <button class="button" ng-click="createEvent()">Create Event</button>
</ion-content>

If event created successfully then you will get alert message 'Event created successfully' otherwise you will get alert an error message like ' There was an error:'




Thanks...

Friday, 5 February 2016

Finding model,platform,UUID and manufacturer of a device in ionic

Hi,

 Create the ionic project using the below commands. Here we are creating the ionic blank project and name it is as “DeviceInformaion”

ionic start DeviceInformaion blank

cd DeviceInformaion

Then add the platform android and ios

ionic platform add android

ionic platform add ios

Then integrate the ng-Cordova library into your project.
Add the ng-cordova.min.js reference above to the cordova.js file in the index.html as mentioned in the below.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="js/ng-cordova.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>

<body ng-app="starter">

ng-cordova integration is still not over. Open your app.js file and alter the angular.module line to look like the following.

angular.module('starter', ['ionic', 'ngCordova'])

The next thing we want to do is add the Apache Cordova device plugin. This can be done by running the following command.

cordova plugin add org.apache.cordova.device

Add get Device information button.

Then index.html file will look like-

<body ng-app="starter" ng-controller="DeviceController">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Device Information</h1>
</ion-header-bar>
<ion-content>
<div class="item item-text-wrap">
<ul class="list">
<li class="item">
Manufacturer : {{manufacturer}}
</li>
<li class="item">
Model : {{model}}
</li>
<li class="item">
Platform : {{platform}}
</li>
<li class="item">
UUID : {{uuid}}
</li>
</ul>
</div>
</ion-content>
</ion-pane>
</body>

Next create the controller for app.js file and add $ionicPlatform.ready function. Then get the device information using getDevice() function and assign the device detail values in respective list elements. Please find the full source code for app.js file in the below.

angular.module('starter', ['ionic','ngCordova'])

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})

.controller('DeviceController', function($ionicPlatform, $scope, $cordovaDevice) {
$ionicPlatform.ready(function() {
$scope.$apply(function() {
// sometimes binding does not work! :/
// getting device infor from $cordovaDevice
var device = $cordovaDevice.getDevice();
$scope.manufacturer = device.manufacturer;
$scope.model = device.model;
$scope.platform = device.platform;
$scope.uuid = device.uuid;
});
});
})

Next we have to run the application using the below command lines. If you are running in emulator you can use emulate instead run.

ionic run ios
ionic run android

Once run the application it will get the device details in the ionic platform ready function.
And it will display on index.html page.



Thanks...






Friday, 29 January 2016

Popover in ionic

Hi

Popover can be created by using ion-popover-view element. This element should be added to HTML template and $ionicPopover service needs to be injected into controller.
There is a way of adding popover. fromTemplate method allows using inline template.
In your controller add the following line of code-
.controller('MyCtrl', function($scope, $ionicPopover) {
   $ionicPopover.fromTemplateUrl('popover.html', {
      scope: $scope
   }).then(function(popover) {
      $scope.popover = popover;
   });
   $scope.openPopover = function($event) {
      $scope.popover.show($event);
   };
   $scope.closePopover = function() {
      $scope.popover.hide();
   };
   //Cleanup the popover when we're done with it!
   $scope.$on('$destroy', function() {
      $scope.popover.remove();
   });
   // Execute action on hide popover
   $scope.$on('popover.hidden', function() {
      // Execute action
   });
   // Execute action on remove popover
   $scope.$on('popover.removed', function() {
      // Execute action
   });
})

Now we will add script with template to the HTML file we are using for calling popover function.

<script id = "popover.html" type = "text/ng-template">
   <ion-popover-view>
      <ion-header-bar>
         <h1 class = "title">Popover Title</h1>
      </ion-header-bar>
      <ion-content>
         Popover Content!
      </ion-content>
   </ion-popover-view>
</script>

Thanks...

Friday, 22 January 2016

Ionic slide box with backward and forward functionality

Hi,

In this article we are going to discuss creating an application that makes use of slide boxes.  The theme of the application will be cars.

Run the following command in your terminal-

ionic start IonicProject blank
cd IonicProject
ionic platform add android
ionic platform add ios


Add the following lines of code in your style.css file-

.slider { height: 100%; text-align: center }
.scroll { height: 100% }


We add the above code because we want each slide in the slide box to take up the full screen.  Any text in these slides will be centered.


Add the following lines of code in your index.html file-


<ion-slide-box>
    <ion-slide>
        <img style="width: 100%" src="http://upload.wikimedia.org/wikipedia/commons/7/79/2001_BMW_Z3_Sideview_Topdown_Topaz_Blue_2.5i.jpg">
    </ion-slide>
    <ion-slide>
        <img style="width: 100%" src="http://upload.wikimedia.org/wikipedia/commons/2/2e/BMW_Z3_1.9L_1998.jpg">
    </ion-slide>
    <ion-slide>
        <img style="width: 100%" src="http://www.bmwblog.com/wp-content/uploads/bmw-z3-black.jpg">
    </ion-slide>
</ion-slide-box>


You’ll notice that I’ve found three random car pictures on the internet and included them in each of the slides.  The image will take up the full width of the slide.

The above code is very basic.  It only allows for swiping.  It doesn’t auto play and it doesn’t loop.  It also doesn’t allow you to choose the current slide.  By adding the following line in index.html file, we can have better control of our slide box:


<ion-slide-box ng-controller="slideController" pager-click="navSlide(index)" auto-play="true" does-continue="true">

The above code will auto play the slides and loop them.  I’ve also added a function that allows you to choose the slide when you click on one of the pager items.  The function is found inside the slideController which can be seen below:

example.controller("slideController", function($scope, $ionicSlideBoxDelegate) {
    $scope.navSlide = function(index) {
        $ionicSlideBoxDelegate.slide(index, 500);
    }
});


Now if you want to add the next and previous slide functionality by clicking on next and previous arrow, then add following lines of code in your slideController-


 $scope.slidePrevious = function() {

        $ionicSlideBoxDelegate.previous();
    }

    $scope.slideNext = function() {

        $ionicSlideBoxDelegate.next();
    }


And now index.html file look like-


<ion-slide-box ng-controller="slideController" pager-click="navSlide(index)">

 <ion-slide>
<h4>
       <b>Slide1</b> <i class="ion-chevron-right" ng-click = "slideNext()"></i>
 </h4>
        <img style="width: 100%" src="http://upload.wikimedia.org/wikipedia/commons/7/79/2001_BMW_Z3_Sideview_Topdown_Topaz_Blue_2.5i.jpg">
    </ion-slide>
    <ion-slide>
<h4>
     <i class="ion-chevron-left" ng-click="slidePrevious()"></i>    <b>Slide2</b> <i class="ion-chevron-right" ng-click = "slideNext()"></i>
 </h4>
        <img style="width: 100%" src="http://upload.wikimedia.org/wikipedia/commons/2/2e/BMW_Z3_1.9L_1998.jpg">
    </ion-slide>
    <ion-slide>
<h4>
     <i class="ion-chevron-left" ng-click="slidePrevious()"></i>    <b>Slide3</b> 
 </h4>
        <img style="width: 100%" src="http://www.bmwblog.com/wp-content/uploads/bmw-z3-black.jpg">
    </ion-slide>
</ion-slide-box>

 
 
Thanks...



Friday, 15 January 2016

Deployment of wordPress on Heroku

Hello,

Here is a way by which you can deploy wordPress on Heroku, by using following sets of command-

Step1-
       Run the following command on your terminal-

git clone git://github.com/mhoofman/wordpress-heroku.git

Step2-
       Open the cloned directory by using following command-

 cd wordpress-heroku

Step3-
         Create an account on heroku by using https://signup.heroku.com/login

Step4- 
        Install the Heroku CLI by using instruction on https://devcenter.heroku.com/articles/heroku-command

Step5-
       Run the following command in terminal-

     heroku login

Step6-
      Run the following command on terminal, so that an app will created on heroku-
    
  heroku create


Step7-

If you want, you can rename the app but it is not necessary-

heroku apps:rename NameOfApp


Step8-

    Add database to your app by using following command-

heroku addons:create heroku-postgresql

Step9-

Replace HEROKU_POSTGRESQL_INSTANCE with the name from the above output-

heroku pg:promote HEROKU_POSTGRESQL_INSTANCE

Step10-

Create a new branch for any configuration/setup changes needed.

git checkout -b production


Step11-

 Store unique keys and salts in Heroku environment variables. WordPress can provide random values here.

heroku config:set AUTH_KEY='put your unique phrase here' \
SECURE_AUTH_KEY='put your unique phrase here' \
LOGGED_IN_KEY='put your unique phrase here' \
NONCE_KEY='put your unique phrase here' \
AUTH_SALT='put your unique phrase here' \
SECURE_AUTH_SALT='put your unique phrase here' \
LOGGED_IN_SALT='put your unique phrase here' \
NONCE_SALT='put your unique phrase here'


Step12-
   
Push the new changes on heroku-

git push heroku production:master


Now, you can use your app.


Thanks...


Saturday, 26 December 2015

Upload image from camera to firebase in ionic

Hello,

Here i am introducing a way, by which an user can click a picture by camera and can upload it on the firebase, with login and register functionality.When an user is login and take a picture. This data will be saved on the firebase beck-end services.And when that user again login , can see his picture.

So,
Let's start with the ionic blank app-

ionic start myapp blank
cd my app
ionic platform add android


Now we will include cordova.js library in it.

bower install ngCordova


Then include following line of code before cordova.js in index.html file-

<script src="lib/ngCordova/dist/ng-cordova.js"></script>

in app.js file include the following dependencies-

var myapp = angular.module('myApp', ['ngCordova'])


Then include the following library-


  • The latest Firebase JavaScript library
  • The latest AngularFire AngularJS library


  • Now your index.html file look like-


    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
        <title></title>
        <link href="lib/ionic/css/ionic.css" rel="stylesheet">
        <link href="css/style.css" rel="stylesheet">
        <script src="lib/ionic/js/ionic.bundle.js"></script>
        <script src="js/ng-cordova.min.js"></script>
        <script src="cordova.js"></script>
        <script src="js/firebase.js"></script>
        <script src="js/angularfire.min.js"></script>
        <script src="js/app.js"></script>
    </head>
    
    
    
    
    Now, we will include the camera plugin-
    
    
    cordova plugin add org.apache.cordova.camera
    
    
    
    

    Getting Firebase Started-

    We're not quite ready to talk about Firebase, but we are at a point where it would be a good idea to initialize it. At the top of your www/js/app.js file, outside any AngularJS code, you want to add the following line:
    var fb = new Firebase("https://INSTANCE_ID_HERE.firebaseio.com/");
    
    
    
    
    Of course you need to replace INSTANCE_ID_HERE with 
    your personal Firebase instance. By setting it globally, it will load 
    before AngularJS and can be used throughout your application.
    
    
    We also need to add firebase to our AngularJS module. In the end it will look something like this:
    
    
    
    
    
    
    var myapp = angular.module("starter", ["ionic", "ngCordova", "firebase"]);
    
    
    
    
    
    
    In your login.html file add following lines of code-
    
    
    
    
    <ion-view title="Firebase Login">
        <ion-content>
            <div>
                <div class="list list-inset">
                    <label class="item item-input">
                        <input ng-model="username" type="text" placeholder="Username" />
                    </label>
                    <label class="item item-input">
                        <input ng-model="password" type="password" placeholder="Password" />
                    </label>
                </div>
                <div class="padding-left padding-right">
                    <div class="button-bar">
                        <a class="button" ng-click="login(username, password)">Login</a>
                        <a class="button" ng-click="register(username, password)">Register</a>
                    </div>
                </div>
            </div>
        </ion-content>
    </ion-view>
    
    
    
    
    And in loginCtrl.js file-
    
    
    
    
    
    
    
    
    
    
    myapp.controller("loginCtrl", function($scope, $state, $firebaseAuth) {
    
        var fbAuth = $firebaseAuth(fb);
    
        $scope.login = function(username, password) {
            fbAuth.$authWithPassword({
                email: username,
                password: password
            }).then(function(authData) {
                $state.go("image");
            }).catch(function(error) {
                alert(error);
                console.error("ERROR: " + error);
            });
        }
    
        $scope.register = function(username, password) {
            fbAuth.$createUser({email: username, password: password}).then(function(userData) {
                return fbAuth.$authWithPassword({
                    email: username,
                    password: password
                });
            }).then(function(authData) {
                $state.go("image");
            }).catch(function(error) {
                console.error("ERROR: " + error);
                alert(error);
            });
        }
    
    });
    
    
    
    
    And in image.html file-
    
    
    
    
    
    
    <ion-view title="My Images" ng-init="">
        <ion-nav-buttons side="right">
            <button class="button button-icon icon ion-camera" ng-click="upload()"></button>
        </ion-nav-buttons>
        <ion-content>
            <div class="row" ng-repeat="image in images" ng-if="$index % 4 === 0">
                <div class="col col-25" ng-if="$index < images.length">
                    <img ng-src="data:image/jpeg;base64,{{images[$index].image}}" width="100%" />
                </div>
                <div class="col col-25" ng-if="$index + 1 < images.length">
                    <img ng-src="data:image/jpeg;base64,{{images[$index + 1].image}}" width="100%" />
                </div>
                <div class="col col-25" ng-if="$index + 2 < images.length">
                    <img ng-src="data:image/jpeg;base64,{{images[$index + 2].image}}" width="100%" />
                </div>
                <div class="col col-25" ng-if="$index + 3 < images.length">
                    <img ng-src="data:image/jpeg;base64,{{images[$index + 3].image}}" width="100%" />
                </div>
            </div>
        </ion-content>
    </ion-view>
    
    
    In imageCtrl.js file-
    
    
    
    
    
    
    myapp.controller("imageCtrl", function($scope,$state, $ionicHistory, $firebaseArray, $cordovaCamera) {
    
        $ionicHistory.clearHistory();
    
        $scope.images = [];
    
        var fbAuth = fb.getAuth();
        if(fbAuth) {
            var userReference = fb.child("users/" + fbAuth.uid);
            var syncArray = $firebaseArray(userReference.child("imageuploadapp"));
            $scope.images = syncArray;
        } else {
            $state.go("login");
        }
    
        $scope.upload = function() {
            var options = {
                quality : 75,
                destinationType : Camera.DestinationType.DATA_URL,
                sourceType : Camera.PictureSourceType.CAMERA,
                allowEdit : true,
                encodingType: Camera.EncodingType.JPEG,
                popoverOptions: CameraPopoverOptions,
                targetWidth: 500,
                targetHeight: 500,
                saveToPhotoAlbum: false
            };
            $cordovaCamera.getPicture(options).then(function(imageData) {
                syncArray.$add({image: imageData}).then(function() {
                    alert("Image has been uploaded");
                });
            }, function(error) {
                console.error(error);
            });
        }
    
    });
    
    Now your app.js file look like-
    var myapp = angular.module('starter', ['ionic','ngCordova','firebase']) var fb = new Firebase("https://INSTANCE_ID_HERE.firebaseio.com/"); myapp.run(function($ionicPlatform) { $ionicPlatform.ready(function() { // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard // for form inputs) if(window.cordova && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); } if(window.StatusBar) { StatusBar.styleDefault(); } }); }) myapp.config(function ($stateProvider,$urlRouterProvider) { $stateProvider .state('login', { url: '/login', templateUrl: 'templates/login.html', controller: 'loginCtrl' }) .state('image', { url: '/image', templateUrl: 'templates/image.html', controller: 'imageCtrl' }); $urlRouterProvider.otherwise('/login'); });
    
    
    In firebase, we will add the following rule in Security & Rules section-
    
    
    {
        "rules": {
            "users": {
                ".write": true,
                "$uid": {
                    ".read": "auth != null && auth.uid == $uid"
                }
            }
        }
    }
    
    
    And include the following JSON in data section-
    
    
    {
        "imageuploadapp": {
            "unique_image_id_here": {
                "image": ""
            }
        }
    }
    
    
    
    
    Thanks...