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

Commit 2d2e30ee authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "More work on voice interaction visuals." into lmp-preview-dev

parents 1d285b09 20d94749
Loading
Loading
Loading
Loading
+156 −152

File changed.

Preview size limit exceeded, changes collapsed.

+18 −3
Original line number Diff line number Diff line
@@ -716,6 +716,7 @@ public class Activity extends ContextThemeWrapper
        HashMap<String, Object> children;
        ArrayList<Fragment> fragments;
        ArrayMap<String, LoaderManagerImpl> loaders;
        VoiceInteractor voiceInteractor;
    }
    /* package */ NonConfigurationInstances mLastNonConfigurationInstances;
    
@@ -920,6 +921,9 @@ public class Activity extends ContextThemeWrapper
        }
        mFragments.dispatchCreate();
        getApplication().dispatchActivityCreated(this, savedInstanceState);
        if (mVoiceInteractor != null) {
            mVoiceInteractor.attachActivity(this);
        }
        mCalled = true;
    }

@@ -1830,7 +1834,8 @@ public class Activity extends ContextThemeWrapper
                }
            }
        }
        if (activity == null && children == null && fragments == null && !retainLoaders) {
        if (activity == null && children == null && fragments == null && !retainLoaders
                && mVoiceInteractor == null) {
            return null;
        }
        
@@ -1839,6 +1844,7 @@ public class Activity extends ContextThemeWrapper
        nci.children = children;
        nci.fragments = fragments;
        nci.loaders = mAllLoaderManagers;
        nci.voiceInteractor = mVoiceInteractor;
        return nci;
    }

@@ -5632,8 +5638,14 @@ public class Activity extends ContextThemeWrapper
        mParent = parent;
        mEmbeddedID = id;
        mLastNonConfigurationInstances = lastNonConfigurationInstances;
        mVoiceInteractor = voiceInteractor != null
                ? new VoiceInteractor(this, this, voiceInteractor, Looper.myLooper()) : null;
        if (voiceInteractor != null) {
            if (lastNonConfigurationInstances != null) {
                mVoiceInteractor = lastNonConfigurationInstances.voiceInteractor;
            } else {
                mVoiceInteractor = new VoiceInteractor(voiceInteractor, this, this,
                        Looper.myLooper());
            }
        }

        mWindow.setWindowManager(
                (WindowManager)context.getSystemService(Context.WINDOW_SERVICE),
@@ -5842,6 +5854,9 @@ public class Activity extends ContextThemeWrapper
        if (mLoaderManager != null) {
            mLoaderManager.doDestroy();
        }
        if (mVoiceInteractor != null) {
            mVoiceInteractor.detachActivity();
        }
    }

    /**
+56 −5
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ import com.android.internal.app.IVoiceInteractorRequest;
import com.android.internal.os.HandlerCaller;
import com.android.internal.os.SomeArgs;

import java.util.WeakHashMap;
import java.util.ArrayList;

/**
 * Interface for an {@link Activity} to interact with the user through voice.
@@ -39,9 +39,11 @@ public class VoiceInteractor {
    static final String TAG = "VoiceInteractor";
    static final boolean DEBUG = true;

    final Context mContext;
    final Activity mActivity;
    final IVoiceInteractor mInteractor;

    Context mContext;
    Activity mActivity;

    final HandlerCaller mHandlerCaller;
    final HandlerCaller.Callback mHandlerCallerCallback = new HandlerCaller.Callback() {
        @Override
@@ -140,6 +142,12 @@ public class VoiceInteractor {
        public void onCancel() {
        }

        public void onAttached(Activity activity) {
        }

        public void onDetached() {
        }

        void clear() {
            mRequestInterface = null;
            mContext = null;
@@ -220,11 +228,11 @@ public class VoiceInteractor {
        }
   }

    VoiceInteractor(Context context, Activity activity, IVoiceInteractor interactor,
    VoiceInteractor(IVoiceInteractor interactor, Context context, Activity activity,
            Looper looper) {
        mInteractor = interactor;
        mContext = context;
        mActivity = activity;
        mInteractor = interactor;
        mHandlerCaller = new HandlerCaller(context, looper, mHandlerCallerCallback, true);
    }

@@ -238,6 +246,49 @@ public class VoiceInteractor {
        }
    }

    private ArrayList<Request> makeRequestList() {
        final int N = mActiveRequests.size();
        if (N < 1) {
            return null;
        }
        ArrayList<Request> list = new ArrayList<Request>(N);
        for (int i=0; i<N; i++) {
            list.add(mActiveRequests.valueAt(i));
        }
        return list;
    }

    void attachActivity(Activity activity) {
        if (mActivity == activity) {
            return;
        }
        mContext = activity;
        mActivity = activity;
        ArrayList<Request> reqs = makeRequestList();
        if (reqs != null) {
            for (int i=0; i<reqs.size(); i++) {
                Request req = reqs.get(i);
                req.mContext = activity;
                req.mActivity = activity;
                req.onAttached(activity);
            }
        }
    }

    void detachActivity() {
        ArrayList<Request> reqs = makeRequestList();
        if (reqs != null) {
            for (int i=0; i<reqs.size(); i++) {
                Request req = reqs.get(i);
                req.onDetached();
                req.mActivity = null;
                req.mContext = null;
            }
        }
        mContext = null;
        mActivity = null;
    }

    public boolean submitRequest(Request request) {
        try {
            IVoiceInteractorRequest ireq = request.submit(mInteractor,
+4 −3
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ class IInputMethodWrapper extends IInputMethod.Stub
    private static final int DO_CHANGE_INPUTMETHOD_SUBTYPE = 80;
   
    final WeakReference<AbstractInputMethodService> mTarget;
    final Context mContext;
    final HandlerCaller mCaller;
    final WeakReference<InputMethod> mInputMethod;
    final int mTargetSdkVersion;
@@ -111,8 +112,8 @@ class IInputMethodWrapper extends IInputMethod.Stub
    public IInputMethodWrapper(AbstractInputMethodService context,
            InputMethod inputMethod) {
        mTarget = new WeakReference<AbstractInputMethodService>(context);
        mCaller = new HandlerCaller(context.getApplicationContext(), null,
                this, true /*asyncHandler*/);
        mContext = context.getApplicationContext();
        mCaller = new HandlerCaller(mContext, null, this, true /*asyncHandler*/);
        mInputMethod = new WeakReference<InputMethod>(inputMethod);
        mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion;
    }
@@ -186,7 +187,7 @@ class IInputMethodWrapper extends IInputMethod.Stub
            case DO_CREATE_SESSION: {
                SomeArgs args = (SomeArgs)msg.obj;
                inputMethod.createSession(new InputMethodSessionCallbackWrapper(
                        mCaller.mContext, (InputChannel)args.arg1,
                        mContext, (InputChannel)args.arg1,
                        (IInputSessionCallback)args.arg2));
                args.recycle();
                return;
+4 −0
Original line number Diff line number Diff line
@@ -115,6 +115,10 @@ public class SoftInputWindow extends Dialog {
        getWindow().setAttributes(lp);
    }

    public int getGravity() {
        return getWindow().getAttributes().gravity;
    }

    private void updateWidthHeight(WindowManager.LayoutParams lp) {
        if (lp.gravity == Gravity.TOP || lp.gravity == Gravity.BOTTOM) {
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
Loading