Showing posts with label ADT. Show all posts
Showing posts with label ADT. Show all posts

Saturday, 27 December 2014

Creating First Android Application using PhoneGap and AngularJS

In this post, I will be showing how you can create your first android application using PhoneGap and AngularJS. First of all you have to follow my another post to setup PhoneGap framework and create first android application using PhoneGap. Once you are done with creating your first application using PhoneGap, you can follow this post to add AngularJS capability to your created PhoneGap project. Adding AngularJS capability to PhoneGap project is pretty much simple. 

If you would like to see the steps in video, you can refer my video attached below:



OR

You can follow below steps:

1. Download AngularJS zip from here and extract it. Extracted directory structure should look like below. While writing this project I downloaded Angular-1.3.8.


2. Now it's time to add AngularJS features into PhoneGap project. Create 'lib/angular' directory under below directory. Notice that, below directory structure is the structure of PhoneGap project which is imported into Android Studio.

<WorkSpace>\<ProjectName>\<ModuleName>\src\main\assets\www 

Copy all  selected *.js files (mentioned as selected in above image) from extracted AngularJS directory to created directory 'lib/angular'.

3. Now create app.js file under below directory.

<WorkSpace>\<ProjectName>\<ModuleName>\src\main\assets\www\js

app.js
var nvhybridandroidapp = angular.module("nvhybridandroidapp", []);
nvhybridandroidapp.controller("MyController", function ($scope) {
   $scope.message = "Welcome to first android app built using PhoneGap and AngularJS";
});

4. Change index.html file to add greed marked text:

<WorkSpace>\<ProjectName>\<ModuleName>\src\main\assets\www\index.html
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>

<!-- Adding Angular specific java script files -->
<script type="text/javascript" src="lib/angular/angular.js"></script>

<!-- Adding created app.js file -->
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript">
            app.initialize();
</script>

<!--Configure ng-app to bind html to the var created in app.js-->
<html  ng-app="nvhybridandroidapp">
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
    <body>

        <!--Configure ng-controller to 'MyController' defined in app.js-->
        <div class="app"  ng-controller="MyController">
            <h1>Apache Cordova</h1>

            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>

            < !--Print the message variable defined in app.js-->
            <h1>Message: {{message}}</h1>

             < !--Bind message variable (defined in app.js) with input element -->
            <input type="text" ng-model="message"/>
        </div>
    </body>
</html>

You can refer below image to visualize above 2,3,4 steps:


5. Changes are done. Now you are pretty much ready to run your application. Once you run the application, your running application in AVD (emulator) looks like below. 



If you are able to see the running application on emulator with given message, I would say congratulations !!. You have created your first android application using PhoneGap and AngularJS.

If you want to refer sample project, you can refer from GitHub.

Saturday, 6 December 2014

Android Application Development Environment Setup and Running Android Sample Application

In this video, I will be showing the steps to setup the Android Application Development Environment and how to run the android sample application in your local environment.


If you liked this Video, please share your valuable feedback. !! Happy Learning !!

Saturday, 22 November 2014

Creating First Android Application

If you want to create your first android application, seems you landed on right post. This post walks you through how you can create your first android application by following simple steps.


Setup Environment: To setup android application development environment, you need to install below software:
  • JDK6
  • Eclipse IDE
  • Android SDK: Software development kit to develop android applications.
  • ADT (Android Development Tools) Eclipse Plugin: This Eclipse plugin provides the integrated environment to build android applications
  • AVD (Android Virtual Device): This facilitates the environment where android application can be tested.
I will not be investing much time to describe about how to setup all these softwares as this link already provides very nice description to setup the environment.

Create Android Application:  Once you are done with environment setup you are ready to create your first android application. In your Eclipse IDE, go to ‘File > New > Project…’ and select ‘Android > Android Application Project’. 


Fill the required information and click Next.


Click Next.


Provide the text or Image, to show your application Icon.


Click Next.


Click Next.


Once you click on Finish button, you will see below android project is created. Generated android project contains ‘MainActivity.java’ file. This class is executed once created application is run.


Run Application: To run the application, right click on your project and go to 'Run As > Android Application'.
 

Once the application is executed, text (which is configured in 'MainActivity.java') is displayed on the screen.


I followed this link to start developing android application . If you need more detail you can refer same link for detailed information. 

!! Happy Android Application Development !!