diff --git a/samples/ApiDemos/src/com/example/android/apis/app/Animation.java b/samples/ApiDemos/src/com/example/android/apis/app/Animation.java index 5ba41c497..bd2bd89b8 100644 --- a/samples/ApiDemos/src/com/example/android/apis/app/Animation.java +++ b/samples/ApiDemos/src/com/example/android/apis/app/Animation.java @@ -30,10 +30,7 @@ import android.widget.Button; /** - *

Example of explicitly starting and stopping the {@link LocalService}. - * This demonstrates the implementation of a service that runs in the same - * process as the rest of the application, which is explicitly started and stopped - * as desired.

+ *

Example of using a custom animation when transitioning between activities.

*/ public class Animation extends Activity { @Override diff --git a/samples/ApiDemos/src/com/example/android/apis/app/ForegroundService.java b/samples/ApiDemos/src/com/example/android/apis/app/ForegroundService.java index f1513ac68..9f84be15a 100644 --- a/samples/ApiDemos/src/com/example/android/apis/app/ForegroundService.java +++ b/samples/ApiDemos/src/com/example/android/apis/app/ForegroundService.java @@ -49,17 +49,33 @@ public class ForegroundService extends Service { static final String ACTION_BACKGROUND = "com.example.android.apis.BACKGROUND"; // BEGIN_INCLUDE(foreground_compatibility) + private static final Class[] mSetForegroundSignature = new Class[] { + boolean.class}; private static final Class[] mStartForegroundSignature = new Class[] { int.class, Notification.class}; private static final Class[] mStopForegroundSignature = new Class[] { boolean.class}; private NotificationManager mNM; + private Method mSetForeground; private Method mStartForeground; private Method mStopForeground; + private Object[] mSetForegroundArgs = new Object[1]; private Object[] mStartForegroundArgs = new Object[2]; private Object[] mStopForegroundArgs = new Object[1]; + void invokeMethod(Method method, Object[] args) { + try { + mStartForeground.invoke(this, mStartForegroundArgs); + } catch (InvocationTargetException e) { + // Should not happen. + Log.w("ApiDemos", "Unable to invoke method", e); + } catch (IllegalAccessException e) { + // Should not happen. + Log.w("ApiDemos", "Unable to invoke method", e); + } + } + /** * This is a wrapper around the new startForeground method, using the older * APIs if it is not available. @@ -69,20 +85,13 @@ public class ForegroundService extends Service { if (mStartForeground != null) { mStartForegroundArgs[0] = Integer.valueOf(id); mStartForegroundArgs[1] = notification; - try { - mStartForeground.invoke(this, mStartForegroundArgs); - } catch (InvocationTargetException e) { - // Should not happen. - Log.w("ApiDemos", "Unable to invoke startForeground", e); - } catch (IllegalAccessException e) { - // Should not happen. - Log.w("ApiDemos", "Unable to invoke startForeground", e); - } + invokeMethod(mStartForeground, mStartForegroundArgs); return; } // Fall back on the old API. - //setForeground(true); + mSetForegroundArgs[0] = Boolean.TRUE; + invokeMethod(mSetForeground, mSetForegroundArgs); mNM.notify(id, notification); } @@ -109,7 +118,8 @@ public class ForegroundService extends Service { // Fall back on the old API. Note to cancel BEFORE changing the // foreground state, since we could be killed at that point. mNM.cancel(id); - //setForeground(false); + mSetForegroundArgs[0] = Boolean.FALSE; + invokeMethod(mSetForeground, mSetForegroundArgs); } @Override @@ -123,6 +133,14 @@ public class ForegroundService extends Service { } catch (NoSuchMethodException e) { // Running on an older platform. mStartForeground = mStopForeground = null; + return; + } + try { + mSetForeground = getClass().getMethod("setForeground", + mSetForegroundSignature); + } catch (NoSuchMethodException e) { + throw new IllegalStateException( + "OS doesn't have Service.startForeground OR Service.setForeground!"); } } diff --git a/samples/ApiDemos/src/com/example/android/apis/app/FragmentAlertDialog.java b/samples/ApiDemos/src/com/example/android/apis/app/FragmentAlertDialog.java index abf9731d8..56ddc6b91 100644 --- a/samples/ApiDemos/src/com/example/android/apis/app/FragmentAlertDialog.java +++ b/samples/ApiDemos/src/com/example/android/apis/app/FragmentAlertDialog.java @@ -30,6 +30,9 @@ import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; +/** + * Demonstrates how to show an AlertDialog that is managed by a Fragment. + */ public class FragmentAlertDialog extends Activity { @Override diff --git a/samples/ApiDemos/src/com/example/android/apis/app/_index.html b/samples/ApiDemos/src/com/example/android/apis/app/_index.html index fff5ce2e7..6fe2d4c3a 100644 --- a/samples/ApiDemos/src/com/example/android/apis/app/_index.html +++ b/samples/ApiDemos/src/com/example/android/apis/app/_index.html @@ -37,47 +37,131 @@
TranslucentBlur
Demonstrates how to make an activity with a transparent background with a special effect (blur).
+ +
Dialog Activity
+
An Activity that sets its theme to android:style/Theme.Dialog so that + it looks like a Dialog.
+ +
Custom Title
+
An Activity that places a custom UI in its title.
+ +
Animation
+
Demonstrates how to use custom animations when moving between activities.
+ +
Activity Recreate
+
Demonstrates how an Activity can cause itself to be recreated.
+ +
Screen Orientation
+
Demonstrates the different screen orientations an Activity can request.
+ +
Soft Input Modes
+
Demonstrates how different soft input modes set in an Activity's + window impacts how it adjusts to accommodate an IME.
+ +
Intent Activity Flags
+
Demonstrates various uses of Intent flags to modify an application + task's activity stack in common ways.
+ +
Reorder on Launch
+
Demonstrates how the activities in a task can be reordered. UI flow + goes through the activities ReorderOnLaunch, + ReorderTwo, ReorderThree, + and ReorderFour.
+ +
Wallpaper Activity
+
An Activity that uses android:style/Theme.Wallpaper to be displayed + on top of the system wallpaper.
+ + +

Fragment

+
+
Fragment Alert Dialog
+
Demonstrates how to use a DialogFragment to show and manage an + AlertDialog.
+ +
Fragment Context Menu
+
Demonstrates how to display and respond to a context menu that is + display from a fragment's view hierarchy.
+ +
Fragment Dialog
+
Demonstrates use of DialogFragment to show various types of dialogs.
+ +
Fragment Dialog or Activity
+
Demonstrates how the same Fragment implementation can be used to provide the UI + for either an Activity or Dialog.
+ +
Fragment Hide Show
+
Demonstrates hiding and showing fragments.
+ +
Fragment Layout
+
Demonstrates use of the <fragment> tag to embed a Fragment in + an Activity's content view layout, and making the layout change based on + configuration to achieve different UI flows.
+ +
Fragment List Array
+
Demonstrates use of ListFragment to show the contents of a simple ArrayAdapter.
+ +
Fragment List Cursor Loader
+
Demonstrates use of LoaderManager to perform a query for a Cursor that + populates a ListFragment.
+ +
Fragment Menu
+
Demonstrates populating custom menu items from a Fragment.
+ +
Fragment Receive Result
+
Demonstrates starting a new Activity from a Fragment, and receiving + a result back from it.
+ +
Fragment Retain Instance
+
Demonstrates a Fragment can be used to easily retain active state across + an Activity's configuration change.
+ +
Fragment Stack
+
Demonstrates creating a stack of Fragment instances similar to the + traditional stack of activities.
+

Service

-
Local Service Controller and - Local Service Binding
+
Local Service
Demonstrate the implementation of a service that runs in the same process as its client(s). Shows how those clients can either start/stop it - with {@link android.content.Context#startService - Context.startService} and {@link android.content.Context#stopService - Context.stopService}, or bind and call it with - {@link android.content.Context#bindService Context.bindService} and - {@link android.content.Context#unbindService Context.unindService}. + with Context.startService and Context.stopService, or bind and call it with + Context.bindService and Context.unindService. This also shows how you can simplify working - with a service when you know it will only run in your own process.
+ with a service when you know it will only run in your own process. The client + code for interacting with the service is in + Local Service Activities. + +
Messenger Service
+
Demonstrates binding to a Service whose interface is implemented with + the Messenger class. This is often an easier way to do remote communication + with a Service than using a raw AIDL interface. The client + code for interacting with the service is in + Messenger Service Activities.
Remote Service Controller and Remove Service Binding
Demonstrates starting a service in a separate process, by assigning android:process=":remote" to the service in the AndroidManifest.xml file. Shows how those clients can either start/stop it - with {@link android.content.Context#startService - Context.startService} and {@link android.content.Context#stopService - Context.stopService}, or bind and call it with - {@link android.content.Context#bindService Context.bindService} and - {@link android.content.Context#unbindService Context.unindService}. + with Context.startService and Context.stopService, or bind and call it with + Context.bindService and Context.unindService. Binding is similar to the local service sample, but illustrates the additional work (defining aidl interfaces) needed to interact with a service in another process. Also shows how a service can publish multiple interfaces and implement callbacks to its clients.
-
Service Start Arguments Controller
+
Service Start Arguments
Demonstrates how you can use a Service as a job queue, where you - submit jobs to it with {@link android.content.Context#startService - Context.startService} instead of binding to the service. Such a service + submit jobs to it with Context.startService instead of binding to the service. Such a service automatically stops itself once all jobs have been processed. This can be a very convenient way to interact with a service when you do not need a result back from it.
-
Foreground Service Controller
+
Foreground Service
Shows how you can write a Service that runs in the foreground and works on both pre-2.0 and post-2.0 versions of the platform. This example will selectively use @@ -126,6 +210,10 @@
IncomingMessage
Demonstrates sending persistent and transient notifications, with a View object in the notification. It also demonstrated inflating a View object from an XML layout resource.
+ +
Status Bar Notifications
+
Demonstrates a variety of different notifications that can be posted in + the status bar, and a standard way for handling them.

Search

@@ -141,3 +229,12 @@ +

Misc

+
+
Alert Dialog Samples
+
Demonstrates various styles of alert dialogs.
+ +
Device Admin Sample
+
Demonstration of the implementation of a simple device administrator + and its use of the DevicePolicyManager.
+