/*
* Copyright (C) 2011 Jake Wharton
* Copyright (C) 2011 Patrik Akerfeldt
* Copyright (C) 2011 Francisco Figueiredo Jr.
*
* 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.zanlabs.widget.infiniteviewpager.indicator;
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.Path;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.ViewConfigurationCompat;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import com.zanlabs.widget.infiniteviewpager.InfiniteViewPager;
import com.zanlabs.widget.infiniteviewpager.R;
import java.util.ArrayList;
/**
* A TitlePageIndicator is a PageIndicator which displays the title of left view
* (if exist), the title of the current select view (centered) and the title of
* the right view (if exist). When the user scrolls the ViewPager then titles are
* also scrolled.
*/
public class TitlePageIndicator extends View implements PageIndicator {
/**
* Percentage indicating what percentage of the screen width away from
* center should the underline be fully faded. A value of 0.25 means that
* halfway between the center of the screen and an edge.
*/
private static final float SELECTION_FADE_PERCENTAGE = 0.25f;
/**
* Percentage indicating what percentage of the screen width away from
* center should the selected text bold turn off. A value of 0.05 means
* that 10% between the center and an edge.
*/
private static final float BOLD_FADE_PERCENTAGE = 0.05f;
/**
* Title text used when no title is provided by the adapter.
*/
private static final String EMPTY_TITLE = "";
/**
* Interface for a callback when the center item has been clicked.
*/
public interface OnCenterItemClickListener {
/**
* Callback when the center item has been clicked.
*
* @param position Position of the current center item.
*/
void onCenterItemClick(int position);
}
public enum IndicatorStyle {
None(0), Triangle(1), Underline(2);
public final int value;
private IndicatorStyle(int value) {
this.value = value;
}
public static IndicatorStyle fromValue(int value) {
for (IndicatorStyle style : IndicatorStyle.values()) {
if (style.value == value) {
return style;
}
}
return null;
}
}
public enum LinePosition {
Bottom(0), Top(1);
public final int value;
private LinePosition(int value) {
this.value = value;
}
public static LinePosition fromValue(int value) {
for (LinePosition position : LinePosition.values()) {
if (position.value == value) {
return position;
}
}
return null;
}
}
private ViewPager mViewPager;
private ViewPager.OnPageChangeListener mListener;
private int mCurrentPage = -1;
private float mPageOffset;
private int mScrollState;
private final Paint mPaintText = new Paint();
private boolean mBoldText;
private int mColorText;
private int mColorSelected;
private Path mPath = new Path();
private final Rect mBounds = new Rect();
private final Paint mPaintFooterLine = new Paint();
private IndicatorStyle mFooterIndicatorStyle;
private LinePosition mLinePosition;
private final Paint mPaintFooterIndicator = new Paint();
private float mFooterIndicatorHeight;
private float mFooterIndicatorUnderlinePadding;
private float mFooterPadding;
private float mTitlePadding;
private float mTopPadding;
/** Left and right side padding for not active view titles. */
private float mClipPadding;
private float mFooterLineHeight;
private static final int INVALID_POINTER = -1;
private int mTouchSlop;
private float mLastMotionX = -1;
private int mActivePointerId = INVALID_POINTER;
private boolean mIsDragging;
private OnCenterItemClickListener mCenterItemClickListener;
public TitlePageIndicator(Context context) {
this(context, null);
}
public TitlePageIndicator(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.vpiTitlePageIndicatorStyle);
}
public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if (isInEditMode()) return;
//Load defaults from resources
final Resources res = getResources();
final int defaultFooterColor = res.getColor(R.color.default_title_indicator_footer_color);
final float defaultFooterLineHeight = res.getDimension(R.dimen.default_title_indicator_footer_line_height);
final int defaultFooterIndicatorStyle = res.getInteger(R.integer.default_title_indicator_footer_indicator_style);
final float defaultFooterIndicatorHeight = res.getDimension(R.dimen.default_title_indicator_footer_indicator_height);
final float defaultFooterIndicatorUnderlinePadding = res.getDimension(R.dimen.default_title_indicator_footer_indicator_underline_padding);
final float defaultFooterPadding = res.getDimension(R.dimen.default_title_indicator_footer_padding);
final int defaultLinePosition = res.getInteger(R.integer.default_title_indicator_line_position);
final int defaultSelectedColor = res.getColor(R.color.default_title_indicator_selected_color);
final boolean defaultSelectedBold = res.getBoolean(R.bool.default_title_indicator_selected_bold);
final int defaultTextColor = res.getColor(R.color.default_title_indicator_text_color);
final float defaultTextSize = res.getDimension(R.dimen.default_title_indicator_text_size);
final float defaultTitlePadding = res.getDimension(R.dimen.default_title_indicator_title_padding);
final float defaultClipPadding = res.getDimension(R.dimen.default_title_indicator_clip_padding);
final float defaultTopPadding = res.getDimension(R.dimen.default_title_indicator_top_padding);
//Retrieve styles attributes
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TitlePageIndicator, defStyle, 0);
//Retrieve the colors to be used for this view and apply them.
mFooterLineHeight = a.getDimension(R.styleable.TitlePageIndicator_footerLineHeight, defaultFooterLineHeight);
mFooterIndicatorStyle = IndicatorStyle.fromValue(a.getInteger(R.styleable.TitlePageIndicator_footerIndicatorStyle, defaultFooterIndicatorStyle));
mFooterIndicatorHeight = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorHeight, defaultFooterIndicatorHeight);
mFooterIndicatorUnderlinePadding = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding, defaultFooterIndicatorUnderlinePadding);
mFooterPadding = a.getDimension(R.styleable.TitlePageIndicator_footerPadding, defaultFooterPadding);
mLinePosition
没有合适的资源?快使用搜索试试~ 我知道了~
仿简书APP源码
共159个文件
png:71个
xml:36个
java:33个
需积分: 29 46 下载量 63 浏览量
2018-08-14
14:11:01
上传
评论 2
收藏 514KB RAR 举报
温馨提示
仿简书APP源码,具体仅做参考。可以学习交流互动,满足开发需求
资源推荐
资源详情
资源评论
收起资源包目录
仿简书APP源码 (159个子文件)
gradlew.bat 2KB
.gitignore 118B
.gitignore 7B
.gitignore 7B
build.gradle 2KB
build.gradle 564B
build.gradle 534B
settings.gradle 37B
gradlew 5KB
说明.htm 3KB
说明.htm 3KB
gradle-wrapper.jar 52KB
TitlePageIndicator.java 32KB
CacheUtil.java 28KB
CirclePageIndicator.java 19KB
LinePageIndicator.java 15KB
UnderlinePageIndicator.java 13KB
InfiniteViewPager.java 11KB
HomeFragment.java 6KB
MainActivity.java 6KB
RecycleBin.java 5KB
RecyclingPagerAdapter.java 4KB
Datas.java 4KB
ApiManage.java 3KB
DetailActivity.java 3KB
TopAdapter.java 2KB
NewsPresenterImpl.java 2KB
PageIndicator.java 2KB
Config.java 2KB
LoadingActivity.java 1KB
NetWorkUtil.java 1KB
MineFragment.java 1KB
GuanzhuFragment.java 874B
TixingFragment.java 872B
BaseFragment.java 870B
InfinitePagerAdapter.java 817B
ExampleInstrumentedTest.java 768B
BasePresneterImpl.java 697B
Banners.java 666B
MyApplication.java 530B
INews.java 496B
ExampleUnitTest.java 412B
NewsServices.java 368B
ApplicationTest.java 367B
BasePrensenter.java 154B
mylove.jpg 225KB
logo.png 26KB
logo.png 26KB
loading_center.png 13KB
ic_launcher.png 10KB
loading_bottom.png 10KB
app_icon.png 8KB
ic_launcher.png 8KB
app_icon.png 5KB
ic_launcher.png 5KB
app_icon.png 4KB
ic_launcher.png 3KB
app_icon.png 2KB
ic_launcher.png 2KB
cb_icon_more_normal.png 2KB
image_guanzhu.png 2KB
image_like.png 2KB
image_reward.png 2KB
image_ask.png 2KB
image_talk.png 1KB
cb_icon_tixing_normal.png 1KB
icon_comment_add_new.png 1KB
remind_icon_tuijian.png 1KB
cb_icon_more_selected.png 1KB
icon_image_share_night.png 1KB
grzy_icon_share_app.png 1KB
hot_icon_pinglun_night.png 1KB
hot_icon_like_night.png 1KB
cb_icon_discover_normal.png 1KB
image_message.png 996B
cb_icon_tixing_selected.png 983B
icon_talk_night.png 705B
cb_icon_discover_selected.png 697B
icon_like_normal.png 674B
image_shouqi.png 651B
icon_history.png 619B
zw_icon_collectionsettings.png 587B
cb_icon_guanzhu_normal.png 551B
grzy_icon_night.png 501B
grzy_icon_rate.png 492B
gywm_icon_tiaozhuan_night.png 482B
icon_like_selected.png 477B
grzy_icon_like_normal.png 464B
icon_share_normal.png 423B
grzy_icon_wallet_normal.png 383B
grzy_icon_article_secret.png 348B
cb_icon_guanzhu_selected.png 337B
icon_zhuanti_night.png 322B
zw_icon_mark_selected.png 290B
grzy_icon_feedback.png 287B
grzy_icon_mark.png 268B
icon_wenji_night.png 227B
image_other.png 220B
grzy_icon_article_public.png 192B
vpi__tab_unselected_holo.9.png 166B
共 159 条
- 1
- 2
资源评论
qq_42966057
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功