scrollToChild(currentPosition, 0);
if (pageListener != null)
{
(currentPosition);
}
}
});
}
private void addTextTab(final int position, String title)
{
TextView tab = new TextView(getContext());
(title);
;
();
addTab(position, tab);
}
private void addIconTab(final int position, int resId)
{
ImageButton tab = new ImageButton(getContext());
(resId);
addTab(position, tab);
}
private void addTab(final int position, View tab)
{
(true);
(new OnClickListener() {
@Override
public void onClick(View v)
{
(position);
}
});
(tabPadding, 0, tabPadding, 0);
(tab, position, shouldExpand expandedTabLayoutParams : defaultTabLayoutParams);
}
private void updateTabStyles()
{
for (int i = 0; i < tabCount; i++)
{
View v = (i);
(tabBackgroundResId);
if (v instanceof TextView)
{
TextView tab = (TextView) v;
, tabTextSize);
(tabTypeface, tabTypefaceStyle);
oString().toUpperCase(locale));
}
}
}
}
}
private void scrollToChild(int position, int offset)
{
if (tabCount == 0) { return; }
int newScrollX = (position).getLeft() + offset;
if (position > 0 || offset > 0)
{
newScrollX -= scrollOffset;
}
if (newScrollX != lastScrollX)
{
lastScrollX = newScrollX;
scrollTo(newScrollX, 0);
}
}
@Override
protected void onDraw(Canvas canvas)
{
(canvas);
if (isInEditMode() || tabCount == 0) { return; }
final int height = getHeight();
etWidth()));
invalidate();
if (delegatePageListener != null)
{
(position, positionOffset, positionOffsetPixels);
}
}
@Override
public void onPageScrollStateChanged(int state)
{
if (state ==
{
scrollToChild(), 0);
}
if (delegatePageListener != null)
{
(state);
}
}
@Override
public void onPageSelected(int position)
{
if (delegatePageListener != null)
{
(position);
}
updateTabStyles();
}
}
public void setIndicatorColor(int indicatorColor)
{
= indicatorColor;
invalidate();
}
public void setIndicatorColorResource(int resId)
{
= getResources().getColor(resId);
invalidate();
}
public int getIndicatorColor()
{
return ;
}
public void setIndicatorHeight(int indicatorLineHeightPx) {
= indicatorLineHeightPx;
invalidate();
}
public int getIndicatorHeight()
{
return indicatorHeight;
}
public void setUnderlineColor(int underlineColor)
{
= underlineColor;
invalidate();
}
public void setUnderlineColorResource(int resId)
{
= getResources().getColor(resId);
invalidate();
}
public int getUnderlineColor()
{
return underlineColor;
}
public void setDividerColor(int piderColor)
{
= piderColor;
invalidate();
}
public void setDividerColorResource(int resId)
{
= getResources().getColor(resId);
invalidate();
}
public int getDividerColor()
{
return piderColor;
}
public void setUnderlineHeight(int underlineHeightPx) {
= underlineHeightPx;
invalidate();
}
public int getUnderlineHeight()
{
return underlineHeight;
}
public void setDividerPadding(int piderPaddingPx) {
= piderPaddingPx;
invalidate();
}
public int getDividerPadding()
{
return piderPadding;
}
public void setScrollOffset(int scrollOffsetPx)
{
= scrollOffsetPx;
invalidate();
}
public int getScrollOffset()
{
return scrollOffset;
}
public void setShouldExpand(boolean shouldExpand) {
= shouldExpand;
requestLayout();
}
public boolean getShouldExpand()
{
return shouldExpand;
}
public boolean isTextAllCaps()
{
return textAllCaps;
}
public void setAllCaps(boolean textAllCaps)
{
= textAllCaps;
}
public void setTextSize(int textSizePx)
{
= textSizePx;
updateTabStyles();
}
public int getTextSize()
{
return tabTextSize;
}
public void setTextColor(int textColor)
{
= textColor;
updateTabStyles();
}
public void setTextColor(int textNormalColor, int textSelectedColor) {
= textNormalColor;
= textSelectedColor;
updateTabStyles();
}
public void setTextColorResource(int resId)
{
= getResources().getColor(resId);
updateTabStyles();
}
public int getTextColor()
{
return tabTextColor;
}
public void setTypeface(Typeface typeface, int style)
{
= typeface;
= style;
updateTabStyles();
}
public void setTabBackground(int resId)
{
= resId;
}
public int getTabBackground()
{
return tabBackgroundResId;
}
public void setTabPaddingLeftRight(int paddingPx)
{
= paddingPx;
updateTabStyles();
}
public int getTabPaddingLeftRight()
{
return tabPadding;
}
@Override
public void onRestoreInstanceState(Parcelable state)
{
SavedState savedState = (SavedState) state;
());
currentPosition = ;
requestLayout();
}
@Override
public Parcelable onSaveInstanceState()
{
Parcelable superState = ();
SavedState savedState = new SavedState(superState);
= currentPosition;
return savedState;
}
static class SavedState extends BaseSavedState
{
int currentPosition;
public SavedState(Parcelable superState) {
super(superState);
}
private SavedState(Parcel in) {
super(in);
currentPosition = ();
}
@Override
public void writeToParcel(Parcel dest, int flags)
{
(dest, flags);
(currentPosition);
}
public static final
@Override
public SavedState createFromParcel(Parcel in)
{
return new SavedState(in);
}
@Override
public SavedState[] newArray(int size)
{
return new SavedState[size];
}
};
}
}
代码3:
*
* Licensed under the Apache License, Version (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* 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.
*/
public class BitmapUtils implements TaskHandler {
private boolean pauseTask = false;
private boolean cancelAllTask = false;
private final Object pauseTaskLock = new Object();
private Context context;
private BitmapGlobalConfig globalConfig;
private BitmapDisplayConfig defaultDisplayConfig;
etDrawable(resId));
return this;
}
public BitmapUtils configDefaultLoadingImage(Bitmap bitmap) {
(new BitmapDrawable(), bitmap));
return this;
}
public BitmapUtils configDefaultLoadFailedImage(Drawable drawable) {