mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-01 00:06:47 +00:00
Add physics motion to items in all apps.
Motion applied to: - Icons - Prediction icons - Prediction divider Bug: 38349031 Change-Id: I376e6e39080c8c80463a0ce8b104b05e4d576f17
This commit is contained in:
@@ -20,6 +20,8 @@ import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.InsetDrawable;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Selection;
|
||||
import android.text.SpannableStringBuilder;
|
||||
@@ -42,6 +44,7 @@ import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.PromiseAppInfo;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.anim.SpringAnimationHandler;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.dragndrop.DragController;
|
||||
import com.android.launcher3.dragndrop.DragOptions;
|
||||
@@ -63,7 +66,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
|
||||
private final Launcher mLauncher;
|
||||
private final AlphabeticalAppsList mApps;
|
||||
private final AllAppsGridAdapter mAdapter;
|
||||
private final RecyclerView.LayoutManager mLayoutManager;
|
||||
private final LinearLayoutManager mLayoutManager;
|
||||
|
||||
private AllAppsRecyclerView mAppsRecyclerView;
|
||||
private SearchUiManager mSearchUiManager;
|
||||
@@ -74,6 +77,8 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
|
||||
private int mNumAppsPerRow;
|
||||
private int mNumPredictedAppsPerRow;
|
||||
|
||||
private SpringAnimationHandler mSpringAnimationHandler;
|
||||
|
||||
public AllAppsContainerView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
@@ -87,7 +92,9 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
|
||||
|
||||
mLauncher = Launcher.getLauncher(context);
|
||||
mApps = new AlphabeticalAppsList(context);
|
||||
mAdapter = new AllAppsGridAdapter(mLauncher, mApps, mLauncher, this);
|
||||
mSpringAnimationHandler = new SpringAnimationHandler(SpringAnimationHandler.Y_DIRECTION);
|
||||
mAdapter = new AllAppsGridAdapter(mLauncher, mApps, mLauncher, this,
|
||||
mSpringAnimationHandler);
|
||||
mApps.setAdapter(mAdapter);
|
||||
mLayoutManager = mAdapter.getLayoutManager();
|
||||
mSearchQueryBuilder = new SpannableStringBuilder();
|
||||
@@ -227,6 +234,10 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
|
||||
mAppsRecyclerView.setLayoutManager(mLayoutManager);
|
||||
mAppsRecyclerView.setAdapter(mAdapter);
|
||||
mAppsRecyclerView.setHasFixedSize(true);
|
||||
if (FeatureFlags.LAUNCHER3_PHYSICS) {
|
||||
mAppsRecyclerView.setSpringAnimationHandler(mSpringAnimationHandler);
|
||||
mAppsRecyclerView.addOnScrollListener(new SpringMotionOnScrollListener());
|
||||
}
|
||||
|
||||
mSearchContainer = findViewById(R.id.search_container);
|
||||
mSearchUiManager = (SearchUiManager) mSearchContainer;
|
||||
@@ -404,4 +415,36 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SpringAnimationHandler getSpringAnimationHandler() {
|
||||
return mSpringAnimationHandler;
|
||||
}
|
||||
|
||||
public class SpringMotionOnScrollListener extends RecyclerView.OnScrollListener {
|
||||
|
||||
private int mScrollState = RecyclerView.SCROLL_STATE_IDLE;
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
if (mScrollState == RecyclerView.SCROLL_STATE_DRAGGING) {
|
||||
mSpringAnimationHandler.skipToEnd();
|
||||
return;
|
||||
}
|
||||
|
||||
int first = mLayoutManager.findFirstVisibleItemPosition();
|
||||
int last = mLayoutManager.findLastVisibleItemPosition();
|
||||
|
||||
// We only show the spring animation when at the top or bottom, so we wait until the
|
||||
// first or last row is visible to ensure that all animations run in sync.
|
||||
if (first == 0 || last >= mAdapter.getItemCount() - mAdapter.getNumAppsPerRow()) {
|
||||
mSpringAnimationHandler.animateToFinalPosition(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
mScrollState = newState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user