Wednesday, June 22, 2011

iOS 4 iPad Camera and UIImagePickerController Application (Xcode 4)

An Overview of the Application

The application user interface for this example will consist of an image view and a toolbar containing two buttons. When selected by the user, the first button will display the camera to the user and allow a photograph to be taken and subsequently displayed in the image view. The second button will provide access to the camera roll where the user may select an existing photo image. In the case of a new image taken with the camera, this will be saved to the camera roll.

Since we will be covering the playback of video in the next chapter (Video Playback from within an iOS 4 iPad Application) the camera roll and camera will be restricted to still images in this example. The addition of video support to this application is left as an exercise for the reader at the end of the next chapter.
Creating the Camera Project

Tuesday, June 14, 2011

Android: Switching screens in an Activity with animations (using ViewFlipper)

how to switch between layers using animations to make it look like you are changing screens… we will be using a ViewFlipper widget in the layout XML.

1. Create a new Android project, unless you already have one

01 new project

2. Create a new Activity class that extends android.app.Activity.

Android: How to switch between Activities

create an Activity, and to switch to another Activity (think of it as another screen) on the click of a button.

1. Create a new Android project – or you might already have one created.

01 new project

2. Add a new Class that extends android.app.Activity. You need a total of two classes that extend Activity. You will switch from one Activity to another.

ExpandableListView on Android

ListView is pretty widely used. There are situations when you would like to group/categorize your list items. To achieve such a thing on Android, you would probably use the ExpandableListView. The data to the ExpandableListView is supplied by a special kind of adapter called the SimpleExpandableListAdapter which extends the BaseExpandableListAdapter.

Monday, June 13, 2011

How to add CoverFlow Effect on your iPhone App


The main criteria of this post is to help you add a cool effect called the “cover flow/open flow” effect to any of your iphone apps. This is cool in two ways actually. One it adds animation kind of effect to your app and the other, its very easy to build too.

I got to learn about this effect when I was working on my “pianos” app where in i’ll have bunch of animals to select which would be displayed as a menu using this “cover flow” effect. Once a particular animal is selected your piano view for that animal comes up. My piano app will be out soon and you can check that out. The source for this post is the link displayed below.

“http://fajkowski.com/blog/2009/08/02/openflow-a-coverflow-api-replacement-for-the-iphone/”

Based on his post I have simplified things further. He uses “flicker API” for the images in his “cover flow”  but in my version I would just use my own library of images so that this post would target the beginners. To begin with we should work with Photoshop a bit to generate your images. If your not acquainted with photoshop, never mind not a problem at all. This particular task with the photoshop just wants you to scale the  images you use in your library to size “225 * 225″ applying “Free Transformation”. That’s all what you got to do. Once you got your images then your ready to go.


Creating the project

Firstly Create a new “view based”  project with project name like “CoverFlow”.

Once you create a new project you would arrive at a screen shown below with predefined classes already generated for you.

Screen shot 2010-04-07 at 4.05.07 PM

Android - Add data to SQLite database, with SimpleCursorAdapter updated dynamically

Work on the article "A simple example using Android's SQLite database, exposes data from Cursor to a ListView", it was modified to add ui for user to add data to SQLite database. Once SQLite database updated, simple call cursor.requery() to update ListView dynamically.

Add data to SQLite database, with SimpleCursorAdapter updated dynamically

Android: Reading, using and working with XML data and web services in Android

One of the most powerful aspects of any mobile application for a 3G phone is that it can connect to the Internet. By connecting to the Internet the application can offer much more value to the user since it becomes an interface for a web-based component, e.g. using Twitter’s API to create a Twitter application so that you can get your Twitter updates without having to open the mobile browser. The most common way of interfacing with a web-based component is by using web services in XML format.

While trying to developer my own app which reads a web service from my own server, I ran into a lot of difficulties in implementing the client that consumes the web service. Android does not have libraries for XPath handling of XML documents, so it makes deciphering XML data a little bit more difficult. From what I’ve read online the Android team is currently working on including such libraries in future versions.

After some digging around I found an amazing link that shows different methods for consuming an XML file in Android and parsing through it without the use of XPaths. The link is this: Working with XML on Android. To start off, this link is an absolute must-read. Everything that I am going to write in my post here relates to this link. The code offered on that webpage uses polymorphism to show you 4 different methods of working with XML data. It provides a fully-functional Android application and all the source code for it. The source code can be found here: AndroidXML.zip.

My post today will concentrate on how to customize the code from the application in the above link, in order to read and parse your own XML data. If you are a Java pro, you might not need this post. My Java is a little rusty, so I needed some time to figure out exactly what I had to change and where in order to get this to work with my own web service XML. Now that I’ve figured it out, I thought I’d share it. In my next post I will give the simplified version of this code – where there is no polymorphism, and thus there are only the minimum number of classes needed to implement this XML-reading solution.

Friday, June 10, 2011

How to read the assets directory resources - Andriod


1. Get the input stream resource


Resource file sample.txt at $ PROJECT_HOME / assets / directory, can be adopted in the Activity

Context.getAssets (). Open ("sample.txt")

Method to obtain input stream.

Note: If the resource file is a text file that you need to consider file encoding and line breaks. Recommend the use of UTF-8 and Unix line breaks.

2. WebView load the assets directory html files


Resource file sample.html at $ PROJECT_HOME / assets / directory, the following code can be

WebView.loadUrl ("file: / / / android_asset / sample.html");

Load html file.

Wednesday, June 8, 2011

A first hand look at building an Android application

Adding a UIButton Programatically

You might know how to add a button via IB – here is a code sample of how to do that using code

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDown];
[btn setTitle:@"SKIP" forState:UIControlStateNormal];
btn.frame = CGRectMake(0, 100, 320, 50);
[self.view addSubview:btn];

and if you want to add a background image


UIImage *someImage = [UIImage imageNamed:@"splashImage.png"];
[btn setBackgroundImage:someImage forState:UIControlStateNormal];

Adding a UIButton Programatically

You might know how to add a button via IB – here is a code sample of how to do that using code

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDown];
[btn setTitle:@"SKIP" forState:UIControlStateNormal];
btn.frame = CGRectMake(0, 100, 320, 50);
[self.view addSubview:btn];

and if you want to add a background image


UIImage *someImage = [UIImage imageNamed:@"splashImage.png"];
[btn setBackgroundImage:someImage forState:UIControlStateNormal];

Difference between 2 UIDatePicker’s in hours

UIDatePicker *date1;
UIDatePicker *date2;

The function to show difference between these two date pickers


NSDate *date1Val = date1.date;
NSDate *date2Val = date2.date;
NSTimeInterval interval = [date2Val timeIntervalSinceDate:date1Val];
int hours = (int)interval / 3600;
int minutes = (interval - (hours*3600)) / 60;
NSString *timeDiff = [NSString stringWithFormat:@"%d:%d", hours, minutes];

Hacking into PhoneGap iPhone/iPad Apps

Initially a lot of web-developers started with PhoneGap which lets you make webpages and embed them inside an iPhone app.

Now similarly its very easy to get access to those web pages. Let me show you how.
Steps:
Get hold of an phonegap iPhone App. I have one, which I had created a long time back.
- So go to – http://www.phonegap.com/apps
- Select iPhone or iPad
- Pick an app for which you want code (Let me pick my application)

iPhone/iPad AirPrinting Tutorial in 3 steps

Step 1:

Start Xcode and make a New Project – Select View-based Application – I call it AirPrinting.

Thursday, June 2, 2011

Mac Terminal Error : Could not determine audit condition

When I launched my terminal today, was welcomed with this error :-

login: PAM Error (line 396): System error
login: Could not determine audit condition

[Process completed]

It is most probably because I was playing with my /usr/bin permissions the other day.
The fix is easy. Just delete the "/usr/bin/login" dir.

But how do I delete it, if I can't access the "Terminal" altogether ?
Come on - You can access any folder using the "Finder".

1. Open "Finder"
2. Open "Go To Folder"
3. Type "/usr/bin/login"
4. Delete it.