1. Cisco Cius: 7 inch diagonal, Android, HD video camera, HD Audio, 3G/4G data and Bluetooth.
Macworld. How Cisco Cius stacks up against iPad
2. BlackBerry Playbook: 1 GHz dual-core processor, 1G RAM, QNX (it's an OS that supports symmetric multiprocessing with use of the QNX Neutrino microkernel architecture), WiFi, no 3G, 1024x600-pixel touchscreen, HD video playback, Adobe Flash Player 10.1 and HTML 5 are both supported for Web browsing
Macworld. RIM launches 7-inch PlayBook tablet
3. Acer developing Android-based tablets.
IntoMobile. Photo: Acer CEO shows off 7 inch Android powered tablet due to hit the market in Q4 2010
4. Samsung Galaxy Tab: Android 3.0 Gingerbread, Cortex A8 1.0GHz chip, 7 inches, WiFi, Bluetooth 3.0 and 3G HSUPA, support for H.263, DivX, MPEG4, XviD, MPEG4, H.264 video formats.
IntoMobile. Hands-on: Samsung Galaxy Tab Android – 7 inches of Android tablet goodness
TechPinas about it.
5. LG Android Optimus Tablet.
CrunchGear about it.
Tuesday, September 28, 2010
Thursday, September 23, 2010
Create Xcode project template
New article from Ohmu:
CodeProject. Creating an Xcode Project Template
shows how to make a project template in Xcode.
Tested. Works fine.
I made a template from the Simple project
CodeProject. Creating an Xcode Project Template
shows how to make a project template in Xcode.
Tested. Works fine.
I made a template from the Simple project
cd to the folder opened in Finder
Copy the following bash script and paste it in Terminal:
You can save this function in .profile, re-open Terminal session and now, to switch to the folder opened in Finder, type 'cdff'.
Nice?
Don't tell me that you simply could drag an item from the Finder to the Terminal Window. :)
(If someone doesn't know, in Terminal type "cd ", then drag from the Finder Window the tiny icon near the folder name:
function ff { osascript -e 'tell application "Finder"' \press Enter, then type cdff and press Enter. You will see that now the current folder in Terminal is the same as in the opened Finder.
-e "if (${1-1} <= (count Finder windows)) then" \
-e "get POSIX path of (target of window ${1-1} as alias)" \
-e 'else' -e 'get POSIX path of (desktop as alias)' \
-e 'end if' -e 'end tell'; };\
function cdff { cd "`ff $@`"; };
You can save this function in .profile, re-open Terminal session and now, to switch to the folder opened in Finder, type 'cdff'.
Nice?
Don't tell me that you simply could drag an item from the Finder to the Terminal Window. :)
(If someone doesn't know, in Terminal type "cd ", then drag from the Finder Window the tiny icon near the folder name:
Open Terminal Here
OpenTerminalHere is a very useful AppleScript: http://www.entropy.ch/software/applescript/The source code, probably, may look so:
OpenTerminalHere and AntHere
You can find more:
Enhanced Open Terminal Here, for Leopard
Here is an Objective-C project "cdto":
http://code.google.com/p/cdto/downloads/list
on runOr so:
tell application "Finder"
activate
try
set this_folder to (the target of the front window) as alias
on error
set this_folder to startup disk
end try
my process_item(this_folder)
end tell
end run
-- This handler processes folders dropped onto the toolbar script icon
--
on open these_items
repeat with this_item in these_items
my process_item(this_item)
end repeat
end open
-- this subroutine does the actual work
--
on process_item(this_item)
set the_path to POSIX path of this_item
repeat until the_path ends with "/"
set the_path to text 1 thru -2 of the_path
end repeat
tell application "Terminal"
if (count of windows) is 0 then
do script with command "cd " & quoted form of the_path
else
if front window is busy then
--Can be tested by looking at a manpage or running top in terminal.app
tell application "Terminal" to activate
tell application "System Events" to tell process "Terminal" to ¬
keystroke "t" using command down
end if
do script with command "cd " & quoted form of the_path in window 1
end if
activate
end tell
end process_item
on runAn update versions are available on james david low:
tell application "Finder"
try
activate
set frontWin to folder of front window as string
set frontWinPath to (get POSIX path of frontWin)
tell application "Terminal"
activate
close
do script with command "cd \"" & frontWinPath & "\""
end tell
on error error_message
beep
display dialog error_message buttons ¬
{"OK"} default button 1
end try
end tell
end run
OpenTerminalHere and AntHere
You can find more:
Enhanced Open Terminal Here, for Leopard
Here is an Objective-C project "cdto":
http://code.google.com/p/cdto/downloads/list
Tuesday, September 21, 2010
Funny Programming
Nice article on Cocoa with Love: Minimalist Cocoa programming
So here is the minimalistic Cocoa application:
So here is the minimalistic Cocoa application:
Friday, September 17, 2010
If You Don't Need Interface Builder.
My new article published on EE:
If You Don't Need Interface Builder.
If You Don't Need Interface Builder.
Freelance
I found few interesting posts:
1. Manage Your Risk –> Don’t Get Taken for a Ride
2. Freelance iPhone Development and the Retainer –> Never Leave Home Without It!
3. Freelance iPhone Development – You’re probably Undercharging!
1. Manage Your Risk –> Don’t Get Taken for a Ride
2. Freelance iPhone Development and the Retainer –> Never Leave Home Without It!
3. Freelance iPhone Development – You’re probably Undercharging!
Saturday, September 4, 2010
Simplest project for iPhone: no xib-file.
Probably, I do know the way to create "empty" iPhone project. Is it useful? I have no idea.
In the Windows world, in Visual Studio, the best way to create new project was to check "Empty project" checkbox in the Win32 application wizard.
In Xcode, for an iPhone project, the IDE generates for me a lot of files, makes folders. If I'm just learning, if I'm just testing all these files and folders just fulfill my hard disk.
So I found a way to create such "empty" project in Xcode:
1. Create new project in Xcode: Window-based template, any name,... everything's as usual.
2. In Xcode sidebar, select "Classes" and delete them. In the alert window choose "Also move to Trash".
3. Delete xib-file.
4. Modify *-info.plist file: delete the line about MainWindow - probably, the last one.
5. Open main.m file and add a simple application delegate. Then set the name of the delegate in the main() function.
Here is my main.m file:
In the Windows world, in Visual Studio, the best way to create new project was to check "Empty project" checkbox in the Win32 application wizard.
In Xcode, for an iPhone project, the IDE generates for me a lot of files, makes folders. If I'm just learning, if I'm just testing all these files and folders just fulfill my hard disk.
So I found a way to create such "empty" project in Xcode:
1. Create new project in Xcode: Window-based template, any name,... everything's as usual.
2. In Xcode sidebar, select "Classes" and delete them. In the alert window choose "Also move to Trash".
3. Delete xib-file.
4. Modify *-info.plist file: delete the line about MainWindow - probably, the last one.
5. Open main.m file and add a simple application delegate. Then set the name of the delegate in the main() function.
Here is my main.m file:
#import <UIKit/UIKit.h>6. Compile and Run:
// Application delegate
@interface Simple : NSObject <UIApplicationDelegate>
{
}
@end
@implementation Simple
- (void)applicationDidFinishLaunching: (UIApplication*)application
{
UIWindow* window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
[window setBackgroundColor: [UIColor yellowColor]];
[window makeKeyAndVisible];
}
@end
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"Simple");
[pool release];
return retVal;
}
Friday, September 3, 2010
iOS. Video.
NGMoviePlayer:
Source code is here: http://bitbucket.org/brentsimmons/ngmovieplayer/src
Source code is here: http://bitbucket.org/brentsimmons/ngmovieplayer/src
Play Video with MPMoviePlayerController in iOS 3.0 and 3.2/4.0
http://iphoneincubator.com /blog/audi o-video/pl ay-video-w ith- mpmovi eplayercon troller-in -ios-3-0-a nd-3-24-0
http://iphoneincubator.com
Thursday, September 2, 2010
iOS 4.1. High Dynamic Range photos
Gigaom. iOS 4.1 Update Next Week, 4.2 in November
I'm not the first to update OS on my iPhone. But this announce looks very interesting. iOS 4.1 is supposed to fix the performance problems and will bring new feature - High Dynamic Range photos:
I'm not the first to update OS on my iPhone. But this announce looks very interesting. iOS 4.1 is supposed to fix the performance problems and will bring new feature - High Dynamic Range photos:
Using High Dynamic Range (HDR), the iPhone takes three photos: one at normal exposure, one under exposed, and one over exposed. iOS 4 then combines the three photos using “advanced algorithms” to create a single high-definition photograph. Both the normal exposure picture and the HDR picture are kept in the photos app on the iPhone, making it easy to choose one or the other. The demos look amazing; the HDR photos bring out features in the background that you couldn’t see in the normal exposure
Worldwide OS Market Share
Just an information:
iOS Over Linux Today, Android Over iOS Tomorrow
iOS Over Linux Today, Android Over iOS Tomorrow
Windows Phone Team is very excited to say
Windows Phone Blog. Windows Phone 7 – Released To Manufacturing
Windows Phone 7 released to manufacturing. Seems like the developers are really proud and believe that this is really a great OS.
Windows Phone 7 released to manufacturing. Seems like the developers are really proud and believe that this is really a great OS.
Sunday, August 22, 2010
Big-O Notation
Big-O Notation is a kind of a strange foreign language. Interviewers use it in order to show that they are smarter than you, the development managers mention it to demonstrate own IQ to the programmers. :)
In case you have to know what is this Big-O notation read these articles in the following order:
1. A Beginners’ Guide to Big O Notation.
2. An Intro to Big Oh Notation with Java.
3. Complexity and Big-O Notation
4. An informal introduction to O(N) notation
5. Algorithmic Efficiency -- Analyzing Algorithms
6. Algorithmic Efficiency -- Various Orders and Examples
From my point of view it's a bureaucracy that comes to the real programming. Yes, it says something about the algorithm performance. But it can be a real mistake to write a fundamental algorithms yourself in complex commercial projects. It's important to see in the source code the bottle necks, but if I see a nested loop, I do know that it is better to "open" it and the fact that now I know that is O(N^2) does not help me at all.
In case you have to know what is this Big-O notation read these articles in the following order:
1. A Beginners’ Guide to Big O Notation.
2. An Intro to Big Oh Notation with Java.
3. Complexity and Big-O Notation
4. An informal introduction to O(N) notation
5. Algorithmic Efficiency -- Analyzing Algorithms
6. Algorithmic Efficiency -- Various Orders and Examples
From my point of view it's a bureaucracy that comes to the real programming. Yes, it says something about the algorithm performance. But it can be a real mistake to write a fundamental algorithms yourself in complex commercial projects. It's important to see in the source code the bottle necks, but if I see a nested loop, I do know that it is better to "open" it and the fact that now I know that is O(N^2) does not help me at all.
Sunday, August 15, 2010
Mac OS X. Terminal curl
Today morning I found this blog post:
See Share Quotes In Terminal / Geek Tool
I'm from the Windows world and didn't know about curl in Terminal, so I tested:
Looks interesting? For me too. So I found how to work with the ftp via curl:
http://www.hyperorg.com/blogger/2008/01/01/beginner-to-beginner-ftp-via-curl/
One more nice example: how to detect my IP address with curl:
curl ifconfig.me
See Share Quotes In Terminal / Geek Tool
I'm from the Windows world and didn't know about curl in Terminal, so I tested:
Looks interesting? For me too. So I found how to work with the ftp via curl:
http://www.hyperorg.com/blogger/2008/01/01/beginner-to-beginner-ftp-via-curl/
One more nice example: how to detect my IP address with curl:
curl ifconfig.me
XML parsing on Mac. Fast and Dirty.
If you know C better than Objective-C, this is a fast and dirty way to parse an XML-file on Mac OS X:
BTW, the standard way to work with the XML on iPhone is shown in this nice tutorial:
Parsing XML Files
#import <Foundation/Foundation.h>As you see, this a Foundation Tool project. It works with data.xml located in the debug folder:
void PrintTree(CFXMLTreeRef tree)
{
int kids = CFTreeGetChildCount(tree);
if (kids > 0)
{
int cnt = 0;
while (cnt < kids)
{
CFXMLTreeRef treeChild = CFTreeGetChildAtIndex(tree, cnt);
PrintTree(treeChild);
CFXMLNodeRef treeNode = CFXMLTreeGetNode(treeChild);
//CFXMLNodeTypeCode subNodeType = CFXMLNodeGetTypeCode(treeNode);
CFStringRef text = CFXMLNodeGetString(treeNode);
NSLog(@"text: %@", text);
++cnt;
}
}
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
CFXMLTreeRef tree;
NSString *str;
NSData* data;
str = [[NSMutableString alloc] initWithContentsOfFile: @"data.xml"];
data = [str dataUsingEncoding:NSUTF8StringEncoding];
tree = CFXMLTreeCreateFromData(kCFAllocatorDefault,
(CFDataRef)data, NULL,
kCFXMLParserSkipWhitespace,
kCFXMLNodeCurrentVersion);
PrintTree(tree);
CFRelease(tree);
[str release];
[pool drain];
return 0;
}
<?xml version="1.0" encoding="UTF-8"?>Of course, it could be written in the pure C. But it's enough to give a direction.
<root>
<person>
<name>Pavel Gnatyuk</name>
<age>40</age>
</person>
</root>
BTW, the standard way to work with the XML on iPhone is shown in this nice tutorial:
Parsing XML Files
Saturday, August 14, 2010
Mac OS X. Keep Safari Alive.
launchctl is a tool allowing to load and unload the daemons on Mac OS X. For example, here I will show how Safari can be re-launched automatically in a case of a crash.
In TextEdit make the following file:
Save it com.apple.KeepSafariAlive.plist in ~/Library/LaunchAgents folder.
Now in Terminal type:
$ launchctl load Library/LaunchAgents/com.apple.KeepSafariAlive.plist
You see Safari running. Try to kill it, for example:
$ killall -9 Safari
To unload the agent use this command:
$ launchctl unload Library/LaunchAgents/com.apple.KeepSafariAlive.plist
This example was taken from this book:
In TextEdit make the following file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.apple.KeepSafariAlive</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/Safari.app/Contents/MacOS/Safari</string>
</array>
<key>OnDemand</key>
<false/>
</dict>
</plist>
Save it com.apple.KeepSafariAlive.plist in ~/Library/LaunchAgents folder.
Now in Terminal type:
$ launchctl load Library/LaunchAgents/com.apple.KeepSafariAlive.plist
You see Safari running. Try to kill it, for example:
$ killall -9 Safari
To unload the agent use this command:
$ launchctl unload Library/LaunchAgents/com.apple.KeepSafariAlive.plist
This example was taken from this book:
Friday, August 13, 2010
Snow Leopard. Terminal. Compile Objective-C program
Google always helps. :)
Today it helped me to compile a standard (or GNUStep ?) Objective-C program with gcc.
Here is the code:
gcc -arch i386 test.m -o test -lobjc
It means that the output file ./test supports the Mach-O architecture. You can verify it as:
file ./test
The output:
./test: Mach-O executable i386
Today it helped me to compile a standard (or GNUStep ?) Objective-C program with gcc.
Here is the code:
#include <objc/Object.h>The command to compile is the following:
#include <stdio.h>
#include <stdio.h>
@interface Test : Object
{
}
- (void) sayHello;
@end;
@implementation Test
- (void) sayHello
{
printf("Hello\n");
}
@end
int main(void)
{
id t;
t = [Test new];
[t sayHello];
[t free];
return 0;
}
gcc -arch i386 test.m -o test -lobjc
It means that the output file ./test supports the Mach-O architecture. You can verify it as:
file ./test
The output:
./test: Mach-O executable i386
GNUStep on Windows.
Today I installed GNUStep on Windows XP computer and compiled a foundation tool program. Actually. I didn't expect such results.
The installation instruction is here: http://www.gnustep.org/experience/Windows.html
Download GNUstep MSYS System and GNUstep Core. Install them in the same order.
If you didn't change anything within the installation you will find GNUStep folder on your C drive. In this folder you find msys.bat. Launch it or launch Shell in Start->All Programs->GNUStep->Shell.
It's a more or less standard shell. Use vi to type a program. If you prepare a Windows editor, for example Notepad++, you can use it and save the program in /GNUStep/hom/ folder.
I began from the simple C-program and compile it ion the shell as:
gcc test.c
Then, I tried a simple Objective-C program:
gcc test.m -lobjc
I got a.exe file and launched it:
Next step - test a Foiundation Tool!
$ gcc `gnustep-config --objc-flags` -L /GNUstep/System/Library/Libraries test1.m -o test1.exe -lgnustep-base -lobjc
But then I got the executable that I can launch in the shell:
Helpfull links about the subject:
1. Compile Objective-C Programs Using gcc.
2. Installing and using GNUstep and Objective-C on Windows
The installation instruction is here: http://www.gnustep.org/experience/Windows.html
Download GNUstep MSYS System and GNUstep Core. Install them in the same order.
If you didn't change anything within the installation you will find GNUStep folder on your C drive. In this folder you find msys.bat. Launch it or launch Shell in Start->All Programs->GNUStep->Shell.
It's a more or less standard shell. Use vi to type a program. If you prepare a Windows editor, for example Notepad++, you can use it and save the program in /GNUStep/hom/
I began from the simple C-program and compile it ion the shell as:
gcc test.c
Then, I tried a simple Objective-C program:
#include <objc/object.h>Then I compiled it:
#include <stdio.h>
@interface Test : Object
{
}
- (void)sayHello;
@end
@implementation Test
- (void) sayHello
{
printf("Hello from Objective-C class\n");
}
@end
int main(void)
{
id t;
t = [Test new];
[t sayHello];
[t free];
return 0;
}
gcc test.m -lobjc
I got a.exe file and launched it:
Next step - test a Foiundation Tool!
#import <Foundation/Foundation.h>The gcc line looks weird:
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"Hello. It's Foundation Tool");
[pool drain];
return 0;
}
$ gcc `gnustep-config --objc-flags` -L /GNUstep/System/Library/Libraries test1.m -o test1.exe -lgnustep-base -lobjc
But then I got the executable that I can launch in the shell:
Helpfull links about the subject:
1. Compile Objective-C Programs Using gcc.
2. Installing and using GNUstep and Objective-C on Windows
Snow Leopard. Terminal. The simplest dissamler
otool is a nice tool showing the dependencies and disassembly listing:
For example, otool -L /bin/pwd:
otool with -h shows the file header:
and otool -tv /bin/ls > ~/Desktop/ls.txt will make a text file on the desktop with the code of the ls.
/bin/ls:
(__TEXT,__text) section
0000000100001478 pushq $0x00
000000010000147a movq %rsp,%rbp
000000010000147d andq $0xf0,%rsp
0000000100001481 movq 0x08(%rbp),%rdi
0000000100001485 leaq 0x10(%rbp),%rsi
0000000100001489 movl %edi,%edx
000000010000148b addl $0x01,%edx
000000010000148e shll $0x03,%edx
And dtrace that requires the sudo password allows to trace. But this is a much more complicated story.
For example, otool -L /bin/pwd:
otool with -h shows the file header:
and otool -tv /bin/ls > ~/Desktop/ls.txt will make a text file on the desktop with the code of the ls.
/bin/ls:
(__TEXT,__text) section
0000000100001478 pushq $0x00
000000010000147a movq %rsp,%rbp
000000010000147d andq $0xf0,%rsp
0000000100001481 movq 0x08(%rbp),%rdi
0000000100001485 leaq 0x10(%rbp),%rsi
0000000100001489 movl %edi,%edx
000000010000148b addl $0x01,%edx
000000010000148e shll $0x03,%edx
And dtrace that requires the sudo password allows to trace. But this is a much more complicated story.
Snow Leopard. Terminal. Currently loaded drivers
kextstat command shows all loaded drivers:
If the loaded address is zero, it's a part of the kernel and not a driver. Such things cannot be unloaded. If you look for a specific driver use:
keystat | grep "file"
You wil see only "file related" drivers in the list.
There are three more command from the same seria: kextfind, kextload and kextunload. Last two require the super user password and should be called as
sudo kextload /System/Library/Extensions/msdosfs.kext
kextfind help to find a driver, for example, so:
kextfind -bundle-id -substring 'file'
If the loaded address is zero, it's a part of the kernel and not a driver. Such things cannot be unloaded. If you look for a specific driver use:
keystat | grep "file"
You wil see only "file related" drivers in the list.
There are three more command from the same seria: kextfind, kextload and kextunload. Last two require the super user password and should be called as
sudo kextload /System/Library/Extensions/msdosfs.kext
kextfind help to find a driver, for example, so:
kextfind -bundle-id -substring 'file'
Wednesday, August 11, 2010
iPhone Explorer
It's happened! iPhone Explorer. I just installed it on my Mac from here:
http://www.macroplant.com/iphoneexplorer/
Sunday, August 1, 2010
Win32: Create window menu programmatically
Standard Windows application contains a menu. Usualy we create the menu in the application resource file. Then load it and pass the menu handle whithin the window class regisration procvedure.
How to create the standard windows menu programmatically?
CreateMenu function in the following Win32 program does it:
How to create the standard windows menu programmatically?
CreateMenu function in the following Win32 program does it:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
LPCWSTR s_szWndName = L"A window with a menu";
ATOM RegisterWndClass(HINSTANCE, LPCWSTR);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void CreateAMenu(HWND hWnd);
int WINAPI wWinMain(HINSTANCE hInstance,
HINSTANCE, LPWSTR, int nShowCmd)
{
RegisterWndClass(hInstance, s_szWndName);
HWND hWnd = CreateWindow(s_szWndName, s_szWndName,
WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
NULL, NULL, hInstance, NULL);
if (hWnd != NULL)
{
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
ATOM RegisterWndClass(HINSTANCE hInstance,
LPCWSTR lpszWndClassName)
{
WNDCLASSEX wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.hInstance = hInstance;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = lpszWndClassName;
return RegisterClassEx(&wcex);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
CreateAMenu(hWnd);
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
}
break;
case WM_LBUTTONDOWN:
PostMessage(hWnd, WM_CLOSE, 0, 0);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
#define ID_NEW_RECORD_ITEM 1001
#define ID_SAVE_RECORD_ITEM 1002
#define ID_QUIT_ITEM 1003
#define ID_SHOW_ALL_ITEM 1004
#define ID_SELECT_REPORT_ITEM 1005
void CreateAMenu(HWND hWnd)
{
HMENU hMenu = CreateMenu();
HMENU hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, ID_NEW_RECORD_ITEM, L"&New Record");
AppendMenu(hSubMenu, MF_STRING, ID_SAVE_RECORD_ITEM, L"&Save Record");
AppendMenu(hSubMenu, MF_STRING, ID_QUIT_ITEM, L"&Quit");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&File");
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, ID_SHOW_ALL_ITEM, L"Show &All Data");
AppendMenu(hSubMenu, MF_STRING, ID_SELECT_REPORT_ITEM, L"S&eelect report");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&Reports");
SetMenu(hWnd, hMenu);
}
Friday, July 30, 2010
Create UIView, UILabel and UIButton programmatically.
A year ago, when I needed to make my first iPhone application, Interface Builder looked for me very complicated. I came from the Microsoft Windows Mobile world where we created all GUI created programmatically (the standard controls are very poor, MFC worked too slow, etc.). My task has nothing to do with the GUI. I needed a test-wrapper for my code that was supposed to test a 3rd party framework. Google helped me to find few tutorials but all of then proposed to work with Interface Builder. It is really nice and simple to choose a control and put it on my application window in the Interface Builder. But how to connect this control with my code? In the beginning it was a kind of a rebus I had to solve. It was not very obvious for me to catch all these outlets, actions and bindings, Command- and Control-clicks, six different Inspectors,...
I hope this article will help to someone who likes me a year ago is looking for a way to make his first program without Interface Builder.
Let's assume that we know nothing about Xcode, Objective-C and Cocoa Touch - these are my conditions a year ago.
The following steps will help us to create a simple iPhone program with a label and a button:
1. Create Window-based iPhone application.
Launch Xcode. In menu File choose item "New Project...". In the project wizard that comes next, in the left panel select "Application" item in the "iPhone OS" section. Select "Windows-based Application" icon on the right and press "Choose". Next window asks to set a name for the project. Type "First" and press "Save" button. By default the project is created in the "My Document" folder.
2. Add UIView programatically.
In the project window, on the left panel that looks like the Finder sidebar you need to find FirstAppDelegate.m file. This sidebar represents as a tree all files of the project. The root of that tree is the project file. You can open this item and all others in the same was as you do with the folder in the Finder. If you have found the FirstAppDelegate.m file, click on it and its content will be shown in the right panel. There is a lot of code but we need only one function application didFinishLaunchingWithOptions. Make it look so:
3. Build and Run.
In Xcode, in project window, in the left-up corner you can a toolbar that now, probably, contains text "Device - 4.0. Debug. First". It is a popup button. You need to click on it and select Simulator. Now press on "Build and Run" button. If you see the simulator ruuning, if you see an ugly yellow window on it - you did everything perfect. Close the simulator and go back to Xcode - there is "Quit" item in the main menu of the simulator.
4. Add a label.
Here is the code that should be added to the same function after the line [window addSubview: view};:
5. Create new button.
After the label code in the same function we need to add the following:
If something goes wrong, verify our working function:
6. Add an action.
In our program the button does nothing. Let's add an action. In the header file (FirstAppDelegate.h) you need to add one line:
I hope this article will help to someone who likes me a year ago is looking for a way to make his first program without Interface Builder.
Let's assume that we know nothing about Xcode, Objective-C and Cocoa Touch - these are my conditions a year ago.
The following steps will help us to create a simple iPhone program with a label and a button:
1. Create Window-based iPhone application.
Launch Xcode. In menu File choose item "New Project...". In the project wizard that comes next, in the left panel select "Application" item in the "iPhone OS" section. Select "Windows-based Application" icon on the right and press "Choose". Next window asks to set a name for the project. Type "First" and press "Save" button. By default the project is created in the "My Document" folder.
2. Add UIView programatically.
In the project window, on the left panel that looks like the Finder sidebar you need to find FirstAppDelegate.m file. This sidebar represents as a tree all files of the project. The root of that tree is the project file. You can open this item and all others in the same was as you do with the folder in the Finder. If you have found the FirstAppDelegate.m file, click on it and its content will be shown in the right panel. There is a lot of code but we need only one function application didFinishLaunchingWithOptions. Make it look so:
/- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
// Window bounds.
CGRect bounds = window.bounds;
// Create a view and add it to the window.
UIView* view = [[UIView alloc] initWithFrame: bounds];
[view setBackgroundColor: [UIColor yellowColor]];
[window addSubview: view];
[window makeKeyAndVisible];
[view release];
return YES;
}
3. Build and Run.
In Xcode, in project window, in the left-up corner you can a toolbar that now, probably, contains text "Device - 4.0. Debug. First". It is a popup button. You need to click on it and select Simulator. Now press on "Build and Run" button. If you see the simulator ruuning, if you see an ugly yellow window on it - you did everything perfect. Close the simulator and go back to Xcode - there is "Quit" item in the main menu of the simulator.
4. Add a label.
Here is the code that should be added to the same function after the line [window addSubview: view};:
CGRect labelFrame = CGRectMake( 10, 40, 100, 30 );You can Build and Run the program again to check the label is on the application screen.
UILabel* label = [[UILabel alloc] initWithFrame: labelFrame];
[label setText: @"My Label"];
[label setTextColor: [UIColor orangeColor]];
[view addSubview: label];
5. Create new button.
After the label code in the same function we need to add the following:
CGRect buttonFrame = CGRectMake( 10, 80, 100, 30 );Build and Run the program. These orange label and white button with the red title is our art.
UIButton *button = [[UIButton alloc] initWithFrame: buttonFrame];
[button setTitle: @"My Button" forState: UIControlStateNormal];
[button setTitleColor: [UIColor redColor] forState: UIControlStateNormal];
[view addSubview: button];
If something goes wrong, verify our working function:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Window bounds.
CGRect bounds = window.bounds;
// Create a view and add it to the window.
UIView* view = [[UIView alloc] initWithFrame: bounds];
[view setBackgroundColor: [UIColor yellowColor]];
[window addSubview: view];
// Create a label and add it to the view.
CGRect labelFrame = CGRectMake( 10, 40, 100, 30 );
UILabel* label = [[UILabel alloc] initWithFrame: labelFrame];
[label setText: @"My Label"];
[label setTextColor: [UIColor orangeColor]];
[view addSubview: label];
// Create a button and add it to the window.
CGRect buttonFrame = CGRectMake( 10, 80, 100, 30 );
UIButton *button = [[UIButton alloc] initWithFrame: buttonFrame];
[button setTitle: @"My Button" forState: UIControlStateNormal];
[button setTitleColor: [UIColor redColor] forState: UIControlStateNormal];
[view addSubview: button];
[window makeKeyAndVisible];
[button release];
[label release];
[view release];
return YES;
}
6. Add an action.
In our program the button does nothing. Let's add an action. In the header file (FirstAppDelegate.h) you need to add one line:
- (void)buttonClicked: (id)sender;In Xcode, Alt-Cmd-Up keyboard shortcut will switch the editor to the header file from the m-file. If you have added this line, use the same keyboard shortcut to switch back to the m-file. and implement the action:
- (void) buttonClicked: (id)senderNow modify the code creating the button and add the following code:
{
NSLog( @"Button clicked." );
}
[button addTarget: selfNow if you will build and run the program in the Xcode console you will see "Button clicked" text.
action: @selector(buttonClicked:)
forControlEvents: UIControlEventTouchDown];
Tuesday, July 27, 2010
Cocoa: Implicit Animation
This program will help to begin with the Core Animation.
1. In Xcode create Max OS X Cocoa Application.
2. In the Application delegate implementation file (automatically created by Xcode on Snow Leopard) add a button to the content view:
Short description: each thread maintain an automation context. It is possible to object the object of this context as:
[NSAnimationContext currentContext];
Then, it is possible to customize this object, for example, change the duration:
[[NSAnimation currentContext] setDuration: 1.0];
1. In Xcode create Max OS X Cocoa Application.
2. In the Application delegate implementation file (automatically created by Xcode on Snow Leopard) add a button to the content view:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification3. As you see from the code above the method -move is set as the button action. So add IBAction move to the application delegate class. The interface should look so:
{
// Create new button in content view.
NSRect frame = NSMakeRect(10, 40, 90, 40);
NSButton* pushButton = [[NSButton alloc] initWithFrame: frame];
pushButton.bezelStyle = NSRoundedBezelStyle;
[pushButton setTitle: @"Move"];
[self.window.contentView addSubview: pushButton];
// Set the button target and action.
pushButton.target = self;
pushButton.action = @selector(move:);
[pushButton release];
}
#import <Cocoa/Cocoa.h>And -move method in the implementation file:
@interface ImplicitAnimationAppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
- (IBAction)move: (id)sender;
@end
- (IBAction)move: (id) senderThe commented line [sender setFrame: senderFrame]; simply moves the button. Line [[sender animator] setFrame: senderFrame]; creates an animation effect - the location change was split up for few movements.
{
// The button frame.
NSRect senderFrame = [sender frame];
//The view bounds. The button belongs to this view.
NSRect superBounds = [[sender superview] bounds];
// Calculate new position within the view bounds.
senderFrame.origin.x = (superBounds.size.width -
senderFrame.size.width) * drand48();
senderFrame.origin.y = (superBounds.size.height -
senderFrame.size.height) * drand48();
// Move the button.
//[sender setFrame: senderFrame];
[[sender animator] setFrame: senderFrame];
}
Short description: each thread maintain an automation context. It is possible to object the object of this context as:
[NSAnimationContext currentContext];
Then, it is possible to customize this object, for example, change the duration:
[[NSAnimation currentContext] setDuration: 1.0];
Subscribe to:
Posts (Atom)