Learn the powerful enterprise adaptable database:

Getting Started With ADABAS & Natural

Showing posts with label ionic native. Show all posts
Showing posts with label ionic native. Show all posts

Wednesday, July 12, 2017

209 IonicV1 Creator Ionic Native Camera


.
209 IonicV1 Creator Ionic Native Camera


1. Create a project.

Eg IonNatCam1


2. Add ionic native to the project.

Get ionic native v.2.0.9 codes from here (github) or here (gdrive)
Create a new JS file.
Paste the codes to JS File.
Add the module ionic.native to angular modules.

3. Add Cordova Plugin.


cordova-plugin-camera

4. Add Components to Layout

Button Bar (by default, it consists of three buttons so delete the third button).
Image.
Upload the following imageplaceholder.
(blankimage.png)
Set the Directive for the Button 1 as follows:
ng-click, captureImage()
Set the Directive for the Button 2 as follows:
ng-click, openImage()
Set the Directive for the image component as follows:
ng-src, {{data.image}}

5. Add test codes to Controller.

function ($scope, $stateParams) {
    $scope.data={image:"https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/SNice.svg/220px-SNice.svg.png"}
}
Outcome.
(The imageplaceholder is replaced by a smiley)

6. Add camera codes to Controller.

function ($scope, $stateParams, $cordovaCamera) {
   $scope.data={image:"https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/SNice.svg/220px-SNice.svg.png"}


$scope.captureImage=function(){
 
     document.addEventListener("deviceready", function () {

   var options = {
     quality: 50,
     destinationType: Camera.DestinationType.DATA_URL,
     sourceType: Camera.PictureSourceType.CAMERA,
     allowEdit: true,
     encodingType: Camera.EncodingType.JPEG,
     targetWidth: 100,
     targetHeight: 100,
     saveToPhotoAlbum: false,
          correctOrientation:true
   };

   $cordovaCamera.getPicture(options).then(function(imageData) {

     $scope.data.image= "data:image/jpeg;base64," + imageData;
   }, function(err) {
     // error
   });

 }, false);
}


$scope.openImage=function(){
 document.addEventListener("deviceready", function () {

   var options = {
       // Some common settings are 20, 50, and 100
       quality: 50,
       destinationType: Camera.DestinationType.FILE_URI,
       // In this app, dynamically set the picture source, Camera or photo gallery
       sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM,
       encodingType: Camera.EncodingType.JPEG,
       mediaType: Camera.MediaType.PICTURE,
       allowEdit: true,
       correctOrientation: true  //Corrects Android orientation quirks
   }

   $cordovaCamera.getPicture(options).then(function(imageURI) {

      $scope.data.image = imageURI;
   }, function(err) {
     // error
   });


   //$cordovaCamera.cleanup().then(); /* only for FILE_URI*/

 }, false);

}

}
Reference:

.

203 IonicV1 Creator Ionic Native App Version


.
203 IonicV1 Creator Ionic Native App Version
Reads the version of your app from the target build settings.
cordova plugin add https://github.com/whiteoctober/cordova-plugin-app-version.git

IONIC CREATOR STEPS

1. Create a project.
3. Add Cordova Plugin.
cordova-plugin-app-version
4. Add codes to Controller.
function ($scope, $cordovaAppVersion) {


 document.addEventListener("deviceready", function () {
   var appVersion='';
   var appBuild ='';
   var appName ='';
   var appPackage ='';
   $cordovaAppVersion.getVersionNumber().then(function(version) {
       appVersion = version || '';
       $cordovaAppVersion.getVersionCode().then(function(build) {
           appBuild = build || 0;
           $cordovaAppVersion.getAppName().then(function(name) {
               appName = name || 0;
               $cordovaAppVersion.getPackageName().then(function(pckg) {
                   appPackage = pckg || 0;
                   alert("appversion:" + appVersion +
                       "\nappbuild:" + appBuild +
                       "\nappname:" + appName +
                       "\napppackage:" + appPackage
                   );

               });
           });
       });
   });
 
 }, false);/*device ready*/

}

REFERENCE


.

202 IonicV1 Creator Ionic Native App Availability


.
202 IonicV1 Creator Ionic Native App Availability
The AppAvailability plugin allows you to check if an app is installed on the user’s device. It requires an URI Scheme (e.g. twitter://) on iOS or a Package Name (e.g com.twitter.android) on Android.
cordova plugin add https://github.com/ohh2ahh/AppAvailability.git

IONIC CREATOR STEPS

1. Create a project.
3. Add Cordova Plugin.
cordova-plugin-appavailability
4. Add codes to Controller.
function ($scope,$cordovaAppAvailability) {
  document.addEventListener("deviceready", function () {
    $cordovaAppAvailability.check('twitter://')
      .then(function() {
        alert("app is available");
      }, function () {
        alert("app not available");
      });
  }, false);

}

REFERENCE



.

200 IonicV1 Creator and Cordova Plugins


.

200 IonicV1 Creator and Cordova Plugins

Accessing native device features from within your app (the camera, for example) requires using Cordova Plugins. This short guide will teach you how to add these plugins in Creator, and then use those plugins with a JS library called Ionic Native.

1. Include the Ionic Native JavaScript In Your App

Or from here.
Then, create a new JS file ie ionic.native.min.js and paste the contents.

2. Add "ionic.native" as an Angular Module

Click on "Code Settings" from the top bar of the code editor, then add "ionic.native"

3. Add Some Cordova Plugins to Your App

For a full listing of Cordova Plugins, see here: https://cordova.apache.org/plugins/
Official Cordova Plugins will be name "cordova-plugin-[something]". For example, "cordova-plugin-camera". To add a plugin to your app, click the Cordova Plugins tab from Code Settings.
You will notice that certain plugins will be pre-populated, because they are always included in your project.

Important

Adding plugins here only effects your app if you package from Creator. It will have no effect when previewing your app in the browser, or on Creator Mobile, or exporting a ZIP file.

4. Now You Can Use the Plugin In Your Page Controllers

Ionic Native works as a stand-in for ngCordova (which is the predecessor for Ionic Native). In many cases, the usage is identical. Even though we are using Ionic Native, you can refer to ngCordova for usage examples: http://ngcordova.com/docs/plugins/camera/
As a rule of thumb: take the ES6 class name of the plugin and add $cordova to get the service name. For example, Geolocation would be $cordovaGeolocation, and Camera will be $cordovaCamera
// Example: this would be the constructor function
// for a Page/Controller in your Creator app

function($scope, $cordovaCamera) {
 $scope.takePicture = function() {
   $cordovaCamera.getPicture(opts).then(function(p) {
     // do something with the results
     // you will sometimes need to wrap $scope updates in $apply
     $scope.$apply(function() {
       $scope.results = p;
     });
   }, function(err) {
           // error handling
   });
 };

5. Writing Services And Directives That Use Cordova Plugins

If you write your own Angular services or directives that will use a Cordova Plugin, the syntax for injecting the plugins will be slightly different. For example:
angular.module('app.services', [])

.service('BlankService', ['$cordovaCamera', 'SomethingElse', function($cordovaCamera, SomethingElse){

}]);

6. Testing Your Apps That Use Cordova Plugins

Cordova Plugins do not run in the browser, and are not added when previewing on Creator Mobile or in ZIP exports.
In order to test the functionality of code you write using Ionic Native / Cordova Plugins, you have two options:
Option 1:
Package your app from within Creator. Your APK/IPA file will be e-mailed to you, and you will need to run your app on your actual device to test native functionality.
Option 2:
(This requires a local Ionic development environment)
Export your app as a ZIP file. Once you have your ZIP file, you will need to start a new Ionic project on your local computer, using the Ionic CLI.
ionic start myApp
This will create a new directory with a starter Ionic app. Then, copy/paste the contents of your ZIP file into the www/ folder of the app created above. Now you have a replica of your Creator app on your local computer.
Next, from the command line, you will need to install each Cordova Plugin you added from STEP 3 of this guide. The command is below.
cordova plugin add cordova-plugin-camera
Now you can run this app on a device:
ionic run ios
ionic run android

REFERENCE


Friday, June 2, 2017

201 Ionic1 ng show hide elements


.

201 Ionic1 ng show hide elements

1) Begin with Startup Codes

2) Add basic VIEW and CONTROL codes

<html>
<head>
<meta charset="utf-8">
<meta  name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no,width=device-width">
<title></title>
<!--local lib-->
<!--<script src="lib/ionic/js/ionic.bundle.js"></script>-->
<!--cloud lib-->
<script src="http://code.ionicframework.com/1.3.2/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above-->
<!--<link href="css/ionic.app.css" rel="stylesheet">-->
<!--local lib-->
<!--<link href="lib/ionic/css/ionic.css" rel="stylesheet">-->
<!--cloud lib-->
<link href="http://code.ionicframework.com/1.3.2/css/ionic.css" rel="stylesheet">
<!--ionic custom styling-->
<style>
 .platform-ios .manual-ios-statusbar-padding{padding-top:20px}.manual-remove-top-padding{padding-top:0}.manual-remove-top-padding .scroll{padding-top:0!important}.list.card.manual-card-fullwidth,ion-list.manual-list-fullwidth div.list{margin-left:-10px;margin-right:-10px}.list.card.manual-card-fullwidth>.item,ion-list.manual-list-fullwidth div.list>.item{border-radius:0;border-left:0;border-right:0}.show-list-numbers-and-dots ul{list-style-type:disc;padding-left:40px}.show-list-numbers-and-dots ol{list-style-type:decimal;padding-left:40px}
</style>
</head>
<body ng-app="app" animation="slide-left-right-ios7" >
 <div>
   <div>
     <ion-nav-bar class="bar-stable">
       <ion-nav-back-button></ion-nav-back-button>
     </ion-nav-bar>
     <ion-nav-view></ion-nav-view>
   </div>
 </div>
 <script id="home.html" type="text/ng-template">
    <ion-view title="Home" id="page1">
 <ion-nav-buttons side="left" class="has-header">
   <button class="button icon ion-log-in"
     ng-click="doLogin()" ng-hide="loggedin"> Login</button>
   <button class="button icon ion-log-out"
     ng-click="doLogout()" ng-show="loggedin"> Logout</button>
 </ion-nav-buttons>
 <ion-nav-buttons side="right" class="has-header">
   <button class="button button-icon icon ion-plus-circled"
     ng-click="showProjectModal()" ng-show="loggedin"></button>
 </ion-nav-buttons>  
     <ion-content padding="true" class="has-header">
       <div ng-hide="loggedin"
         style="text-align:center;font-size:600%;margin-top: 50%;
   left: 50%;">
         <i class="icon ion-locked"></i>
       </div>
       <div ng-show="loggedin"
         style="text-align:center;font-size:600%;margin-top: 50%;
   left: 50%;">    
         <i class="icon ion-unlocked"></i>
       </div>
     </ion-content>
   </ion-view>

 </script>
 <script>
/*create js object app, bind to html app, use ionic framework*/  
var app=angular.module('app',['ionic']);
/******************************/
/*define CONTROLLERS & CONFIGS*/
/******************************/    
/*define app.controller methods*/  
app.controller('homeCtrl',['$scope',function($scope){
 $scope.loggedin=false;
 $scope.doLogin=function(){$scope.loggedin=true}
 $scope.doLogout=function(){$scope.loggedin=false}

}]); 

/*define app.config method*/  
app.config(function($stateProvider,$urlRouterProvider){
 $stateProvider.state('home',{url:'/page1',templateUrl:'home.html',controller:'homeCtrl'});
 $urlRouterProvider.otherwise('/page1')
});
/************************/
/*define SYSTEM SETTINGS*/
/************************/
app.config(function($ionicConfigProvider, $sceDelegateProvider){
 $sceDelegateProvider.resourceUrlWhitelist([ 'self','*://www.youtube.com/**', '*://player.vimeo.com/video/**']);
})
app.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 && window.cordova.plugins.Keyboard) {
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
     cordova.plugins.Keyboard.disableScroll(true);
   }
   if (window.StatusBar) {
     // org.apache.cordova.statusbar required
     StatusBar.styleDefault();
   }
 });
});

/*
 This directive is used to disable the "drag to open" functionality of the Side-Menu
 when you are dragging a Slider component.
*/
app.directive('disableSideMenuDrag', ['$ionicSideMenuDelegate', '$rootScope', function($ionicSideMenuDelegate, $rootScope) {
   return {
       restrict: "A",
       controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {

           function stopDrag(){
             $ionicSideMenuDelegate.canDragContent(false);
           }

           function allowDrag(){
             $ionicSideMenuDelegate.canDragContent(true);
           }

           $rootScope.$on('$ionicSlides.slideChangeEnd', allowDrag);
           $element.on('touchstart', stopDrag);
           $element.on('touchend', allowDrag);
           $element.on('mousedown', stopDrag);
           $element.on('mouseup', allowDrag);

       }]
   };
}]);

/*
 This directive is used to open regular and dynamic href links inside of inappbrowser.
*/
app.directive('hrefInappbrowser', function() {
 return {
   restrict: 'A',
   replace: false,
   transclude: false,
   link: function(scope, element, attrs) {
     var href = attrs['hrefInappbrowser'];

     attrs.$observe('hrefInappbrowser', function(val){
       href = val;
     });
   
     element.bind('click', function (event) {

       window.open(href, '_system', 'location=yes');

       event.preventDefault();
       event.stopPropagation();

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

Outcome Preview

Live Demo

.