Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions library/src/com/viewpagerindicator/UnderlinePageIndicator.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.adkdevelopment.e_contact.utils;

/*
* Copyright (C) 2012 Jake Wharton
*
Expand All @@ -13,15 +15,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.viewpagerindicator;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.view.MotionEventCompat;
Expand All @@ -32,6 +35,8 @@
import android.view.View;
import android.view.ViewConfiguration;

import com.adkdevelopment.e_contact.R;

/**
* Draws a line for each page. The current page line is colored differently
* than the unselected page lines.
Expand Down Expand Up @@ -62,16 +67,16 @@ public class UnderlinePageIndicator extends View implements PageIndicator {
private float mCornerRadius;

private final Runnable mFadeRunnable = new Runnable() {
@Override public void run() {
if (!mFades) return;
@Override public void run() {
if (!mFades) return;

final int alpha = Math.max(mPaint.getAlpha() - mFadeBy, 0);
mPaint.setAlpha(alpha);
invalidate();
if (alpha > 0) {
postDelayed(this, FADE_FRAME_MS);
final int alpha = Math.max(mPaint.getAlpha() - mFadeBy, 0);
mPaint.setAlpha(alpha);
invalidate();
if (alpha > 0) {
postDelayed(this, FADE_FRAME_MS);
}
}
}
};

public UnderlinePageIndicator(Context context) {
Expand All @@ -82,6 +87,7 @@ public UnderlinePageIndicator(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.vpiUnderlinePageIndicatorStyle);
}

@TargetApi(Build.VERSION_CODES.M)
public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if (isInEditMode()) return;
Expand All @@ -92,7 +98,13 @@ public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle)
final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades);
final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay);
final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length);
final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color);

int defaultSelectedColor;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color, context.getTheme());
} else {
defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color);
}

//Retrieve styles attributes
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePageIndicator, defStyle, 0);
Expand All @@ -106,7 +118,7 @@ public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle)

Drawable background = a.getDrawable(R.styleable.UnderlinePageIndicator_android_background);
if (background != null) {
setBackgroundDrawable(background);
setBackgroundDrawable(background);
}

a.recycle();
Expand Down Expand Up @@ -275,13 +287,13 @@ public void setViewPager(ViewPager viewPager) {
}
if (mViewPager != null) {
//Clear us from the old pager.
mViewPager.setOnPageChangeListener(null);
mViewPager.addOnPageChangeListener(null);
}
if (viewPager.getAdapter() == null) {
throw new IllegalStateException("ViewPager does not have adapter instance.");
}
mViewPager = viewPager;
mViewPager.setOnPageChangeListener(this);
mViewPager.addOnPageChangeListener(this);
invalidate();
post(new Runnable() {
@Override public void run() {
Expand Down