change package name to uiuios
This commit is contained in:
28
src/com/android/uiuios/pageindicators/PageIndicator.java
Normal file
28
src/com/android/uiuios/pageindicators/PageIndicator.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.uiuios.pageindicators;
|
||||
|
||||
/**
|
||||
* Base class for a page indicator.
|
||||
*/
|
||||
public interface PageIndicator {
|
||||
|
||||
void setScroll(int currentScroll, int totalScroll);
|
||||
|
||||
void setActiveMarker(int activePage);
|
||||
|
||||
void setMarkersCount(int numMarkers);
|
||||
}
|
||||
340
src/com/android/uiuios/pageindicators/PageIndicatorDots.java
Normal file
340
src/com/android/uiuios/pageindicators/PageIndicatorDots.java
Normal file
@@ -0,0 +1,340 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.uiuios.pageindicators;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.animation.ValueAnimator.AnimatorUpdateListener;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Outline;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.RectF;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Property;
|
||||
import android.view.View;
|
||||
import android.view.ViewOutlineProvider;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
|
||||
import com.android.uiuios.R;
|
||||
import com.android.uiuios.Utilities;
|
||||
import com.android.uiuios.util.Themes;
|
||||
|
||||
/**
|
||||
* {@link PageIndicator} which shows dots per page. The active page is shown with the current
|
||||
* accent color.
|
||||
*/
|
||||
public class PageIndicatorDots extends View implements PageIndicator {
|
||||
|
||||
private static final float SHIFT_PER_ANIMATION = 0.5f;
|
||||
private static final float SHIFT_THRESHOLD = 0.1f;
|
||||
private static final long ANIMATION_DURATION = 150;
|
||||
|
||||
private static final int ENTER_ANIMATION_START_DELAY = 300;
|
||||
private static final int ENTER_ANIMATION_STAGGERED_DELAY = 150;
|
||||
private static final int ENTER_ANIMATION_DURATION = 400;
|
||||
|
||||
// This value approximately overshoots to 1.5 times the original size.
|
||||
private static final float ENTER_ANIMATION_OVERSHOOT_TENSION = 4.9f;
|
||||
|
||||
private static final RectF sTempRect = new RectF();
|
||||
|
||||
private static final Property<PageIndicatorDots, Float> CURRENT_POSITION
|
||||
= new Property<PageIndicatorDots, Float>(float.class, "current_position") {
|
||||
@Override
|
||||
public Float get(PageIndicatorDots obj) {
|
||||
return obj.mCurrentPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(PageIndicatorDots obj, Float pos) {
|
||||
obj.mCurrentPosition = pos;
|
||||
obj.invalidate();
|
||||
obj.invalidateOutline();
|
||||
}
|
||||
};
|
||||
|
||||
private final Paint mCirclePaint;
|
||||
private final float mDotRadius;
|
||||
private final int mActiveColor;
|
||||
private final int mInActiveColor;
|
||||
private final boolean mIsRtl;
|
||||
|
||||
private int mNumPages;
|
||||
private int mActivePage;
|
||||
|
||||
/**
|
||||
* The current position of the active dot including the animation progress.
|
||||
* For ex:
|
||||
* 0.0 => Active dot is at position 0
|
||||
* 0.33 => Active dot is at position 0 and is moving towards 1
|
||||
* 0.50 => Active dot is at position [0, 1]
|
||||
* 0.77 => Active dot has left position 0 and is collapsing towards position 1
|
||||
* 1.0 => Active dot is at position 1
|
||||
*/
|
||||
private float mCurrentPosition;
|
||||
private float mFinalPosition;
|
||||
private ObjectAnimator mAnimator;
|
||||
|
||||
private float[] mEntryAnimationRadiusFactors;
|
||||
|
||||
public PageIndicatorDots(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public PageIndicatorDots(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public PageIndicatorDots(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mCirclePaint.setStyle(Style.FILL);
|
||||
mDotRadius = getResources().getDimension(R.dimen.page_indicator_dot_size) / 2;
|
||||
setOutlineProvider(new MyOutlineProver());
|
||||
|
||||
mActiveColor = Themes.getColorAccent(context);
|
||||
mInActiveColor = Themes.getAttrColor(context, android.R.attr.colorControlHighlight);
|
||||
|
||||
mIsRtl = Utilities.isRtl(getResources());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScroll(int currentScroll, int totalScroll) {
|
||||
if (mNumPages > 1) {
|
||||
if (mIsRtl) {
|
||||
currentScroll = totalScroll - currentScroll;
|
||||
}
|
||||
int scrollPerPage = totalScroll / (mNumPages - 1);
|
||||
int pageToLeft = currentScroll / scrollPerPage;
|
||||
int pageToLeftScroll = pageToLeft * scrollPerPage;
|
||||
int pageToRightScroll = pageToLeftScroll + scrollPerPage;
|
||||
|
||||
float scrollThreshold = SHIFT_THRESHOLD * scrollPerPage;
|
||||
if (currentScroll < pageToLeftScroll + scrollThreshold) {
|
||||
// scroll is within the left page's threshold
|
||||
animateToPosition(pageToLeft);
|
||||
} else if (currentScroll > pageToRightScroll - scrollThreshold) {
|
||||
// scroll is far enough from left page to go to the right page
|
||||
animateToPosition(pageToLeft + 1);
|
||||
} else {
|
||||
// scroll is between left and right page
|
||||
animateToPosition(pageToLeft + SHIFT_PER_ANIMATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void animateToPosition(float position) {
|
||||
mFinalPosition = position;
|
||||
if (Math.abs(mCurrentPosition - mFinalPosition) < SHIFT_THRESHOLD) {
|
||||
mCurrentPosition = mFinalPosition;
|
||||
}
|
||||
if (mAnimator == null && Float.compare(mCurrentPosition, mFinalPosition) != 0) {
|
||||
float positionForThisAnim = mCurrentPosition > mFinalPosition ?
|
||||
mCurrentPosition - SHIFT_PER_ANIMATION : mCurrentPosition + SHIFT_PER_ANIMATION;
|
||||
mAnimator = ObjectAnimator.ofFloat(this, CURRENT_POSITION, positionForThisAnim);
|
||||
mAnimator.addListener(new AnimationCycleListener());
|
||||
mAnimator.setDuration(ANIMATION_DURATION);
|
||||
mAnimator.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopAllAnimations() {
|
||||
if (mAnimator != null) {
|
||||
mAnimator.cancel();
|
||||
mAnimator = null;
|
||||
}
|
||||
mFinalPosition = mActivePage;
|
||||
CURRENT_POSITION.set(this, mFinalPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up up the page indicator to play the entry animation.
|
||||
* {@link #playEntryAnimation()} must be called after this.
|
||||
*/
|
||||
public void prepareEntryAnimation() {
|
||||
mEntryAnimationRadiusFactors = new float[mNumPages];
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void playEntryAnimation() {
|
||||
int count = mEntryAnimationRadiusFactors.length;
|
||||
if (count == 0) {
|
||||
mEntryAnimationRadiusFactors = null;
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
Interpolator interpolator = new OvershootInterpolator(ENTER_ANIMATION_OVERSHOOT_TENSION);
|
||||
AnimatorSet animSet = new AnimatorSet();
|
||||
for (int i = 0; i < count; i++) {
|
||||
ValueAnimator anim = ValueAnimator.ofFloat(0, 1).setDuration(ENTER_ANIMATION_DURATION);
|
||||
final int index = i;
|
||||
anim.addUpdateListener(new AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
mEntryAnimationRadiusFactors[index] = (Float) animation.getAnimatedValue();
|
||||
invalidate();
|
||||
}
|
||||
});
|
||||
anim.setInterpolator(interpolator);
|
||||
anim.setStartDelay(ENTER_ANIMATION_START_DELAY + ENTER_ANIMATION_STAGGERED_DELAY * i);
|
||||
animSet.play(anim);
|
||||
}
|
||||
|
||||
animSet.addListener(new AnimatorListenerAdapter() {
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mEntryAnimationRadiusFactors = null;
|
||||
invalidateOutline();
|
||||
invalidate();
|
||||
}
|
||||
});
|
||||
animSet.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActiveMarker(int activePage) {
|
||||
if (mActivePage != activePage) {
|
||||
mActivePage = activePage;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMarkersCount(int numMarkers) {
|
||||
mNumPages = numMarkers;
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
// Add extra spacing of mDotRadius on all sides so than entry animation could be run.
|
||||
int width = MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY ?
|
||||
MeasureSpec.getSize(widthMeasureSpec) : (int) ((mNumPages * 3 + 2) * mDotRadius);
|
||||
int height= MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY ?
|
||||
MeasureSpec.getSize(heightMeasureSpec) : (int) (4 * mDotRadius);
|
||||
setMeasuredDimension(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
// Draw all page indicators;
|
||||
float circleGap = 3 * mDotRadius;
|
||||
float startX = (getWidth() - mNumPages * circleGap + mDotRadius) / 2;
|
||||
|
||||
float x = startX + mDotRadius;
|
||||
float y = getHeight() / 2;
|
||||
|
||||
if (mEntryAnimationRadiusFactors != null) {
|
||||
// During entry animation, only draw the circles
|
||||
if (mIsRtl) {
|
||||
x = getWidth() - x;
|
||||
circleGap = -circleGap;
|
||||
}
|
||||
for (int i = 0; i < mEntryAnimationRadiusFactors.length; i++) {
|
||||
mCirclePaint.setColor(i == mActivePage ? mActiveColor : mInActiveColor);
|
||||
canvas.drawCircle(x, y, mDotRadius * mEntryAnimationRadiusFactors[i], mCirclePaint);
|
||||
x += circleGap;
|
||||
}
|
||||
} else {
|
||||
mCirclePaint.setColor(mInActiveColor);
|
||||
for (int i = 0; i < mNumPages; i++) {
|
||||
canvas.drawCircle(x, y, mDotRadius, mCirclePaint);
|
||||
x += circleGap;
|
||||
}
|
||||
|
||||
mCirclePaint.setColor(mActiveColor);
|
||||
canvas.drawRoundRect(getActiveRect(), mDotRadius, mDotRadius, mCirclePaint);
|
||||
}
|
||||
}
|
||||
|
||||
private RectF getActiveRect() {
|
||||
float startCircle = (int) mCurrentPosition;
|
||||
float delta = mCurrentPosition - startCircle;
|
||||
float diameter = 2 * mDotRadius;
|
||||
float circleGap = 3 * mDotRadius;
|
||||
float startX = (getWidth() - mNumPages * circleGap + mDotRadius) / 2;
|
||||
|
||||
sTempRect.top = getHeight() * 0.5f - mDotRadius;
|
||||
sTempRect.bottom = getHeight() * 0.5f + mDotRadius;
|
||||
sTempRect.left = startX + startCircle * circleGap;
|
||||
sTempRect.right = sTempRect.left + diameter;
|
||||
|
||||
if (delta < SHIFT_PER_ANIMATION) {
|
||||
// dot is capturing the right circle.
|
||||
sTempRect.right += delta * circleGap * 2;
|
||||
} else {
|
||||
// Dot is leaving the left circle.
|
||||
sTempRect.right += circleGap;
|
||||
|
||||
delta -= SHIFT_PER_ANIMATION;
|
||||
sTempRect.left += delta * circleGap * 2;
|
||||
}
|
||||
|
||||
if (mIsRtl) {
|
||||
float rectWidth = sTempRect.width();
|
||||
sTempRect.right = getWidth() - sTempRect.left;
|
||||
sTempRect.left = sTempRect.right - rectWidth;
|
||||
}
|
||||
return sTempRect;
|
||||
}
|
||||
|
||||
private class MyOutlineProver extends ViewOutlineProvider {
|
||||
|
||||
@Override
|
||||
public void getOutline(View view, Outline outline) {
|
||||
if (mEntryAnimationRadiusFactors == null) {
|
||||
RectF activeRect = getActiveRect();
|
||||
outline.setRoundRect(
|
||||
(int) activeRect.left,
|
||||
(int) activeRect.top,
|
||||
(int) activeRect.right,
|
||||
(int) activeRect.bottom,
|
||||
mDotRadius
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener for keep running the animation until the final state is reached.
|
||||
*/
|
||||
private class AnimationCycleListener extends AnimatorListenerAdapter {
|
||||
|
||||
private boolean mCancelled = false;
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
mCancelled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (!mCancelled) {
|
||||
mAnimator = null;
|
||||
animateToPosition(mFinalPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
package com.android.uiuios.pageindicators;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Property;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.android.uiuios.DeviceProfile;
|
||||
import com.android.uiuios.Insettable;
|
||||
import com.android.uiuios.Launcher;
|
||||
import com.android.uiuios.R;
|
||||
import com.android.uiuios.Utilities;
|
||||
import com.android.uiuios.uioverrides.WallpaperColorInfo;
|
||||
|
||||
/**
|
||||
* A PageIndicator that briefly shows a fraction of a line when moving between pages
|
||||
*
|
||||
* The fraction is 1 / number of pages and the position is based on the progress of the page scroll.
|
||||
*/
|
||||
public class WorkspacePageIndicator extends View implements Insettable, PageIndicator {
|
||||
|
||||
private static final int LINE_ANIMATE_DURATION = ViewConfiguration.getScrollBarFadeDuration();
|
||||
private static final int LINE_FADE_DELAY = ViewConfiguration.getScrollDefaultDelay();
|
||||
public static final int WHITE_ALPHA = (int) (0.70f * 255);
|
||||
public static final int BLACK_ALPHA = (int) (0.65f * 255);
|
||||
|
||||
private static final int LINE_ALPHA_ANIMATOR_INDEX = 0;
|
||||
private static final int NUM_PAGES_ANIMATOR_INDEX = 1;
|
||||
private static final int TOTAL_SCROLL_ANIMATOR_INDEX = 2;
|
||||
private static final int ANIMATOR_COUNT = 3;
|
||||
|
||||
private ValueAnimator[] mAnimators = new ValueAnimator[ANIMATOR_COUNT];
|
||||
|
||||
private final Handler mDelayedLineFadeHandler = new Handler(Looper.getMainLooper());
|
||||
private final Launcher mLauncher;
|
||||
|
||||
private boolean mShouldAutoHide = true;
|
||||
|
||||
// The alpha of the line when it is showing.
|
||||
private int mActiveAlpha = 0;
|
||||
// The alpha that the line is being animated to or already at (either 0 or mActiveAlpha).
|
||||
private int mToAlpha;
|
||||
// A float value representing the number of pages, to allow for an animation when it changes.
|
||||
private float mNumPagesFloat;
|
||||
private int mCurrentScroll;
|
||||
private int mTotalScroll;
|
||||
private Paint mLinePaint;
|
||||
private final int mLineHeight;
|
||||
|
||||
private static final Property<WorkspacePageIndicator, Integer> PAINT_ALPHA
|
||||
= new Property<WorkspacePageIndicator, Integer>(Integer.class, "paint_alpha") {
|
||||
@Override
|
||||
public Integer get(WorkspacePageIndicator obj) {
|
||||
return obj.mLinePaint.getAlpha();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(WorkspacePageIndicator obj, Integer alpha) {
|
||||
obj.mLinePaint.setAlpha(alpha);
|
||||
obj.invalidate();
|
||||
}
|
||||
};
|
||||
|
||||
private static final Property<WorkspacePageIndicator, Float> NUM_PAGES
|
||||
= new Property<WorkspacePageIndicator, Float>(Float.class, "num_pages") {
|
||||
@Override
|
||||
public Float get(WorkspacePageIndicator obj) {
|
||||
return obj.mNumPagesFloat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(WorkspacePageIndicator obj, Float numPages) {
|
||||
obj.mNumPagesFloat = numPages;
|
||||
obj.invalidate();
|
||||
}
|
||||
};
|
||||
|
||||
private static final Property<WorkspacePageIndicator, Integer> TOTAL_SCROLL
|
||||
= new Property<WorkspacePageIndicator, Integer>(Integer.class, "total_scroll") {
|
||||
@Override
|
||||
public Integer get(WorkspacePageIndicator obj) {
|
||||
return obj.mTotalScroll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(WorkspacePageIndicator obj, Integer totalScroll) {
|
||||
obj.mTotalScroll = totalScroll;
|
||||
obj.invalidate();
|
||||
}
|
||||
};
|
||||
|
||||
private Runnable mHideLineRunnable = () -> animateLineToAlpha(0);
|
||||
|
||||
public WorkspacePageIndicator(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public WorkspacePageIndicator(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public WorkspacePageIndicator(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
Resources res = context.getResources();
|
||||
mLinePaint = new Paint();
|
||||
mLinePaint.setAlpha(0);
|
||||
|
||||
mLauncher = Launcher.getLauncher(context);
|
||||
mLineHeight = res.getDimensionPixelSize(R.dimen.dynamic_grid_page_indicator_line_height);
|
||||
|
||||
boolean darkText = WallpaperColorInfo.getInstance(context).supportsDarkText();
|
||||
mActiveAlpha = darkText ? BLACK_ALPHA : WHITE_ALPHA;
|
||||
mLinePaint.setColor(darkText ? Color.BLACK : Color.WHITE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
if (mTotalScroll == 0 || mNumPagesFloat == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute and draw line rect.
|
||||
float progress = Utilities.boundToRange(((float) mCurrentScroll) / mTotalScroll, 0f, 1f);
|
||||
int availableWidth = getWidth();
|
||||
int lineWidth = (int) (availableWidth / mNumPagesFloat);
|
||||
int lineLeft = (int) (progress * (availableWidth - lineWidth));
|
||||
int lineRight = lineLeft + lineWidth;
|
||||
|
||||
canvas.drawRoundRect(lineLeft, getHeight() / 2 - mLineHeight / 2, lineRight,
|
||||
getHeight() / 2 + mLineHeight / 2, mLineHeight, mLineHeight, mLinePaint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScroll(int currentScroll, int totalScroll) {
|
||||
if (getAlpha() == 0) {
|
||||
return;
|
||||
}
|
||||
animateLineToAlpha(mActiveAlpha);
|
||||
|
||||
mCurrentScroll = currentScroll;
|
||||
if (mTotalScroll == 0) {
|
||||
mTotalScroll = totalScroll;
|
||||
} else if (mTotalScroll != totalScroll) {
|
||||
animateToTotalScroll(totalScroll);
|
||||
} else {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
if (mShouldAutoHide) {
|
||||
hideAfterDelay();
|
||||
}
|
||||
}
|
||||
|
||||
private void hideAfterDelay() {
|
||||
mDelayedLineFadeHandler.removeCallbacksAndMessages(null);
|
||||
mDelayedLineFadeHandler.postDelayed(mHideLineRunnable, LINE_FADE_DELAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActiveMarker(int activePage) { }
|
||||
|
||||
@Override
|
||||
public void setMarkersCount(int numMarkers) {
|
||||
if (Float.compare(numMarkers, mNumPagesFloat) != 0) {
|
||||
setupAndRunAnimation(ObjectAnimator.ofFloat(this, NUM_PAGES, numMarkers),
|
||||
NUM_PAGES_ANIMATOR_INDEX);
|
||||
} else {
|
||||
if (mAnimators[NUM_PAGES_ANIMATOR_INDEX] != null) {
|
||||
mAnimators[NUM_PAGES_ANIMATOR_INDEX].cancel();
|
||||
mAnimators[NUM_PAGES_ANIMATOR_INDEX] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setShouldAutoHide(boolean shouldAutoHide) {
|
||||
mShouldAutoHide = shouldAutoHide;
|
||||
if (shouldAutoHide && mLinePaint.getAlpha() > 0) {
|
||||
hideAfterDelay();
|
||||
} else if (!shouldAutoHide) {
|
||||
mDelayedLineFadeHandler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void animateLineToAlpha(int alpha) {
|
||||
if (alpha == mToAlpha) {
|
||||
// Ignore the new animation if it is going to the same alpha as the current animation.
|
||||
return;
|
||||
}
|
||||
mToAlpha = alpha;
|
||||
setupAndRunAnimation(ObjectAnimator.ofInt(this, PAINT_ALPHA, alpha),
|
||||
LINE_ALPHA_ANIMATOR_INDEX);
|
||||
}
|
||||
|
||||
private void animateToTotalScroll(int totalScroll) {
|
||||
setupAndRunAnimation(ObjectAnimator.ofInt(this, TOTAL_SCROLL, totalScroll),
|
||||
TOTAL_SCROLL_ANIMATOR_INDEX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the given animator and stores it in the provided index in {@link #mAnimators} until
|
||||
* the animation ends.
|
||||
*
|
||||
* If an animator is already at the index (i.e. it is already playing), it is canceled and
|
||||
* replaced with the new animator.
|
||||
*/
|
||||
private void setupAndRunAnimation(ValueAnimator animator, final int animatorIndex) {
|
||||
if (mAnimators[animatorIndex] != null) {
|
||||
mAnimators[animatorIndex].cancel();
|
||||
}
|
||||
mAnimators[animatorIndex] = animator;
|
||||
mAnimators[animatorIndex].addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mAnimators[animatorIndex] = null;
|
||||
}
|
||||
});
|
||||
mAnimators[animatorIndex].setDuration(LINE_ANIMATE_DURATION);
|
||||
mAnimators[animatorIndex].start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pauses all currently running animations.
|
||||
*/
|
||||
public void pauseAnimations() {
|
||||
for (int i = 0; i < ANIMATOR_COUNT; i++) {
|
||||
if (mAnimators[i] != null) {
|
||||
mAnimators[i].pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force-ends all currently running or paused animations.
|
||||
*/
|
||||
public void skipAnimationsToEnd() {
|
||||
for (int i = 0; i < ANIMATOR_COUNT; i++) {
|
||||
if (mAnimators[i] != null) {
|
||||
mAnimators[i].end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInsets(Rect insets) {
|
||||
DeviceProfile grid = mLauncher.getDeviceProfile();
|
||||
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
|
||||
|
||||
if (grid.isVerticalBarLayout()) {
|
||||
Rect padding = grid.workspacePadding;
|
||||
lp.leftMargin = padding.left + grid.workspaceCellPaddingXPx;
|
||||
lp.rightMargin = padding.right + grid.workspaceCellPaddingXPx;
|
||||
lp.bottomMargin = padding.bottom;
|
||||
} else {
|
||||
lp.leftMargin = lp.rightMargin = 0;
|
||||
lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
|
||||
lp.bottomMargin = grid.hotseatBarSizePx + insets.bottom;
|
||||
}
|
||||
setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user