diff options
Diffstat (limited to 'core/java/android/gadget')
-rw-r--r-- | core/java/android/gadget/GadgetHost.java | 249 | ||||
-rw-r--r-- | core/java/android/gadget/GadgetHostView.java | 312 | ||||
-rw-r--r-- | core/java/android/gadget/GadgetManager.java | 320 | ||||
-rwxr-xr-x | core/java/android/gadget/GadgetProvider.java | 154 | ||||
-rw-r--r-- | core/java/android/gadget/GadgetProviderInfo.aidl | 19 | ||||
-rw-r--r-- | core/java/android/gadget/GadgetProviderInfo.java | 168 | ||||
-rw-r--r-- | core/java/android/gadget/package.html | 136 |
7 files changed, 0 insertions, 1358 deletions
diff --git a/core/java/android/gadget/GadgetHost.java b/core/java/android/gadget/GadgetHost.java deleted file mode 100644 index 3d88b58..0000000 --- a/core/java/android/gadget/GadgetHost.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (C) 2006 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 android.gadget; - -import android.content.Context; -import android.os.Handler; -import android.os.IBinder; -import android.os.Looper; -import android.os.Message; -import android.os.RemoteException; -import android.os.ServiceManager; -import android.widget.RemoteViews; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import com.android.internal.gadget.IGadgetHost; -import com.android.internal.gadget.IGadgetService; - -/** - * GadgetHost provides the interaction with the Gadget Service for apps, - * like the home screen, that want to embed gadgets in their UI. - */ -public class GadgetHost { - - static final int HANDLE_UPDATE = 1; - static final int HANDLE_PROVIDER_CHANGED = 2; - - static Object sServiceLock = new Object(); - static IGadgetService sService; - - Context mContext; - String mPackageName; - - class Callbacks extends IGadgetHost.Stub { - public void updateGadget(int gadgetId, RemoteViews views) { - Message msg = mHandler.obtainMessage(HANDLE_UPDATE); - msg.arg1 = gadgetId; - msg.obj = views; - msg.sendToTarget(); - } - - public void providerChanged(int gadgetId, GadgetProviderInfo info) { - Message msg = mHandler.obtainMessage(HANDLE_PROVIDER_CHANGED); - msg.arg1 = gadgetId; - msg.obj = info; - msg.sendToTarget(); - } - } - - class UpdateHandler extends Handler { - public UpdateHandler(Looper looper) { - super(looper); - } - - public void handleMessage(Message msg) { - switch (msg.what) { - case HANDLE_UPDATE: { - updateGadgetView(msg.arg1, (RemoteViews)msg.obj); - break; - } - case HANDLE_PROVIDER_CHANGED: { - onProviderChanged(msg.arg1, (GadgetProviderInfo)msg.obj); - break; - } - } - } - } - - Handler mHandler; - - int mHostId; - Callbacks mCallbacks = new Callbacks(); - HashMap<Integer,GadgetHostView> mViews = new HashMap(); - - public GadgetHost(Context context, int hostId) { - mContext = context; - mHostId = hostId; - mHandler = new UpdateHandler(context.getMainLooper()); - synchronized (sServiceLock) { - if (sService == null) { - IBinder b = ServiceManager.getService(Context.GADGET_SERVICE); - sService = IGadgetService.Stub.asInterface(b); - } - } - } - - /** - * Start receiving onGadgetChanged calls for your gadgets. Call this when your activity - * becomes visible, i.e. from onStart() in your Activity. - */ - public void startListening() { - int[] updatedIds = null; - ArrayList<RemoteViews> updatedViews = new ArrayList(); - - try { - if (mPackageName == null) { - mPackageName = mContext.getPackageName(); - } - updatedIds = sService.startListening(mCallbacks, mPackageName, mHostId, updatedViews); - } - catch (RemoteException e) { - throw new RuntimeException("system server dead?", e); - } - - final int N = updatedIds.length; - for (int i=0; i<N; i++) { - updateGadgetView(updatedIds[i], updatedViews.get(i)); - } - } - - /** - * Stop receiving onGadgetChanged calls for your gadgets. Call this when your activity is - * no longer visible, i.e. from onStop() in your Activity. - */ - public void stopListening() { - try { - sService.stopListening(mHostId); - } - catch (RemoteException e) { - throw new RuntimeException("system server dead?", e); - } - } - - /** - * Get a gadgetId for a host in the calling process. - * - * @return a gadgetId - */ - public int allocateGadgetId() { - try { - if (mPackageName == null) { - mPackageName = mContext.getPackageName(); - } - return sService.allocateGadgetId(mPackageName, mHostId); - } - catch (RemoteException e) { - throw new RuntimeException("system server dead?", e); - } - } - - /** - * Stop listening to changes for this gadget. - */ - public void deleteGadgetId(int gadgetId) { - synchronized (mViews) { - mViews.remove(gadgetId); - try { - sService.deleteGadgetId(gadgetId); - } - catch (RemoteException e) { - throw new RuntimeException("system server dead?", e); - } - } - } - - /** - * Remove all records about this host from the gadget manager. - * <ul> - * <li>Call this when initializing your database, as it might be because of a data wipe.</li> - * <li>Call this to have the gadget manager release all resources associated with your - * host. Any future calls about this host will cause the records to be re-allocated.</li> - * </ul> - */ - public void deleteHost() { - try { - sService.deleteHost(mHostId); - } - catch (RemoteException e) { - throw new RuntimeException("system server dead?", e); - } - } - - /** - * Remove all records about all hosts for your package. - * <ul> - * <li>Call this when initializing your database, as it might be because of a data wipe.</li> - * <li>Call this to have the gadget manager release all resources associated with your - * host. Any future calls about this host will cause the records to be re-allocated.</li> - * </ul> - */ - public static void deleteAllHosts() { - try { - sService.deleteAllHosts(); - } - catch (RemoteException e) { - throw new RuntimeException("system server dead?", e); - } - } - - public final GadgetHostView createView(Context context, int gadgetId, - GadgetProviderInfo gadget) { - GadgetHostView view = onCreateView(context, gadgetId, gadget); - view.setGadget(gadgetId, gadget); - synchronized (mViews) { - mViews.put(gadgetId, view); - } - RemoteViews views = null; - try { - views = sService.getGadgetViews(gadgetId); - } catch (RemoteException e) { - throw new RuntimeException("system server dead?", e); - } - view.updateGadget(views); - return view; - } - - /** - * Called to create the GadgetHostView. Override to return a custom subclass if you - * need it. {@more} - */ - protected GadgetHostView onCreateView(Context context, int gadgetId, - GadgetProviderInfo gadget) { - return new GadgetHostView(context); - } - - /** - * Called when the gadget provider for a gadget has been upgraded to a new apk. - */ - protected void onProviderChanged(int gadgetId, GadgetProviderInfo gadget) { - } - - void updateGadgetView(int gadgetId, RemoteViews views) { - GadgetHostView v; - synchronized (mViews) { - v = mViews.get(gadgetId); - } - if (v != null) { - v.updateGadget(views); - } - } -} - - diff --git a/core/java/android/gadget/GadgetHostView.java b/core/java/android/gadget/GadgetHostView.java deleted file mode 100644 index 5cbd988..0000000 --- a/core/java/android/gadget/GadgetHostView.java +++ /dev/null @@ -1,312 +0,0 @@ -/* - * 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 android.gadget; - -import android.content.Context; -import android.content.pm.PackageManager; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.os.Handler; -import android.os.Message; -import android.os.SystemClock; -import android.util.Config; -import android.util.Log; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.animation.Animation; -import android.widget.FrameLayout; -import android.widget.RemoteViews; -import android.widget.TextView; - -/** - * Provides the glue to show gadget views. This class offers automatic animation - * between updates, and will try recycling old views for each incoming - * {@link RemoteViews}. - */ -public class GadgetHostView extends FrameLayout { - static final String TAG = "GadgetHostView"; - static final boolean LOGD = false; - static final boolean CROSSFADE = false; - - static final int VIEW_MODE_NOINIT = 0; - static final int VIEW_MODE_CONTENT = 1; - static final int VIEW_MODE_ERROR = 2; - static final int VIEW_MODE_DEFAULT = 3; - - static final int FADE_DURATION = 1000; - - // When we're inflating the initialLayout for a gadget, we only allow - // views that are allowed in RemoteViews. - static final LayoutInflater.Filter sInflaterFilter = new LayoutInflater.Filter() { - public boolean onLoadClass(Class clazz) { - return clazz.isAnnotationPresent(RemoteViews.RemoteView.class); - } - }; - - Context mContext; - - int mGadgetId; - GadgetProviderInfo mInfo; - View mView; - int mViewMode = VIEW_MODE_NOINIT; - int mLayoutId = -1; - long mFadeStartTime = -1; - Bitmap mOld; - Paint mOldPaint = new Paint(); - - /** - * Create a host view. Uses default fade animations. - */ - public GadgetHostView(Context context) { - this(context, android.R.anim.fade_in, android.R.anim.fade_out); - } - - /** - * Create a host view. Uses specified animations when pushing - * {@link #updateGadget(RemoteViews)}. - * - * @param animationIn Resource ID of in animation to use - * @param animationOut Resource ID of out animation to use - */ - public GadgetHostView(Context context, int animationIn, int animationOut) { - super(context); - mContext = context; - } - - /** - * Set the gadget that will be displayed by this view. - */ - public void setGadget(int gadgetId, GadgetProviderInfo info) { - mGadgetId = gadgetId; - mInfo = info; - } - - public int getGadgetId() { - return mGadgetId; - } - - public GadgetProviderInfo getGadgetInfo() { - return mInfo; - } - - /** - * Process a set of {@link RemoteViews} coming in as an update from the - * gadget provider. Will animate into these new views as needed. - */ - public void updateGadget(RemoteViews remoteViews) { - if (LOGD) Log.d(TAG, "updateGadget called mOld=" + mOld); - - boolean recycled = false; - View content = null; - Exception exception = null; - - // Capture the old view into a bitmap so we can do the crossfade. - if (CROSSFADE) { - if (mFadeStartTime < 0) { - if (mView != null) { - final int width = mView.getWidth(); - final int height = mView.getHeight(); - try { - mOld = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - } catch (OutOfMemoryError e) { - // we just won't do the fade - mOld = null; - } - if (mOld != null) { - //mView.drawIntoBitmap(mOld); - } - } - } - } - - if (remoteViews == null) { - if (mViewMode == VIEW_MODE_DEFAULT) { - // We've already done this -- nothing to do. - return; - } - content = getDefaultView(); - mLayoutId = -1; - mViewMode = VIEW_MODE_DEFAULT; - } else { - int layoutId = remoteViews.getLayoutId(); - - // If our stale view has been prepared to match active, and the new - // layout matches, try recycling it - if (content == null && layoutId == mLayoutId) { - try { - remoteViews.reapply(mContext, mView); - content = mView; - recycled = true; - if (LOGD) Log.d(TAG, "was able to recycled existing layout"); - } catch (RuntimeException e) { - exception = e; - } - } - - // Try normal RemoteView inflation - if (content == null) { - try { - content = remoteViews.apply(mContext, this); - if (LOGD) Log.d(TAG, "had to inflate new layout"); - } catch (RuntimeException e) { - exception = e; - } - } - - mLayoutId = layoutId; - mViewMode = VIEW_MODE_CONTENT; - } - - if (content == null) { - if (mViewMode == VIEW_MODE_ERROR) { - // We've already done this -- nothing to do. - return ; - } - Log.w(TAG, "updateGadget couldn't find any view, using error view", exception); - content = getErrorView(); - mViewMode = VIEW_MODE_ERROR; - } - - if (!recycled) { - prepareView(content); - addView(content); - } - - if (mView != content) { - removeView(mView); - mView = content; - } - - if (CROSSFADE) { - if (mFadeStartTime < 0) { - // if there is already an animation in progress, don't do anything -- - // the new view will pop in on top of the old one during the cross fade, - // and that looks okay. - mFadeStartTime = SystemClock.uptimeMillis(); - invalidate(); - } - } - } - - protected boolean drawChild(Canvas canvas, View child, long drawingTime) { - if (CROSSFADE) { - int alpha; - int l = child.getLeft(); - int t = child.getTop(); - if (mFadeStartTime > 0) { - alpha = (int)(((drawingTime-mFadeStartTime)*255)/FADE_DURATION); - if (alpha > 255) { - alpha = 255; - } - Log.d(TAG, "drawChild alpha=" + alpha + " l=" + l + " t=" + t - + " w=" + child.getWidth()); - if (alpha != 255 && mOld != null) { - mOldPaint.setAlpha(255-alpha); - //canvas.drawBitmap(mOld, l, t, mOldPaint); - } - } else { - alpha = 255; - } - int restoreTo = canvas.saveLayerAlpha(l, t, child.getWidth(), child.getHeight(), alpha, - Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); - boolean rv = super.drawChild(canvas, child, drawingTime); - canvas.restoreToCount(restoreTo); - if (alpha < 255) { - invalidate(); - } else { - mFadeStartTime = -1; - if (mOld != null) { - mOld.recycle(); - mOld = null; - } - } - return rv; - } else { - return super.drawChild(canvas, child, drawingTime); - } - } - - /** - * Prepare the given view to be shown. This might include adjusting - * {@link FrameLayout.LayoutParams} before inserting. - */ - protected void prepareView(View view) { - // Take requested dimensions from parent, but apply default gravity. - ViewGroup.LayoutParams requested = view.getLayoutParams(); - if (requested == null) { - requested = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, - LayoutParams.FILL_PARENT); - } - - FrameLayout.LayoutParams params = - new FrameLayout.LayoutParams(requested.width, requested.height); - params.gravity = Gravity.CENTER; - view.setLayoutParams(params); - } - - /** - * Inflate and return the default layout requested by gadget provider. - */ - protected View getDefaultView() { - View defaultView = null; - Exception exception = null; - - try { - if (mInfo != null) { - Context theirContext = mContext.createPackageContext( - mInfo.provider.getPackageName(), 0 /* no flags */); - LayoutInflater inflater = (LayoutInflater) - theirContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - inflater = inflater.cloneInContext(theirContext); - inflater.setFilter(sInflaterFilter); - defaultView = inflater.inflate(mInfo.initialLayout, this, false); - } else { - Log.w(TAG, "can't inflate defaultView because mInfo is missing"); - } - } catch (PackageManager.NameNotFoundException e) { - exception = e; - } catch (RuntimeException e) { - exception = e; - } - - if (exception != null && LOGD) { - Log.w(TAG, "Error inflating gadget " + mInfo, exception); - } - - if (defaultView == null) { - if (LOGD) Log.d(TAG, "getDefaultView couldn't find any view, so inflating error"); - defaultView = getErrorView(); - } - - return defaultView; - } - - /** - * Inflate and return a view that represents an error state. - */ - protected View getErrorView() { - TextView tv = new TextView(mContext); - tv.setText(com.android.internal.R.string.gadget_host_error_inflating); - // TODO: get this color from somewhere. - tv.setBackgroundColor(Color.argb(127, 0, 0, 0)); - return tv; - } -} diff --git a/core/java/android/gadget/GadgetManager.java b/core/java/android/gadget/GadgetManager.java deleted file mode 100644 index d2c4055..0000000 --- a/core/java/android/gadget/GadgetManager.java +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Copyright (C) 2006 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 android.gadget; - -import android.content.ComponentName; -import android.content.Context; -import android.os.IBinder; -import android.os.RemoteException; -import android.os.ServiceManager; -import android.util.Log; -import android.widget.RemoteViews; - -import com.android.internal.gadget.IGadgetService; - -import java.lang.ref.WeakReference; -import java.util.List; -import java.util.WeakHashMap; - -/** - * Updates gadget state; gets information about installed gadget providers and other - * gadget related state. - */ -public class GadgetManager { - static final String TAG = "GadgetManager"; - - /** - * Send this from your gadget host activity when you want to pick a gadget to display. - * The gadget picker activity will be launched. - * <p> - * You must supply the following extras: - * <table> - * <tr> - * <td>{@link #EXTRA_GADGET_ID}</td> - * <td>A newly allocated gadgetId, which will be bound to the gadget provider - * once the user has selected one.</td> - * </tr> - * </table> - * - * <p> - * The system will respond with an onActivityResult call with the following extras in - * the intent: - * <table> - * <tr> - * <td>{@link #EXTRA_GADGET_ID}</td> - * <td>The gadgetId that you supplied in the original intent.</td> - * </tr> - * </table> - * <p> - * When you receive the result from the gadget pick activity, if the resultCode is - * {@link android.app.Activity#RESULT_OK}, a gadget has been selected. You should then - * check the GadgetProviderInfo for the returned gadget, and if it has one, launch its configuration - * activity. If {@link android.app.Activity#RESULT_CANCELED} is returned, you should delete - * the gadgetId. - * - * @see #ACTION_GADGET_CONFIGURE - */ - public static final String ACTION_GADGET_PICK = "android.gadget.action.GADGET_PICK"; - - /** - * Sent when it is time to configure your gadget while it is being added to a host. - * This action is not sent as a broadcast to the gadget provider, but as a startActivity - * to the activity specified in the {@link GadgetProviderInfo GadgetProviderInfo meta-data}. - * - * <p> - * The intent will contain the following extras: - * <table> - * <tr> - * <td>{@link #EXTRA_GADGET_ID}</td> - * <td>The gadgetId to configure.</td> - * </tr> - * </table> - * - * <p>If you return {@link android.app.Activity#RESULT_OK} using - * {@link android.app.Activity#setResult Activity.setResult()}, the gadget will be added, - * and you will receive an {@link #ACTION_GADGET_UPDATE} broadcast for this gadget. - * If you return {@link android.app.Activity#RESULT_CANCELED}, the host will cancel the add - * and not display this gadget, and you will receive a {@link #ACTION_GADGET_DELETED} broadcast. - */ - public static final String ACTION_GADGET_CONFIGURE = "android.gadget.action.GADGET_CONFIGURE"; - - /** - * An intent extra that contains one gadgetId. - * <p> - * The value will be an int that can be retrieved like this: - * {@sample frameworks/base/tests/gadgets/GadgetHostTest/src/com/android/tests/gadgethost/GadgetHostActivity.java getExtra_EXTRA_GADGET_ID} - */ - public static final String EXTRA_GADGET_ID = "gadgetId"; - - /** - * An intent extra that contains multiple gadgetIds. - * <p> - * The value will be an int array that can be retrieved like this: - * {@sample frameworks/base/tests/gadgets/GadgetHostTest/src/com/android/tests/gadgethost/TestGadgetProvider.java getExtra_EXTRA_GADGET_IDS} - */ - public static final String EXTRA_GADGET_IDS = "gadgetIds"; - - /** - * A sentiel value that the gadget manager will never return as a gadgetId. - */ - public static final int INVALID_GADGET_ID = 0; - - /** - * Sent when it is time to update your gadget. - * - * <p>This may be sent in response to a new instance for this gadget provider having - * been instantiated, the requested {@link GadgetProviderInfo#updatePeriodMillis update interval} - * having lapsed, or the system booting. - * - * <p> - * The intent will contain the following extras: - * <table> - * <tr> - * <td>{@link #EXTRA_GADGET_IDS}</td> - * <td>The gadgetIds to update. This may be all of the gadgets created for this - * provider, or just a subset. The system tries to send updates for as few gadget - * instances as possible.</td> - * </tr> - * </table> - * - * @see GadgetProvider#onUpdate GadgetProvider.onUpdate(Context context, GadgetManager gadgetManager, int[] gadgetIds) - */ - public static final String ACTION_GADGET_UPDATE = "android.gadget.action.GADGET_UPDATE"; - - /** - * Sent when an instance of a gadget is deleted from its host. - * - * @see GadgetProvider#onDeleted GadgetProvider.onDeleted(Context context, int[] gadgetIds) - */ - public static final String ACTION_GADGET_DELETED = "android.gadget.action.GADGET_DELETED"; - - /** - * Sent when an instance of a gadget is removed from the last host. - * - * @see GadgetProvider#onEnabled GadgetProvider.onEnabled(Context context) - */ - public static final String ACTION_GADGET_DISABLED = "android.gadget.action.GADGET_DISABLED"; - - /** - * Sent when an instance of a gadget is added to a host for the first time. - * This broadcast is sent at boot time if there is a gadget host installed with - * an instance for this provider. - * - * @see GadgetProvider#onEnabled GadgetProvider.onEnabled(Context context) - */ - public static final String ACTION_GADGET_ENABLED = "android.gadget.action.GADGET_ENABLED"; - - /** - * Field for the manifest meta-data tag. - * - * @see GadgetProviderInfo - */ - public static final String META_DATA_GADGET_PROVIDER = "android.gadget.provider"; - - static WeakHashMap<Context, WeakReference<GadgetManager>> sManagerCache = new WeakHashMap(); - static IGadgetService sService; - - Context mContext; - - /** - * Get the GadgetManager instance to use for the supplied {@link android.content.Context - * Context} object. - */ - public static GadgetManager getInstance(Context context) { - synchronized (sManagerCache) { - if (sService == null) { - IBinder b = ServiceManager.getService(Context.GADGET_SERVICE); - sService = IGadgetService.Stub.asInterface(b); - } - - WeakReference<GadgetManager> ref = sManagerCache.get(context); - GadgetManager result = null; - if (ref != null) { - result = ref.get(); - } - if (result == null) { - result = new GadgetManager(context); - sManagerCache.put(context, new WeakReference(result)); - } - return result; - } - } - - private GadgetManager(Context context) { - mContext = context; - } - - /** - * Set the RemoteViews to use for the specified gadgetIds. - * - * <p> - * It is okay to call this method both inside an {@link #ACTION_GADGET_UPDATE} broadcast, - * and outside of the handler. - * This method will only work when called from the uid that owns the gadget provider. - * - * @param gadgetIds The gadget instances for which to set the RemoteViews. - * @param views The RemoteViews object to show. - */ - public void updateGadget(int[] gadgetIds, RemoteViews views) { - try { - sService.updateGadgetIds(gadgetIds, views); - } - catch (RemoteException e) { - throw new RuntimeException("system server dead?", e); - } - } - - /** - * Set the RemoteViews to use for the specified gadgetId. - * - * <p> - * It is okay to call this method both inside an {@link #ACTION_GADGET_UPDATE} broadcast, - * and outside of the handler. - * This method will only work when called from the uid that owns the gadget provider. - * - * @param gadgetId The gadget instance for which to set the RemoteViews. - * @param views The RemoteViews object to show. - */ - public void updateGadget(int gadgetId, RemoteViews views) { - updateGadget(new int[] { gadgetId }, views); - } - - /** - * Set the RemoteViews to use for all gadget instances for the supplied gadget provider. - * - * <p> - * It is okay to call this method both inside an {@link #ACTION_GADGET_UPDATE} broadcast, - * and outside of the handler. - * This method will only work when called from the uid that owns the gadget provider. - * - * @param provider The {@link ComponentName} for the {@link - * android.content.BroadcastReceiver BroadcastReceiver} provider - * for your gadget. - * @param views The RemoteViews object to show. - */ - public void updateGadget(ComponentName provider, RemoteViews views) { - try { - sService.updateGadgetProvider(provider, views); - } - catch (RemoteException e) { - throw new RuntimeException("system server dead?", e); - } - } - - /** - * Return a list of the gadget providers that are currently installed. - */ - public List<GadgetProviderInfo> getInstalledProviders() { - try { - return sService.getInstalledProviders(); - } - catch (RemoteException e) { - throw new RuntimeException("system server dead?", e); - } - } - - /** - * Get the available info about the gadget. - * - * @return A gadgetId. If the gadgetId has not been bound to a provider yet, or - * you don't have access to that gadgetId, null is returned. - */ - public GadgetProviderInfo getGadgetInfo(int gadgetId) { - try { - return sService.getGadgetInfo(gadgetId); - } - catch (RemoteException e) { - throw new RuntimeException("system server dead?", e); - } - } - - /** - * Set the component for a given gadgetId. - * - * <p class="note">You need the GADGET_LIST permission. This method is to be used by the - * gadget picker. - * - * @param gadgetId The gadget instance for which to set the RemoteViews. - * @param provider The {@link android.content.BroadcastReceiver} that will be the gadget - * provider for this gadget. - */ - public void bindGadgetId(int gadgetId, ComponentName provider) { - try { - sService.bindGadgetId(gadgetId, provider); - } - catch (RemoteException e) { - throw new RuntimeException("system server dead?", e); - } - } - - /** - * Get the list of gadgetIds that have been bound to the given gadget - * provider. - * - * @param provider The {@link android.content.BroadcastReceiver} that is the - * gadget provider to find gadgetIds for. - */ - public int[] getGadgetIds(ComponentName provider) { - try { - return sService.getGadgetIds(provider); - } - catch (RemoteException e) { - throw new RuntimeException("system server dead?", e); - } - } -} - diff --git a/core/java/android/gadget/GadgetProvider.java b/core/java/android/gadget/GadgetProvider.java deleted file mode 100755 index 7e10e78..0000000 --- a/core/java/android/gadget/GadgetProvider.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2006 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 android.gadget; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; - -/** - * A conveience class to aid in implementing a gadget provider. - * Everything you can do with GadgetProvider, you can do with a regular {@link BroadcastReceiver}. - * GadgetProvider merely parses the relevant fields out of the Intent that is received in - * {@link #onReceive(Context,Intent) onReceive(Context,Intent)}, and calls hook methods - * with the received extras. - * - * <p>Extend this class and override one or more of the {@link #onUpdate}, {@link #onDeleted}, - * {@link #onEnabled} or {@link #onDisabled} methods to implement your own gadget functionality. - * - * <h3>Sample Code</h3> - * For an example of how to write a gadget provider, see the - * <a href="{@toroot}reference/android/gadget/package-descr.html#providers">android.gadget - * package overview</a>. - */ -public class GadgetProvider extends BroadcastReceiver { - /** - * Constructor to initialize GadgetProvider. - */ - public GadgetProvider() { - } - - /** - * Implements {@link BroadcastReceiver#onReceive} to dispatch calls to the various - * other methods on GadgetProvider. - * - * @param context The Context in which the receiver is running. - * @param intent The Intent being received. - */ - // BEGIN_INCLUDE(onReceive) - public void onReceive(Context context, Intent intent) { - // Protect against rogue update broadcasts (not really a security issue, - // just filter bad broacasts out so subclasses are less likely to crash). - String action = intent.getAction(); - if (GadgetManager.ACTION_GADGET_UPDATE.equals(action)) { - Bundle extras = intent.getExtras(); - if (extras != null) { - int[] gadgetIds = extras.getIntArray(GadgetManager.EXTRA_GADGET_IDS); - if (gadgetIds != null && gadgetIds.length > 0) { - this.onUpdate(context, GadgetManager.getInstance(context), gadgetIds); - } - } - } - else if (GadgetManager.ACTION_GADGET_DELETED.equals(action)) { - Bundle extras = intent.getExtras(); - if (extras != null) { - int[] gadgetIds = extras.getIntArray(GadgetManager.EXTRA_GADGET_IDS); - if (gadgetIds != null && gadgetIds.length > 0) { - this.onDeleted(context, gadgetIds); - } - } - } - else if (GadgetManager.ACTION_GADGET_ENABLED.equals(action)) { - this.onEnabled(context); - } - else if (GadgetManager.ACTION_GADGET_DISABLED.equals(action)) { - this.onDisabled(context); - } - } - // END_INCLUDE(onReceive) - - /** - * Called in response to the {@link GadgetManager#ACTION_GADGET_UPDATE} broadcast when - * this gadget provider is being asked to provide {@link android.widget.RemoteViews RemoteViews} - * for a set of gadgets. Override this method to implement your own gadget functionality. - * - * {@more} - * - * @param context The {@link android.content.Context Context} in which this receiver is - * running. - * @param gadgetManager A {@link GadgetManager} object you can call {@link - * GadgetManager#updateGadget} on. - * @param gadgetIds The gadgetsIds for which an update is needed. Note that this - * may be all of the gadget instances for this provider, or just - * a subset of them. - * - * @see GadgetManager#ACTION_GADGET_UPDATE - */ - public void onUpdate(Context context, GadgetManager gadgetManager, int[] gadgetIds) { - } - - /** - * Called in response to the {@link GadgetManager#ACTION_GADGET_DELETED} broadcast when - * one or more gadget instances have been deleted. Override this method to implement - * your own gadget functionality. - * - * {@more} - * - * @param context The {@link android.content.Context Context} in which this receiver is - * running. - * @param gadgetIds The gadgetsIds that have been deleted from their host. - * - * @see GadgetManager#ACTION_GADGET_DELETED - */ - public void onDeleted(Context context, int[] gadgetIds) { - } - - /** - * Called in response to the {@link GadgetManager#ACTION_GADGET_ENABLED} broadcast when - * the a gadget for this provider is instantiated. Override this method to implement your - * own gadget functionality. - * - * {@more} - * When the last gadget for this provider is deleted, - * {@link GadgetManager#ACTION_GADGET_DISABLED} is sent by the gadget manager, and - * {@link #onDisabled} is called. If after that, a gadget for this provider is created - * again, onEnabled() will be called again. - * - * @param context The {@link android.content.Context Context} in which this receiver is - * running. - * - * @see GadgetManager#ACTION_GADGET_ENABLED - */ - public void onEnabled(Context context) { - } - - /** - * Called in response to the {@link GadgetManager#ACTION_GADGET_DISABLED} broadcast, which - * is sent when the last gadget instance for this provider is deleted. Override this method - * to implement your own gadget functionality. - * - * {@more} - * - * @param context The {@link android.content.Context Context} in which this receiver is - * running. - * - * @see GadgetManager#ACTION_GADGET_DISABLED - */ - public void onDisabled(Context context) { - } -} diff --git a/core/java/android/gadget/GadgetProviderInfo.aidl b/core/java/android/gadget/GadgetProviderInfo.aidl deleted file mode 100644 index 589f886..0000000 --- a/core/java/android/gadget/GadgetProviderInfo.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 android.gadget; - -parcelable GadgetProviderInfo; diff --git a/core/java/android/gadget/GadgetProviderInfo.java b/core/java/android/gadget/GadgetProviderInfo.java deleted file mode 100644 index 95c0432..0000000 --- a/core/java/android/gadget/GadgetProviderInfo.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2006 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 android.gadget; - -import android.os.Parcel; -import android.os.Parcelable; -import android.content.ComponentName; - -/** - * Describes the meta data for an installed gadget provider. The fields in this class - * correspond to the fields in the <code><gadget-provider></code> xml tag. - */ -public class GadgetProviderInfo implements Parcelable { - /** - * Identity of this gadget component. This component should be a {@link - * android.content.BroadcastReceiver}, and it will be sent the Gadget intents - * {@link android.gadget as described in the gadget package documentation}. - * - * <p>This field corresponds to the <code>android:name</code> attribute in - * the <code><receiver></code> element in the AndroidManifest.xml file. - */ - public ComponentName provider; - - /** - * Minimum width of the gadget, in dp. - * - * <p>This field corresponds to the <code>android:minWidth</code> attribute in - * the gadget meta-data file. - */ - public int minWidth; - - /** - * Minimum height of the gadget, in dp. - * - * <p>This field corresponds to the <code>android:minHeight</code> attribute in - * the gadget meta-data file. - */ - public int minHeight; - - /** - * How often, in milliseconds, that this gadget wants to be updated. - * The gadget manager may place a limit on how often a gadget is updated. - * - * <p>This field corresponds to the <code>android:updatePeriodMillis</code> attribute in - * the gadget meta-data file. - */ - public int updatePeriodMillis; - - /** - * The resource id of the initial layout for this gadget. This should be - * displayed until the RemoteViews for the gadget is available. - * - * <p>This field corresponds to the <code>android:initialLayout</code> attribute in - * the gadget meta-data file. - */ - public int initialLayout; - - /** - * The activity to launch that will configure the gadget. - * - * <p>This class name of field corresponds to the <code>android:configure</code> attribute in - * the gadget meta-data file. The package name always corresponds to the package containing - * the gadget provider. - */ - public ComponentName configure; - - /** - * The label to display to the user in the gadget picker. If not supplied in the - * xml, the application label will be used. - * - * <p>This field corresponds to the <code>android:label</code> attribute in - * the <code><receiver></code> element in the AndroidManifest.xml file. - */ - public String label; - - /** - * The icon to display for this gadget in the gadget picker. If not supplied in the - * xml, the application icon will be used. - * - * <p>This field corresponds to the <code>android:icon</code> attribute in - * the <code><receiver></code> element in the AndroidManifest.xml file. - */ - public int icon; - - public GadgetProviderInfo() { - } - - /** - * Unflatten the GadgetProviderInfo from a parcel. - */ - public GadgetProviderInfo(Parcel in) { - if (0 != in.readInt()) { - this.provider = new ComponentName(in); - } - this.minWidth = in.readInt(); - this.minHeight = in.readInt(); - this.updatePeriodMillis = in.readInt(); - this.initialLayout = in.readInt(); - if (0 != in.readInt()) { - this.configure = new ComponentName(in); - } - this.label = in.readString(); - this.icon = in.readInt(); - } - - - public void writeToParcel(android.os.Parcel out, int flags) { - if (this.provider != null) { - out.writeInt(1); - this.provider.writeToParcel(out, flags); - } else { - out.writeInt(0); - } - out.writeInt(this.minWidth); - out.writeInt(this.minHeight); - out.writeInt(this.updatePeriodMillis); - out.writeInt(this.initialLayout); - if (this.configure != null) { - out.writeInt(1); - this.configure.writeToParcel(out, flags); - } else { - out.writeInt(0); - } - out.writeString(this.label); - out.writeInt(this.icon); - } - - public int describeContents() { - return 0; - } - - /** - * Parcelable.Creator that instantiates GadgetProviderInfo objects - */ - public static final Parcelable.Creator<GadgetProviderInfo> CREATOR - = new Parcelable.Creator<GadgetProviderInfo>() - { - public GadgetProviderInfo createFromParcel(Parcel parcel) - { - return new GadgetProviderInfo(parcel); - } - - public GadgetProviderInfo[] newArray(int size) - { - return new GadgetProviderInfo[size]; - } - }; - - public String toString() { - return "GadgetProviderInfo(provider=" + this.provider + ")"; - } -} - - diff --git a/core/java/android/gadget/package.html b/core/java/android/gadget/package.html deleted file mode 100644 index 4c04396..0000000 --- a/core/java/android/gadget/package.html +++ /dev/null @@ -1,136 +0,0 @@ -<body> -<p>Android allows applications to publish views to be embedded in other applications. These -views are called gadgets, and are published by "gadget providers." The component that can -contain gadgets is called a "gadget host." -</p> -<h3><a href="package-descr.html#providers">Gadget Providers</a></h3> -<ul> - <li><a href="package-descr.html#provider_manifest">Declaring a gadget in the AndroidManifest</a></li> - <li><a href="package-descr.html#provider_meta_data">Adding the GadgetProviderInfo meta-data</a></li> - <li><a href="package-descr.html#provider_GadgetProvider">Using the GadgetProvider class</a></li> - <li><a href="package-descr.html#provider_configuration">Gadget Configuration UI</a></li> - <li><a href="package-descr.html#provider_broadcasts">Gadget Broadcast Intents</a></li> -</ul> -<h3><a href="package-descr.html#">Gadget Hosts</a></h3> - - -{@more} - - -<h2><a name="providers"></a>Gadget Providers</h2> -<p> -Any application can publish gadgets. All an application needs to do to publish a gadget is -to have a {@link android.content.BroadcastReceiver} that receives the {@link -android.gadget.GadgetManager#ACTION_GADGET_UPDATE GadgetManager.ACTION_GADGET_UPDATE} intent, -and provide some meta-data about the gadget. Android provides the -{@link android.gadget.GadgetProvider} class, which extends BroadcastReceiver, as a convenience -class to aid in handling the broadcasts. - -<h3><a name="provider_manifest"></a>Declaring a gadget in the AndroidManifest</h3> - -<p> -First, declare the {@link android.content.BroadcastReceiver} in your application's -<code>AndroidManifest.xml</code> file. - -{@sample frameworks/base/tests/gadgets/GadgetHostTest/AndroidManifest.xml GadgetProvider} - -<p> -The <b><code><receiver></b> element has the following attributes: -<ul> - <li><b><code>android:name</code> -</b> which specifies the - {@link android.content.BroadcastReceiver} or {@link android.gadget.GadgetProvider} - class.</li> - <li><b><code>android:label</code> -</b> which specifies the string resource that - will be shown by the gadget picker as the label.</li> - <li><b><code>android:icon</code> -</b> which specifies the drawable resource that - will be shown by the gadget picker as the icon.</li> -</ul> - -<p> -The <b><code><intent-filter></b> element tells the {@link android.content.pm.PackageManager} -that this {@link android.content.BroadcastReceiver} receives the {@link -android.gadget.GadgetManager#ACTION_GADGET_UPDATE GadgetManager.ACTION_GADGET_UPDATE} broadcast. -The gadget manager will send other broadcasts directly to your gadget provider as required. -It is only necessary to explicitly declare that you accept the {@link -android.gadget.GadgetManager#ACTION_GADGET_UPDATE GadgetManager.ACTION_GADGET_UPDATE} broadcast. - -<p> -The <b><code><meta-data></code></b> element tells the gadget manager which xml resource to -read to find the {@link android.gadget.GadgetProviderInfo} for your gadget provider. It has the following -attributes: -<ul> - <li><b><code>android:name="android.gadget.provider"</code> -</b> identifies this meta-data - as the {@link android.gadget.GadgetProviderInfo} descriptor.</li> - <li><b><code>android:resource</code> -</b> is the xml resource to use as that descriptor.</li> -</ul> - - -<h3><a name="provider_meta_data"></a>Adding the {@link android.gadget.GadgetProviderInfo GadgetProviderInfo} meta-data</h3> - -<p> -For a gadget, the values in the {@link android.gadget.GadgetProviderInfo} structure are supplied -in an XML resource. In the example above, the xml resource is referenced with -<code>android:resource="@xml/gadget_info"</code>. That XML file would go in your application's -directory at <code>res/xml/gadget_info.xml</code>. Here is a simple example. - -{@sample frameworks/base/tests/gadgets/GadgetHostTest/res/xml/gadget_info.xml GadgetProviderInfo} - -<p> -The attributes are as documented in the {@link android.gadget.GadgetProviderInfo GagetInfo} class. (86400000 milliseconds means once per day) - - -<h3><a name="provider_GadgetProvider"></a>Using the {@link android.gadget.GadgetProvider GadgetProvider} class</h3> - -<p>The GadgetProvider class is the easiest way to handle the gadget provider intent broadcasts. -See the <code>src/com/example/android/apis/gadget/ExampleGadgetProvider.java</code> -sample class in ApiDemos for an example. - -<p class="note">Keep in mind that since the the GadgetProvider is a BroadcastReceiver, -your process is not guaranteed to keep running after the callback methods return. See -<a href="../../../guide/topics/fundamentals.html#broadlife">Application Fundamentals > -Broadcast Receiver Lifecycle</a> for more information. - - - -<h3><a name="provider_configuration"></a>Gadget Configuration UI</h3> - -<p> -Gadget hosts have the ability to start a configuration activity when a gadget is instantiated. -The activity should be declared as normal in AndroidManifest.xml, and it should be listed in -the GadgetProviderInfo XML file in the <code>android:configure</code> attribute. - -<p>The activity you specified will be launched with the {@link -android.gadget.GadgetManager#ACTION_GADGET_CONFIGURE} action. See the documentation for that -action for more info. - -<p>See the <code>src/com/example/android/apis/gadget/ExampleGadgetConfigure.java</code> -sample class in ApiDemos for an example. - - - -<h3><a name="providers_broadcasts"></a>Gadget Broadcast Intents</h3> - -<p>{@link android.gadget.GadgetProvider} is just a convenience class. If you would like -to receive the gadget broadcasts directly, you can. The four intents you need to care about are: -<ul> - <li>{@link android.gadget.GadgetManager#ACTION_GADGET_UPDATE}</li> - <li>{@link android.gadget.GadgetManager#ACTION_GADGET_DELETED}</li> - <li>{@link android.gadget.GadgetManager#ACTION_GADGET_ENABLED}</li> - <li>{@link android.gadget.GadgetManager#ACTION_GADGET_DISABLED}</li> -</ul> - -<p>By way of example, the implementation of -{@link android.gadget.GadgetProvider#onReceive} is quite simple:</p> - -{@sample frameworks/base/core/java/android/gadget/GadgetProvider.java onReceive} - - -<h2>Gadget Hosts</h3> -<p>Gadget hosts are the containers in which gadgets can be placed. Most of the look and feel -details are left up to the gadget hosts. For example, the home screen has one way of viewing -gadgets, but the lock screen could also contain gadgets, and it would have a different way of -adding, removing and otherwise managing gadgets.</p> -<p>For more information on implementing your own gadget host, see the -{@link android.gadget.GadgetHost GadgetHost} class.</p> -</body> - |