package hong.specialEffects.wheel;
import hong.specialEffects.R;
import hong.specialEffects.wheel.adapter.WheelViewAdapter;
import java.util.LinkedList;
import java.util.List;
import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Interpolator;
import android.widget.LinearLayout;
/**
* Numeric wheel view.
*
* @author Yuri Kanivets
*/
public class WheelView extends View {
/** Top and bottom shadows colors */
private static final int[] SHADOWS_COLORS = new int[] { 0xFF111111,
0x00AAAAAA, 0x00AAAAAA };
/** Top and bottom items offset (to hide that) */
private static final int ITEM_OFFSET_PERCENT = 10;
/** Left and right padding value */
private static final int PADDING = 10;
/** Default count of visible items */
private static final int DEF_VISIBLE_ITEMS = 5;
// Wheel Values
private int currentItem = 0;
// Count of visible items
private int visibleItems = DEF_VISIBLE_ITEMS;
// Item height
private int itemHeight = 0;
// Center Line
private Drawable centerDrawable;
// Shadows drawables
private GradientDrawable topShadow;
private GradientDrawable bottomShadow;
// Scrolling
private WheelScroller scroller;
private boolean isScrollingPerformed;
private int scrollingOffset;
// Cyclic
boolean isCyclic = false;
// Items layout
private LinearLayout itemsLayout;
// The number of first item in layout
private int firstItem;
// View adapter
private WheelViewAdapter viewAdapter;
// Recycle
private WheelRecycle recycle = new WheelRecycle(this);
// Listeners
private List<OnWheelChangedListener> changingListeners = new LinkedList<OnWheelChangedListener>();
private List<OnWheelScrollListener> scrollingListeners = new LinkedList<OnWheelScrollListener>();
private List<OnWheelClickedListener> clickingListeners = new LinkedList<OnWheelClickedListener>();
/**
* Constructor
*/
public WheelView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initData(context);
}
/**
* Constructor
*/
public WheelView(Context context, AttributeSet attrs) {
super(context, attrs);
initData(context);
}
/**
* Constructor
*/
public WheelView(Context context) {
super(context);
initData(context);
}
/**
* Initializes class data
* @param context the context
*/
private void initData(Context context) {
scroller = new WheelScroller(getContext(), scrollingListener);
}
// Scrolling listener
WheelScroller.ScrollingListener scrollingListener = new WheelScroller.ScrollingListener() {
@Override
public void onStarted() {
isScrollingPerformed = true;
notifyScrollingListenersAboutStart();
}
@Override
public void onScroll(int distance) {
doScroll(distance);
int height = getHeight();
if (scrollingOffset > height) {
scrollingOffset = height;
scroller.stopScrolling();
} else if (scrollingOffset < -height) {
scrollingOffset = -height;
scroller.stopScrolling();
}
}
@Override
public void onFinished() {
if (isScrollingPerformed) {
notifyScrollingListenersAboutEnd();
isScrollingPerformed = false;
}
scrollingOffset = 0;
invalidate();
}
@Override
public void onJustify() {
if (Math.abs(scrollingOffset) > WheelScroller.MIN_DELTA_FOR_SCROLLING) {
scroller.scroll(scrollingOffset, 0);
}
}
};
/**
* Set the the specified scrolling interpolator
* @param interpolator the interpolator
*/
public void setInterpolator(Interpolator interpolator) {
scroller.setInterpolator(interpolator);
}
/**
* Gets count of visible items
*
* @return the count of visible items
*/
public int getVisibleItems() {
return visibleItems;
}
/**
* Sets the desired count of visible items.
* Actual amount of visible items depends on wheel layout parameters.
* To apply changes and rebuild view call measure().
*
* @param count the desired count for visible items
*/
public void setVisibleItems(int count) {
visibleItems = count;
}
/**
* Gets view adapter
* @return the view adapter
*/
public WheelViewAdapter getViewAdapter() {
return viewAdapter;
}
// Adapter listener
private DataSetObserver dataObserver = new DataSetObserver() {
@Override
public void onChanged() {
invalidateWheel(false);
}
@Override
public void onInvalidated() {
invalidateWheel(true);
}
};
/**
* Sets view adapter. Usually new adapters contain different views, so
* it needs to rebuild view by calling measure().
*
* @param viewAdapter the view adapter
*/
public void setViewAdapter(WheelViewAdapter viewAdapter) {
if (this.viewAdapter != null) {
this.viewAdapter.unregisterDataSetObserver(dataObserver);
}
this.viewAdapter = viewAdapter;
if (this.viewAdapter != null) {
this.viewAdapter.registerDataSetObserver(dataObserver);
}
invalidateWheel(true);
}
/**
* Adds wheel changing listener
* @param listener the listener
*/
public void addChangingListener(OnWheelChangedListener listener) {
changingListeners.add(listener);
}
/**
* Removes wheel changing listener
* @param listener the listener
*/
public void removeChangingListener(OnWheelChangedListener listener) {
changingListeners.remove(listener);
}
/**
* Notifies changing listeners
* @param oldValue the old wheel value
* @param newValue the new wheel value
*/
protected void notifyChangingListeners(int oldValue, int newValue) {
for (OnWheelChangedListener listener : changingListeners) {
listener.onChanged(this, oldValue, newValue);
}
}
/**
* Adds wheel scrolling listener
* @param listener the listener
*/
public void addScrollingListener(OnWheelScrollListener listener) {
scrollingListeners.add(listener);
}
/**
* Re
没有合适的资源?快使用搜索试试~ 我知道了~
Android项目之——页面特效集合(附源码).zip
共208个文件
xml:88个
java:56个
png:52个
需积分: 5 0 下载量 91 浏览量
2022-11-05
02:44:33
上传
评论
收藏 4.01MB ZIP 举报
温馨提示
Android项目之——页面特效集合(附源码)
资源推荐
资源详情
资源评论
收起资源包目录
Android项目之——页面特效集合(附源码).zip (208个子文件)
proguard.cfg 1KB
.classpath 364B
WheelView.java 30KB
BookPageWidget.java 18KB
FlingGallery.java 18KB
R.java 14KB
NinePointLineView.java 10KB
NinePointView.java 10KB
HorizontialListView.java 9KB
AbstractWheelTextAdapter.java 8KB
BookPageFactory.java 8KB
WheelScroller.java 7KB
FlingGalleryActivity.java 7KB
ButtonAdapter.java 5KB
CoverFlow.java 5KB
WheelActivity.java 4KB
WheelRecycle.java 4KB
MuiltGradeListAdapter.java 4KB
CoverFlowImageAdapter.java 3KB
FileUtils.java 3KB
BookpageActivity.java 3KB
Processor.java 3KB
Animation_BeginActivity.java 3KB
MuiltGradeListActivity.java 3KB
MuiltTableActivity.java 3KB
CoverFlowActivity.java 2KB
SplashScreen_BeginActivity.java 2KB
CornerListView.java 2KB
RoundCornerActivity.java 2KB
NumericWheelAdapter.java 2KB
CircleCornerActivity.java 2KB
DrawerActivity.java 2KB
WheelViewAdapter.java 2KB
HorListviewActivity.java 2KB
PlasmaView.java 2KB
CustomSpinnerActivity.java 2KB
MyLog.java 2KB
ViewHolderBean.java 2KB
AbstractWheelAdapter.java 2KB
ItemsRange.java 2KB
HorizontialListAdapter.java 1KB
AdapterWheel.java 1KB
ArrayWheelAdapter.java 1010B
HeaderBottomListActivity.java 943B
LeftRightSlideActivity.java 874B
Animation_TargetActivity.java 815B
WheelAdapter.java 726B
HorizontalListViewActivity.java 692B
CustonActivity.java 623B
CustomRadioGroup.java 533B
OnWheelScrollListener.java 464B
CustomRadioButtonActivity.java 450B
SplashScreen_TargetActivity.java 400B
OnWheelChangedListener.java 400B
SlideSecondActivity.java 369B
PlasmaActivity.java 343B
OnWheelClickedListener.java 312B
BuildConfig.java 161B
mm.jpg 45KB
bg.jpg 42KB
btn_bg1.jpg 881B
btn_bg_click.jpg 744B
btn_bg.jpg 672B
bookpage.png 261KB
muilt_grade_list.PNG 191KB
plasma.png 191KB
custon.png 98KB
splashscreen.png 84KB
header_bottom_list.png 77KB
lnxins.png 66KB
scroll_tab.png 66KB
drawer.png 60KB
hor_list_view.png 43KB
animation.png 41KB
f07.png 40KB
f06.png 40KB
f08.png 40KB
f05.png 40KB
f09.png 40KB
f10.png 40KB
f04.png 40KB
f03.png 40KB
custom_spinner.png 39KB
up.png 32KB
down.png 32KB
wheel.png 25KB
fling_gallery.png 22KB
hor_list_scorll.png 20KB
left_right_slide.png 19KB
muilt_table.png 19KB
cus_radio_btn.png 17KB
circle_list_view.png 12KB
circle_corner.png 11KB
animat.png 10KB
indicator_lock_area_next.png 6KB
indicator_lock_area.png 6KB
ic_menu_search.png 5KB
ig.png 5KB
ic_launcher.png 4KB
usa.png 3KB
共 208 条
- 1
- 2
- 3
资源评论
程序员一灯
- 粉丝: 836
- 资源: 2134
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功