Android Development From Scratch-1

Hi Friends,

           I started to learn Android mobile application development. Am sharing my learning stuffs to you. I hope it will be helpful for the beginners who is starting to develop Android apps like me.

What is Android?

           Android is the name of the mobile operating system owned by Google. Android is based on the Linux Kernel and designed primarily for Touchscreen mobile devices such as Smartphones and Tablets.

          Android is an Open Source Operating system for smart devices. The source code for Android is available under free and open source software licenses.

          The first beta version of the Android Software Development Kit (SDK) was released by Google in 2007 where as the first commercial version, Android 1.0, was released in September 2008.

What is Android Applications?

          Android applications are usually developed in the Java language using the Android Software Development Kit. Android applications can be packaged easily and sold out either through a store such as Google Play Store, Opera Mobile Store, and the Amazon Appstore.

           Every day more than 1 million new Android devices are activated worldwide.

           Android applications are the world largest installed mobile OS and growing fast.

Android Versions:

android-versions

Android OS Versions. Courtesy: Recombu

Work Environment Setup:

          Android application development on either of the following Operating Systems –

  •       Windows OS
  •       Mac OS X
  •       Linux

          We required some tools to develop Android applications and the tools can be downloaded from the web.

  •        Java SE Development Kit (JDK)
  •        Android Software Development Kit (SDK)
  •        Integrated Development Environment (IDE)
  •        Android Studio
  •        Eclipse + Android Developer Tools (ADT)

           I personally using and suggesting the Android Studio for Android application development.

Why Android Studio?

  •         Supported by Google
  •         Fast to use and understand
  •         It is providing the Android SDK
  •         SDK manager provides the SDK updates
  •         Providing the code suggestions

       

Android Architecture:

              Android is an open source, Linux-based software stack created for a wide array of devices and form factors. The following diagram shows the major components of the Android platform.

android-architecture

Android Architecture Courtesy: developer.android.com

 

Application Components:

             Application components are the essential building blocks of an Android application. The main components are listed below,

  •  Activities: An activity represents a single screen with a user interface,in-short Activity performs actions on the screen.
  •  Service: A service is a component that runs in the background to perform long-running operations.
  •  Broadcast Receivers: Broadcast Receivers simply respond to broadcast messages from other applications or from the system.
  •  Content Providers: A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolverclass. The data may be stored in the file system, the database or somewhere else entirely.

Will share the basic of the code components, memory management in the next post.

Please share your comments if anything missed or if any information is wrong. Thanks.

Ref:

  1. developer.android.com
  2. tutorialspoint.com

iOS 10 developer notes

Hi Team,

Apple Announced iOS 10, Mac OS X Sierra, Watch OS 3,  with new features and some enhancement on the older features.

iOS 10 new Features:

1. SiriKit:

Now we can use Siri services in iOS apps by using Intents.framework. When the user requests our app services through Siri, the iOS Device will forwards those requests to our extension for handling the requests. We can use the classes of Intents framework classes to receive the data from Siri.

Framework: Intents.framework

2. Proactive Suggestions:

Earlier if we want to adopt our app search, we gave users access to activities and content deep within our app through Spotlight and Safari search results, Hand off and Siri suggestion. From iOS 10, we can provide information what users do in our app, which helps the system promote our app in other places like, Keyboard with QuickType suggestions, Map and CarPlay, the app switcher, Siri interaction and the lock screen. We know that NSUserActivity class provides the option to make our app searchable.

3. Integrating with the Messages App:

iOS 10 allows the developers to create app extensions that interact with the Messages app and let the users send text, stickers, media files, and interactive messages that update as each recipient responds to the message.

Framework: Messages.framework

4. User Notifications:

The User Notification framework supports the delivery and handling of local and remote notifications. The classes of this framework to schedule the delivery of local notification based on the time or location.

Framework: UserNotifications.framework

5. Speech Recognition:

Speech framework provides APIs to convert the Speech to the text. We can perform speech transcription of both real-time and recorded audio.

Framework: Speech.framework

6. CallKit:

This framework helps the VoIP apps integrate with the iOS device UI and give users a great experience. Also, the user can view and answer the incoming VoIP calls on the lock screen and manage contacts from VoIP calls.

Framework: CallKit.framework

7. App Extensions:

This new OS has new extensions,

  • Call Directory
  • Intents
  • Intents UI
  • Messages
  • Notification Content
  • Notification Service
  • Sticker Pack

Also, iOS 10 has enhancements on the following topics,

  • App Search Enhancements
  • Widget Enhancements
  • Apple Pay Enhancements
  • Security and Privacy Enhancements

Please share your comments and please let me know if I missed anything to mention here. Thanks.

How to make UITableviewCell Dynamic Height and Expand iOS

Many application has dynamic contents to show from the server. Also many applications has a design to show some controls/views when the user selects the cell to expand.

So, we need to calculate the tableview cell height dynamic and assign to the UITableView Datasource and Delegates.

1. Calculate Table Cell Height

CGFloat height = 5.0f;

    // We are calculating the height based on the value..

    if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@”6.0″)) {

      NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];

        paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;

        height += [dynamicString boundingRectWithSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width20, 9999) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:@”Helvetica” size:16], NSParagraphStyleAttributeName:paragraphStyle} context:nil].size.height;

}

    else {

        height += ceilf([dynamicString sizeWithFont:[UIFont fontWithName:@”Helvetica” size:16] constrainedToSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width20, 9999) lineBreakMode:NSLineBreakByWordWrapping].height);

    }

Here is a sample view controller with Tableview integrated..

#import “ViewController.h”

#import “DemoTableViewCell.h”

@interface ViewController ()

@property (nonatomic, unsafe_unretained) IBOutlet UITableView *demoTV;

@property (nonatomic, strong) NSMutableArray *heightArray;

@property (assign) BOOL isNeedToExpand;

@end

static NSString *demoTableCellID = @”DemoTableViewCellIdentifier”;

#define IS_IPHONE5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height – ( double )568 ) < DBL_EPSILON )

#define SYSTEM_VERSION_EQUAL_TO(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)

#define SYSTEM_VERSION_GREATER_THAN(v)             ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN(v)                ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)    ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

@implementation ViewController

– (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    self.title = @”Home”;

    self.isNeedToExpand = NO;

    

}

#pragma mark- Webservice Call

– (void) fetchDataFromServer {

    

    // Storing the dynamic height in an array…

    CGFloat height = 0;

    CGFloat captionHeight = [ViewController calculateDynamicCellHeight:@”Value from server”];

    height = height + captionHeight + 10;

    [self.heightArray addObject:[NSString stringWithFormat:@”%f”,captionHeight]];

}

#pragma mark- UITableview Delegate

– (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;

}

– (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 4;

}

– (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    

    // Here you can handle the dynamic height from an heightArray values..

    

    if (self.isNeedToExpand) {

        if ((indexPath.row == 2) || (indexPath.row == 1)) {

            return 110;

        } else {

            return 50;

        }

    }

    return 50;

}

– (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    

    DemoTableViewCell *cell = (DemoTableViewCell *) [tableView dequeueReusableCellWithIdentifier:demoTableCellID forIndexPath:indexPath];

    

    if ((indexPath.row == 2) || (indexPath.row == 1)) {

        cell.hiddenLabel.hidden = NO;

    } else {

        cell.hiddenLabel.hidden = YES;

    }

    

    return cell;

}

– (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    

    // Here you have to handle the indexPath which needs to be expand based on the height..

    

    [self.demoTV beginUpdates];

    if ((indexPath.row == 2) || (indexPath.row == 1)) {

        self.isNeedToExpand = YES;

    } else {

        self.isNeedToExpand = NO;

    }

    [self.demoTV endUpdates];

}

// We are calculating the dynamic cell height based on the string…

#pragma mark- Calcualte Cell Height

+ (CGFloat) calculateDynamicCellHeight: (NSString *) dynamicString {

    

    CGFloat height = 5.0f;

    // We are calculating the height based on the value..

    if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@”6.0″)) {

        

        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];

        paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;

        

        height += [dynamicString boundingRectWithSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width20, 9999) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:@”Helvetica” size:16], NSParagraphStyleAttributeName:paragraphStyle} context:nil].size.height;

        

    }

    else {

        height += ceilf([dynamicString sizeWithFont:[UIFont fontWithName:@”Helvetica” size:16] constrainedToSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width20, 9999) lineBreakMode:NSLineBreakByWordWrapping].height);

    }

    

    return height;

}

– (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end

The above source code is just for an idea about dynamic height and expanding cells. Ourself we have to manage the cell views as per our requirement.

Hope it will help someone. Happy Coding. Thanks.

How to check Internet connection in iOS apps?

Hi Coders,

Am going to explain about to manage the Internet check in Xcode projects. Apple providing the “Reachability” class to manage the Internet connection and connection status.

Here you can download the “Reachability” class files.

Follow the steps in Xcode project:

1. Import “Reachability” class files both .m and .h into the project

2. I have one Singleton class file named “MyAppManager”. There I Imported “Reachability.h” file

3. Create a  BOOL method like below,

    In .h file:

      + (BOOL) checkForInternetConnection;      

    In .m file:

  + (BOOL) checkForInternetConnection {

    Reachability *reachabilityObj = [Reachability reachabilityForInternetConnection];

    NetworkStatus status = [reachabilityObj currentReachabilityStatus];

    

    if (!status == NotReachable) {

        return YES;

    } else {

        return NO;

    }

}

4. In the ViewController class import “MyAppManager.h” file

5. Add the code like below to check the Internet connection,

 

if ([MyAppManager checkForInternetConnection]) {

NSLog(@“Internet connected”);

} else {

NSLog(@“No Internet Connection. Please check your Internet connection”);

}

6. Here we can manage the API Call or other stuffs.

Hope it will help you lot. Please share your comments and feedback. Thanks.

Happy Coding!

Yuvaraj Manickam

How to compare two NSDate values in iOS app?

Hi coders,

Now am going to post about to compare two NSDate values in iOS.

We all know well to compare two NSString values but recently I came to know about to compare two NSDate values ha ha…
Am going to share with you all about that,

NSDate *today = [NSDate date];
NSDate *compareDate = [NSDate dateWithString:@”your date”];

NSComparisonResult compareResult = [today compare : compareDate];

if (compareResult == NSOrderedAscending)
{
NSLog(@”CompareDate is in the future”);
}
else if (compareResult == NSOrderDescending)
{
NSLog(@”CompareDate is in the past”);
}
else
{
NSLog(@”Both dates are the same”);
}

 

This is the simple way to compare two Date Values. Please share your feedback on this.

Happy Coding!

Warm Regards,
Yuvaraj Manickam

CocoaPod integration in XCode

Basically we may use many third party frameworks/libraries, class files in our iOS development. The frameworks and libraries will be updated frequently with new iOS version comfortability.

Here am going to write about What is CocoaPod? And How to implement in Xcode app?

What is CocoaPod?

       CocoaPods is an open source dependency manager for Swift and Objective-C Cocoa projects. CocoaPods makes it easy to install or update new SDKs when working with Xcode.

It has over ten thousand libraries and can help you scale your projects elegantly. For more info https://cocoapods.org/.

How to install CocoaPod in Xcode project?

  1. Navigate to the project folder in Terminal: cd /projectPath
  2. Install CocoaPod in OS X: sudo gem install cocoapods
  3. It will ask for the Machine Password. Then the cocoapods will be installed.
  4. Now, we need to set up Cocoapod: pod setup
  5. Now the cocoapod setup will be downloaded the setup
  6. Now we can see the Pod setup in our Xcode project. .xcworkspace will be installed for our project. There we can see the podfile.
  7. Open the podfile and add the frameworks what we required for the project.
  8. Eg: target ‘sampleApp’ do

end

target ‘sampleApp’ do

end

target ‘sampleApp’ do

end

platform :ios, ‘7.0’

pod “AFNetworking”, “~> 2.0”

pod ‘MBProgressHUD’, ‘~> 0.9.1’

  1. Now, its time to install the framework dependencies: pod install

 

These are the simple steps to install the CocoaPod for our iOS project.

Hope it will be useful and please share your feedback on this.

Happy coding.

 

What is Extensions in Swift?

What is Extension in Swift?

Extensions add new functionality to an existing class, structure, enumeration, or protocol type. This includes the ability to extend types for which you do not have access to the original source code.
Extensions are similar to the Categories in Objective- C.

Extensions in Swift can:
•    Add computed properties and computed type properties
•    Define instance methods and type methods
•    Provide new initializers
•    Define subscripts
•    Define and use new nested types
•    Make an existing type conform to a protocol
The important thing is we can’t override the existing functionality of the superclass. We
can extend the superclass with new functionalities.

We no need to import the extension class anywhere to access.

Syntax:

extension className {
// Methods Or Functionalities
}

Eg:
1. Create a new Swift File and name it as “String+Extension” it will be created with the extension “swift”.
2. Import the UIKit framework in the extension class. import UIKit
3. Create an Extension of the superclass String like below:

extension String {

}

4. Add the own methods by extending the functionality of the superclass “String”. Here I added simple methods to understand the use of Extension.

import Foundation
import UIKit

extension String {

static func stringAdding (firstString: String?, secondString: String?) -> String     {

return firstString! + secondString!
}

static func stringUppercase (inputString: String) -> String {
return inputString.uppercaseString;
}
}

5. From your ViewController you can access the Extension methods of String. It will be accessible in all classes. We no need to import

var finalString = String.stringAdding(“Abc”, secondString: “Def”)
print(“FinalString: \(finalString)”)
finalString = String.stringUppercase(finalString)
print(“Uppercase: \(finalString)”)

6. The output will be like below

FinalString: AbcDef
Uppercase: ABCDEF

Hope this post will give you simple understand on Extension in Swift. If you have any queries please share with me. Also share your feedback on this. Thanks.