Making page indicator an abstract class and implementing some common methods.
Change-Id: I06613428c54f1f086090580db8242cf81f7fb128
This commit is contained in:
@@ -259,9 +259,9 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
|
||||
|
||||
OnClickListener listener = getPageIndicatorClickListener();
|
||||
if (listener != null) {
|
||||
mPageIndicator.getView().setOnClickListener(listener);
|
||||
mPageIndicator.setOnClickListener(listener);
|
||||
}
|
||||
mPageIndicator.getView().setContentDescription(getPageIndicatorDescription());
|
||||
mPageIndicator.setContentDescription(getPageIndicatorDescription());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,7 +467,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
|
||||
private void updatePageIndicator() {
|
||||
// Update the page indicator (when we aren't reordering)
|
||||
if (mPageIndicator != null) {
|
||||
mPageIndicator.getView().setContentDescription(getPageIndicatorDescription());
|
||||
mPageIndicator.setContentDescription(getPageIndicatorDescription());
|
||||
if (!isReordering(false)) {
|
||||
mPageIndicator.setActiveMarker(getNextPage());
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ public class PinchAnimationManager {
|
||||
animateShowHideView(INDEX_HOTSEAT, mLauncher.getHotseat(), show);
|
||||
if (mWorkspace.getPageIndicator() != null) {
|
||||
// There aren't page indicators in landscape mode on phones, hence the null check.
|
||||
animateShowHideView(INDEX_PAGE_INDICATOR, mWorkspace.getPageIndicator().getView(), show);
|
||||
animateShowHideView(INDEX_PAGE_INDICATOR, mWorkspace.getPageIndicator(), show);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1339,9 +1339,7 @@ public class Workspace extends PagedView
|
||||
// different effects based on device performance. On at least one relatively high-end
|
||||
// device I've tried, translating the launcher causes things to get quite laggy.
|
||||
setTranslationAndAlpha(mLauncher.getSearchDropTargetBar(), transX, alpha);
|
||||
if (getPageIndicator() != null) {
|
||||
setTranslationAndAlpha(getPageIndicator().getView(), transX, alpha);
|
||||
}
|
||||
setTranslationAndAlpha(getPageIndicator(), transX, alpha);
|
||||
setTranslationAndAlpha(getChildAt(getCurrentPage()), transX, alpha);
|
||||
setTranslationAndAlpha(mLauncher.getHotseat(), transX, alpha);
|
||||
|
||||
@@ -1554,7 +1552,7 @@ public class Workspace extends PagedView
|
||||
}
|
||||
|
||||
if (getPageIndicator() != null) {
|
||||
getPageIndicator().getView().setTranslationX(translationX);
|
||||
getPageIndicator().setTranslationX(translationX);
|
||||
}
|
||||
|
||||
if (mCustomContentCallbacks != null) {
|
||||
@@ -1603,7 +1601,7 @@ public class Workspace extends PagedView
|
||||
// attach to window
|
||||
OnClickListener listener = getPageIndicatorClickListener();
|
||||
if (listener != null) {
|
||||
getPageIndicator().getView().setOnClickListener(listener);
|
||||
getPageIndicator().setOnClickListener(listener);
|
||||
}
|
||||
|
||||
showPageIndicatorAtCurrentScroll();
|
||||
|
||||
@@ -357,8 +357,7 @@ public class WorkspaceStateTransitionAnimation {
|
||||
|
||||
final ViewGroup overviewPanel = mLauncher.getOverviewPanel();
|
||||
final View hotseat = mLauncher.getHotseat();
|
||||
final View pageIndicator = mWorkspace.getPageIndicator() == null ? null
|
||||
: mWorkspace.getPageIndicator().getView();
|
||||
final View pageIndicator = mWorkspace.getPageIndicator();
|
||||
if (animated) {
|
||||
LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(mWorkspace);
|
||||
scale.scaleX(mNewScale)
|
||||
|
||||
@@ -365,7 +365,7 @@ public class FolderPagedView extends PagedView {
|
||||
setEnableOverscroll(getPageCount() > 1);
|
||||
|
||||
// Update footer
|
||||
mPageIndicator.getView().setVisibility(getPageCount() > 1 ? View.VISIBLE : View.GONE);
|
||||
mPageIndicator.setVisibility(getPageCount() > 1 ? View.VISIBLE : View.GONE);
|
||||
// Set the gravity as LEFT or RIGHT instead of START, as START depends on the actual text.
|
||||
mFolder.mFolderName.setGravity(getPageCount() > 1 ?
|
||||
(mIsRtl ? Gravity.RIGHT : Gravity.LEFT) : Gravity.CENTER_HORIZONTAL);
|
||||
|
||||
@@ -1,16 +1,37 @@
|
||||
package com.android.launcher3.pageindicators;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.ArrayList;
|
||||
/**
|
||||
* Base class for a page indicator.
|
||||
*/
|
||||
public abstract class PageIndicator extends View {
|
||||
|
||||
public interface PageIndicator {
|
||||
View getView();
|
||||
void setScroll(int currentScroll, int totalScroll);
|
||||
protected int mNumPages = 1;
|
||||
|
||||
void setActiveMarker(int activePage);
|
||||
public PageIndicator(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
void addMarker();
|
||||
void removeMarker();
|
||||
void setMarkersCount(int numMarkers);
|
||||
public abstract void setScroll(int currentScroll, int totalScroll);
|
||||
|
||||
public abstract void setActiveMarker(int activePage);
|
||||
|
||||
public void addMarker() {
|
||||
mNumPages++;
|
||||
onPageCountChanged();
|
||||
}
|
||||
|
||||
public void removeMarker() {
|
||||
mNumPages--;
|
||||
onPageCountChanged();
|
||||
}
|
||||
public void setMarkersCount(int numMarkers) {
|
||||
mNumPages = numMarkers;
|
||||
onPageCountChanged();
|
||||
}
|
||||
|
||||
protected abstract void onPageCountChanged();
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ import com.android.launcher3.Utilities;
|
||||
* {@link PageIndicator} which shows dots per page. The active page is shown with the current
|
||||
* accent color.
|
||||
*/
|
||||
public class PageIndicatorDots extends View implements PageIndicator {
|
||||
public class PageIndicatorDots extends PageIndicator {
|
||||
|
||||
private static final float SHIFT_PER_ANIMATION = 0.5f;
|
||||
private static final float SHIFT_THRESHOLD = 0.1f;
|
||||
@@ -90,7 +90,6 @@ public class PageIndicatorDots extends View implements PageIndicator {
|
||||
private final int mInActiveColor;
|
||||
private final boolean mIsRtl;
|
||||
|
||||
private int mNumPages;
|
||||
private int mActivePage;
|
||||
|
||||
/**
|
||||
@@ -130,11 +129,6 @@ public class PageIndicatorDots extends View implements PageIndicator {
|
||||
mIsRtl = Utilities.isRtl(getResources());
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScroll(int currentScroll, int totalScroll) {
|
||||
if (mNumPages > 1) {
|
||||
@@ -235,20 +229,7 @@ public class PageIndicatorDots extends View implements PageIndicator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMarker() {
|
||||
mNumPages++;
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMarker() {
|
||||
mNumPages--;
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMarkersCount(int numMarkers) {
|
||||
mNumPages = numMarkers;
|
||||
protected void onPageCountChanged() {
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.android.launcher3.dynamicui.ExtractedColors;
|
||||
*
|
||||
* The fraction is 1 / number of pages and the position is based on the progress of the page scroll.
|
||||
*/
|
||||
public class PageIndicatorLine extends View implements PageIndicator {
|
||||
public class PageIndicatorLine extends PageIndicator {
|
||||
private static final String TAG = "PageIndicatorLine";
|
||||
|
||||
private static final int LINE_FADE_DURATION = ViewConfiguration.getScrollBarFadeDuration();
|
||||
@@ -38,7 +38,6 @@ public class PageIndicatorLine extends View implements PageIndicator {
|
||||
private ValueAnimator mLineAlphaAnimator;
|
||||
private int mAlpha = 0;
|
||||
private float mProgress = 0f;
|
||||
private int mNumPages = 1;
|
||||
private Paint mLinePaint;
|
||||
|
||||
private static final Property<PageIndicatorLine, Integer> PAINT_ALPHA
|
||||
@@ -78,8 +77,6 @@ public class PageIndicatorLine extends View implements PageIndicator {
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
if (mNumPages == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -91,11 +88,6 @@ public class PageIndicatorLine extends View implements PageIndicator {
|
||||
canvas.drawRect(lineLeft, 0, lineRight, canvas.getHeight(), mLinePaint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScroll(int currentScroll, int totalScroll) {
|
||||
if (getAlpha() == 0) {
|
||||
@@ -115,18 +107,8 @@ public class PageIndicatorLine extends View implements PageIndicator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMarker() {
|
||||
mNumPages++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMarker() {
|
||||
mNumPages--;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMarkersCount(int numMarkers) {
|
||||
mNumPages = numMarkers;
|
||||
protected void onPageCountChanged() {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user