/*
* Copyright (C) 2011 Daniel Berndt - Codeus Ltd - DateSlider
*
* This class contains all the scrolling logic of the slidable elements
*
* 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.googlecode.android.widgets.DateSlider;
import java.lang.reflect.Constructor;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.Scroller;
import com.googlecode.android.widgets.DateSlider.labeler.Labeler;
import com.googlecode.android.widgets.DateSlider.timeview.TimeView;
/**
* This is where most of the magic happens. This is a subclass of LinearLayout
* that display a collection of TimeViews and handles the scrolling, shuffling
* the TimeViews around to keep the display up-to-date, and managing the Labelers
* to populate the TimeViews with the correct data.
*
* This class is configured via xml attributes that specify the class of the
* labeler to use to generate views, the format string for the labeler to use
* to populate the views, and optionally width and height values to override
* the default width and height of the views.
*/
public class ScrollLayout extends LinearLayout {
private static String TAG = "SCROLLLAYOUT";
private Scroller mScroller;
/**
* Indicates if we are currently tracking touch events that are dragging
* (scrolling) us.
*/
private boolean mDragMode;
/**
* The aggregate width of all of our children
*/
private int childrenWidth;
/**
* The aggregate width of our children is very likely to be wider than the
* bounds of our view. Since we keep everything centered, we need to keep
* our view scrolled by enough to center our children, rather than
* left-aligning them. This variable tracks how much to scroll to achieve this.
*/
private int mInitialOffset;
private int mLastX, mLastScroll, mScrollX;
private VelocityTracker mVelocityTracker;
private int mMinimumVelocity, mMaximumVelocity;
/**
* The time that we are currently displaying
*/
private long currentTime = System.currentTimeMillis();
private long minTime = -1, maxTime = -1;
private int minuteInterval = 1;
/**
* The width of each child
*/
private int objWidth;
/**
* The height of each child
*/
private int objHeight;
private Drawable rightShadow, leftShadow;
private Labeler mLabeler;
private OnScrollListener listener;
private TimeView mCenterView;
public ScrollLayout(Context context, AttributeSet attrs) {
super(context, attrs);
this.setWillNotDraw(false);
rightShadow = getContext().getResources().getDrawable(R.drawable.right_shadow);
leftShadow = getContext().getResources().getDrawable(R.drawable.left_shadow);
mScroller = new Scroller(getContext());
setGravity(Gravity.CENTER_VERTICAL);
setOrientation(HORIZONTAL);
final ViewConfiguration configuration = ViewConfiguration.get(getContext());
mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
// as mMaximumVelocity does not exist in API<4
float density = getContext().getResources().getDisplayMetrics().density;
mMaximumVelocity = (int)(4000 * 0.5f * density);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScrollLayout,
0, 0);
// Get the labeler class and construct an instance
String className = a.getNonResourceString(R.styleable.ScrollLayout_labelerClass);
if (className == null) {
throw new RuntimeException("Must specify labeler class at " + a.getPositionDescription());
}
String labelerFormat = a.getString(R.styleable.ScrollLayout_labelerFormat);
if (labelerFormat == null) {
throw new RuntimeException("Must specify labelerFormat at " + a.getPositionDescription());
}
try {
Class<?> klazz = Class.forName(className);
Constructor<?> ctor = klazz.getConstructor(String.class);
mLabeler = (Labeler)ctor.newInstance(labelerFormat);
} catch (Exception e) {
throw new RuntimeException("Failed to construct labeler at " + a.getPositionDescription(), e);
}
// Determine the width and height of our children, using the labelers preferred
// values as defaults
objWidth = a.getDimensionPixelSize(R.styleable.ScrollLayout_childWidth,
mLabeler.getPreferredViewWidth(context));
objHeight = a.getDimensionPixelSize(R.styleable.ScrollLayout_childHeight,
mLabeler.getPreferredViewHeight(context));
a.recycle();
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
//
// We need to generate enough children to fill all of our desired space, and
// it needs to be an odd number of children because we treat the center view
// specially. So, first compute how many children we will need.
//
final Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
final int displayWidth = display.getWidth();
int childCount = displayWidth / objWidth;
// Make sure to round up
if (displayWidth % objWidth != 0) {
childCount++;
}
// Now make sure we have an odd number of children
if (childCount % 2 == 0) {
childCount++;
}
// We have an odd number of children, so childCount / 2 will round down to the
// index just before the center in 1-based indexing, meaning that it will be the
// center index in 0-based indexing.
final int centerIndex = (childCount / 2);
// Make sure we weren't inflated with any views for some odd reason
removeAllViews();
// Now add all of the child views, making sure to make the center view as such.
for (int i = 0; i < childCount; i++) {
LayoutParams lp = new LayoutParams(objWidth, objHeight);
TimeView ttv = mLabeler.createView(getContext(), i == centerIndex);
addView((View)ttv, lp);
}
// Now we need to set the times on all of the TimeViews. We start with the center
// view, work our way to the end, then starting from the center again, work our
// way back to the beginning.
mCenterView = (TimeView)getChildAt(centerIndex);
mCenterView.setVals(mLabeler.getElem(currentTime));
Log.v(TAG, "mCenter: " + mCenterView.getTimeText() + " minInterval " + minuteInterval);
// TODO: Do I need to use endTime, or can I just use the point time?
for (int i = centerIndex + 1; i < childCount; i++) {
TimeView lastView = (TimeView)getChildAt(i - 1);
TimeView thisView = (TimeView)getChildAt(i);
thisView.setVals(mLabeler.add(lastView.getEndTime(), 1));
}
for (int i = centerIndex - 1; i >= 0; i--) {
TimeVi
没有合适的资源?快使用搜索试试~ 我知道了~
android多功能滚动日历控件
共112个文件
class:57个
java:28个
xml:17个
5星 · 超过95%的资源 需积分: 48 224 下载量 69 浏览量
2013-03-15
16:03:08
上传
评论 1
收藏 158KB RAR 举报
温馨提示
android多功能滚动日历控件,值得下载的自定义控件,已经很成熟的代码,可以直接使用
资源推荐
资源详情
资源评论
收起资源包目录
android多功能滚动日历控件 (112个子文件)
resources.ap_ 17KB
Demo.apk 38KB
proguard.cfg 1KB
ScrollLayout.class 13KB
DateSlider.class 6KB
Demo.class 5KB
SliderContainer.class 4KB
Util.class 4KB
TimeLayoutView.class 3KB
TimeTextView.class 2KB
MinimalDemo.class 2KB
MonthYearDateSlider.class 2KB
DayTimeLayoutView.class 2KB
WeekLabeler.class 2KB
DateTimeSlider.class 2KB
TimeSlider.class 2KB
Labeler.class 2KB
TimeLabeler.class 2KB
CustomDateSlider.class 2KB
Demo$4.class 2KB
DefaultDateSlider.class 1KB
MinimalDemo$1.class 1KB
Demo$1.class 1KB
Demo$2.class 1KB
Demo$3.class 1KB
MinuteLabeler.class 1KB
AlternativeDateSlider.class 1KB
WeekLabeler$CustomTimeTextView.class 1KB
DateSlider$1.class 1KB
SliderContainer$1.class 1KB
MonthLabeler.class 1KB
YearLabeler.class 1KB
HourLabeler.class 1KB
DayLabeler.class 1KB
R$id.class 1KB
DateSlider$3.class 963B
MinimalDemo$2.class 923B
Demo$11.class 884B
Demo$12.class 883B
Demo$10.class 883B
Demo$6.class 882B
Demo$9.class 881B
Demo$8.class 881B
Demo$5.class 881B
Demo$7.class 881B
MonthYearLabeler.class 863B
DateSlider$2.class 862B
DayDateLabeler.class 858B
R.class 842B
R$layout.class 803B
R$styleable.class 792B
R$drawable.class 575B
R$attr.class 571B
TimeObject.class 547B
R$string.class 506B
R$style.class 464B
TimeView.class 458B
DateSlider$OnDateSetListener.class 370B
SliderContainer$OnTimeChangeListener.class 340B
ScrollLayout$OnScrollListener.class 300B
.classpath 280B
classes.dex 41KB
ScrollLayout.java 20KB
R.java 9KB
Demo.java 8KB
DateSlider.java 6KB
Util.java 6KB
SliderContainer.java 5KB
TimeLayoutView.java 4KB
Labeler.java 4KB
WeekLabeler.java 3KB
MinimalDemo.java 3KB
DayTimeLayoutView.java 3KB
TimeTextView.java 2KB
TimeView.java 2KB
TimeSlider.java 2KB
DateTimeSlider.java 2KB
MonthYearDateSlider.java 2KB
CustomDateSlider.java 1KB
AlternativeDateSlider.java 1KB
DefaultDateSlider.java 1KB
TimeLabeler.java 1KB
MonthYearLabeler.java 846B
DayDateLabeler.java 844B
MinuteLabeler.java 841B
MonthLabeler.java 659B
YearLabeler.java 655B
HourLabeler.java 654B
DayLabeler.java 649B
TimeObject.java 456B
LICENSE 635B
icon.png 4KB
.project 840B
default.properties 362B
README 3KB
main.xml 2KB
datetimeslider.xml 1KB
altdateslider.xml 1KB
customdateslider.xml 1KB
defaultdateslider.xml 1012B
共 112 条
- 1
- 2
俊哥唯一
- 粉丝: 5
- 资源: 27
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- pta题库答案c语言之排序4统计工龄.zip
- pta题库答案c语言之树结构7堆中的路径.zip
- pta题库答案c语言之树结构3TreeTraversalsAgain.zip
- pta题库答案c语言之树结构2ListLeaves.zip
- pta题库答案c语言之树结构1树的同构.zip
- 基于C++实现民航飞行与地图简易管理系统可执行程序+说明+详细注释.zip
- pta题库答案c语言之复杂度1最大子列和问题.zip
- 三维装箱问题(Three-Dimensional Bin Packing Problem,3D-BPP)是一个经典的组合优化问题
- 以下是一些关于Linux线程同步的基本概念和方法.txt
- 以下是一个简化的示例,它使用pygame库来模拟烟花动画的框架.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页