/*
* Android Wheel Control.
* https://code.google.com/p/android-wheel/
*
* Copyright 2010 Yuri Kanivets
*
* 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 kankan.wheel.widget;
import java.util.LinkedList;
import java.util.List;
import kankan.wheel.R;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.os.Handler;
import android.os.Message;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.FloatMath;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Interpolator;
import android.widget.Scroller;
/**
* Numeric wheel view.
*
* @author Yuri Kanivets
*/
public class WheelView extends View {
/** Scrolling duration */
private static final int SCROLLING_DURATION = 400;
/** Minimum delta for scrolling */
private static final int MIN_DELTA_FOR_SCROLLING = 1;
/** Current value & label text color */
private static final int VALUE_TEXT_COLOR = 0xF0000000;
/** Items text color */
private static final int ITEMS_TEXT_COLOR = 0xFF000000;
/** Top and bottom shadows colors */
private static final int[] SHADOWS_COLORS = new int[] { 0xFF111111,
0x00AAAAAA, 0x00AAAAAA };
/** Additional items height (is added to standard text item height) */
private static final int ADDITIONAL_ITEM_HEIGHT = 15;
/** Text size */
private static final int TEXT_SIZE = 24;
/** Top and bottom items offset (to hide that) */
private static final int ITEM_OFFSET = TEXT_SIZE / 5;
/** Additional width for items layout */
private static final int ADDITIONAL_ITEMS_SPACE = 10;
/** Label offset */
private static final int LABEL_OFFSET = 8;
/** 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 WheelAdapter adapter = null;
private int currentItem = 0;
// Widths
private int itemsWidth = 0;
private int labelWidth = 0;
// Count of visible items
private int visibleItems = DEF_VISIBLE_ITEMS;
// Item height
private int itemHeight = 0;
// Text paints
private TextPaint itemsPaint;
private TextPaint valuePaint;
// Layouts
private StaticLayout itemsLayout;
private StaticLayout labelLayout;
private StaticLayout valueLayout;
// Label & background
private String label;
private Drawable centerDrawable;
// Shadows drawables
private GradientDrawable topShadow;
private GradientDrawable bottomShadow;
// Scrolling
private boolean isScrollingPerformed;
private int scrollingOffset;
// Scrolling animation
private GestureDetector gestureDetector;
private Scroller scroller;
private int lastScrollY;
// Cyclic
boolean isCyclic = false;
// Listeners
private List<OnWheelChangedListener> changingListeners = new LinkedList<OnWheelChangedListener>();
private List<OnWheelScrollListener> scrollingListeners = new LinkedList<OnWheelScrollListener>();
/**
* 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) {
gestureDetector = new GestureDetector(context, gestureListener);
gestureDetector.setIsLongpressEnabled(false);
scroller = new Scroller(context);
}
/**
* Gets wheel adapter
* @return the adapter
*/
public WheelAdapter getAdapter() {
return adapter;
}
/**
* Sets wheel adapter
* @param adapter the new wheel adapter
*/
public void setAdapter(WheelAdapter adapter) {
this.adapter = adapter;
invalidateLayouts();
invalidate();
}
/**
* Set the the specified scrolling interpolator
* @param interpolator the interpolator
*/
public void setInterpolator(Interpolator interpolator) {
scroller.forceFinished(true);
scroller = new Scroller(getContext(), interpolator);
}
/**
* Gets count of visible items
*
* @return the count of visible items
*/
public int getVisibleItems() {
return visibleItems;
}
/**
* Sets count of visible items
*
* @param count
* the new count
*/
public void setVisibleItems(int count) {
visibleItems = count;
invalidate();
}
/**
* Gets label
*
* @return the label
*/
public String getLabel() {
return label;
}
/**
* Sets label
*
* @param newLabel
* the label to set
*/
public void setLabel(String newLabel) {
if (label == null || !label.equals(newLabel)) {
label = newLabel;
labelLayout = null;
invalidate();
}
}
/**
* 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);
}
/**
* Removes wheel scrolling listener
* @param listener the listener
*/
public void removeScrollingListener(OnWheelScrollListener listener) {
scrollingListeners.remove(listener);
}
/**
* Notifies listeners about starting scrolling
*/
protected void notifyScrollingListenersAboutStart() {
for (OnWheelScrollListener listener : scrollingListeners) {
listener.onScrollingStarted(this);
}
}
/**
* Notifies listeners about ending scrolling
*/
protected void notifyScrollingListenersAboutEnd() {
for (OnWheelScrollListener listener : scrollingListeners) {
listener.onScrollingFinished(this);
}
}
/**
* Gets current value
*
* @return the current value
*/
public int getCurrentItem() {
return currentItem;
}
/**
* Sets the current item. Does nothing when index is wrong.
*
* @param index the item index
* @param animated the animation flag
*/
public void setCurrentItem(int index, boolean animated) {
if (adapter == null || adapter.getItemsCount() == 0) {
return; // throw?
}
if (index < 0 || i
没有合适的资源?快使用搜索试试~ 我知道了~
Android 实现Iphone PickerView 大滚轮效果
共138个文件
svn-base:41个
class:27个
all-wcprops:20个
5星 · 超过95%的资源 需积分: 10 271 下载量 55 浏览量
2012-03-14
23:37:40
上传
评论
收藏 183KB RAR 举报
温馨提示
Android 实现Iphone PickerView 大滚轮效果 实现效果很有新意,可以大大增强用户体验
资源推荐
资源详情
资源评论
收起资源包目录
Android 实现Iphone PickerView 大滚轮效果 (138个子文件)
all-wcprops 919B
all-wcprops 919B
all-wcprops 726B
all-wcprops 726B
all-wcprops 534B
all-wcprops 459B
all-wcprops 406B
all-wcprops 190B
all-wcprops 190B
all-wcprops 190B
all-wcprops 186B
all-wcprops 86B
all-wcprops 86B
all-wcprops 80B
all-wcprops 80B
all-wcprops 80B
all-wcprops 73B
all-wcprops 73B
all-wcprops 73B
all-wcprops 73B
resources.ap_ 15KB
PickerView.apk 33KB
WheelView.class 17KB
WheelDemo.class 6KB
PasswActivity.class 3KB
TimeActivity.class 3KB
WheelView$1.class 2KB
CitiesActivity.class 2KB
NumericWheelAdapter.class 2KB
WheelView$2.class 2KB
TimeActivity$1.class 1KB
TimeActivity$2.class 1KB
ArrayWheelAdapter.class 1KB
TimeActivity$4.class 1KB
TimeActivity$3.class 1KB
CitiesActivity$1.class 1KB
WheelDemo$1.class 1018B
PasswActivity$1.class 933B
PasswActivity$3.class 903B
PasswActivity$2.class 898B
R$id.class 697B
EmptyActivity.class 518B
R$layout.class 492B
R$drawable.class 480B
R.class 445B
R$attr.class 322B
OnWheelScrollListener.class 239B
WheelAdapter.class 224B
OnWheelChangedListener.class 204B
.classpath 280B
Thumbs.db 5KB
classes.dex 30KB
entries 1KB
entries 1KB
entries 1KB
entries 1KB
entries 858B
entries 852B
entries 682B
entries 381B
entries 381B
entries 381B
entries 371B
entries 296B
entries 245B
entries 245B
entries 227B
entries 227B
entries 227B
entries 221B
entries 221B
entries 221B
WheelView.java 24KB
WheelDemo.java 4KB
PasswActivity.java 4KB
TimeActivity.java 3KB
NumericWheelAdapter.java 2KB
ArrayWheelAdapter.java 2KB
CitiesActivity.java 2KB
R.java 1KB
WheelAdapter.java 1KB
OnWheelChangedListener.java 1KB
OnWheelScrollListener.java 1KB
EmptyActivity.java 337B
icon.png 4KB
icon.png 3KB
icon.png 2KB
.project 841B
default.properties 449B
WheelView.java.svn-base 24KB
WheelView.java.svn-base 24KB
WheelDemo.java.svn-base 4KB
WheelDemo.java.svn-base 4KB
icon.png.svn-base 4KB
PasswActivity.java.svn-base 4KB
PasswActivity.java.svn-base 4KB
TimeActivity.java.svn-base 3KB
TimeActivity.java.svn-base 3KB
icon.png.svn-base 3KB
NumericWheelAdapter.java.svn-base 2KB
共 138 条
- 1
- 2
109905418
- 粉丝: 2426
- 资源: 186
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页