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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

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

Интервал:

Закладка:

Сделать

}

}

As you can see, we are using TabActivityas the base class, and so we do not need our own layout XML — TabActivitysupplies it for us. All we do is get access to the TabHostand add two tabs, each specifying an Intent that directly refers to another class. In this case, our two tabs will host a CWBrowserand an AndroidBrowser, respectively.

Those activities are simple modifications to the earlier browser demos:

public classCWBrowser extendsActivity {

WebView browser;

@Override

publicvoid onCreate(Bundle icicle) {

super. onCreate(icicle);

browser = new WebView( this);

setContentView(browser);

browser. loadUrl("http://commonsware.com");

}

}

public classAndroidBrowser extendsActivity {

WebView browser;

@Override

publicvoid onCreate(Bundle icicle) {

super. onCreate(icicle);

browser = new WebView( this);

setContentView(browser);

browser. loadUrl("http://code.google.com/android");

}

}

They simply load a different URL into the browser: the CommonsWare home page in one (Figure 24-3), the Android home page in the other (Figure 24-4). The resulting UI shows what tabbed browsing could look like on Android.

Figure 243 The IntentTabDemo sample application showing the first tab - фото 75

Figure 24-3. The IntentTabDemo sample application, showing the first tab

Figure 244 The IntentTabDemo sample application showing the second tab - фото 76

Figure 24-4. The IntentTabDemo sample application, showing the second tab

Using distinct subclasses for each targeted page is rather wasteful. Instead we could have packaged the URL to open as an “extra” in an Intentand used that Intentto spawn a general-purpose BrowserTabactivity, which would read the URL out of the Intent“extra,” and use that. The proof of this is left as an exercise for the reader.

CHAPTER 25

Finding Available Actions via Introspection

Sometimes you know just what you want to do, such as display one of your other activities. Sometimes, you have a pretty good idea of what you want to do, such as view the content represented by a Uri, or have the user pick a piece of content of some MIME type. Sometimes you’re lost. All you have is a content Uri, and you don’t really know what you can do with it.

For example, suppose you were creating a common tagging sub-system for Android, where users could tag pieces of content — contacts, Web URLs, geographic locations, etc. Your sub-system would hold onto the Uriof the content plus the associated tags, so other sub-systems could, say, ask for all pieces of content referencing some tag.

That’s all well and good. However, you probably need some sort of maintenance activity, where users could view all their tags and the pieces of content so tagged. This might even serve as a quasi-bookmark service for items on their phone. The problem is, the user is going to expect to be able to do useful things with the content they find in your sub-system, such as dial a contact or show a map for a location.

The problem is, you have absolutely no idea what is possible with any given content Uri. You probably can view any of them, but can you edit them? Can you dial them? Since new applications with new types of content could be added by any user at any time, you can’t even assume you know all possible combinations just by looking at the stock applications shipped on all Android devices.

Fortunately, the Android developers thought of this.

Android offers various means by which you can present to your users a set of likely activities to spawn for a given content Uri— even if you have no idea what that content Urireally represents. This chapter explores some of these Uriaction introspection tools.

Pick ’Em

Sometimes you know your content Urirepresents a collection of some type, such as content://contacts/peoplerepresenting the list of contacts in the stock Android contacts list. In this case, you can let the user pick a contact that your activity can then use (e.g., tag it, dial it).

To do this, you need to create an Intent for the ACTION_PICKon the target Uri, then start a sub-activity (via startActivityForResult()) to allow the user to pick a piece of content of the specified type. If your onActivityResult()callback for this request gets a RESULT_OKresult code, your data string can be parsed into a Urirepresenting the chosen piece of content.

For example, take a look at Introspection/Pickin the sample applications in the Source Code section of http://apress.com. This activity gives you a field for a collection Uri(with content://contacts/peoplepre-filled in for your convenience), plus a really big Gimme! button:

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:cursorVisible="true"

android:editable="true"

android:singleLine="true"

android:text="content://contacts/people"

/>

android:id="@+id/pick"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:text="Gimme!"

android:layout_weight="1"

/>

Upon being clicked, the button creates the ACTION_PICKon the user-supplied collection Uriand starts the sub-activity. When that sub-activity completes with RESULT_OK, the ACTION_VIEWis invoked on the resulting content Uri.

public classPickDemo extendsActivity {

static finalint PICK_REQUEST = 1337;

privateEditText type;

@Override

publicvoid onCreate(Bundle icicle) {

super. onCreate(icicle);

setContentView(R.layout.main);

type = (EditText) findViewById(R.id.type);

Button btn = (Button) findViewById(R.id.pick);

btn. setOnClickListener( newView. OnClickListener() {

publicvoid onClick(View view) {

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

Интервал:

Закладка:

Сделать

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

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


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

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

x