Merge "Animating the folder title & page indicator when a multi-page folder is opened for the first time" into ub-launcher3-burnaby
This commit is contained in:
@@ -45,20 +45,16 @@
|
|||||||
android:id="@+id/folder_footer"
|
android:id="@+id/folder_footer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical" >
|
android:orientation="horizontal"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
<include
|
android:paddingRight="8dp" >
|
||||||
android:id="@+id/folder_page_indicator"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="12dp"
|
|
||||||
android:layout_gravity="center_horizontal"
|
|
||||||
layout="@layout/page_indicator" />
|
|
||||||
|
|
||||||
<com.android.launcher3.FolderEditText
|
<com.android.launcher3.FolderEditText
|
||||||
android:id="@+id/folder_name"
|
android:id="@+id/folder_name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="1"
|
||||||
android:background="#00000000"
|
android:background="#00000000"
|
||||||
android:fontFamily="sans-serif-condensed"
|
android:fontFamily="sans-serif-condensed"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
@@ -72,6 +68,13 @@
|
|||||||
android:textColorHint="#ff808080"
|
android:textColorHint="#ff808080"
|
||||||
android:textCursorDrawable="@null"
|
android:textCursorDrawable="@null"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/folder_page_indicator"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="12dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
layout="@layout/page_indicator" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</com.android.launcher3.Folder>
|
</com.android.launcher3.Folder>
|
||||||
@@ -90,6 +90,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
|
|||||||
*/
|
*/
|
||||||
private static final float ICON_OVERSCROLL_WIDTH_FACTOR = 0.45f;
|
private static final float ICON_OVERSCROLL_WIDTH_FACTOR = 0.45f;
|
||||||
|
|
||||||
|
public static final int FOOTER_ANIMATION_DURATION = 200;
|
||||||
|
|
||||||
private static final int REORDER_DELAY = 250;
|
private static final int REORDER_DELAY = 250;
|
||||||
private static final int ON_EXIT_CLOSE_DELAY = 400;
|
private static final int ON_EXIT_CLOSE_DELAY = 400;
|
||||||
private static final Rect sTempRect = new Rect();
|
private static final Rect sTempRect = new Rect();
|
||||||
@@ -211,10 +213,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
|
|||||||
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
|
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
|
||||||
|
|
||||||
mFooter = findViewById(R.id.folder_footer);
|
mFooter = findViewById(R.id.folder_footer);
|
||||||
updateFooterHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateFooterHeight() {
|
|
||||||
// We find out how tall footer wants to be (it is set to wrap_content), so that
|
// We find out how tall footer wants to be (it is set to wrap_content), so that
|
||||||
// we can allocate the appropriate amount of space for it.
|
// we can allocate the appropriate amount of space for it.
|
||||||
int measureSpec = MeasureSpec.UNSPECIFIED;
|
int measureSpec = MeasureSpec.UNSPECIFIED;
|
||||||
@@ -547,6 +546,36 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
|
|||||||
mContent.setFocusOnFirstChild();
|
mContent.setFocusOnFirstChild();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Footer animation
|
||||||
|
if (mContent.getPageCount() > 1 && !mInfo.hasOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION)) {
|
||||||
|
int footerWidth = mContent.getDesiredWidth()
|
||||||
|
- mFooter.getPaddingLeft() - mFooter.getPaddingRight();
|
||||||
|
|
||||||
|
float textWidth = mFolderName.getPaint().measureText(mFolderName.getText().toString());
|
||||||
|
mFolderName.setTranslationX((footerWidth - textWidth) / 2);
|
||||||
|
mContent.setMarkerScale(0);
|
||||||
|
|
||||||
|
// Do not update the flag if we are in drag mode. The flag will be updated, when we
|
||||||
|
// actually drop the icon.
|
||||||
|
final boolean updateAnimationFlag = !mDragInProgress;
|
||||||
|
openFolderAnim.addListener(new AnimatorListenerAdapter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationEnd(Animator animation) {
|
||||||
|
mFolderName.animate().setDuration(FOOTER_ANIMATION_DURATION).translationX(0);
|
||||||
|
mContent.animateMarkers();
|
||||||
|
|
||||||
|
if (updateAnimationFlag) {
|
||||||
|
mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
mFolderName.setTranslationX(0);
|
||||||
|
mContent.setMarkerScale(1);
|
||||||
|
}
|
||||||
|
|
||||||
openFolderAnim.start();
|
openFolderAnim.start();
|
||||||
|
|
||||||
// Make sure the folder picks up the last drag move even if the finger doesn't move.
|
// Make sure the folder picks up the last drag move even if the finger doesn't move.
|
||||||
@@ -823,6 +852,14 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
|
|||||||
// Reordering may have occured, and we need to save the new item locations. We do this once
|
// Reordering may have occured, and we need to save the new item locations. We do this once
|
||||||
// at the end to prevent unnecessary database operations.
|
// at the end to prevent unnecessary database operations.
|
||||||
updateItemLocationsInDatabaseBatch();
|
updateItemLocationsInDatabaseBatch();
|
||||||
|
|
||||||
|
// Use the item count to check for multi-page as the folder UI may not have
|
||||||
|
// been refreshed yet.
|
||||||
|
if (getItemCount() <= mContent.itemsPerPage()) {
|
||||||
|
// Show the animation, next time something is added to the folder.
|
||||||
|
mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, false, mLauncher);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1200,6 +1237,11 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
|
|||||||
// Clear the drag info, as it is no longer being dragged.
|
// Clear the drag info, as it is no longer being dragged.
|
||||||
mCurrentDragInfo = null;
|
mCurrentDragInfo = null;
|
||||||
mDragInProgress = false;
|
mDragInProgress = false;
|
||||||
|
|
||||||
|
if (mContent.getPageCount() > 1) {
|
||||||
|
// The animation has already been shown while opening the folder.
|
||||||
|
mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncher);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is used so the item doesn't immediately appear in the folder when added. In one case
|
// This is used so the item doesn't immediately appear in the folder when added. In one case
|
||||||
@@ -1214,6 +1256,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
|
|||||||
v.setVisibility(VISIBLE);
|
v.setVisibility(VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onAdd(ShortcutInfo item) {
|
public void onAdd(ShortcutInfo item) {
|
||||||
// If the item was dropped onto this open folder, we have done the work associated
|
// If the item was dropped onto this open folder, we have done the work associated
|
||||||
// with adding the item to the folder, as indicated by mSuppressOnAdd being set
|
// with adding the item to the folder, as indicated by mSuppressOnAdd being set
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ public class FolderInfo extends ItemInfo {
|
|||||||
*/
|
*/
|
||||||
public static final int FLAG_WORK_FOLDER = 0x00000002;
|
public static final int FLAG_WORK_FOLDER = 0x00000002;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The multi-page animation has run for this folder
|
||||||
|
*/
|
||||||
|
public static final int FLAG_MULTI_PAGE_ANIMATION = 0x00000004;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether this folder has been opened
|
* Whether this folder has been opened
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -20,9 +20,11 @@ import android.annotation.SuppressLint;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.animation.DecelerateInterpolator;
|
import android.view.animation.DecelerateInterpolator;
|
||||||
|
import android.view.animation.OvershootInterpolator;
|
||||||
|
|
||||||
import com.android.launcher3.FocusHelper.PagedFolderKeyEventListener;
|
import com.android.launcher3.FocusHelper.PagedFolderKeyEventListener;
|
||||||
import com.android.launcher3.PageIndicator.PageMarkerResources;
|
import com.android.launcher3.PageIndicator.PageMarkerResources;
|
||||||
@@ -44,6 +46,8 @@ public class FolderPagedView extends PagedView {
|
|||||||
private static final int START_VIEW_REORDER_DELAY = 30;
|
private static final int START_VIEW_REORDER_DELAY = 30;
|
||||||
private static final float VIEW_REORDER_DELAY_FACTOR = 0.9f;
|
private static final float VIEW_REORDER_DELAY_FACTOR = 0.9f;
|
||||||
|
|
||||||
|
private static final int PAGE_INDICATOR_ANIMATION_DELAY = 150;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fraction of the width to scroll when showing the next page hint.
|
* Fraction of the width to scroll when showing the next page hint.
|
||||||
*/
|
*/
|
||||||
@@ -70,7 +74,7 @@ public class FolderPagedView extends PagedView {
|
|||||||
private FocusIndicatorView mFocusIndicatorView;
|
private FocusIndicatorView mFocusIndicatorView;
|
||||||
private PagedFolderKeyEventListener mKeyListener;
|
private PagedFolderKeyEventListener mKeyListener;
|
||||||
|
|
||||||
private View mPageIndicator;
|
private PageIndicator mPageIndicator;
|
||||||
|
|
||||||
public FolderPagedView(Context context, AttributeSet attrs) {
|
public FolderPagedView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
@@ -93,7 +97,7 @@ public class FolderPagedView extends PagedView {
|
|||||||
mFolder = folder;
|
mFolder = folder;
|
||||||
mFocusIndicatorView = (FocusIndicatorView) folder.findViewById(R.id.focus_indicator);
|
mFocusIndicatorView = (FocusIndicatorView) folder.findViewById(R.id.focus_indicator);
|
||||||
mKeyListener = new PagedFolderKeyEventListener(folder);
|
mKeyListener = new PagedFolderKeyEventListener(folder);
|
||||||
mPageIndicator = folder.findViewById(R.id.folder_page_indicator);
|
mPageIndicator = (PageIndicator) folder.findViewById(R.id.folder_page_indicator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -330,11 +334,8 @@ public class FolderPagedView extends PagedView {
|
|||||||
setEnableOverscroll(getPageCount() > 1);
|
setEnableOverscroll(getPageCount() > 1);
|
||||||
|
|
||||||
// Update footer
|
// Update footer
|
||||||
int indicatorVisibility = mPageIndicator.getVisibility();
|
|
||||||
mPageIndicator.setVisibility(getPageCount() > 1 ? View.VISIBLE : View.GONE);
|
mPageIndicator.setVisibility(getPageCount() > 1 ? View.VISIBLE : View.GONE);
|
||||||
if (indicatorVisibility != mPageIndicator.getVisibility()) {
|
mFolder.mFolderName.setGravity(getPageCount() > 1 ? Gravity.START : Gravity.CENTER_HORIZONTAL);
|
||||||
mFolder.updateFooterHeight();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDesiredWidth() {
|
public int getDesiredWidth() {
|
||||||
@@ -624,4 +625,29 @@ public class FolderPagedView extends PagedView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMarkerScale(float scale) {
|
||||||
|
int count = mPageIndicator.getChildCount();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
View marker = mPageIndicator.getChildAt(i);
|
||||||
|
marker.animate().cancel();
|
||||||
|
marker.setScaleX(scale);
|
||||||
|
marker.setScaleY(scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void animateMarkers() {
|
||||||
|
int count = mPageIndicator.getChildCount();
|
||||||
|
OvershootInterpolator interpolator = new OvershootInterpolator(4);
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
mPageIndicator.getChildAt(i).animate().scaleX(1).scaleY(1)
|
||||||
|
.setInterpolator(interpolator)
|
||||||
|
.setDuration(Folder.FOOTER_ANIMATION_DURATION)
|
||||||
|
.setStartDelay(PAGE_INDICATOR_ANIMATION_DELAY * i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int itemsPerPage() {
|
||||||
|
return mMaxItemsPerPage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user