Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c39a6e0c authored by The Android Open Source Project's avatar The Android Open Source Project
Browse files

auto import from //branches/cupcake/...@137873

parent b2a3dd88
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -98,8 +98,8 @@ LOCAL_SRC_FILES += \
	core/java/android/view/IWindowSession.aidl \
	core/java/com/android/internal/app/IBatteryStats.aidl \
	core/java/com/android/internal/app/IUsageStats.aidl \
	core/java/com/android/internal/gadget/IGadgetService.aidl \
	core/java/com/android/internal/gadget/IGadgetHost.aidl \
	core/java/com/android/internal/appwidget/IAppWidgetService.aidl \
	core/java/com/android/internal/appwidget/IAppWidgetHost.aidl \
	core/java/com/android/internal/os/IResultReceiver.aidl \
	core/java/com/android/internal/view/IInputContext.aidl \
	core/java/com/android/internal/view/IInputContextCallback.aidl \
@@ -168,7 +168,7 @@ aidl_files := \
	frameworks/base/core/java/android/content/Intent.aidl \
	frameworks/base/core/java/android/content/SyncStats.aidl \
	frameworks/base/core/java/android/content/res/Configuration.aidl \
	frameworks/base/core/java/android/gadget/GadgetProviderInfo.aidl \
	frameworks/base/core/java/android/appwidget/AppWidgetProviderInfo.aidl \
	frameworks/base/core/java/android/net/Uri.aidl \
	frameworks/base/core/java/android/os/Bundle.aidl \
	frameworks/base/core/java/android/os/ParcelFileDescriptor.aidl \
+0 −11
Original line number Diff line number Diff line
@@ -25763,17 +25763,6 @@
 visibility="public"
>
</field>
<field name="CATEGORY_GADGET"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;android.intent.category.GADGET&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="CATEGORY_HOME"
 type="java.lang.String"
 transient="false"
+772 −737

File changed.

Preview size limit exceeded, changes collapsed.

+22 −4
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
@@ -125,7 +126,14 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS

    // support for AutoCompleteTextView suggestions display
    private SuggestionsAdapter mSuggestionsAdapter;

    private Handler mHandler = new Handler();
    private Runnable mInstallSuggestionAdapter = new Runnable() {
        public void run() {
            if (mSearchTextField != null) {
                mSearchTextField.setAdapter(mSuggestionsAdapter);
            }
        }
    };

    /**
     * Constructor - fires it up and makes it look like the search UI.
@@ -253,7 +261,8 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
            mSearchTextField.setAdapter(mSuggestionsAdapter);
            mSearchTextField.setText(initialQuery);
        } else {
            mSuggestionsAdapter = new SuggestionsAdapter(getContext(), mSearchable);
            mSuggestionsAdapter = new SuggestionsAdapter(getContext(), mSearchable,
                    mHandler, mInstallSuggestionAdapter);
            mSearchTextField.setAdapter(mSuggestionsAdapter);

            // finally, load the user's initial text (which may trigger suggestions)
@@ -1296,10 +1305,15 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
        // These private variables are shared by the filter thread and must be protected
        private WeakReference<Cursor> mRecentCursor = new WeakReference<Cursor>(null);
        private boolean mNonUserQuery = false;
        private Handler mHandler;
        private Runnable mInstallSuggestionAdapter;

        public SuggestionsAdapter(Context context, SearchableInfo searchable) {
        public SuggestionsAdapter(Context context, SearchableInfo searchable,
                Handler handler, Runnable installSuggestionAdapter) {
            super(context, -1, null, null, null);
            mSearchable = searchable;
            mHandler = handler;
            mInstallSuggestionAdapter = installSuggestionAdapter;
            
            // set up provider resources (gives us icons, etc.)
            Context activityContext = mSearchable.getActivityContext(mContext);
@@ -1415,6 +1429,10 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
                // Now actually set up the cursor, columns, and the list view
                changeCursorAndColumns(c, from, to);
                setViewResource(layout);          
                // Force the underlying ListView to discard and reload all layouts
                // (Note, this could be optimized for cases where layout/cursor remain same)
                mHandler.post(mInstallSuggestionAdapter);

            } else {
                // Provide some help for developers instead of just silently discarding
                Log.w(LOG_TAG, "Suggestions cursor discarded due to missing required columns.");
+49 −50
Original line number Diff line number Diff line
/*
 * 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.
@@ -14,7 +13,7 @@
 * limitations under the License.
 */

package android.gadget;
package android.appwidget;

import android.content.Context;
import android.os.Handler;
@@ -29,35 +28,35 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.android.internal.gadget.IGadgetHost;
import com.android.internal.gadget.IGadgetService;
import com.android.internal.appwidget.IAppWidgetHost;
import com.android.internal.appwidget.IAppWidgetService;

/**
 * GadgetHost provides the interaction with the Gadget Service for apps,
 * like the home screen, that want to embed gadgets in their UI.
 * AppWidgetHost provides the interaction with the AppWidget service for apps,
 * like the home screen, that want to embed AppWidgets in their UI.
 */
public class GadgetHost {
public class AppWidgetHost {

    static final int HANDLE_UPDATE = 1;
    static final int HANDLE_PROVIDER_CHANGED = 2;

    static Object sServiceLock = new Object();
    static IGadgetService sService;
    static IAppWidgetService sService;

    Context mContext;
    String mPackageName;

    class Callbacks extends IGadgetHost.Stub {
        public void updateGadget(int gadgetId, RemoteViews views) {
    class Callbacks extends IAppWidgetHost.Stub {
        public void updateAppWidget(int appWidgetId, RemoteViews views) {
            Message msg = mHandler.obtainMessage(HANDLE_UPDATE);
            msg.arg1 = gadgetId;
            msg.arg1 = appWidgetId;
            msg.obj = views;
            msg.sendToTarget();
        }

        public void providerChanged(int gadgetId, GadgetProviderInfo info) {
        public void providerChanged(int appWidgetId, AppWidgetProviderInfo info) {
            Message msg = mHandler.obtainMessage(HANDLE_PROVIDER_CHANGED);
            msg.arg1 = gadgetId;
            msg.arg1 = appWidgetId;
            msg.obj = info;
            msg.sendToTarget();
        }
@@ -71,11 +70,11 @@ public class GadgetHost {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case HANDLE_UPDATE: {
                    updateGadgetView(msg.arg1, (RemoteViews)msg.obj);
                    updateAppWidgetView(msg.arg1, (RemoteViews)msg.obj);
                    break;
                }
                case HANDLE_PROVIDER_CHANGED: {
                    onProviderChanged(msg.arg1, (GadgetProviderInfo)msg.obj);
                    onProviderChanged(msg.arg1, (AppWidgetProviderInfo)msg.obj);
                    break;
                }
            }
@@ -86,22 +85,22 @@ public class GadgetHost {

    int mHostId;
    Callbacks mCallbacks = new Callbacks();
    HashMap<Integer,GadgetHostView> mViews = new HashMap();
    HashMap<Integer,AppWidgetHostView> mViews = new HashMap();

    public GadgetHost(Context context, int hostId) {
    public AppWidgetHost(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);
                IBinder b = ServiceManager.getService(Context.APPWIDGET_SERVICE);
                sService = IAppWidgetService.Stub.asInterface(b);
            }
        }
    }

    /**
     * Start receiving onGadgetChanged calls for your gadgets.  Call this when your activity
     * Start receiving onAppWidgetChanged calls for your AppWidgets.  Call this when your activity
     * becomes visible, i.e. from onStart() in your Activity.
     */
    public void startListening() {
@@ -120,12 +119,12 @@ public class GadgetHost {

        final int N = updatedIds.length;
        for (int i=0; i<N; i++) {
            updateGadgetView(updatedIds[i], updatedViews.get(i));
            updateAppWidgetView(updatedIds[i], updatedViews.get(i));
        }
    }

    /**
     * Stop receiving onGadgetChanged calls for your gadgets.  Call this when your activity is
     * Stop receiving onAppWidgetChanged calls for your AppWidgets.  Call this when your activity is
     * no longer visible, i.e. from onStop() in your Activity.
     */
    public void stopListening() {
@@ -138,16 +137,16 @@ public class GadgetHost {
    }

    /**
     * Get a gadgetId for a host in the calling process.
     * Get a appWidgetId for a host in the calling process.
     *
     * @return a gadgetId
     * @return a appWidgetId
     */
    public int allocateGadgetId() {
    public int allocateAppWidgetId() {
        try {
            if (mPackageName == null) {
                mPackageName = mContext.getPackageName();
            }
            return sService.allocateGadgetId(mPackageName, mHostId);
            return sService.allocateAppWidgetId(mPackageName, mHostId);
        }
        catch (RemoteException e) {
            throw new RuntimeException("system server dead?", e);
@@ -155,13 +154,13 @@ public class GadgetHost {
    }

    /**
     * Stop listening to changes for this gadget.  
     * Stop listening to changes for this AppWidget.  
     */
    public void deleteGadgetId(int gadgetId) {
    public void deleteAppWidgetId(int appWidgetId) {
        synchronized (mViews) {
            mViews.remove(gadgetId);
            mViews.remove(appWidgetId);
            try {
                sService.deleteGadgetId(gadgetId);
                sService.deleteAppWidgetId(appWidgetId);
            }
            catch (RemoteException e) {
                throw new RuntimeException("system server dead?", e);
@@ -170,10 +169,10 @@ public class GadgetHost {
    }

    /**
     * Remove all records about this host from the gadget manager.
     * Remove all records about this host from the AppWidget 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
     *   <li>Call this to have the AppWidget manager release all resources associated with your
     *   host.  Any future calls about this host will cause the records to be re-allocated.</li>
     * </ul>
     */
@@ -190,7 +189,7 @@ public class GadgetHost {
     * 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
     *   <li>Call this to have the AppWidget manager release all resources associated with your
     *   host.  Any future calls about this host will cause the records to be re-allocated.</li>
     * </ul>
     */
@@ -203,45 +202,45 @@ public class GadgetHost {
        }
    }

    public final GadgetHostView createView(Context context, int gadgetId,
            GadgetProviderInfo gadget) {
        GadgetHostView view = onCreateView(context, gadgetId, gadget);
        view.setGadget(gadgetId, gadget);
    public final AppWidgetHostView createView(Context context, int appWidgetId,
            AppWidgetProviderInfo appWidget) {
        AppWidgetHostView view = onCreateView(context, appWidgetId, appWidget);
        view.setAppWidget(appWidgetId, appWidget);
        synchronized (mViews) {
            mViews.put(gadgetId, view);
            mViews.put(appWidgetId, view);
        }
        RemoteViews views = null;
        try {
            views = sService.getGadgetViews(gadgetId);
            views = sService.getAppWidgetViews(appWidgetId);
        } catch (RemoteException e) {
            throw new RuntimeException("system server dead?", e);
        }
        view.updateGadget(views);
        view.updateAppWidget(views);
        return view;
    }

    /**
     * Called to create the GadgetHostView.  Override to return a custom subclass if you
     * Called to create the AppWidgetHostView.  Override to return a custom subclass if you
     * need it.  {@more}
     */
    protected GadgetHostView onCreateView(Context context, int gadgetId,
            GadgetProviderInfo gadget) {
        return new GadgetHostView(context);
    protected AppWidgetHostView onCreateView(Context context, int appWidgetId,
            AppWidgetProviderInfo appWidget) {
        return new AppWidgetHostView(context);
    }
    
    /**
     * Called when the gadget provider for a gadget has been upgraded to a new apk.
     * Called when the AppWidget provider for a AppWidget has been upgraded to a new apk.
     */
    protected void onProviderChanged(int gadgetId, GadgetProviderInfo gadget) {
    protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidget) {
    }

    void updateGadgetView(int gadgetId, RemoteViews views) {
        GadgetHostView v;
    void updateAppWidgetView(int appWidgetId, RemoteViews views) {
        AppWidgetHostView v;
        synchronized (mViews) {
            v = mViews.get(gadgetId);
            v = mViews.get(appWidgetId);
        }
        if (v != null) {
            v.updateGadget(views);
            v.updateAppWidget(views);
        }
    }
}
Loading