Made XmlAdapter sample a standalone application.

Change-Id: If34f2086da65f81968f630a42e4b9e725cb65efe
This commit is contained in:
Gilles Debunne
2011-01-06 18:21:18 -08:00
parent 010c2d5761
commit 3fc9318ce5
13 changed files with 1345 additions and 32 deletions

View File

@@ -6,12 +6,11 @@ LOCAL_MODULE_TAGS := samples
# Only compile source java files in this apk. # Only compile source java files in this apk.
LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := XmlAdaptersSample LOCAL_PACKAGE_NAME := xmladapters
LOCAL_PROGUARD_ENABLED := disabled LOCAL_PROGUARD_ENABLED := disabled
# XXX These APIs are not yet available in the platform. include $(BUILD_PACKAGE)
#include $(BUILD_PACKAGE)
# Use the following include to make our test apk. # Use the following include to make our test apk.
#include $(call all-makefiles-under,$(LOCAL_PATH)) #include $(call all-makefiles-under,$(LOCAL_PATH))

Binary file not shown.

After

Width:  |  Height:  |  Size: 1003 B

View File

@@ -19,7 +19,6 @@
<ListView <ListView
android:id="@android:id/list" android:id="@android:id/list"
android:adapter="@xml/contacts"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />

View File

@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<!-- Adapter used to bind cursors. -->
<declare-styleable name="CursorAdapter">
<!-- URI to get the cursor from. Optional. -->
<attr name="uri" format="string" />
<!-- Selection statement for the query. Optional. -->
<attr name="selection" format="string" />
<!-- Sort order statement for the query. Optional. -->
<attr name="sortOrder" format="string" />
<!-- Layout resource used to display each row from the cursor. Mandatory. -->
<attr name="layout" format="reference" />
</declare-styleable>
<!-- Attributes used in bind items for XML cursor adapters. -->
<declare-styleable name="CursorAdapter_BindItem">
<!-- The name of the column to bind from. Mandatory. -->
<attr name="from" format="string" />
<!-- The resource id of the view to bind to. Mandatory. -->
<attr name="to" format="reference" />
<!-- The type of binding. If this value is not specified, the type will be
inferred from the type of the "to" target view. Mandatory.
The type can be one of:
<ul>
<li>string, The content of the column is interpreted as a string.</li>
<li>image, The content of the column is interpreted as a blob describing an image.</li>
<li>image-uri, The content of the column is interpreted as a URI to an image.</li>
<li>drawable, The content of the column is interpreted as a resource id to a drawable.</li>
<li>A fully qualified class name, corresponding to an implementation of
android.widget.Adapters.CursorBinder.</li>
</ul>
-->
<attr name="as" format="string" />
</declare-styleable>
<!-- Attributes used in select items for XML cursor adapters.-->
<declare-styleable name="CursorAdapter_SelectItem">
<!-- The name of the column to select. Mandatory. -->
<attr name="column" format="string" />
</declare-styleable>
<!-- Attributes used to map values to new values in XML cursor adapters' bind items. -->
<declare-styleable name="CursorAdapter_MapItem">
<!-- The original value from the column. Mandatory. -->
<attr name="fromValue" format="string" />
<!-- The new value from the column. Mandatory. -->
<attr name="toValue" format="string" />
</declare-styleable>
<!-- Attributes used to map values to new values in XML cursor adapters' bind items. -->
<declare-styleable name="CursorAdapter_TransformItem">
<!-- The transformation expression. Mandatory if "withClass" is not specified. -->
<attr name="withExpression" format="string" />
<!-- The transformation class, an implementation of
android.widget.Adapters.CursorTransformation. Mandatory if "withExpression"
is not specified. -->
<attr name="withClass" format="string" />
</declare-styleable>
</resources>

View File

@@ -15,16 +15,16 @@
--> -->
<cursor-adapter xmlns:android="http://schemas.android.com/apk/res/android" <cursor-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:uri="content://com.android.contacts/contacts" xmlns:app="http://schemas.android.com/apk/res/com.example.android.xmladapters"
android:selection="has_phone_number=1" app:uri="content://com.android.contacts/contacts"
android:layout="@layout/contact_item"> app:selection="has_phone_number=1"
app:layout="@layout/contact_item">
<bind android:from="display_name" android:to="@id/name" android:as="string" /> <bind app:from="display_name" app:to="@id/name" app:as="string" />
<bind android:from="starred" android:to="@id/star" android:as="drawable"> <bind app:from="starred" app:to="@id/star" app:as="drawable">
<map android:fromValue="0" android:toValue="@android:drawable/star_big_off" /> <map app:fromValue="0" app:toValue="@android:drawable/star_big_off" />
<map android:fromValue="1" android:toValue="@android:drawable/star_big_on" /> <map app:fromValue="1" app:toValue="@android:drawable/star_big_on" />
</bind> </bind>
<bind android:from="_id" android:to="@id/name" <bind app:from="_id" app:to="@id/name" app:as="com.example.android.xmladapters.ContactPhotoBinder" />
android:as="com.example.android.xmladapters.ContactPhotoBinder" />
</cursor-adapter> </cursor-adapter>

View File

@@ -15,11 +15,12 @@
--> -->
<cursor-adapter xmlns:android="http://schemas.android.com/apk/res/android" <cursor-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:selection="/feed/entry" xmlns:app="http://schemas.android.com/apk/res/com.example.android.xmladapters"
android:layout="@layout/photo_item"> app:selection="/feed/entry"
app:layout="@layout/photo_item">
<bind android:from="/summary" android:to="@id/title" android:as="string" /> <bind app:from="/summary" app:to="@id/title" app:as="string" />
<bind android:from="/media:group/media:thumbnail\@url" android:to="@id/photo" <bind app:from="/media:group/media:thumbnail\@url" app:to="@id/photo"
android:as="com.example.android.xmladapters.UrlImageBinder" /> app:as="com.example.android.xmladapters.UrlImageBinder" />
</cursor-adapter> </cursor-adapter>

View File

@@ -15,16 +15,16 @@
--> -->
<cursor-adapter xmlns:android="http://schemas.android.com/apk/res/android" <cursor-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:selection="/rss/channel/item" xmlns:app="http://schemas.android.com/apk/res/com.example.android.xmladapters"
android:layout="@layout/rss_feed_item"> app:selection="/rss/channel/item"
app:layout="@layout/rss_feed_item">
<bind android:from="/title" android:to="@id/title" android:as="string" /> <bind app:from="/title" app:to="@id/title" app:as="string" />
<bind android:from="/media:content@url" android:to="@id/image" <bind app:from="/media:content@url" app:to="@id/image" app:as="com.example.android.xmladapters.UrlImageBinder"/>
android:as="com.example.android.xmladapters.UrlImageBinder"/> <bind app:from="/media:description" app:to="@id/description" app:as="string" />
<bind android:from="/media:description" android:to="@id/description" android:as="string" /> <bind app:from="/guid" app:to="@id/item_layout" app:as="tag" />
<bind android:from="/guid" android:to="@id/item_layout" android:as="tag" /> <bind app:from="/pubDate" app:to="@id/date" app:as="string">
<bind android:from="/pubDate" android:to="@id/date" android:as="string"> <transform app:withExpression="Published on {/pubDate}." />
<transform android:withExpression="Published on {/pubDate}." />
</bind> </bind>
</cursor-adapter> </cursor-adapter>

File diff suppressed because it is too large Load Diff

View File

@@ -27,7 +27,6 @@ import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.view.View; import android.view.View;
import android.widget.Adapters;
import android.widget.TextView; import android.widget.TextView;
import java.io.InputStream; import java.io.InputStream;

View File

@@ -30,6 +30,8 @@ public class ContactsListActivity extends ListActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.contacts_list); setContentView(R.layout.contacts_list);
setListAdapter(Adapters.loadAdapter(this, R.xml.contacts));
} }
} }

View File

@@ -19,7 +19,6 @@ package com.example.android.xmladapters;
import android.app.ListActivity; import android.app.ListActivity;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Adapters;
/** /**
* This activity uses a custom cursor adapter which fetches a XML photo feed and parses the XML to * This activity uses a custom cursor adapter which fetches a XML photo feed and parses the XML to

View File

@@ -20,7 +20,6 @@ import android.app.ListActivity;
import android.content.XmlDocumentProvider; import android.content.XmlDocumentProvider;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Adapters;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
/** /**
@@ -39,6 +38,7 @@ public class RssReaderActivity extends ListActivity {
setContentView(R.layout.rss_feeds_list); setContentView(R.layout.rss_feeds_list);
setListAdapter(Adapters.loadCursorAdapter(this, R.xml.rss_feed, setListAdapter(Adapters.loadCursorAdapter(this, R.xml.rss_feed,
"content://xmldocument/?url=" + Uri.encode(FEED_URI))); "content://xmldocument/?url=" + Uri.encode(FEED_URI)));
getListView().setOnItemClickListener(new UrlIntentListener()); getListView().setOnItemClickListener(new UrlIntentListener());
} }
} }

View File

@@ -19,7 +19,6 @@ package com.example.android.xmladapters;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.view.View; import android.view.View;
import android.widget.Adapters;
import android.widget.ImageView; import android.widget.ImageView;
/** /**