Mark Murphy - Beginning Android

Здесь есть возможность читать онлайн «Mark Murphy - Beginning Android» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: New York, Год выпуска: 2009, ISBN: 2009, Издательство: Apress, Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Beginning Android: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Beginning Android»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Master Android from first principles and begin the journey toward your own successful Android applications!
Dear Reader,
First, welcome to the world of Android! We’re entering a new era of mobile application development, one marked by open platforms and open source, to take ‘walled gardens’ and make them green houses for any and all to participate in. Android is relatively easy for developers, and I believe that this innovation will help generate a large ecosystem of developers and consumers within a very short time. This means that budding developers such as yourself will have many opportunities to design and build your own applications and you’ll have a huge and hungry customer base.
Second, welcome to the book! Its purpose is to start you on your way with building Android applications, and to help you master the learning curve. Android is already a rich framework, comparable in many ways to the richness Android of desktop Java environments. This means that there is a lot of cool stuff for you to pick up along your journey in order to create the slickest, most useful apps Android you can imagine.
The source code for the code samples in this book is all available from the Apress site, so you can stay as hands-on and practical as you like while I introduce you to the core of Android, and invite you to experiment with the various classes and APIs we’ll be looking at. By the time you’ve finished this book, you’ll be creating your own Android applications and asking yourself what your next great application will be…!
Enjoy! Mark Murphy

Beginning Android — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Beginning Android», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

• A Stringrepresenting what amounts to a SQL ORDER BYclause

You are responsible for interpreting these parameters however they make sense and returning a Cursorthat can be used to iterate over and access the data.

As you can imagine, these parameters are aimed toward people using a SQLite database for storage. You are welcome to ignore some of these parameters (e.g., you can elect not to try to roll your own SQL WHERE-clause parser), but you need to document that fact so activities attempt to query you only by instance Uri and not using parameters you elect not to handle.

For SQLite-backed storage providers, however, the query()method implementation should be largely boilerplate. Use a SQLiteQueryBuilderto convert the various parameters into a single SQL statement, then use query()on the builder to actually invoke the query and give you a Cursorback. The Cursoris what your query()method then returns.

For example, here is query()from Provider:

@Override

publicCursor query(Uri url, String[] projection, String selection,

String[] selectionArgs, String sort) {

SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

qb. setTables( getTableName());

if( isCollectionUri(url)) {

qb. setProjectionMap( getDefaultProjection());

} else{

qb. appendWhere( getIdColumnName()+"="+url. getPathSegments(). get(1));

}

String orderBy;

if(TextUtils. isEmpty(sort)) {

orderBy = getDefaultSortOrder();

} else{

orderBy = sort;

}

Cursor c = qb. query(db, projection, selection, selectionArgs,

null, null, orderBy);

c. setNotificationUri( getContext(). getContentResolver(), url);

returnc;

}

We create a SQLiteQueryBuilderand pour the query details into the builder. Note that the query could be based on either a collection or an instance Uri— in the latter case, we need to add the instance ID to the query. When done, we use the query()method on the builder to get a Cursorfor the results.

insert()

Your insert()method will receive a Urirepresenting the collection and a ContentValuesstructure with the initial data for the new instance. You are responsible for creating the new instance, filling in the supplied data, and returning a Urito the new instance.

If this is a SQLite-backed content provider, once again, the implementation is mostly boilerplate: validate that all required values were supplied by the activity, merge your own notion of default values with the supplied data, and call insert()on the database to actually create the instance.

For example, here is insert()from Provider:

@Override

publicUri insert(Uri url, ContentValues initialValues) {

long rowID;

ContentValues values;

if(initialValues!= null) {

values = new ContentValues(initialValues);

} else{

values = new ContentValues();

}

if(! isCollectionUri(url)) {

throw new IllegalArgumentException("Unknown URL " + url);

}

for(String colName : getRequiredColumns()) {

if(values. containsKey(colName) == false) {

throw new IllegalArgumentException("Missing column: " + colName);

}

}

populateDefaultValues(values);

rowID = db. insert( getTableName(), getNullColumnHack(), values);

if(rowID > 0) {

Uri uri = ContentUris. withAppendedId( getContentUri(), rowID);

getContext(). getContentResolver(). notifyChange(uri, null);

returnuri;

}

throw new SQLException("Failed to insert row into " + url);

}

The pattern is the same as before: use the provider particulars plus the data to be inserted to actually do the insertion. Please note the following:

• You can insert only into a collection Uri, so we validate that by calling isCollectionUri().

• The provider knows what columns are required ( getRequiredColumns()), so we iterate over those and confirm our supplied values cover the requirements.

• The provider is responsible for filling in any default values ( populateDefaultValues()) for columns not supplied in the insert()call and not automatically handled by the SQLite table definition.

update()

Your update()method gets the Uriof the instance or collection to change, a ContentValuesstructure with the new values to apply, a Stringfor a SQL WHEREclause, and a String[]with parameters to use to replace ?found in the WHEREclause. Your responsibility is to identify the instance(s) to be modified (based on the Uriand WHEREclause), then replace those instances’ current property values with the ones supplied.

This will be annoying unless you’re using SQLite for storage. Then you can pretty much pass all the parameters you received to the update()call to the database, though the update()call will vary slightly depending on whether you are updating one instance or several.

For example, here is update()from Provider:

@Override

publicint update(Uri url, ContentValues values, String where,

String[] whereArgs) {

int count;

if( isCollectionUri(url)) {

count = db. update( getTableName(), values, where, whereArgs);

} else{

String segment = url. getPathSegments(). get(1);

count = db. update( getTableName(), values, getIdColumnName() + "="

+ segment + (!TextUtils. isEmpty(where) ? " AND (" + where + ')' : ""),

whereArgs);

}

getContext(). getContentResolver(). notifyChange(url, null);

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Beginning Android»

Представляем Вашему вниманию похожие книги на «Beginning Android» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Beginning Android»

Обсуждение, отзывы о книге «Beginning Android» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x