summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/widget
diff options
context:
space:
mode:
authorHyunyoung Song <hyunyoungs@google.com>2015-06-04 11:37:46 -0700
committerHyunyoung Song <hyunyoungs@google.com>2015-06-04 11:37:46 -0700
commitec84728b270004494dc483c141628ec6417175fb (patch)
tree7c3e053e32a0dd1b22f88bdcfd96bfc24dc4103f /src/com/android/launcher3/widget
parent585b764ae24c7869704c428d1739e151e989674d (diff)
downloadandroid_packages_apps_Trebuchet-ec84728b270004494dc483c141628ec6417175fb.tar.gz
android_packages_apps_Trebuchet-ec84728b270004494dc483c141628ec6417175fb.tar.bz2
android_packages_apps_Trebuchet-ec84728b270004494dc483c141628ec6417175fb.zip
Consistent scrolling experience for All apps and widget tray
b/21375339 Change-Id: I8362b3ca94b7c4e75932d42cd09a989e0e3919c0
Diffstat (limited to 'src/com/android/launcher3/widget')
-rw-r--r--src/com/android/launcher3/widget/WidgetsContainerView.java20
-rw-r--r--src/com/android/launcher3/widget/WidgetsRecyclerView.java59
2 files changed, 68 insertions, 11 deletions
diff --git a/src/com/android/launcher3/widget/WidgetsContainerView.java b/src/com/android/launcher3/widget/WidgetsContainerView.java
index 11c2107f2..18b93c3b1 100644
--- a/src/com/android/launcher3/widget/WidgetsContainerView.java
+++ b/src/com/android/launcher3/widget/WidgetsContainerView.java
@@ -20,8 +20,8 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
+import android.graphics.drawable.InsetDrawable;
import android.support.v7.widget.LinearLayoutManager;
-import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.State;
import android.util.AttributeSet;
import android.util.Log;
@@ -92,7 +92,6 @@ public class WidgetsContainerView extends BaseContainerView
mWidgetHostViewLoader = new WidgetHostViewLoader(mLauncher);
mAdapter = new WidgetsListAdapter(context, this, this, mLauncher);
mIconCache = (LauncherAppState.getInstance()).getIconCache();
-
if (DEBUG) {
Log.d(TAG, "WidgetsContainerView constructor");
}
@@ -345,6 +344,23 @@ public class WidgetsContainerView extends BaseContainerView
setPadding(mFixedBounds.left, mFixedBounds.top, getMeasuredWidth() - mFixedBounds.right,
mFixedBounds.bottom);
}
+
+ int inset = mFixedBounds.isEmpty() ? mView.getScrollbarWidth() : mFixedBoundsContainerInset;
+ mView.setPadding(inset + mView.getScrollbarWidth(), inset,
+ inset, inset);
+ }
+
+ @Override
+ protected void onUpdateBackgrounds() {
+ InsetDrawable background;
+ // Update the background of the reveal view and list to be inset with the fixed bound
+ // insets instead of the default insets
+ // TODO: Use quantum_panel instead of quantum_panel_shape.
+ int inset = mFixedBounds.isEmpty() ? mView.getScrollbarWidth() : mFixedBoundsContainerInset;
+ background = new InsetDrawable(
+ getContext().getResources().getDrawable(R.drawable.quantum_panel_shape),
+ inset, 0, inset, 0);
+ mView.updateBackgroundPadding(background);
}
/**
diff --git a/src/com/android/launcher3/widget/WidgetsRecyclerView.java b/src/com/android/launcher3/widget/WidgetsRecyclerView.java
index bef255908..4aa332380 100644
--- a/src/com/android/launcher3/widget/WidgetsRecyclerView.java
+++ b/src/com/android/launcher3/widget/WidgetsRecyclerView.java
@@ -19,20 +19,25 @@ package com.android.launcher3.widget;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
-import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.LinearLayoutManager;
import android.util.AttributeSet;
-import android.view.MotionEvent;
+import android.view.View;
import com.android.launcher3.BaseRecyclerView;
+import com.android.launcher3.Utilities;
+import com.android.launcher3.compat.AlphabeticIndexCompat;
import com.android.launcher3.model.WidgetsModel;
+import com.android.launcher3.model.PackageItemInfo;
/**
* The widgets recycler view.
*/
public class WidgetsRecyclerView extends BaseRecyclerView {
+ private static final String TAG = "WidgetsRecyclerView";
private WidgetsModel mWidgets;
private Rect mBackgroundPadding = new Rect();
+ private PackageItemInfo mLastPackageItemInfo;
public WidgetsRecyclerView(Context context) {
this(context, null);
@@ -68,8 +73,17 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
*/
@Override
public String scrollToPositionAtProgress(float touchFraction) {
- // Ensure that we have any sections
- return "";
+ float pos = mWidgets.getPackageSize() * touchFraction;
+
+ int posInt = (int) pos;
+ LinearLayoutManager layoutManager = ((LinearLayoutManager) getLayoutManager());
+ getCurScrollState(scrollPosState);
+ layoutManager.scrollToPositionWithOffset((int) pos,
+ (int) (scrollPosState.rowHeight * ((float) posInt - pos)));
+
+ posInt = (int) ((touchFraction == 1)? pos -1 : pos);
+ PackageItemInfo p = mWidgets.getPackageItemInfo(posInt);
+ return p.titleSectionName;
}
/**
@@ -78,19 +92,41 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
@Override
public void updateVerticalScrollbarBounds() {
int rowCount = mWidgets.getPackageSize();
+ verticalScrollbarBounds.setEmpty();
- // Skip early if there are no items.
+ // Skip early if, there are no items.
if (rowCount == 0) {
- verticalScrollbarBounds.setEmpty();
return;
}
- int x, y;
+ // Skip early if, there no child laid out in the container.
getCurScrollState(scrollPosState);
if (scrollPosState.rowIndex < 0) {
+ return;
+ }
+
+ int actualHeight = getHeight() - getPaddingTop() - getPaddingBottom();
+ int totalScrollHeight = rowCount * scrollPosState.rowHeight;
+ // Skip early if the height of all the rows are actually less than the container height.
+ if (totalScrollHeight < actualHeight) {
verticalScrollbarBounds.setEmpty();
+ return;
}
- // TODO
+
+ int scrollbarHeight = (int) (actualHeight / ((float) totalScrollHeight / actualHeight));
+ int availableY = totalScrollHeight - actualHeight;
+ int availableScrollY = actualHeight - scrollbarHeight;
+ int y = (scrollPosState.rowIndex * scrollPosState.rowHeight)
+ - scrollPosState.rowTopOffset;
+ y = getPaddingTop() +
+ (int) (((float) (getPaddingTop() + y) / availableY) * availableScrollY);
+
+ // Calculate the position and size of the scroll bar.
+ int x = getWidth() - getScrollbarWidth() - mBackgroundPadding.right;
+ if (Utilities.isRtl(getResources())) {
+ x = mBackgroundPadding.left;
+ }
+ verticalScrollbarBounds.set(x, y, x + getScrollbarWidth(), y + scrollbarHeight);
}
/**
@@ -107,6 +143,11 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
if (rowCount == 0) {
return;
}
- // TODO
+ View child = getChildAt(0);
+ int position = getChildPosition(child);
+
+ stateOut.rowIndex = position;
+ stateOut.rowTopOffset = getLayoutManager().getDecoratedTop(child);
+ stateOut.rowHeight = child.getHeight();
}
} \ No newline at end of file