/*
* 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 com.amo.demo.wheelview;
import java.util.LinkedList;
import java.util.List;
import com.ly.control.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.MotionEvent;
import android.view.View;
import android.view.GestureDetector.SimpleOnGestureListener;
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 */
public int TEXT_SIZE;
/** Top and bottom items offset (to hide that) */
private 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
荣华富贵8
- 粉丝: 223
- 资源: 7653
最新资源
- 流水线贴膜机完成项目程序,包含PLC程序和触摸屏程序,程序内 包含上下气缸控制,夹紧气缸控制,输送带电机控制,贴膜伺服控制,旋转电机控制等类容,非常适合学习简单控制工艺及运动控制初学者学习,该程序支持
- PLC与变频器RS指令无协议通讯 适应支持MODBUS.RTU模式的各品牌变频器 RS485ADP或者RS485BD板都可以 本程序编写了CRC循环冗余校验码程序,针对FX1N.2N没有CRC专
- 自己封装的爱普生机器人与三菱的MC协议通信驱动程序,提供项目源码、MC协议源码,需要一定基础(通信 MC协议 爱普生机器人编程)才能调的通
- 紧急道,紧急避障,横纵向联合控制,模型预测控制+pid控制方案,通过控制转角以及车轮力矩实现道,避障轨迹 matlab用的是2016,carsim用的是2018
- 基于plc智能停车场车位控制仿真 功能介绍: ①假设某停车场共有16个车位 ②在停车场入口处装设有一传感器,用来检测车辆进入的数目 ③在停车场出口处装设有一传感器,用来检测车辆出去的数目 ④尚有
- 能量和储备调度的分布鲁棒联合机会约束 测试环境:MATLAB 关键词:分布式鲁棒优化,能量和储备调度,联合机会约束 我们开发了一个两阶段的随机计划,为能源和储备调度的联合电力和天然气系统的高渗透的可再
- 插电式混合动力汽车的能量管理:模型预测控制的凸优化算法 测试环境:MATLAB 关键词:乘法器交替方向法、能量管理、内点法、模型预测控制、插电式混合动力汽车 求解非线性损耗混合动力汽车能量管理模型预测
- 储能参与调频调峰联合优化运行 关键词:储能 调频 调峰 储能优化 联合优化 测试环境:matlab平台 通过一个联合优化框架同时使用电池存储系统进行调峰和频率调节,该框架可以捕捉到电池 化、操作限
- 基于最小二乘法和快速解耦法的电网状态估计 测试环境:MATLAB 电网状态估计问题的实质是当方程的个数大于变量的个数时,对方程变量进行无偏估计 对于电网系统,变量为节点电压(即状态值,由实部和虚部
- 四轮轮毂电机驱动车辆,驱动电机故障状态估计(UKF) 软件使用:Matlab Simulink 适用场景:采用无迹卡尔曼滤波UKF进行轮毂电机状态估计,失效电机估计状态为0,正常电机状态为1 产品
- 汇川H3UCAN总线高性能PLC实机程序,本体应用五轴?CAN总线轴控两轴SV630总线伺服电机,最大可扩充16轴运动总线 另外一路MODBUS总线控制高频温控器 配合台湾威纶通TK6071IP触
- 倒立摆源码 13年国赛电赛旋转倒立摆 完整全功能 程序 倒立摆 pid算法 程序使用时可根据硬件需要自行调节 基本要求 1. 摆杆从处于自然下垂状态(摆角 0°)开始,驱动电机带动旋转臂作往复旋转使
- 成熟 步进电机驱动 方案 全套
- 考虑电动汽车调度潜力的两阶段充电桩市场投标 代码 测试环境:MATLAB 关键词:电动汽车,车并网,纳什均衡,投标策略 充电站投标优化能降低电力成本甚至通过电取益 考虑了电动汽车成为柔性储荷资源的
- 四相8 6极开关磁阻电机maxwell仿真资料
- labview串口,网口,DSC可用OPC通讯链接三菱欧姆龙西门子等PLC 需要的取,可帮助使用 通过NI-OPC控制三菱,欧姆龙西门子等各种型号PLC
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈