For information, shoot us an email askus@smugappventures.com

Quick Tip: Adding Existing Frameworks in XCode 4

Many of us familiar with XCode 3.x will simple right click the Frameworks folder if we need to add additional to be used on our project. Frameworks like CoreLocation can be easily added on the Add Existing Frameworks menu item. But this steps are now gone in XCode 4 instead, Apple lifted the option to add existing Frameworks and placed it on a tab named Build Phases under your Target App. Going on this menu is straightforward as stated on the screen shot:

  1. 1. Click on your root project on the left pane.
  2. Under Targets, click the App name
  3. Clicking the App name under Targets will reveal the Build Phases tab on the right pane, click on it.
  4. Click the Link Binary With Libraries dropdown to reveal the existing frameworks that your project is using.
  5. Just click the ‘+’ button to add more frameworks!

 

Xcode 2

Advertisements
Categories: iOS, Resources Tags:

[Android Beginner Series] Preparing your Android Development Environment

First things first is to download the stuff that we will need to setup our Android Development Environment. Here’s a list with download links provided.

After downloading, install Eclipse. Extract the Android SDK archive file you just downloaded. Note where you put it for we are going to provide the location of the Android SDK later in Eclipse. I suggest you put it somewhere where it’ll be easier to find like C:\AndroidSDK.

Now we need to install the ADT (Android Development Tools) Plugin for our Eclipse.

  1. Run Eclipse
  2. Click “Help > Install New Software
  3. Enter the Google Android URL (https://dl-ssl.google.com/android/eclipse/ or http://dl-ssl.google.com/android/eclipse/) and then click “Add” button as show below:
  4. Click “Next” and then “Finish”
  5. Now we need to let Eclipse know where our Android SDK is residing in our machine. Do this by clicking “Preferences” and selecting “Android”. Browse to where you extracted your Android SDK. Click “Apply” and the “OK”

Voila! You may now start developing you first Android application. On the next article, we will discuss about developing your first Hello World Android application!

Categories: Android, Eclipse, Resources

Setting the font in your Android application

To set the font that you want to use in your Android application programmatically, you have to package your font (i.e. “Calibri.TTF”) with your application. Under MySmugProject/resources, create another folder named: “fonts”. Effectively, it should look like – “/MySmugProject/resources/fonts/Calibri.TTF”.

Now in your code append the following:

Typeface calibri = Typeface.createFromAsset(getAssets(), “fonts/Calibri.ttf”);

TextView fname = new TextView(this);
fname.setText(“Dennis”);
fname.setTypeface(calibri);

And we’re done!

Changing Company Name in XCode 4

With the release of XCode 4, a lot has changed on the interface and some things we used to do in XCode 3.x are now gone. Like for instance, if we like to change the Organization Name or Company Name of our XCode project, we just simply click the Info button on the top menu and we can now modify its value.

Today, in XCode 4, there’s no Info button to do the changes but instead it is buried under the View –> Utilities –> File Inspector or simply hit Option+Cmd+1 to slide the menu on the right. And under Project Document, there’s a label Organization on which you can set your desired value.

Xcode

A nice tip to new users of XCode 4!

Categories: iOS, Resources

Android Development in Eclipse. Strange “Unparsed aapt error(s)

I got this error(Unparsed aapt error – triggered by another error – “Invalid filename: must contain only [a-z0-9_.]“) when I modified a resource XML file in my Android project. This can also happen when you accidentally click the “Run” button having an XML file selected in your file browser (project root must be the one selected and on focus). After fixing the problem that triggered this “Unparsed aapt error”, I was expecting that my code is ready to be deployed in my device, but it won’t build. After going around, blindly searching for other might-be problems in my XML resources. I knew I had to run Eclipse’s debug. And it just won’t work. I realized that at this point, Eclipse wasn’t able to identify anymore that the problem has already been solved. I right clicked on the error in Eclipse’s “Problems” view and deleted the error manually.

– Perform a “Clean” project after deleting the error manually in the Problems view.

Categories: Android, Eclipse, Resources

Parsing XML File using APXML Library

Recently, I just got the chance to work on an assignment that requires me to read XML file from the internet and display the fetch data on a simple UITableView. And to be honest, this is the first time I am parsing an XML documents as I am more familiar with the JSON format instead and JSON is fairly simple to work with on an iOS project using the great json-framework open-source library.

There are plenty of resources out there that will do the job very quickly and easily but I opted to try the clean and simple open-source library APXML that does exactly what I like to do – to parse an XML file with minimal effort.

First of all, I need to create a sample XML file which can be found here. This XML file  holds sample books with its title, price, authors and description on every node and has a single attribute that holds the bookId.

Content of our sample books.xml is like this:

01

Reading the XML file and place it in my NSString is pretty straightforward:

02

For simplicity, I just use ASCII encoding on line 6 but you can quickly change it to UTF if you need to. Just for the demo, this approach loads the XML synchronously and will block the main thread until the XML file has been loaded. And on line 11 is a private method that will call the APXML library to perform the actual parsing of the XML file like this:

03

With the above code, APDocument initializes with the given XML string and calls its rootElement to determine the root value which is the <catalog> in order tor the parser to determine the object for which it can get all the childElements under it. Child elements is an NSArray of APElement which we can iterate until the last <book> node is read.

APXML library gives you simple method call to get the attribute name:

   1: [child valueForAttributeNamed:@"id"]

Or getting the value of each element in a given node (<book>):

   1: NSLog(@"Author: %@", [[subElements objectAtIndex:0] value]);

After the method parseBooks has been executed, the usual UITableView will fill-up all the books from our dictionary:

04

And if you click on each cell, we can display the details of the book with our UIAlertView:

05

The output of our test project is something like below:

xml_21  xml_22

Haven’t tried other XML libraries for iOS yet, but I’m sure APXML will do most of the job on parsing XML file. You could try this cool library also!

Categories: iOS, Resources

Creating a multiple options dialog in Android

Below is the code for creating a multiple options dialog in Android. This dialog is triggered by clicking an option from a context menu in my application which determines what Activity class my app should direct to.


final String items[] = {“Movie”,”Music”,”Book”};
AlertDialog.Builder ab=new AlertDialog.Builder(SmugActivity.this);
ab.setTitle(“Dialog Title”);
ab.setItems(items, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface d, int choice) {
if(choice == 0) {
Intent mainIntent = new Intent(SampleActivity.this, MovieActivity.class);
SampleActivity.this.startActivity(mainIntent);
SampleActivity.this.finish();
}
else if(choice == 1) {
Intent mainIntent = new Intent(SampleActivity.this, MusicActivity.class);
SampleActivity.this.startActivity(mainIntent);
SampleActivity.this.finish();
}
else if(choice == 2) {
Intent mainIntent = new Intent(SampleActivity.this, BookActivity.class);
SampleActivity.this.startActivity(mainIntent);
SampleActivity.this.finish();
}
}
});
ab.show();

The code above should look like this:

Categories: Android, Resources