- 浏览: 2477699 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Android Introduce(I)concepts and NoteBook example
1. Open Handset Alliance
Consist of the system
View----->lists, grids, text boxes, buttons, web browser
Content Providers-----> access to other applications(for example, contact database)
Resource Manager----->
Notification Manager----->
Activity Manager ----->
Application lib
System C -----> libc for embedded linux
Media lib -----> MPEG4, H.264, MP3, AAC, AMR, JPG, PNG
Surface Manager ---->
LibWebCore -----> Web browser engine
SGL ------> 2D
3D libraries ----> 3D
FreeType -------> bitmap and vector
SQLite -----> database engine
Dalvik ----> .dex
2. Build Android Envirenment
3. Application Analytic
Activity
Sometimes one activity means one screen. One activity is one class which extends from base activity
(android.app.Activity). There are data send/receive between 2 screens/activities.
Intent
Action and Data.
Action: MAIN, VIEW, PICK, EDIT
Intent ------> IntentFilter ------> IntentReceiver
IntentReceiver
Service
Without activity, it will run in the system. Context.startService().
Content Provider
Share the data among in different applications
4. Dalvik Virtual Machine
android.app ---------->runtime envirement
android.content--------->access and publish the data
android.database------>db
android.graphics--------> diagram lib, point, line and others, draw them on screen
android.location -------->
android.media -----------> music, video
android.net ---------------->
android.os -----------------> system service, message transfer, IPC
android.opengl ---------> OpenGL tool
android.provider -------> content provider
android.telephony ----->
android.view --------------> look and feel
android.util ----------------> date and time util
android.webkit ---------->
android.widget ----------> UI
Java file ------> Class -------> Dex ------> apk
5. Android Source Codes HelloActivity
AndroidManifest.xml configuration file
layout/main.xml setContentView(R.layout.main);
values/strings.xml android:text="@string/hello"
R.java gen from the xml files under res
content of main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
</LinearLayout>
steps in java sources:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//create the UI with codes
//TextView tv = new TextView(this);
//tv.setText("This is test about say hello to Carl!");
//setContentView(tv);
//create the UI with the help of XML file
setContentView(R.layout.main);
}
6. Priority of threads
front thread
Activities are using.
visual thread
for example, pause activity
service thread
backend thread
unvisual activity
empty thread
7. Get more steps on the HelloActivity, try to write a Note book
get the sample codes from here
http://www.chinaup.org/docs/intro/codelab/NotepadCodeLab.zip
Reading the code of Notepadv1
public class Notepadv1 extends ListActivity {
public void onCreate(Bundle savedInstanceState); //load the activity, show the page
public boolean onCreateOptionsMenu(Menu menu); //draw the menu
public boolean onOptionsItemSelected(MenuItem item);// menu was clicked
}
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS notes");
onCreate(db);
}
}
Reading the code of Notepadv2
public class Notepadv2 extends ListActivity {
//use intent to communicate with another activity
private void createNote() {
Intent i = new Intent(this, NoteEdit.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
//send extra message to another activity
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Cursor c = mNotesCursor;
c.moveToPosition(position);
Intent i = new Intent(this, NoteEdit.class);
i.putExtra(NotesDbAdapter.KEY_ROWID, id);
i.putExtra(NotesDbAdapter.KEY_TITLE, c.getString(
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
i.putExtra(NotesDbAdapter.KEY_BODY, c.getString(
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
startActivityForResult(i, ACTIVITY_EDIT);
}
//get the message back from Bundle
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
Bundle extras = intent.getExtras();
switch(requestCode) {
case ACTIVITY_CREATE:
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
String body = extras.getString(NotesDbAdapter.KEY_BODY);
mDbHelper.createNote(title, body);
fillData();
break;
case ACTIVITY_EDIT:
Long rowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
if (rowId != null) {
String editTitle = extras.getString(NotesDbAdapter.KEY_TITLE);
String editBody = extras.getString(NotesDbAdapter.KEY_BODY);
mDbHelper.updateNote(rowId, editTitle, editBody);
}
fillData();
break;
}
}
}
public class NoteEdit extends Activity {
protected void onCreate(Bundle savedInstanceState) {
...snip...
mTitleText = (EditText) findViewById(R.id.title);
mBodyText = (EditText) findViewById(R.id.body);
Button confirmButton = (Button) findViewById(R.id.confirm);
mRowId = null;
Bundle extras = getIntent().getExtras();
if (extras != null) {
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
String body = extras.getString(NotesDbAdapter.KEY_BODY);
mRowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
if (title != null) {
mTitleText.setText(title);
}
if (body != null) {
mBodyText.setText(body);
}
}
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Bundle bundle = new Bundle();
bundle.putString(NotesDbAdapter.KEY_TITLE, mTitleText.getText().toString());
bundle.putString(NotesDbAdapter.KEY_BODY, mBodyText.getText().toString());
if (mRowId != null) {
bundle.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
}
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
}
});
}
}
Reading the code of Notepadv3
Only send the id of the data, move the createNote database functions to NoteEdit.java
public class Notepadv3 extends ListActivity {
...snip...
private void createNote() {
Intent i = new Intent(this, NoteEdit.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(this, NoteEdit.class);
i.putExtra(NotesDbAdapter.KEY_ROWID, id);
startActivityForResult(i, ACTIVITY_EDIT);
}
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
fillData();
}
...snip...
}
public class NoteEdit extends Activity {
...snip...
mTitleText = (EditText) findViewById(R.id.title);
mBodyText = (EditText) findViewById(R.id.body);
Button confirmButton = (Button) findViewById(R.id.confirm);
mRowId = savedInstanceState != null ? savedInstanceState.getLong(NotesDbAdapter.KEY_ROWID)
: null;
if (mRowId == null) {
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID) : null;
}
populateFields();
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
setResult(RESULT_OK);
finish();
}
});
}
private void populateFields() {
if (mRowId != null) {
Cursor note = mDbHelper.fetchNote(mRowId);
startManagingCursor(note);
mTitleText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
mBodyText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
}
}
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
}
protected void onPause() {
super.onPause();
saveState();
}
protected void onResume() {
super.onResume();
populateFields();
}
...snip...
}
1. Open Handset Alliance
Consist of the system
View----->lists, grids, text boxes, buttons, web browser
Content Providers-----> access to other applications(for example, contact database)
Resource Manager----->
Notification Manager----->
Activity Manager ----->
Application lib
System C -----> libc for embedded linux
Media lib -----> MPEG4, H.264, MP3, AAC, AMR, JPG, PNG
Surface Manager ---->
LibWebCore -----> Web browser engine
SGL ------> 2D
3D libraries ----> 3D
FreeType -------> bitmap and vector
SQLite -----> database engine
Dalvik ----> .dex
2. Build Android Envirenment
3. Application Analytic
Activity
Sometimes one activity means one screen. One activity is one class which extends from base activity
(android.app.Activity). There are data send/receive between 2 screens/activities.
Intent
Action and Data.
Action: MAIN, VIEW, PICK, EDIT
Intent ------> IntentFilter ------> IntentReceiver
IntentReceiver
Service
Without activity, it will run in the system. Context.startService().
Content Provider
Share the data among in different applications
4. Dalvik Virtual Machine
android.app ---------->runtime envirement
android.content--------->access and publish the data
android.database------>db
android.graphics--------> diagram lib, point, line and others, draw them on screen
android.location -------->
android.media -----------> music, video
android.net ---------------->
android.os -----------------> system service, message transfer, IPC
android.opengl ---------> OpenGL tool
android.provider -------> content provider
android.telephony ----->
android.view --------------> look and feel
android.util ----------------> date and time util
android.webkit ---------->
android.widget ----------> UI
Java file ------> Class -------> Dex ------> apk
5. Android Source Codes HelloActivity
AndroidManifest.xml configuration file
layout/main.xml setContentView(R.layout.main);
values/strings.xml android:text="@string/hello"
R.java gen from the xml files under res
content of main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
</LinearLayout>
steps in java sources:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//create the UI with codes
//TextView tv = new TextView(this);
//tv.setText("This is test about say hello to Carl!");
//setContentView(tv);
//create the UI with the help of XML file
setContentView(R.layout.main);
}
6. Priority of threads
front thread
Activities are using.
visual thread
for example, pause activity
service thread
backend thread
unvisual activity
empty thread
7. Get more steps on the HelloActivity, try to write a Note book
get the sample codes from here
http://www.chinaup.org/docs/intro/codelab/NotepadCodeLab.zip
Reading the code of Notepadv1
public class Notepadv1 extends ListActivity {
public void onCreate(Bundle savedInstanceState); //load the activity, show the page
public boolean onCreateOptionsMenu(Menu menu); //draw the menu
public boolean onOptionsItemSelected(MenuItem item);// menu was clicked
}
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS notes");
onCreate(db);
}
}
Reading the code of Notepadv2
public class Notepadv2 extends ListActivity {
//use intent to communicate with another activity
private void createNote() {
Intent i = new Intent(this, NoteEdit.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
//send extra message to another activity
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Cursor c = mNotesCursor;
c.moveToPosition(position);
Intent i = new Intent(this, NoteEdit.class);
i.putExtra(NotesDbAdapter.KEY_ROWID, id);
i.putExtra(NotesDbAdapter.KEY_TITLE, c.getString(
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
i.putExtra(NotesDbAdapter.KEY_BODY, c.getString(
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
startActivityForResult(i, ACTIVITY_EDIT);
}
//get the message back from Bundle
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
Bundle extras = intent.getExtras();
switch(requestCode) {
case ACTIVITY_CREATE:
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
String body = extras.getString(NotesDbAdapter.KEY_BODY);
mDbHelper.createNote(title, body);
fillData();
break;
case ACTIVITY_EDIT:
Long rowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
if (rowId != null) {
String editTitle = extras.getString(NotesDbAdapter.KEY_TITLE);
String editBody = extras.getString(NotesDbAdapter.KEY_BODY);
mDbHelper.updateNote(rowId, editTitle, editBody);
}
fillData();
break;
}
}
}
public class NoteEdit extends Activity {
protected void onCreate(Bundle savedInstanceState) {
...snip...
mTitleText = (EditText) findViewById(R.id.title);
mBodyText = (EditText) findViewById(R.id.body);
Button confirmButton = (Button) findViewById(R.id.confirm);
mRowId = null;
Bundle extras = getIntent().getExtras();
if (extras != null) {
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
String body = extras.getString(NotesDbAdapter.KEY_BODY);
mRowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
if (title != null) {
mTitleText.setText(title);
}
if (body != null) {
mBodyText.setText(body);
}
}
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Bundle bundle = new Bundle();
bundle.putString(NotesDbAdapter.KEY_TITLE, mTitleText.getText().toString());
bundle.putString(NotesDbAdapter.KEY_BODY, mBodyText.getText().toString());
if (mRowId != null) {
bundle.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
}
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
}
});
}
}
Reading the code of Notepadv3
Only send the id of the data, move the createNote database functions to NoteEdit.java
public class Notepadv3 extends ListActivity {
...snip...
private void createNote() {
Intent i = new Intent(this, NoteEdit.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(this, NoteEdit.class);
i.putExtra(NotesDbAdapter.KEY_ROWID, id);
startActivityForResult(i, ACTIVITY_EDIT);
}
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
fillData();
}
...snip...
}
public class NoteEdit extends Activity {
...snip...
mTitleText = (EditText) findViewById(R.id.title);
mBodyText = (EditText) findViewById(R.id.body);
Button confirmButton = (Button) findViewById(R.id.confirm);
mRowId = savedInstanceState != null ? savedInstanceState.getLong(NotesDbAdapter.KEY_ROWID)
: null;
if (mRowId == null) {
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID) : null;
}
populateFields();
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
setResult(RESULT_OK);
finish();
}
});
}
private void populateFields() {
if (mRowId != null) {
Cursor note = mDbHelper.fetchNote(mRowId);
startManagingCursor(note);
mTitleText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
mBodyText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
}
}
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
}
protected void onPause() {
super.onPause();
saveState();
}
protected void onResume() {
super.onResume();
populateFields();
}
...snip...
}
发表评论
-
ionic UI(4)ionic2 framework - basic and components and native
2016-03-24 02:33 1218ionic UI(4)ionic2 framework - b ... -
ionic UI(3)TypeScript - handbook
2016-03-22 23:21 586ionic UI(3)TypeScript - handboo ... -
ionic UI(2)ionic2 framework - TypeScript - tutorial
2016-03-22 06:52 1616ionic UI(2)ionic2 framework - T ... -
Parse and Heroku Service(3)Parse Server and Parse Dashboard
2016-03-22 06:30 937Parse and Heroku Service(3)Pars ... -
Parse and Heroku Service(2)Mail Templates and Push Notification
2016-03-22 02:45 536Parse and Heroku Service(2)Mail ... -
ionic UI(1)Introduction
2016-03-19 03:18 672ionic UI(1)Introduction 1 Inst ... -
Parse and Heroku Service(1)Heroku Installation and Play
2016-03-19 00:13 782Parse and Heroic Service(1)Hero ... -
Hybrid(5)Customize Meteor Directly Google Login
2015-09-01 02:33 880Hybrid(5)Customize Meteor Direc ... -
Hybrid(4)Favorite Places - Google Login
2015-09-01 02:02 1292Hybrid(4)Favorite Places - Goog ... -
Hybrid(3)More Meteor Example - Social
2015-08-11 05:04 722Hybrid(3)More Meteor Example - ... -
Hybrid(2)meteor Running Android and iOS
2015-07-28 23:59 1000Hybrid(2)meteor Running Android ... -
Create the Google Play Account
2015-07-18 06:42 1049Create the Google Play Account ... -
Secure REST API and Mobile(1)Document Read and Understand OAUTH2
2015-07-14 00:36 722Secure REST API and Mobile(1)Do ... -
Screen Size and Web Design
2015-07-11 01:11 686Screen Size and Web Design iPh ... -
Hybrid(1)ionic Cordova meteor
2015-06-25 05:49 425Hybrid(1)ionic Cordova meteor ... -
Android Fire Project(1)Recall Env and Knowledge
2015-02-11 12:28 644Android Fire Project(1)Recall ... -
Android Content Framework(1)Concept
2014-06-14 13:54 1043Android Content Framework(1)Con ... -
Feel Android Studio(1)Install and Update Android Studio
2014-04-11 03:12 1966Feel Android Studio(1)Install a ... -
IOS7 App Development Essentials(2)iBeacon
2014-03-05 05:55 842IOS7 App Development Essentials ... -
IOS7 App Development Essentials(1) Persistent Store
2014-03-05 05:54 1272IOS7 App Development Essentials ...
相关推荐
This book teaches both core Java language concepts and how to wisely but rapidly employ the design patterns and logic using the Android SDK, which is based on Java APIs. You'll also learn best ...
Android RIL introduce
Several example projects within this book introduce you to using the GPIO, SPI, and I2C hardware interfaces of the BeagleBone Black. You'll create Android apps that communicate directly with actual ...
Programming Concepts in C++ is one in a series of books that introduce the basic concepts of computer programming, using a selected programming language. Other books in the series use languages like ...
Introduce the concepts and principles of Spin
Lastly, we'll introduce a set of Android tools that help you debug and profile your apps. Unit 2, Project Framework, discusses the storyline and framework of your first game Raccoon Rob. You'll be ...
This book is for Android developers who want to learn how to build multithreaded and reliable Android applications using high-level and advanced asynchronous techniques and concepts. What You Will ...
We will introduce you to all the fundamental concepts of programming in an Android context, from the Java basics to working with the Android API. All examples are created from within Android Studio, ...
里面介绍了PD方案和在实际中应用说明,及遇到的问题,解决方法,里面有市场上主流IC的介绍,供各工程技术人员学习和参考。
These chapters introduce the MonoTouch product, the basics of developing with MonoTouch and MonoDevelop, and finally, the basics of presenting data to a user with screen and data controls and how to ...
Android 开放手机联盟(OHA介绍)
If you are looking to automate Excel routine tasks, this book will progressively introduce you to programming concepts via numerous, illustrated, hands-on exercises. Includes a comprehensive disc ...
Professional iPhone® Programming with monotouch and .net/c# ...these concepts, you can typically move from one chapter to another and not necessarily have to read the chapters sequentially.
This paper examines an open ... Additionally, I introduce Open Source infrastructure which not only supports development, but also has the potential to become a main business activity in the future.
The central chapters of the book introduce, explain, and demonstrate the elements of the theory that are most important for building simulation tools. They are bracketed by applications to robotics, ...
As each language is presented, the authors introduce new concepts as they appear, and revisit familiar ones, comparing their implementation with those from languages seen in prior chapters....
The OP Amp. Introduce and Applications
Green Coffee Green Coffee is a library that allows you to run your acceptance tests written in Gherkin in your Android instrumentation tests using the step ... And I introduce an invalid password
IR Remote Control introduce and protocol
Fresh writing filled with many fun examples that introduce you to game programming concepts and implementation with XNA 4.0 A practical beginner’s guide with a fast-paced but friendly and engaging ...