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

Commit 326403e9 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Moving some calls off the UI thread

This saves ~5ms in onNewIntent

Bug: 67305604
Change-Id: Ic97727b1c526e50bd3c8a1d8f511e1d7fd5e05e7
parent ec21a599
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -16,12 +16,16 @@
package com.android.launcher3;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.DragEvent;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.android.launcher3.util.UiThreadHelper;


/**
 * The edit text that reports back when the back key has been pressed.
@@ -102,8 +106,7 @@ public class ExtendedEditText extends EditText {
    }

    public void dispatchBackKey() {
        ((InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE))
                .hideSoftInputFromWindow(getWindowToken(), 0);
        UiThreadHelper.hideKeyboardAsync(getContext(), getWindowToken());
        if (mBackKeyListener != null) {
            mBackKeyListener.onBackKey();
        }
@@ -121,4 +124,17 @@ public class ExtendedEditText extends EditText {
    public boolean isSuggestionsEnabled() {
        return !mForceDisableSuggestions && super.isSuggestionsEnabled();
    }

    public void reset() {
        if (!TextUtils.isEmpty(getText())) {
            setText("");
        }
        if (isFocused()) {
            View nextFocus = focusSearch(View.FOCUS_DOWN);
            if (nextFocus != null) {
                nextFocus.requestFocus();
            }
        }
        UiThreadHelper.hideKeyboardAsync(getContext(), getWindowToken());
    }
}
+6 −10
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.launcher3;

import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_APPS;
import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_WIDGETS;

import android.Manifest;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -53,8 +56,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Process;
import android.os.StrictMode;
import android.os.SystemClock;
import android.os.Trace;
import android.os.UserHandle;
import android.support.annotation.Nullable;
import android.text.Selection;
@@ -119,7 +120,6 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
import com.android.launcher3.util.ActivityResultInfo;
import com.android.launcher3.util.RunnableWithId;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.ComponentKeyMapper;
import com.android.launcher3.util.ItemInfoMatcher;
@@ -127,11 +127,13 @@ import com.android.launcher3.util.MultiHashMap;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.PendingRequestArgs;
import com.android.launcher3.util.RunnableWithId;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.util.TestingUtils;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.TraceHelper;
import com.android.launcher3.util.UiThreadHelper;
import com.android.launcher3.util.ViewOnDrawExecutor;
import com.android.launcher3.widget.PendingAddShortcutInfo;
import com.android.launcher3.widget.PendingAddWidgetInfo;
@@ -140,7 +142,6 @@ import com.android.launcher3.widget.WidgetHostViewLoader;
import com.android.launcher3.widget.WidgetsContainerView;
import com.android.launcher3.widget.custom.CustomWidgetParser;


import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -150,9 +151,6 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;

import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_APPS;
import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_WIDGETS;

/**
 * Default launcher application.
 */
@@ -1606,9 +1604,7 @@ public class Launcher extends BaseActivity

            final View v = getWindow().peekDecorView();
            if (v != null && v.getWindowToken() != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(
                        INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken());
            }

            // Reset the apps view
+1 −22
Original line number Diff line number Diff line
@@ -15,16 +15,13 @@
 */
package com.android.launcher3.allapps.search;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

@@ -50,7 +47,6 @@ public class AllAppsSearchBarController
    protected String mQuery;

    protected SearchAlgorithm mSearchAlgorithm;
    protected InputMethodManager mInputMethodManager;

    public void setVisibility(int visibility) {
        mInput.setVisibility(visibility);
@@ -68,10 +64,6 @@ public class AllAppsSearchBarController
        mInput.addTextChangedListener(this);
        mInput.setOnEditorActionListener(this);
        mInput.setOnBackKeyListener(this);

        mInputMethodManager = (InputMethodManager)
                mInput.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

        mSearchAlgorithm = searchAlgorithm;
    }

@@ -137,22 +129,9 @@ public class AllAppsSearchBarController
     * Resets the search bar state.
     */
    public void reset() {
        unfocusSearchField();
        mCb.clearSearchResult();
        mInput.setText("");
        mInput.reset();
        mQuery = null;
        hideKeyboard();
    }

    protected void hideKeyboard() {
        mInputMethodManager.hideSoftInputFromWindow(mInput.getWindowToken(), 0);
    }

    protected void unfocusSearchField() {
        View nextFocus = mInput.focusSearch(View.FOCUS_DOWN);
        if (nextFocus != null) {
            nextFocus.requestFocus();
        }
    }

    /**
+2 −3
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget;
@@ -39,6 +38,7 @@ import com.android.launcher3.accessibility.DragViewStateAnnouncer;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.TouchController;
import com.android.launcher3.util.UiThreadHelper;

import java.util.ArrayList;

@@ -138,8 +138,7 @@ public class DragController implements DragDriver.EventListener, TouchController
        }

        // Hide soft keyboard, if visible
        mLauncher.getSystemService(InputMethodManager.class)
                .hideSoftInputFromWindow(mWindowToken, 0);
        UiThreadHelper.hideKeyboardAsync(mLauncher, mWindowToken);

        mOptions = options;
        if (mOptions.systemDndStartPoint != null) {
+2 −2
Original line number Diff line number Diff line
@@ -32,10 +32,10 @@ import android.view.View;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppWidgetHostView;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.R;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.util.UiThreadHelper;

import java.nio.ByteBuffer;

@@ -151,7 +151,7 @@ public class DragPreviewProvider {
        }

        mOutlineGeneratorCallback = new OutlineGeneratorCallback(preview);
        new Handler(LauncherModel.getWorkerLooper()).postAtFrontOfQueue(mOutlineGeneratorCallback);
        new Handler(UiThreadHelper.getBackgroundLooper()).post(mOutlineGeneratorCallback);
    }

    protected static Rect getDrawableBounds(Drawable d) {
Loading