viernes, 27 de agosto de 2010

Daily accomplishments

I was reading “No B.S. Ruthless Management of People and Profits: The Ultimate, No Holds Barred, Kick Butt, Take No Prisoners Guide to Really Getting Rich” by Dan Kennedy.

It makes reference to a study made to top executives.
According with the referenced study, the executives, by their own account only averages 40 minutes or less of actual accomplishment.
In my work as a Project Manager, we found an average developer to be productive for 80% of their time, in an 8 hours shift, it will be about 6:30 hours; plans where made with this in mind.
Could that be that when responsibilities are increased and more people need to be managed by us, our own accomplishments decrease?

viernes, 13 de agosto de 2010

iPhone's Numeric Pad keyboard with a DOT

I was developing an application for iPhone which handl
es numeric fields to register information. To my disappointment, even in iOS 4, there is no default keyboard for a Number pad including a dot “.”; there is a Number pad with numbers from 0 to 9 and the backspace, in the other hand we have the Numbers and punctuations, which includes numbers, dot, parenthesis, and other symbols. T
he problem with the former is the absence of a dot and the later is that we can easily switch to the alphabetical keyboard.

But what happen with the Number pad including a dot? The Number pad keyboard includes a blank space


After a little search a found a couple of examples of including the dot in the kwyboard, using the blank space.

First, lets say we have a text field defined and connected to the interface

IBOutlet UITextField * textMoney;

And wich keyboard type is the Number Pad

self.textMoney.keyboardType = UIKeyboardTypeNumberPad;

In order to include the Dot, we need to stat receiving notifications to act propperly when the keyboard shows:

/**

View will appear

**/

- (void)viewWillAppear:(BOOL)animtated

{

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2)

{

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil];

}

else

{

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

}

}


We include the notification, according with the detected iOS.

/**

View will disappear

**/

- (void)viewWillDisappear:(BOOL)animtated

{

[[NSNotificationCenter defaultCenter] removeObserver:self];

}


The dismiss te notification once the view is not showed.

Now, all interesting process begin with when we received the notification in the configured function, in this case keyboardWillShow

/**

The Keyboard will be shown

**/

- (void)keyboardWillShow:(NSNotification *)notification

{

if ([textNotes isFirstResponder])

{

// Skip for Notes keyboard

return;

}

// Locate fist view

UIWindow *tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];

UIView *keyboard;

// Define Button

UIButton * utilityButton = [UIButton buttonWithType:UIButtonTypeCustom];

utilityButton.frame = CGRectMake(0, 163, 105, 53);


// Set Text and font

[utilityButton.titleLabel setFont:[UIFont systemFontOfSize:35]];

[utilityButton setTitle:[Dot or Comma according with localized settings] forState:UIControlStateNormal];

// Set Solors

[utilityButton setTitleColor:[UIColor colorWithRed:77.0f/255.0f green:84.0f/255.0f blue:98.0f/255.0f alpha:1.0] forState:UIControlStateNormal];

[utilityButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];

// Background for the pressed state

[utilityButton setBackgroundImage:[UIImage imageNamed:@"background.png"] forState:UIControlStateHighlighted];

// Add call to functionality

[utilityButton addTarget:self action:@selector(addDecimalPointToField) forControlEvents:UIControlEventTouchUpInside];

// Behavior when orientation is changed

[utilityButton setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight)];


// Locate keyboard view and add button

for(int i=0; i<[tempWindow.subviews count]; i++)

{

keyboard = [tempWindow.subviews objectAtIndex:i];

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2)

{

if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)

{

[keyboard addSubview:utilityButton];

}

}

else

{

if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)

{

[keyboard addSubview:utilityButton];

}

}

}

}


Again, we need to make a distinction for the iOS.

One little extra t
hing, to add the dot to the current field with the focus, we use a trick, copy the dot to memory and then call the paste function of the current field, this is done in addDecimalPointToField.

/**

Send Decimal Point event to field with focus

**/

- (void)addDecimalPointToField

{

UIView * objectToEdit = nil;

// Locate field with the focus

for (UIView * localView in self.scrollView.subviews)

{

if ([localView isFirstResponder])

{

objectToEdit = localView;

}

}

// Try to insert dot

if (objectToEdit != nil)

{

// Detect if the Dot has been already inserted

NSString * localText = [(UITextField *)objectToEdit text];

NSRange separatorPosition = [localText rangeOfString:[Dot or Comma according with localized settings]];


if (separatorPosition.location == NSNotFound)

{

// Dot wasn't found, add it

[objectToEdit insertText:[NSString stringWithFormat:[Dot or Comma according with localized settings]]];

}

}

}


I have change part of the code with [According with the localization options, add a Dot or a Comma], this in order to let you decide what punctuation symbol to use.

The result will be something like:


I'm not really sure it this will be accepted by Apple to be release to iTunes Store, I haven't use it for a commercial application, at least, my AdHoc application implements it.

Hope this help you.

lunes, 2 de agosto de 2010

Migrating Contacts over phones

Recently I was helping in a cell phone migration; contacts were the most important thing to migrate, but the devices where not directly compatible as the devices where a Nokia and a Samsung.

After a couple of Google’s searches, I got to the idea that there were no application so make my life easier, so I got to the task to investigate what the vendor’s applications were capable of.

I install in a Windows PC both suites, Nokia PC Suite and Samsung PC Studio, after I connect and synchronize both devices I got the option of exporting and importing contacts.

From the Nokia PC Suite, I exported all contacts; as a result I got a single file including all the 100+ contacts. I then turn to Samsung’s suite and try to import from the file, but it only imports the first one.

I don’t know if it has something to do with the vCard standard, but, most of the products I´ve tried do the same when reading multiple cards within a file.

So, next thing to do was to create as many files as contacts to import, wait a minute, this is more than 100 files!

What if I want to make a migration of a device with thousand of contacts?

To make my life easier, I start creating a DOS shell script to separate the file in as many contacts as is has. Its operation will be easy:
1. Read source file line by line
2. When detects the tag “BEGIN:VCARD” create a new file
3. Writes all read lines to the created file

Whit this simple process I got all the files I need and next step was to imported in Samsung’s suite. Fortunately, it support to drag-n-drop many files at a time, so, just in a moment the Agenda was introduced in the new phone.

Here is the code to create the vCards.

It reads the input file in the same path. File with contacts need to be named as “contacts.txt”


@echo off

set fileNumber=0

setLocal EnableDelayedExpansion
for /f "tokens=* delims==" %%a in ('type contacts.txt') do (
if "BEGIN:VCARD" == "%%a" (
set /a fileNumber+=1
echo BEGIN:VCARD > !fileNumber!.vcf
)
if NOT "BEGIN:VCARD" == "%%a" (
echo %%a >> !fileNumber!.vcf
)
)

goto :eof


Here you can find a copy of the script in case you want to test it yourself: readCards.zip