diff options
author | Adam Lesinski <adamlesinski@google.com> | 2014-01-29 18:20:45 -0800 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2014-03-25 12:09:56 -0700 |
commit | de898ff42912bd7ca1bfb099cd439562496765a4 (patch) | |
tree | 849b591a99a7e6a8fd790aedca3afff6f6b6eade /tests/SharedLibrary/client | |
parent | 05f79758cd2688f89444a38baba326a0a1c1a438 (diff) | |
download | frameworks_base-de898ff42912bd7ca1bfb099cd439562496765a4.zip frameworks_base-de898ff42912bd7ca1bfb099cd439562496765a4.tar.gz frameworks_base-de898ff42912bd7ca1bfb099cd439562496765a4.tar.bz2 |
Shared library resource support
Shared libraries can now export resources for applications
to use.
Exporting resources works the same way the framework exports
resources, by defining the public symbols in res/values/public.xml.
Building a shared library requires aapt to be invoked with the
--shared-lib option. Shared libraries will be assigned a package
ID of 0x00 at build-time. At runtime, all loaded shared libraries
will be assigned a new package ID.
Currently, shared libraries should not import other shared libraries,
as those dependencies will not be loaded at runtime.
At runtime, reflection is used to update the package ID of resource
symbols in the shared library's R class file. The package name of
the R class file is assumed to be the same as the shared library's
package name declared in its manifest. This will be customizable in
a future commit.
See /tests/SharedLibrary/ for examples of a shared library and its
client.
Bug:12724178
Change-Id: I60c0cb8ab87849f8f8a1a13431562fe8603020a7
Diffstat (limited to 'tests/SharedLibrary/client')
5 files changed, 52 insertions, 5 deletions
diff --git a/tests/SharedLibrary/client/AndroidManifest.xml b/tests/SharedLibrary/client/AndroidManifest.xml index c6a43c0..a39c754 100644 --- a/tests/SharedLibrary/client/AndroidManifest.xml +++ b/tests/SharedLibrary/client/AndroidManifest.xml @@ -16,7 +16,7 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.android.test.lib_client"> - <application android:label="@string/app_title"> + <application android:label="@string/app_title" android:theme="@style/Theme"> <uses-library android:name="android.test.runner" /> <uses-library android:name="com.google.android.test.shared_library" /> <activity android:name="ActivityMain"> diff --git a/tests/SharedLibrary/client/res/layout/main.xml b/tests/SharedLibrary/client/res/layout/main.xml new file mode 100644 index 0000000..067ef9f --- /dev/null +++ b/tests/SharedLibrary/client/res/layout/main.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <TextView android:id="@+id/label" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@com.google.android.test.shared_library:string/shared_string" + style="@com.google.android.test.shared_library:style/CodeFont"/> + + <com.google.android.test.shared_library.AddressView + xmlns:custom="http://schemas.android.com/apk/res/com.google.android.test.shared_library" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + custom:name="Professor Android" + custom:streetNumber="44" + custom:streetName="KitKat Lane" + custom:city="AndroidVille" + custom:state="OS" + custom:country="Mobile" + custom:zip="12345"/> +</LinearLayout> diff --git a/tests/SharedLibrary/client/res/values/strings.xml b/tests/SharedLibrary/client/res/values/strings.xml index 3757a25..d9efdc7 100644 --- a/tests/SharedLibrary/client/res/values/strings.xml +++ b/tests/SharedLibrary/client/res/values/strings.xml @@ -16,4 +16,5 @@ <resources> <string name="app_title">SharedLibrary client</string> + <string name="changes">@com.google.android.test.shared_library:string/shared_string</string> </resources> diff --git a/tests/SharedLibrary/client/res/values/themes.xml b/tests/SharedLibrary/client/res/values/themes.xml new file mode 100644 index 0000000..a14f98a --- /dev/null +++ b/tests/SharedLibrary/client/res/values/themes.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> + +<resources> + <style name="Theme" parent="com.google.android.test.shared_library:Theme"> + </style> +</resources> diff --git a/tests/SharedLibrary/client/src/com/google/android/test/lib_client/ActivityMain.java b/tests/SharedLibrary/client/src/com/google/android/test/lib_client/ActivityMain.java index d6121a5..7276b3c 100644 --- a/tests/SharedLibrary/client/src/com/google/android/test/lib_client/ActivityMain.java +++ b/tests/SharedLibrary/client/src/com/google/android/test/lib_client/ActivityMain.java @@ -18,18 +18,33 @@ package com.google.android.test.lib_client; import android.app.Activity; import android.os.Bundle; -import android.widget.TextView; import com.google.android.test.shared_library.SharedLibraryMain; public class ActivityMain extends Activity { + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + String[] expectedAnimals = new String[] { + "Racoon", + "Rhino", + "Elephant" + }; + + String[] animals = getResources().getStringArray(com.google.android.test.shared_library.R.array.animals); + if (animals == null || animals.length != expectedAnimals.length) { + throw new AssertionError("Animal list from shared library is null or wrong length."); + } - TextView content = new TextView(this); - content.setText("Library version: " + SharedLibraryMain.getVersion(this) + "!"); + for (int i = 0; i < expectedAnimals.length; i++) { + if (!expectedAnimals[i].equals(animals[i])) { + throw new AssertionError("Expected '" + expectedAnimals[i] + + "' at index " + i + " but got '" + animals[i]); + } + } SharedLibraryMain.ensureVersion(this, SharedLibraryMain.VERSION_BASE); - setContentView(content); } } |