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

Commit 50245037 authored by Sunny Goyal's avatar Sunny Goyal Committed by Peter Schiller
Browse files

Preventing unnecessary layouts on search focus change

Instead of expanding the edittext, using a separate textview
which is shown/hidden as the hint text

Change-Id: Ib4cedeaed9291f972be2ee407c06f4944c983e27
parent 7b8f1eab
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@
            android:focusable="true"
            android:theme="@style/CustomOverscroll.Light" />

        <LinearLayout
        <FrameLayout
            android:id="@+id/search_container"
            android:layout_width="match_parent"
            android:layout_height="@dimen/all_apps_search_bar_height"
@@ -68,25 +68,28 @@
            android:paddingRight="@dimen/container_fastscroll_thumb_max_width"
            android:gravity="center|bottom"
            android:orientation="horizontal"
            android:saveEnabled="false">
            android:saveEnabled="false"
            android:paddingTop="@dimen/all_apps_search_bar_margin_top" >

            <ImageView
                android:id="@+id/search_icon"
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:scaleType="fitCenter"
                android:layout_marginTop="@dimen/all_apps_search_bar_icon_margin_top"
                android:paddingEnd="@dimen/all_apps_search_bar_icon_margin_right"
                android:src="@drawable/ic_allapps_search" />
                android:gravity="center_vertical"
                android:id="@+id/search_hint"
                android:layout_gravity="center_horizontal"
                android:drawablePadding="@dimen/all_apps_search_bar_icon_margin_right"
                android:drawableStart="@drawable/ic_allapps_search"
                android:text="@string/all_apps_search_bar_hint"
                android:textColor="@drawable/all_apps_search_hint"
                android:textSize="16sp" />

            <com.android.launcher3.ExtendedEditText
                android:id="@+id/search_box_input"
                android:layout_width="wrap_content"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/transparent"
                android:focusableInTouchMode="true"
                android:gravity="start|center_vertical"
                android:hint="@string/all_apps_search_bar_hint"
                android:imeOptions="actionSearch|flagNoExtractUi"
                android:inputType="text|textNoSuggestions|textCapWords"
                android:maxLines="1"
@@ -95,7 +98,7 @@
                android:textColor="#4c4c4c"
                android:textColorHint="@drawable/all_apps_search_hint"
                android:textSize="16sp" />
        </LinearLayout>
        </FrameLayout>

    </com.android.launcher3.allapps.AllAppsRecyclerViewContainerView>
    <View
+3 −0
Original line number Diff line number Diff line
@@ -33,6 +33,9 @@
         is used for internal (baked-in) padding -->
    <integer name="config_allAppsButtonPaddingPercent">17</integer>

    <!-- The duration of the animation from search hint to text entry -->
    <integer name="config_searchHintAnimationDuration">50</integer>

<!-- Workspace -->
    <!-- The duration (in ms) of the fade animation on the object outlines, used when
         we are dragging objects around on the home screen. -->
+29 −44
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.launcher3.allapps;

import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
@@ -25,19 +26,15 @@ import android.text.Selection;
import android.text.SpannableStringBuilder;
import android.text.method.TextKeyListener;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.view.animation.AnimationUtils;

import com.android.launcher3.AppInfo;
import com.android.launcher3.BaseContainerView;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.CellLayout;
import com.android.launcher3.DeleteDropTarget;
import com.android.launcher3.DeviceProfile;
@@ -150,7 +147,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc

    private View mSearchContainer;
    private ExtendedEditText mSearchInput;
    private ImageView mSearchIcon;
    private HeaderElevationController mElevationController;
    private int mSearchContainerOffsetTop;

@@ -313,39 +309,34 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc

        mSearchContainer = findViewById(R.id.search_container);
        mSearchInput = (ExtendedEditText) findViewById(R.id.search_box_input);
        mSearchIcon = (ImageView) findViewById(R.id.search_icon);
        mSearchContainerOffsetTop = getResources().getDimensionPixelSize(
                R.dimen.all_apps_search_bar_margin_top);

        final LinearLayout.LayoutParams searchParams =
                (LinearLayout.LayoutParams) mSearchInput.getLayoutParams();
        final View searchHint = findViewById(R.id.search_hint);
        final ObjectAnimator searchInputAnimator = ObjectAnimator.ofFloat(mSearchInput,
                View.TRANSLATION_X, 0);
        searchInputAnimator.setDuration(getContext().getResources().getInteger(
                R.integer.config_searchHintAnimationDuration));
        searchInputAnimator.setInterpolator(AnimationUtils.loadInterpolator(getContext(),
                android.R.interpolator.accelerate_decelerate));

        mSearchInput.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean focused) {
                if (focused) {
                    searchParams.width = LayoutParams.MATCH_PARENT;
                    mSearchInput.setLayoutParams(searchParams);
                    mSearchInput.setGravity(Gravity.FILL_HORIZONTAL | Gravity.CENTER_VERTICAL);
                    mSearchIcon.setVisibility(View.GONE);
                } else {
                    searchParams.width = LayoutParams.WRAP_CONTENT;
                    mSearchInput.setLayoutParams(searchParams);
                    mSearchInput.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
                    mSearchIcon.setVisibility(View.VISIBLE);
                }
                    searchHint.setVisibility(View.INVISIBLE);
                    if (searchInputAnimator.isRunning()) {
                        searchInputAnimator.end();
                    }
        });

        final OnClickListener searchFocusListener = new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!mSearchBarController.isSearchFieldFocused()) {
                    mSearchBarController.focusSearchField();
                    searchInputAnimator.setFloatValues(searchHint.getLeft(), 0);
                    searchInputAnimator.start();
                } else {
                    searchHint.setVisibility(View.VISIBLE);
                    mSearchInput.setTranslationX(0);
                }
            }
        };
        mSearchInput.setOnClickListener(searchFocusListener);
        mSearchContainer.setOnClickListener(searchFocusListener);
        });

        mElevationController = Utilities.ATLEAST_LOLLIPOP
                ? new HeaderElevationController.ControllerVL(mSearchContainer)
@@ -405,8 +396,11 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
                    final int thumbMaxWidth =
                            getResources().getDimensionPixelSize(
                                    R.dimen.container_fastscroll_thumb_max_width);
                    mSearchContainer.setPaddingRelative(rvPadding + thumbMaxWidth, 0, rvPadding +
                            thumbMaxWidth, 0);
                    mSearchContainer.setPadding(
                            rvPadding - mHorizontalPadding + thumbMaxWidth,
                            mSearchContainer.getPaddingTop(),
                            rvPadding - mHorizontalPadding + thumbMaxWidth,
                            mSearchContainer.getPaddingBottom());
                }
            }
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
@@ -435,14 +429,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
            mAppsRecyclerView.setNumAppsPerRow(grid, mNumAppsPerRow);
            mAdapter.setNumAppsPerRow(mNumAppsPerRow);
            mApps.setNumAppsPerRow(mNumAppsPerRow, mNumPredictedAppsPerRow, mergeAlgorithm);

            // TODO: should we not do all this complicated computation but just match the
            // numAppsPerRow with the workspace?
            if (mNumAppsPerRow > 0) {
                int iconSize = availableWidth / mNumAppsPerRow;
                int iconSpacing = (iconSize - grid.allAppsIconSizePx) / 2;
                mSearchInput.setPaddingRelative(iconSpacing, 0, iconSpacing, 0);
            }
        }

        // --- remove END when {@code FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP} is enabled. ---
@@ -499,12 +485,11 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
                mlp.topMargin = height;
                mAppsRecyclerView.setLayoutParams(mlp);

                LinearLayout.LayoutParams llp =
                        (LinearLayout.LayoutParams) mSearchInput.getLayoutParams();
                llp.topMargin = insets.top + mSearchContainerOffsetTop;
                mSearchInput.setLayoutParams(llp);
                mSearchIcon.setLayoutParams(llp);

                mSearchContainer.setPadding(
                        mSearchContainer.getPaddingLeft(),
                        insets.top + mSearchContainerOffsetTop,
                        mSearchContainer.getPaddingRight(),
                        mSearchContainer.getPaddingBottom());
                lp.height = height;

                View navBarBg = findViewById(R.id.nav_bar_bg);