Update ViewPagerIndicator dependency to latest version.

This commit is contained in:
Sebastian Kaspari 2012-04-13 11:21:56 +02:00
parent 35b896c3d6
commit c292892307
8 changed files with 59 additions and 13 deletions

View File

@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.viewpagerindicator" package="com.viewpagerindicator"
android:versionCode="26" android:versionCode="30"
android:versionName="2.2.2"> android:versionName="2.2.3">
<uses-sdk android:minSdkVersion="4" /> <uses-sdk android:minSdkVersion="4" />
</manifest> </manifest>

View File

@ -1,3 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
</lint>

View File

@ -11,13 +11,13 @@
<parent> <parent>
<groupId>com.viewpagerindicator</groupId> <groupId>com.viewpagerindicator</groupId>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<version>2.2.2</version> <version>2.2.3</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>android</groupId> <groupId>com.google.android</groupId>
<artifactId>android</artifactId> <artifactId>android</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@ -35,7 +35,7 @@
<plugins> <plugins>
<plugin> <plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId> <groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>maven-android-plugin</artifactId> <artifactId>android-maven-plugin</artifactId>
<extensions>true</extensions> <extensions>true</extensions>
</plugin> </plugin>

View File

@ -34,6 +34,8 @@
<attr name="centered" format="boolean" /> <attr name="centered" format="boolean" />
<!-- Color of the filled circle that represents the current page. --> <!-- Color of the filled circle that represents the current page. -->
<attr name="fillColor" format="color" /> <attr name="fillColor" format="color" />
<!-- Color of the filled circles that represents pages. -->
<attr name="pageColor" format="color" />
<!-- Orientation of the indicator. --> <!-- Orientation of the indicator. -->
<attr name="orientation"> <attr name="orientation">
<enum name="horizontal" value="0" /> <enum name="horizontal" value="0" />

View File

@ -17,6 +17,7 @@
<resources> <resources>
<bool name="default_circle_indicator_centered">true</bool> <bool name="default_circle_indicator_centered">true</bool>
<color name="default_circle_indicator_fill_color">#FFFFFFFF</color> <color name="default_circle_indicator_fill_color">#FFFFFFFF</color>
<color name="default_circle_indicator_page_color">#00000000</color>
<integer name="default_circle_indicator_orientation">0</integer> <integer name="default_circle_indicator_orientation">0</integer>
<dimen name="default_circle_indicator_radius">3dp</dimen> <dimen name="default_circle_indicator_radius">3dp</dimen>
<bool name="default_circle_indicator_snap">false</bool> <bool name="default_circle_indicator_snap">false</bool>
@ -33,7 +34,7 @@
<color name="default_title_indicator_selected_color">#FFFFFFFF</color> <color name="default_title_indicator_selected_color">#FFFFFFFF</color>
<bool name="default_title_indicator_selected_bold">true</bool> <bool name="default_title_indicator_selected_bold">true</bool>
<color name="default_title_indicator_text_color">#BBFFFFFF</color> <color name="default_title_indicator_text_color">#BBFFFFFF</color>
<dimen name="default_title_indicator_text_size">15sp</dimen> <dimen name="default_title_indicator_text_size">15dp</dimen>
<dimen name="default_title_indicator_title_padding">5dp</dimen> <dimen name="default_title_indicator_title_padding">5dp</dimen>
<dimen name="default_title_indicator_top_padding">7dp</dimen> <dimen name="default_title_indicator_top_padding">7dp</dimen>
</resources> </resources>

View File

@ -27,6 +27,7 @@
<style name="Widget.CirclePageIndicator" parent="Widget"> <style name="Widget.CirclePageIndicator" parent="Widget">
<item name="centered">@bool/default_circle_indicator_centered</item> <item name="centered">@bool/default_circle_indicator_centered</item>
<item name="fillColor">@color/default_circle_indicator_fill_color</item> <item name="fillColor">@color/default_circle_indicator_fill_color</item>
<item name="pageColor">@color/default_circle_indicator_page_color</item>
<item name="orientation">@integer/default_circle_indicator_orientation</item> <item name="orientation">@integer/default_circle_indicator_orientation</item>
<item name="radius">@dimen/default_circle_indicator_radius</item> <item name="radius">@dimen/default_circle_indicator_radius</item>
<item name="snap">@bool/default_circle_indicator_snap</item> <item name="snap">@bool/default_circle_indicator_snap</item>

View File

@ -41,6 +41,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
public static final int VERTICAL = 1; public static final int VERTICAL = 1;
private float mRadius; private float mRadius;
private final Paint mPaintPageFill;
private final Paint mPaintStroke; private final Paint mPaintStroke;
private final Paint mPaintFill; private final Paint mPaintFill;
private ViewPager mViewPager; private ViewPager mViewPager;
@ -75,6 +76,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
//Load defaults from resources //Load defaults from resources
final Resources res = getResources(); final Resources res = getResources();
final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color); final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation); final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color); final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
@ -88,6 +90,9 @@ public class CirclePageIndicator extends View implements PageIndicator {
mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered); mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
mOrientation = a.getInt(R.styleable.CirclePageIndicator_orientation, defaultOrientation); mOrientation = a.getInt(R.styleable.CirclePageIndicator_orientation, defaultOrientation);
mPaintPageFill = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaintPageFill.setStyle(Style.FILL);
mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
mPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG); mPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaintStroke.setStyle(Style.STROKE); mPaintStroke.setStyle(Style.STROKE);
mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor)); mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
@ -114,6 +119,15 @@ public class CirclePageIndicator extends View implements PageIndicator {
return mCentered; return mCentered;
} }
public void setPageColor(int pageColor) {
mPaintPageFill.setColor(pageColor);
invalidate();
}
public int getPageColor() {
return mPaintPageFill.getColor();
}
public void setFillColor(int fillColor) { public void setFillColor(int fillColor) {
mPaintFill.setColor(fillColor); mPaintFill.setColor(fillColor);
invalidate(); invalidate();
@ -194,6 +208,11 @@ public class CirclePageIndicator extends View implements PageIndicator {
return; return;
} }
if (mCurrentPage >= count) {
setCurrentItem(count - 1);
return;
}
int longSize; int longSize;
int longPaddingBefore; int longPaddingBefore;
int longPaddingAfter; int longPaddingAfter;
@ -220,6 +239,11 @@ public class CirclePageIndicator extends View implements PageIndicator {
float dX; float dX;
float dY; float dY;
float pageFillRadius = mRadius;
if (mPaintStroke.getStrokeWidth() > 0) {
pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f;
}
//Draw stroked circles //Draw stroked circles
for (int iLoop = 0; iLoop < count; iLoop++) { for (int iLoop = 0; iLoop < count; iLoop++) {
float drawLong = longOffset + (iLoop * threeRadius); float drawLong = longOffset + (iLoop * threeRadius);
@ -230,7 +254,15 @@ public class CirclePageIndicator extends View implements PageIndicator {
dX = shortOffset; dX = shortOffset;
dY = drawLong; dY = drawLong;
} }
canvas.drawCircle(dX, dY, mRadius, mPaintStroke); // Only paint fill if not completely transparent
if (mPaintPageFill.getAlpha() > 0) {
canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);
}
// Only paint stroke if a stroke width was non-zero
if (pageFillRadius != mRadius) {
canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
}
} }
//Draw the filled circle according to the current scroll //Draw the filled circle according to the current scroll
@ -249,6 +281,9 @@ public class CirclePageIndicator extends View implements PageIndicator {
} }
public boolean onTouchEvent(android.view.MotionEvent ev) { public boolean onTouchEvent(android.view.MotionEvent ev) {
if (super.onTouchEvent(ev)) {
return true;
}
if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
return false; return false;
} }

View File

@ -321,10 +321,12 @@ public class TitlePageIndicator extends View implements PageIndicator {
//Calculate views bounds //Calculate views bounds
ArrayList<RectF> bounds = calculateAllBounds(mPaintText); ArrayList<RectF> bounds = calculateAllBounds(mPaintText);
final int boundsSize = bounds.size();
//Make sure we're on a page that still exists //Make sure we're on a page that still exists
if (mCurrentPage >= bounds.size()) { if (mCurrentPage >= boundsSize) {
setCurrentItem(bounds.size()-1); setCurrentItem(boundsSize - 1);
return;
} }
final int countMinusOne = count - 1; final int countMinusOne = count - 1;
@ -400,6 +402,7 @@ public class TitlePageIndicator extends View implements PageIndicator {
} }
//Now draw views //Now draw views
int colorTextAlpha = mColorText >>> 24;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
//Get the title //Get the title
RectF bound = bounds.get(i); RectF bound = bounds.get(i);
@ -411,6 +414,10 @@ public class TitlePageIndicator extends View implements PageIndicator {
//Draw text as unselected //Draw text as unselected
mPaintText.setColor(mColorText); mPaintText.setColor(mColorText);
if(currentPage && currentSelected) {
//Fade out/in unselected text as the selected text fades in/out
mPaintText.setAlpha(colorTextAlpha - (int)(colorTextAlpha * selectedPercent));
}
canvas.drawText(mTitleProvider.getTitle(i), bound.left, bound.bottom + mTopPadding, mPaintText); canvas.drawText(mTitleProvider.getTitle(i), bound.left, bound.bottom + mTopPadding, mPaintText);
//If we are within the selected bounds draw the selected text //If we are within the selected bounds draw the selected text
@ -440,7 +447,7 @@ public class TitlePageIndicator extends View implements PageIndicator {
break; break;
case Underline: case Underline:
if (!currentSelected) { if (!currentSelected || page >= boundsSize) {
break; break;
} }
@ -460,6 +467,9 @@ public class TitlePageIndicator extends View implements PageIndicator {
} }
public boolean onTouchEvent(android.view.MotionEvent ev) { public boolean onTouchEvent(android.view.MotionEvent ev) {
if (super.onTouchEvent(ev)) {
return true;
}
if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
return false; return false;
} }