diff options
| author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:29:09 -0800 |
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:29:09 -0800 |
| commit | 52d4c30ca52320ec92d1d1ddc8db3f07f69c4f98 (patch) | |
| tree | 2eb01432fa3da41550dd622d29fb672509122b51 /samples/SkeletonApp | |
| parent | d4aee0c0caa00aa02d4c50ed28151591ac0456b5 (diff) | |
| download | android_development-52d4c30ca52320ec92d1d1ddc8db3f07f69c4f98.tar.gz android_development-52d4c30ca52320ec92d1d1ddc8db3f07f69c4f98.tar.bz2 android_development-52d4c30ca52320ec92d1d1ddc8db3f07f69c4f98.zip | |
auto import from //depot/cupcake/@135843
Diffstat (limited to 'samples/SkeletonApp')
| -rw-r--r-- | samples/SkeletonApp/Android.mk | 16 | ||||
| -rw-r--r-- | samples/SkeletonApp/AndroidManifest.xml | 58 | ||||
| -rw-r--r-- | samples/SkeletonApp/readme.txt | 65 | ||||
| -rw-r--r-- | samples/SkeletonApp/res/drawable/violet.jpg | bin | 0 -> 2492 bytes | |||
| -rw-r--r-- | samples/SkeletonApp/res/layout/skeleton_activity.xml | 73 | ||||
| -rw-r--r-- | samples/SkeletonApp/res/values/colors.xml | 28 | ||||
| -rw-r--r-- | samples/SkeletonApp/res/values/strings.xml | 29 | ||||
| -rw-r--r-- | samples/SkeletonApp/res/values/styles.xml | 37 | ||||
| -rw-r--r-- | samples/SkeletonApp/src/com/example/android/skeletonapp/SkeletonActivity.java | 135 | ||||
| -rw-r--r-- | samples/SkeletonApp/tests/Android.mk | 14 | ||||
| -rw-r--r-- | samples/SkeletonApp/tests/AndroidManifest.xml | 32 | ||||
| -rw-r--r-- | samples/SkeletonApp/tests/src/com/example/android/skeletonapp/SkeletonAppTest.java | 32 |
12 files changed, 519 insertions, 0 deletions
diff --git a/samples/SkeletonApp/Android.mk b/samples/SkeletonApp/Android.mk new file mode 100644 index 000000000..5bada0297 --- /dev/null +++ b/samples/SkeletonApp/Android.mk @@ -0,0 +1,16 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := samples + +# Only compile source java files in this apk. +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_PACKAGE_NAME := SkeletonApp + +LOCAL_SDK_VERSION := current + +include $(BUILD_PACKAGE) + +# Use the following include to make our test apk. +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/samples/SkeletonApp/AndroidManifest.xml b/samples/SkeletonApp/AndroidManifest.xml new file mode 100644 index 000000000..b0b4ef2a8 --- /dev/null +++ b/samples/SkeletonApp/AndroidManifest.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 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. +--> + +<!-- This file describes the code in the SkeletonApp package, which is + used by the system to determine how to start your application and + integrate it with the rest of the system. --> + +<!-- Declare the contents of this Android application. The namespace + attribute brings in the Android platform namespace, and the package + supplies a unique name for the application. When writing your + own application, the package name must be changed from "com.example.*" + to come from a domain that you own or have control over. --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.android.skeletonapp"> + + <!-- This package contains an application... The 'label' is the name + to display to the user for the overall application, and provides + a default label for all following components. The syntax here is a + reference to one of our string resources.--> + <application android:label="@string/skeleton_app"> + + <!-- An Activity in the application - this is something the user + can launch and interact with. The "name" attribute is the + name of the class within your package that implements this + activity. --> + <activity android:name="SkeletonActivity"> + + <!-- An IntentFilter tells the system when it should use your + activity. This allows the user to get to your activity + without someone having to explicitly know to launch your + class "com.examplel.android.skeletonapp.SkeletonActivity". --> + <intent-filter> + <!-- The MAIN action describes a main entry point into an + activity, without any associated data. --> + <action android:name="android.intent.action.MAIN" /> + + <!-- This places this activity into the main app list. --> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + + </activity> + + </application> + +</manifest> diff --git a/samples/SkeletonApp/readme.txt b/samples/SkeletonApp/readme.txt new file mode 100644 index 000000000..1ebddbd69 --- /dev/null +++ b/samples/SkeletonApp/readme.txt @@ -0,0 +1,65 @@ +Android Skeleton App +~~~~~~~~~~~~~~~~~~~~ + + +This directory contains the full implementation of a basic application for +the Android platform, demonstrating the basic facilities that applications +will use. You can run the application either directly from the "test" +list in the app launcher (it is named Skeleton App) or by selecting it from +the top list in the Sample Code app. + +The files contained here: + + +AndroidManifest.xml + +This XML file describes to the Android platform what your application can do. +It is a required file, and is the mechanism you use to show your application +to the user (in the app launcher's list), handle data types, etc. + + +src/* + +Under this directory is the Java source for for your application. + + +src/com/android/skeletonapp/SkeletonActivity.java + +This is the implementation of the "activity" feature described in +AndroidManifest.xml. The path each class implementation is +{src/PACKAGE/CLASS.java}, where PACKAGE comes from the name in the <package> +tag and CLASS comes from the class in the <activity> tag. + + +res/* + +Under this directory are the resources for your application. + + +res/layout/skeleton_activity.xml + +The res/layout/ directory contains XML files describing user interface +view hierarchies. The skeleton_activity.xml file here is used by +SkeletonActivity.java to construct its UI. The base name of each file +(all text before a '.' character) is taken as the resource name; +it must be lower-case. + + +res/drawable/violet.png + +The res/drawable/ directory contains images and other things that can be +drawn to the screen. These can be bitmaps (in .png or .jpeg format) or +special XML files describing more complex drawings. The violet.png file +here is used as the image to display in one of the views in +skeleton_activity.xml. Like layout files, the base name is used for the +resulting resource name. + + +res/values/colors.xml +res/values/strings.xml +res/values/styles.xml + +These XML files describe additional resources included in the application. +They all use the same syntax; all of these resources could be defined in one +file, but we generally split them apart as shown here to keep things organized. + diff --git a/samples/SkeletonApp/res/drawable/violet.jpg b/samples/SkeletonApp/res/drawable/violet.jpg Binary files differnew file mode 100644 index 000000000..d892c4036 --- /dev/null +++ b/samples/SkeletonApp/res/drawable/violet.jpg diff --git a/samples/SkeletonApp/res/layout/skeleton_activity.xml b/samples/SkeletonApp/res/layout/skeleton_activity.xml new file mode 100644 index 000000000..b8dcac7e7 --- /dev/null +++ b/samples/SkeletonApp/res/layout/skeleton_activity.xml @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 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. +--> + +<!-- This file describes the layout of the main SkeletonApp activity + user interface. + --> + +<!-- The top view is a layout manager that places its child views into + a row, here set to be vertical (so the first is at the top) --> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" android:layout_height="fill_parent" + android:orientation="vertical"> + + <!-- First view is a text editor. We want it to use all available + horizontal space, and stretch to fill whatever vertical space + is available to it. Note the use of the "id" attribute, which + allows us to find this object from the Java code. --> + <EditText android:id="@+id/editor" + android:layout_width="fill_parent" android:layout_height="0dip" + android:autoText="true" + android:capitalize="sentences" + android:layout_weight="1" + android:freezesText="true" > + <requestFocus /> + </EditText> + + <!-- Next view is another linear layout manager, now horizontal. We + give it a custom background; see colors.xml for the definition + of drawable/semi_black--> + <LinearLayout + android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_gravity="center_vertical" android:gravity="center_horizontal" + android:orientation="horizontal" + android:background="@drawable/semi_black"> + + <!-- On the left: the "back" button. See styles.xml for the + definition of style/ActionButton, which we use to hold + common attributes that are used for both this and the + clear button. See strings.xml for the definition of + string/back. --> + <Button android:id="@+id/back" style="@style/ActionButton" + android:text="@string/back" /> + + <!-- In the middle: a custom image, --> + <ImageView android:id="@+id/image" + android:layout_width="wrap_content" android:layout_height="wrap_content" + android:paddingLeft="4dip" android_paddingRight="4dip" + android:src="@drawable/violet" /> + + <!-- On the right: another button, this time with its text color + changed to red. Again, see colors.xml for the definition. --> + <Button android:id="@+id/clear" style="@style/ActionButton" + android:text="@string/clear" android:textColor="@color/red" /> + + </LinearLayout> + +</LinearLayout> + + diff --git a/samples/SkeletonApp/res/values/colors.xml b/samples/SkeletonApp/res/values/colors.xml new file mode 100644 index 000000000..1d985bcb5 --- /dev/null +++ b/samples/SkeletonApp/res/values/colors.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 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. +--> + +<!-- This file contains resource definitions for solid colors. In + addition to plain color resources (retrieved via Resources.getColor() + and friends), we are also using it to define drawables that are + a solid color. --> + +<resources> + <!-- Retrieved via Resources.getColor() and friends. --> + <color name="red">#f00</color> + + <!-- Retrieved via Resources.getDrawable() and friends. --> + <drawable name="semi_black">#80000000</drawable> +</resources> diff --git a/samples/SkeletonApp/res/values/strings.xml b/samples/SkeletonApp/res/values/strings.xml new file mode 100644 index 000000000..4dc998d15 --- /dev/null +++ b/samples/SkeletonApp/res/values/strings.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 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. +--> + +<!-- This file contains resource definitions for displayed strings, allowing + them to be changed based on the locale and options. --> + +<resources> + <!-- Simple strings. --> + <string name="skeleton_app">Skeleton App</string> + <string name="back">Back</string> + <string name="clear">Clear</string> + + <!-- This is a complex string containing style runs. --> + <string name="main_label">Hello <u>th<ignore>e</ignore>re</u>, <i>you</i> <b>Activity</b>!</string> +</resources> + diff --git a/samples/SkeletonApp/res/values/styles.xml b/samples/SkeletonApp/res/values/styles.xml new file mode 100644 index 000000000..050514fff --- /dev/null +++ b/samples/SkeletonApp/res/values/styles.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 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. +--> + +<!-- This file contains resource definitions for style. A style is + a collection of named values that can be applied as a group. Here, + we are using a style to define a common set of XML attributes that + will be used in multiple tags. --> + +<resources> + <style name="ActionButton"> + <item name="android:layout_width">wrap_content</item> + <item name="android:layout_height">wrap_content</item> + <item name="android:textAppearance">@style/TextAppearance.ActionButton</item> + </style> + + <style name="TextAppearance" parent="android:TextAppearance"> + </style> + + <style name="TextAppearance.ActionButton"> + <item name="android:textStyle">italic</item> + </style> + +</resources> + diff --git a/samples/SkeletonApp/src/com/example/android/skeletonapp/SkeletonActivity.java b/samples/SkeletonApp/src/com/example/android/skeletonapp/SkeletonActivity.java new file mode 100644 index 000000000..7abf3ae50 --- /dev/null +++ b/samples/SkeletonApp/src/com/example/android/skeletonapp/SkeletonActivity.java @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2007 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. + */ + +package com.example.android.skeletonapp; + +import android.app.Activity; +import android.os.Bundle; +import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.EditText; + +/** + * This class provides a basic demonstration of how to write an Android + * activity. Inside of its window, it places a single view: an EditText that + * displays and edits some internal text. + */ +public class SkeletonActivity extends Activity { + + static final private int BACK_ID = Menu.FIRST; + static final private int CLEAR_ID = Menu.FIRST + 1; + + private EditText mEditor; + + public SkeletonActivity() { + } + + /** Called with the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Inflate our UI from its XML layout description. + setContentView(R.layout.skeleton_activity); + + // Find the text editor view inside the layout, because we + // want to do various programmatic things with it. + mEditor = (EditText) findViewById(R.id.editor); + + // Hook up button presses to the appropriate event handler. + ((Button) findViewById(R.id.back)).setOnClickListener(mBackListener); + ((Button) findViewById(R.id.clear)).setOnClickListener(mClearListener); + + mEditor.setText(getText(R.string.main_label)); + } + + /** + * Called when the activity is about to start interacting with the user. + */ + @Override + protected void onResume() { + super.onResume(); + } + + /** + * Called when your activity's options menu needs to be created. + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + + // We are going to create two menus. Note that we assign them + // unique integer IDs, labels from our string resources, and + // given them shortcuts. + menu.add(0, BACK_ID, 0, R.string.back).setShortcut('0', 'b'); + menu.add(0, CLEAR_ID, 0, R.string.clear).setShortcut('1', 'c'); + + return true; + } + + /** + * Called right before your activity's option menu is displayed. + */ + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + + // Before showing the menu, we need to decide whether the clear + // item is enabled depending on whether there is text to clear. + menu.findItem(CLEAR_ID).setVisible(mEditor.getText().length() > 0); + + return true; + } + + /** + * Called when a menu item is selected. + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case BACK_ID: + finish(); + return true; + case CLEAR_ID: + mEditor.setText(""); + return true; + } + + return super.onOptionsItemSelected(item); + } + + /** + * A call-back for when the user presses the back button. + */ + OnClickListener mBackListener = new OnClickListener() { + public void onClick(View v) { + finish(); + } + }; + + /** + * A call-back for when the user presses the clear button. + */ + OnClickListener mClearListener = new OnClickListener() { + public void onClick(View v) { + mEditor.setText(""); + } + }; +} diff --git a/samples/SkeletonApp/tests/Android.mk b/samples/SkeletonApp/tests/Android.mk new file mode 100644 index 000000000..7f26bfa0f --- /dev/null +++ b/samples/SkeletonApp/tests/Android.mk @@ -0,0 +1,14 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_JAVA_LIBRARIES := android.test.runner + +LOCAL_PACKAGE_NAME := SkeletonAppTests + +LOCAL_MODULE_TAGS := tests + +LOCAL_INSTRUMENTATION_FOR := SkeletonApp + +include $(BUILD_PACKAGE) diff --git a/samples/SkeletonApp/tests/AndroidManifest.xml b/samples/SkeletonApp/tests/AndroidManifest.xml new file mode 100644 index 000000000..fac1f41df --- /dev/null +++ b/samples/SkeletonApp/tests/AndroidManifest.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2008 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. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.android.skeletonapp.tests"> + + <!-- We add an application tag here just so that we can indicate that + this package needs to link against the android.test library, + which is needed when building test cases. --> + <application> + <uses-library android:name="android.test.runner" /> + </application> + + <instrumentation android:name="android.test.InstrumentationTestRunner" + android:targetPackage="com.example.android.skeletonapp" + android:label="SkeletonApp sample tests"> + </instrumentation> + +</manifest> diff --git a/samples/SkeletonApp/tests/src/com/example/android/skeletonapp/SkeletonAppTest.java b/samples/SkeletonApp/tests/src/com/example/android/skeletonapp/SkeletonAppTest.java new file mode 100644 index 000000000..3123348eb --- /dev/null +++ b/samples/SkeletonApp/tests/src/com/example/android/skeletonapp/SkeletonAppTest.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2008 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. + */ + +package com.example.android.skeletonapp; + +import android.test.ActivityInstrumentationTestCase; + +import com.example.android.skeletonapp.SkeletonActivity; + +/** + * Make sure that the main launcher activity opens up properly, which will be + * verified by {@link ActivityTestCase#testActivityTestCaseSetUpProperly}. + */ +public class SkeletonAppTest extends ActivityInstrumentationTestCase<SkeletonActivity> { + + public SkeletonAppTest() { + super("com.example.android.skeletonapp", SkeletonActivity.class); + } +} |
