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

Commit 1ae2937f authored by Hyunyoung Song's avatar Hyunyoung Song Committed by Android (Google) Code Review
Browse files

Merge "Hookup existing AllAppsSearchPlugin interface to SearchBarController...

Merge "Hookup existing AllAppsSearchPlugin interface to SearchBarController Bug: 161801331" into ub-launcher3-master
parents 5fb83a47 8cac927b
Loading
Loading
Loading
Loading
+70 −5
Original line number Diff line number Diff line
@@ -15,15 +15,23 @@
 */
package com.android.launcher3.allapps.search;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.ExtendedEditText;
@@ -32,23 +40,31 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.allapps.AlphabeticalAppsList;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.systemui.plugins.AllAppsSearchPlugin;
import com.android.systemui.plugins.PluginListener;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
 * An interface to a search box that AllApps can command.
 */
public class AllAppsSearchBarController
        implements TextWatcher, OnEditorActionListener, ExtendedEditText.OnBackKeyListener,
        OnFocusChangeListener {
        OnFocusChangeListener, PluginListener<AllAppsSearchPlugin> {

    private static final String TAG = "AllAppsSearchBarContoller";
    protected BaseDraggingActivity mLauncher;
    protected Callbacks mCb;
    protected ExtendedEditText mInput;
    protected String mQuery;

    protected SearchAlgorithm mSearchAlgorithm;
    private AllAppsSearchPlugin mPlugin;
    private Consumer mPlubinCb;

    public void setVisibility(int visibility) {
        mInput.setVisibility(visibility);
@@ -59,7 +75,7 @@ public class AllAppsSearchBarController
     */
    public final void initialize(
            SearchAlgorithm searchAlgorithm, ExtendedEditText input,
            BaseDraggingActivity launcher, Callbacks cb) {
            BaseDraggingActivity launcher, Callbacks cb, Consumer<List<Bundle>> secondaryCb) {
        mCb = cb;
        mLauncher = launcher;

@@ -69,11 +85,19 @@ public class AllAppsSearchBarController
        mInput.setOnBackKeyListener(this);
        mInput.setOnFocusChangeListener(this);
        mSearchAlgorithm = searchAlgorithm;

        PluginManagerWrapper.INSTANCE.get(launcher).addPluginListener(this,
                AllAppsSearchPlugin.class);
        mPlubinCb = secondaryCb;
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // Do nothing
        if (mPlugin != null) {
            if (s.length() == 0) {
                mPlugin.startedTyping();
            }
        }
    }

    @Override
@@ -90,6 +114,9 @@ public class AllAppsSearchBarController
        } else {
            mSearchAlgorithm.cancel(false);
            mSearchAlgorithm.doSearch(mQuery, mCb);
            if (mPlugin != null) {
                mPlugin.performSearch(mQuery, mPlubinCb);
            }
        }
    }

@@ -170,13 +197,52 @@ public class AllAppsSearchBarController
        return mInput.isFocused();
    }

    @Override
    public void onPluginConnected(AllAppsSearchPlugin allAppsSearchPlugin, Context context) {
        if (FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
            mPlugin = allAppsSearchPlugin;
            checkCallPermission();
        }
    }

    /**
     * Check call permissions.
     */
    public void checkCallPermission() {
        final String[] permission = {"android.permission.CALL_PHONE",
                "android.permission.READ_CONTACTS"};
        boolean request = false;
        for (String p : permission) {
            int permissionCheck = ContextCompat.checkSelfPermission(mLauncher, p);
            if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
                request = true;
            }
        }

        if (!request) return;
        boolean rationale = false;
        for (String p : permission) {
            if (mLauncher.shouldShowRequestPermissionRationale(p)) {
                rationale = true;
            }
            if (rationale) {
                Log.e(TAG, p + " Show rationale");
                Toast.makeText(mLauncher, "Requesting Permissions", Toast.LENGTH_SHORT).show();
            } else {
                ActivityCompat.requestPermissions(mLauncher,  permission,  123);
                Log.e(TAG, p + " request permission");
            }
        }

    }

    /**
     * Callback for getting search results.
     */
    public interface Callbacks {

        /**
         * Called when the search is complete.
         * Called when the search from primary source is complete.
         *
         * @param items sorted list of search result adapter items.
         */
@@ -187,5 +253,4 @@ public class AllAppsSearchBarController
         */
        void clearSearchResult();
    }

}
 No newline at end of file
+10 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static com.android.launcher3.icons.IconNormalizer.ICON_VISIBLE_AREA_FACTO

import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.text.Selection;
import android.text.SpannableStringBuilder;
import android.text.method.TextKeyListener;
@@ -47,13 +48,15 @@ import com.android.launcher3.allapps.SearchUiManager;
import com.android.launcher3.anim.PropertySetter;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
 * Layout to contain the All-apps search UI.
 */
public class AppsSearchContainerLayout extends ExtendedEditText
        implements SearchUiManager, AllAppsSearchBarController.Callbacks,
        AllAppsStore.OnUpdateListener, Insettable {
        AllAppsStore.OnUpdateListener, Insettable, Consumer<List<Bundle>> {

    private final BaseDraggingActivity mLauncher;
    private final AllAppsSearchBarController mSearchBarController;
@@ -136,7 +139,7 @@ public class AppsSearchContainerLayout extends ExtendedEditText
        mAppsView = appsView;
        mSearchBarController.initialize(
                new DefaultAppSearchAlgorithm(LauncherAppState.getInstance(mLauncher)), this,
                mLauncher, this);
                mLauncher, this, this);
    }

    @Override
@@ -220,4 +223,9 @@ public class AppsSearchContainerLayout extends ExtendedEditText
    public EditText getEditText() {
        return this;
    }

    @Override
    public void accept(List<Bundle> bundles) {
        // TODO: Render the result on mAppsView object
    }
}
+12 −19
Original line number Diff line number Diff line
@@ -16,35 +16,28 @@

package com.android.systemui.plugins;

import android.app.Activity;
import android.view.ViewGroup;
import android.widget.EditText;
import android.os.Bundle;

import com.android.systemui.plugins.annotations.ProvidesInterface;

import java.util.List;
import java.util.function.Consumer;

/**
 * Implement this plugin interface to replace the all apps recycler view of the all apps drawer.
 * Implement this plugin interface to fetch search result data from the plugin side.
 */
@ProvidesInterface(action = AllAppsSearchPlugin.ACTION, version = AllAppsSearchPlugin.VERSION)
public interface AllAppsSearchPlugin extends Plugin {
    String ACTION = "com.android.systemui.action.PLUGIN_ALL_APPS_SEARCH_ACTIONS";
    int VERSION = 3;

    /** Following are the order that these methods should be called. */
    void setup(ViewGroup parent, Activity activity, float allAppsContainerHeight);
    int VERSION = 4;

    /**
     * When drag starts, pass window inset related fields and the progress to indicate
     * whether user is swiping down or swiping up
     * Send signal when user starts typing.
     */
    void onDragStart(float progress);

    /** progress is between [0, 1] 1: down, 0: up */
    void setProgress(float progress);
    void startedTyping();

    /** Called when container animation stops, so that plugin can perform cleanups */
    void onAnimationEnd(float progress);

    /** pass over the search box object */
    void setEditText(EditText editText);
    /**
     * Send over the query and get the search results.
     */
    void performSearch(String query, Consumer<List<Bundle>> results);
}