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

Commit f16fc51d authored by Michael Jurka's avatar Michael Jurka
Browse files

Remove unnecessary code

Found cleaner way to improve recents scrolling
performance on crespo-- instead of rendering the
background in the items, instead we just set
a window flag. Removed need for a lot of code.
parent b442eca2
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@
    <drawable name="notification_item_background_color_pressed">#ff257390</drawable>
    <drawable name="ticker_background_color">#ff1d1d1d</drawable>
    <drawable name="status_bar_background">#ff000000</drawable>
    <drawable name="status_bar_recents_background_solid">#b3000000</drawable>
    <drawable name="status_bar_recents_app_thumbnail_background">#88000000</drawable>
    <color name="status_bar_recents_app_label_color">#ffffffff</color>
    <drawable name="status_bar_notification_row_background_color">#ff090909</drawable>
+0 −4
Original line number Diff line number Diff line
@@ -27,9 +27,5 @@ public interface RecentsCallback {
    void handleOnClick(View selectedView);
    void handleSwipe(View selectedView);
    void handleLongPress(View selectedView, View anchorView, View thumbnailView);
    void handleShowBackground(boolean show);
    void dismiss();

    // TODO: find another way to get this info from RecentsPanelView
    boolean isRecentsVisible();
}
+0 −17
Original line number Diff line number Diff line
@@ -211,14 +211,6 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView
        return v.findViewById(R.id.recent_item);
    }

    @Override
    protected void onLayout (boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        if (mPerformanceHelper != null) {
            mPerformanceHelper.onLayoutCallback();
        }
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
@@ -322,12 +314,6 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView
        });
    }

    public void onRecentsVisibilityChanged() {
        if (mPerformanceHelper != null) {
            mPerformanceHelper.updateShowBackground();
        }
    }

    @Override
    protected void onVisibilityChanged(View changedView, int visibility) {
        super.onVisibilityChanged(changedView, visibility);
@@ -374,9 +360,6 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView

    @Override
    public void setLayoutTransition(LayoutTransition transition) {
        if (mPerformanceHelper != null) {
            mPerformanceHelper.setLayoutTransitionCallback(transition);
        }
        // The layout transition applies to our embedded LinearLayout
        mLinearLayout.setLayoutTransition(transition);
    }
+11 −31
Original line number Diff line number Diff line
@@ -32,13 +32,14 @@ import android.net.Uri;
import android.provider.Settings;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewRootImpl;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
@@ -325,18 +326,6 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
        }
    }

    public void handleShowBackground(boolean show) {
        if (show) {
            mRecentsScrim.setBackgroundResource(R.drawable.status_bar_recents_background_solid);
        } else {
            mRecentsScrim.setBackgroundDrawable(null);
        }
    }

    public boolean isRecentsVisible() {
        return getVisibility() == VISIBLE;
    }

    public void onAnimationCancel(Animator animation) {
    }

@@ -457,10 +446,16 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
        mRecentsNoApps = findViewById(R.id.recents_no_apps);
        mChoreo = new Choreographer(this, mRecentsScrim, mRecentsContainer, mRecentsNoApps, this);

        if (mRecentsScrim != null) {
            Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();
            if (!ActivityManager.isHighEndGfx(d)) {
                mRecentsScrim.setBackgroundDrawable(null);
            } else if (mRecentsScrim.getBackground() instanceof BitmapDrawable) {
                // In order to save space, we make the background texture repeat in the Y direction
        if (mRecentsScrim != null && mRecentsScrim.getBackground() instanceof BitmapDrawable) {
                ((BitmapDrawable) mRecentsScrim.getBackground()).setTileModeY(TileMode.REPEAT);
            }
        }

        mPreloadTasksRunnable = new Runnable() {
            public void run() {
@@ -478,21 +473,6 @@ public class RecentsPanelView extends FrameLayout implements OnItemClickListener
        transitioner.setAnimator(LayoutTransition.DISAPPEARING, null);
    }

    @Override
    protected void onVisibilityChanged(View changedView, int visibility) {
        super.onVisibilityChanged(changedView, visibility);
        if (DEBUG) Log.v(TAG, "onVisibilityChanged(" + changedView + ", " + visibility + ")");

        if (mRecentsContainer instanceof RecentsHorizontalScrollView) {
            ((RecentsHorizontalScrollView) mRecentsContainer).onRecentsVisibilityChanged();
        } else if (mRecentsContainer instanceof RecentsVerticalScrollView) {
            ((RecentsVerticalScrollView) mRecentsContainer).onRecentsVisibilityChanged();
        } else {
            throw new IllegalArgumentException("missing Recents[Horizontal]ScrollView");
        }
    }


    private void updateIcon(ViewHolder h, Drawable icon, boolean show, boolean anim) {
        if (icon != null) {
            h.iconView.setImageDrawable(icon);
+2 −119
Original line number Diff line number Diff line
@@ -78,39 +78,13 @@ public class RecentsScrollViewPerformanceHelper {
            mScrollView.setVerticalFadingEdgeEnabled(false);
            mScrollView.setHorizontalFadingEdgeEnabled(false);
        }
        if (mSoftwareRendered && OPTIMIZE_SW_RENDERED_RECENTS) {
            mCallback = callback;
            mLinearLayout = layout;
            mAttachedToWindow = true;
            mBackgroundDrawable = mContext.getResources()
                .getDrawable(R.drawable.status_bar_recents_background_solid).getConstantState();
            updateShowBackground();
        }

    }

    public void addViewCallback(View newLinearLayoutChild) {
        if (mSoftwareRendered && OPTIMIZE_SW_RENDERED_RECENTS) {
            final View view = newLinearLayoutChild;
            if (mShowBackground) {
                view.setBackgroundDrawable(mBackgroundDrawable.newDrawable());
            view.setDrawingCacheEnabled(true);
            view.buildDrawingCache();
            } else {
                view.setBackgroundDrawable(null);
                view.setDrawingCacheEnabled(false);
                view.destroyDrawingCache();
            }
        }
    }

    public void onLayoutCallback() {
        if (mSoftwareRendered && OPTIMIZE_SW_RENDERED_RECENTS) {
            mScrollView.post(new Runnable() {
                public void run() {
                    updateShowBackground();
                }
            });
        }
    }

@@ -118,37 +92,6 @@ public class RecentsScrollViewPerformanceHelper {
            int left, int right, int top, int bottom, int scrollX, int scrollY,
            float topFadingEdgeStrength, float bottomFadingEdgeStrength,
            float leftFadingEdgeStrength, float rightFadingEdgeStrength) {
        if (mSoftwareRendered && OPTIMIZE_SW_RENDERED_RECENTS) {
            if (mIsVertical) {
                if (scrollY < 0) {
                    Drawable d = mBackgroundDrawable.newDrawable().getCurrent();
                    d.setBounds(0, scrollY, mScrollView.getWidth(), 0);
                    d.draw(canvas);
                } else {
                    final int childHeight = mLinearLayout.getHeight();
                    if (scrollY + mScrollView.getHeight() > childHeight) {
                        Drawable d = mBackgroundDrawable.newDrawable().getCurrent();
                        d.setBounds(0, childHeight, mScrollView.getWidth(),
                                scrollY + mScrollView.getHeight());
                        d.draw(canvas);
                    }
                }
            } else {
                if (scrollX < 0) {
                    Drawable d = mBackgroundDrawable.newDrawable().getCurrent();
                    d.setBounds(scrollX, 0, 0, mScrollView.getHeight());
                    d.draw(canvas);
                } else {
                    final int childWidth = mLinearLayout.getWidth();
                    if (scrollX + mScrollView.getWidth() > childWidth) {
                        Drawable d = mBackgroundDrawable.newDrawable().getCurrent();
                        d.setBounds(childWidth, 0,
                                scrollX + mScrollView.getWidth(), mScrollView.getHeight());
                        d.draw(canvas);
                    }
                }
            }
        }

        if ((mSoftwareRendered && OPTIMIZE_SW_RENDERED_RECENTS)
                || USE_DARK_FADE_IN_HW_ACCELERATED_MODE) {
@@ -241,64 +184,4 @@ public class RecentsScrollViewPerformanceHelper {
        return mFadingEdgeLength;
    }

    public void setLayoutTransitionCallback(LayoutTransition transition) {
        if (mSoftwareRendered && OPTIMIZE_SW_RENDERED_RECENTS) {
            if (transition != null) {
                transition.addTransitionListener(new LayoutTransition.TransitionListener() {
                    @Override
                    public void startTransition(LayoutTransition transition,
                            ViewGroup container, View view, int transitionType) {
                        updateShowBackground();
                    }

                    @Override
                    public void endTransition(LayoutTransition transition,
                            ViewGroup container, View view, int transitionType) {
                        updateShowBackground();
                    }
                });
            }
        }
    }

    // Turn on/off drawing the background in our ancestor, and turn on/off drawing
    // in the items in LinearLayout contained by this scrollview.
    // Moving the background drawing to our children, and turning on a drawing cache
    // for each of them, gives us a ~20fps gain when Recents is rendered in software
    public void updateShowBackground() {
        if (!mAttachedToWindow) {
            // We haven't been initialized yet-- we'll get called again when we are
            return;
        }
        if (mSoftwareRendered && OPTIMIZE_SW_RENDERED_RECENTS) {
            LayoutTransition transition = mLinearLayout.getLayoutTransition();
            int linearLayoutSize =
                mIsVertical ? mLinearLayout.getHeight() : mLinearLayout.getWidth();
            int scrollViewSize =
                mIsVertical ? mScrollView.getHeight() : mScrollView.getWidth();
            boolean show = !mScrollView.isHardwareAccelerated() &&
                (linearLayoutSize > scrollViewSize) &&
                !(transition != null && transition.isRunning()) &&
                mCallback.isRecentsVisible();

            if (!mFirstTime && show == mShowBackground) return;
            mShowBackground = show;
            mFirstTime = false;

            mCallback.handleShowBackground(!show);
            for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
                View v = mLinearLayout.getChildAt(i);
                if (show) {
                    v.setBackgroundDrawable(mBackgroundDrawable.newDrawable());
                    v.setDrawingCacheEnabled(true);
                    v.buildDrawingCache();
                } else {
                    v.setDrawingCacheEnabled(false);
                    v.destroyDrawingCache();
                    v.setBackgroundDrawable(null);
                }
            }
        }
    }

}
Loading