When Updating ADT in Eclipse, I get the problem.
At last I found that it is due to admin right program in Windows 7. I need to run Eclipse as administrator in order to successfully upgated ADT in Eclipse.
Android Programming Tips
I am learning Android Programming. So I drop down what I have learned.
2012年11月21日 星期三
Check Time for the program
long count = System.currentTimeMillis();
:
: // Your code to measure time
:
count = System.currentTimeMillis() - count;
Log.d("Graph draw","Time (ms): " + count);
2012年11月12日 星期一
Android Buld-in Content Providers
http://developer.android.com/reference/android/provider/package-summary.html
Here are a few of the providers listed on that documentation page:
Browser
CallLog
Contacts
People
Phones
Photos
Groups
MediaStore
Audio
Albums
Artists
Genres
Playlists
Images
Thumbnails
Video
Settings
Here are a few of the providers listed on that documentation page:
Browser
CallLog
Contacts
People
Phones
Photos
Groups
MediaStore
Audio
Albums
Artists
Genres
Playlists
Images
Thumbnails
Video
Settings
Android Resources Directory
/res/values/strings.xml
/colors.xml
/dimens.xml
/attrs.xml
/styles.xml
/drawable/*.png
/*.jpg
/*.gif
/*.9.png
/anim/*.xml
/layout/*.xml
/raw/*.*
/xml/*.xml
/assets/*.*/*.*
mccAAA: AAA is the mobile country code
mncAAA: AAA is the carrier/network code
en-rUS: Language and region
small, normal, large, xlarge: Screen size
long, notlong: Screen type
port, land: Portrait or landscape
car, desk: Type of docking
night, notnight: Night or day
ldpi, mdpi, hdpi, xhdpi, nodpi: Screen density
notouch, stylus, finger: What kind of screen
keysexposed, keyssoft, keyshidden: What kind of keyboard
nokeys, qwerty, 12key: How many keys
navexposed, navhidden: Navigation keys hidden or exposed
nonav, dpad, trackball, wheel: The type of navigation device
v3, v4, v7: API level
\res\layout
\res\layout-port
\res\layout-land
\res\layout-en
\res\layout-mcc312-mnc222-en-rUS
\res\layout-ldpi
\res\layout-hdpi
\res\layout-car
/colors.xml
/dimens.xml
/attrs.xml
/styles.xml
/drawable/*.png
/*.jpg
/*.gif
/*.9.png
/anim/*.xml
/layout/*.xml
/raw/*.*
/xml/*.xml
/assets/*.*/*.*
mccAAA: AAA is the mobile country code
mncAAA: AAA is the carrier/network code
en-rUS: Language and region
small, normal, large, xlarge: Screen size
long, notlong: Screen type
port, land: Portrait or landscape
car, desk: Type of docking
night, notnight: Night or day
ldpi, mdpi, hdpi, xhdpi, nodpi: Screen density
notouch, stylus, finger: What kind of screen
keysexposed, keyssoft, keyshidden: What kind of keyboard
nokeys, qwerty, 12key: How many keys
navexposed, navhidden: Navigation keys hidden or exposed
nonav, dpad, trackball, wheel: The type of navigation device
v3, v4, v7: API level
\res\layout
\res\layout-port
\res\layout-land
\res\layout-en
\res\layout-mcc312-mnc222-en-rUS
\res\layout-ldpi
\res\layout-hdpi
\res\layout-car
Android Assets
Android offers one more directory where you can keep files to be included in the package: /assets. It’s at the same level as /res, meaning it’s not part of the /res subdirectories. The files in /assets do not generate IDs in R.java; you must specify the file path to read them. The file path is a relative path starting at /assets.
String getStringFromAssetFile(Activity activity) {
AssetManager am = activity.getAssets();
InputStream is = am.open("test.txt");
String s = convertStreamToString(is);
is.close();
return s;
}
String getStringFromAssetFile(Activity activity) {
AssetManager am = activity.getAssets();
InputStream is = am.open("test.txt");
String s = convertStreamToString(is);
is.close();
return s;
}
Android Resources - RAW
Android also allows raw files in addition to arbitrary XML files. These raw resources, placed in /res/raw, are raw file resources such as audio, video, or text files that require localization or references through resource IDs.
String getStringFromRawFile(Activity activity)
throws IOException {
Resources r = activity.getResources();
InputStream is = r.openRawResource(R.raw.test);
String myText = convertStreamToString(is);
is.close();
return myText;
}
String convertStreamToString(InputStream is)
throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = is.read();
while (i != -1) {
baos.write(i);
i = is.read();
}
return baos.toString()
}
String getStringFromRawFile(Activity activity)
throws IOException {
Resources r = activity.getResources();
InputStream is = r.openRawResource(R.raw.test);
String myText = convertStreamToString(is);
is.close();
return myText;
}
String convertStreamToString(InputStream is)
throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = is.read();
while (i != -1) {
baos.write(i);
i = is.read();
}
return baos.toString()
}
Android Resources - Arbitrary XML
Android allows arbitrary XML files as resources.
XML files that need to be read in this fashion are stored under the /res/xml subdirectory.
<rootelem1>
<subelem1>
Hello World from an xml sub element
</subelem1>
</rootelem1>
Resources res = activity.getResources();
XmlResourceParser xpp = res.getXml(R.xml.test);
private String getEventsFromAnXMLFile(Activity activity)
throws XmlPullParserException, IOException {
StringBuffer sb = new StringBuffer();
Resources res = activity.getResources();
XmlResourceParser xpp = res.getXml(R.xml.test);
xpp.next();
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
sb.append("******Start document");
}
else if(eventType == XmlPullParser.START_TAG) {
sb.append("\nStart tag "+xpp.getName());
}
else if(eventType == XmlPullParser.END_TAG) {
sb.append("\nEnd tag "+xpp.getName());
}
else if(eventType == XmlPullParser.TEXT) {
sb.append("\nText "+xpp.getText());
}
eventType = xpp.next();
}//eof-while
sb.append("\n******End document");
return sb.toString();
}//eof-function
XML files that need to be read in this fashion are stored under the /res/xml subdirectory.
<rootelem1>
<subelem1>
Hello World from an xml sub element
</subelem1>
</rootelem1>
Resources res = activity.getResources();
XmlResourceParser xpp = res.getXml(R.xml.test);
private String getEventsFromAnXMLFile(Activity activity)
throws XmlPullParserException, IOException {
StringBuffer sb = new StringBuffer();
Resources res = activity.getResources();
XmlResourceParser xpp = res.getXml(R.xml.test);
xpp.next();
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
sb.append("******Start document");
}
else if(eventType == XmlPullParser.START_TAG) {
sb.append("\nStart tag "+xpp.getName());
}
else if(eventType == XmlPullParser.END_TAG) {
sb.append("\nEnd tag "+xpp.getName());
}
else if(eventType == XmlPullParser.TEXT) {
sb.append("\nText "+xpp.getText());
}
eventType = xpp.next();
}//eof-while
sb.append("\n******End document");
return sb.toString();
}//eof-function
訂閱:
文章 (Atom)