Thứ Bảy, 2 tháng 2, 2013
WOMAN HESITATES TO REVEAL SECRET LOVE FOR COLLEAGUE
DEAR ABBY:
I am a single woman in my early 30s who has never been married. I recently fell in love with a won-
derful man with whom I spend a great deal of time. He is unaware of the intensity of my feelings,
and I'm afraid of telling him out of fear of rejection.
There are a couple of additional concerns: He is 15 years my senior and a medical doctor. I am a
social worker in a lower economic class. In addition, we are of different religions, but we have simi-
lar spiritual beliefs and values. He is also my co-worker.
I am very interested in pursuing a deeper relationship with this man, but would like to hear your
advice first. Thank you for your thoughts on this.
-- LONGING FOR MORE IN CHICAGO
Secret Love
Thứ Tư, 30 tháng 1, 2013
android book2
When you integrate a WebView into your activity, you can control what Web
pages are displayed, whether they are from a local provider or come from
over the Internet, what should happen when a link is clicked, and so forth.
And between WebView, WebViewClient, and WebSettings, you can control a fair
bit about how the embedded browser behaves. Yet, by default, the browser
itself is just a browser, capable of showing Web pages and interacting with
Web sites, but otherwise gaining nothing from being hosted by an Android
application.
Except for one thing: addJavascriptInterface().
The addJavascriptInterface() method on WebView allows you to inject a Java
object into the WebView, exposing its methods, so they can be called by
Javascript loaded by the Web content in the WebView itself.
Now you have the power to provide access to a wide range of Android
features and capabilities to your WebView-hosted content. If you can access it
from your activity, and if you can wrap it in something convenient for use
by Javascript, your Web pages can access it as well.
For example, Google's Gears project offers a Geolocation API, so Web pages
loaded in a Gears-enabled browser can find out where the browser is
located. This information could be used for everything from fine-tuning a
search to emphasize local content to serving up locale-tailored advertising.
We can do much of the same thing with Android and
addJavascriptInterface().
In the WebView/GeoWeb1 project, you will find a fairly simple layout
(main.xml):
Thứ Năm, 10 tháng 1, 2013
iOS object-C
That Wacky #import Thing
Just like C, Objective- C uses header files to hold the declarations of elements such as
structs, symbolic constants, and function prototypes. In C, you use the #include statement
to inform the compiler that it should consult a header file for some definitions. You can
use #include in Objective- C programs for the same purpose, but you probably never will.
Instead, you’ll use #import, like this:
#import <Foundation/Foundation.h>
#import is a feature provided by the GCC compiler, which is what Xcode uses when you’re
compiling Objective- C, C, and C++ programs. #import guarantees that a header file will be
included only once, no matter how many times the #import directive is actually seen for
that file.
NOTE
In C, programmers typically use a scheme based on the #ifdef directive to avoid the situation where
one file includes a second file, which then, recursively, includes the first.
In Objective- C, programmers use #import to accomplish the same thing.
The #import <Foundation/Foundation.h> statement tells the compiler to look at the
Foundation.h header file in the Foundation framework.
What’s a framework? We’re glad you asked. A framework is a collection of parts—header
files, libraries, images, sounds, and more—collected together into a single unit. Apple ships
technologies such as Cocoa, Carbon , QuickTime , and OpenGL as sets of frameworks. Cocoa
consists of a pair of frameworks, Foundation and Application Kit (also known as AppKit),
along with a suite of supporting frameworks, including Core Animation and Core Image ,
which add all sorts of cool stuff to Cocoa.
The Foundation framework handles features found in the layers beneath the user interface,
such as data structures and communication mechanisms. All the programs in this book are
based on the Foundation framework.
------------------
NOTE
Once you finish this book, your next step along the road to becoming a Cocoa guru is to master Cocoa’s
Application Kit, which contains Cocoa’s high- level features: user interface elements, printing, color and
sound management, AppleScript support, and so on. To find out more, check out Learn Cocoa on the Mac by
Dave Mark and Jeff LaMarche (Apress 2009).
Each framework is a significant collection of technology, often containing dozens or even
hundreds of header files. Each framework has a master header file that includes all the
framework’s individual header files. By using #import on the master header file, you have
access to all the framework’s features.
The header files for the Foundation framework take up nearly a megabyte of disk storage,
and contain more than 14,000 lines of code, spread across over a hundred files. When you
include the master header file with #import <Foundation/Foundation.h>, you get that
whole vast collection. You might think wading through all that text for every file would take
the compiler a lot of time, but Xcode is smart: it speeds up the task by using precompiled
headers, a compressed and digested form of the header that’s loaded quickly when you
#import it.
If you’re curious about which headers are included with the Foundation framework, you
can peek inside its Headers directory ( /System/Library/Frameworks/Foundation.framework/
Headers/). You won’t break anything if you browse the files in there; just don’t remove or
change anything.
NSLog() and @”strings”
Now that we have used #import on the master header file for the Foundation framework,
you’re ready to write code that takes advantage of some Cocoa features. The first (and only)
real line of code in Hello Objective- C uses the NSLog() function, like so:
NSLog (@"Hello, Objective- C!");
This prints “Hello, Objective- C!” to the console. If you’ve used C at all, you have undoubtedly
encountered printf() in your travels. NSLog() is a Cocoa function that works very much like
printf() .
Just like printf() , NSLog()takes a string as its first argument. This string can contain format
specifiers (such as %d), and the function takes additional parameters that match the format
specifiers. printf() plugs these extra parameters into the string before it gets printed.
As we’ve said before, Objective- C is just C with a little bit of special sauce, so you’re wel -
come to use printf() instead of NSLog() if you want. We recommend NSLog(), however,
because it adds features such as time and date stamps, as well as automatically appending
the newline ( ‘\n’) character for you.
You might be thinking that NSLog() is kind of a strange name for a function. What is that
“NS” doing there? It turns out that Cocoa prefixes all its function, constant, and type names
with “NS”. This prefix tells you the function comes from Cocoa instead of some other toolkit.
The prefix helps prevent name collisions , big problems that result when the same identi -
fier is used for two different things. If Cocoa had named this function Log(), there’s a good
chance the name would clash with a Log() function created by some innocent programmer
somewhere. When a program containing Log() is built with Cocoa included, Xcode com -
plains that Log() is defined multiple times, and sadness results.
Now that you have an idea why a prefix is a good idea, you might wonder about the specific
choice: why “NS” instead of “Cocoa,” for example? Well, the “NS” prefix dates back from the
time when the toolkit was called NextSTEP and was the product of NeXT Software (formerly
NeXT, Inc.), which was acquired by Apple in 1996. Rather than break compatibility with code
already written for NextSTEP, Apple just continued to use the “NS” prefix. It’s a historical curi -
osity now, like your appendix.
Cocoa has staked its claim on the NS prefix, so obviously, you should not prefix any of your
own variables or function names with “NS”. If you do, you will confuse the readers of your
code, making them think your stuff actually belongs to Cocoa. Also, your code might break
in the future if Apple happens to add a function to Cocoa with the same name as yours.
There is no centralized prefix registry, so you can pick your own prefix. Many people prefix
names with their initials or company names. To make our examples a little simpler, we won’t
use a prefix for the code in this book.
Let’s take another look at that NSLog() statement:
NSLog (@"Hello, Objective- C!");
Did you notice the at sign before the string? It’s not a typo that made it past our vigilant edi -
tors. The at sign is one of the features that Objective- C adds to standard C. A string in double
quotes preceded by an at sign means that the quoted string should be treated as a Cocoa
NSString element.
So what’s an NSString element? Peel the “NS” prefix off the name and you see a familiar term:
“String”. You already know that a string is a sequence of characters, usually human- readable, so
you can probably guess (correctly) that an NSString is a sequence of characters in Cocoa.
Đăng ký:
Bài đăng (Atom)