/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*
* Modifications by: Alessandro Crugnola
*/
package it.sephiroth.demo.slider.widget;
import it.sephiroth.demo.slider.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SoundEffectConstants;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
public class MultiDirectionSlidingDrawer extends ViewGroup {
public static final int ORIENTATION_RTL = 0;
public static final int ORIENTATION_BTT = 1;
public static final int ORIENTATION_LTR = 2;
public static final int ORIENTATION_TTB = 3;
private static final int TAP_THRESHOLD = 6;
private static final float MAXIMUM_TAP_VELOCITY = 100.0f;
private static final float MAXIMUM_MINOR_VELOCITY = 150.0f;
private static final float MAXIMUM_MAJOR_VELOCITY = 200.0f;
private static final float MAXIMUM_ACCELERATION = 2000.0f;
private static final int VELOCITY_UNITS = 1000;
private static final int MSG_ANIMATE = 1000;
private static final int ANIMATION_FRAME_DURATION = 1000 / 60;
private static final int EXPANDED_FULL_OPEN = -10001;
private static final int COLLAPSED_FULL_CLOSED = -10002;
private final int mHandleId;
private final int mContentId;
private View mHandle;
private View mContent;
private final Rect mFrame = new Rect();
private final Rect mInvalidate = new Rect();
private boolean mTracking;
private boolean mLocked;
private VelocityTracker mVelocityTracker;
private boolean mInvert;
private boolean mVertical;
private boolean mExpanded;
private int mBottomOffset;
private int mTopOffset;
private int mHandleHeight;
private int mHandleWidth;
private OnDrawerOpenListener mOnDrawerOpenListener;
private OnDrawerCloseListener mOnDrawerCloseListener;
private OnDrawerScrollListener mOnDrawerScrollListener;
private final Handler mHandler = new SlidingHandler();
private float mAnimatedAcceleration;
private float mAnimatedVelocity;
private float mAnimationPosition;
private long mAnimationLastTime;
private long mCurrentAnimationTime;
private int mTouchDelta;
private boolean mAnimating;
private boolean mAllowSingleTap;
private boolean mAnimateOnClick;
private final int mTapThreshold;
private final int mMaximumTapVelocity;
private int mMaximumMinorVelocity;
private int mMaximumMajorVelocity;
private int mMaximumAcceleration;
private final int mVelocityUnits;
/**
* Callback invoked when the drawer is opened.
*/
public static interface OnDrawerOpenListener {
/**
* Invoked when the drawer becomes fully open.
*/
public void onDrawerOpened();
}
/**
* Callback invoked when the drawer is closed.
*/
public static interface OnDrawerCloseListener {
/**
* Invoked when the drawer becomes fully closed.
*/
public void onDrawerClosed();
}
/**
* Callback invoked when the drawer is scrolled.
*/
public static interface OnDrawerScrollListener {
/**
* Invoked when the user starts dragging/flinging the drawer's handle.
*/
public void onScrollStarted();
/**
* Invoked when the user stops dragging/flinging the drawer's handle.
*/
public void onScrollEnded();
}
/**
* Creates a new SlidingDrawer from a specified set of attributes defined in
* XML.
*
* @param context
* The application's environment.
* @param attrs
* The attributes defined in XML.
*/
public MultiDirectionSlidingDrawer( Context context, AttributeSet attrs )
{
this( context, attrs, 0 );
}
/**
* Creates a new SlidingDrawer from a specified set of attributes defined in
* XML.
*
* @param context
* The application's environment.
* @param attrs
* The attributes defined in XML.
* @param defStyle
* The style to apply to this widget.
*/
public MultiDirectionSlidingDrawer( Context context, AttributeSet attrs, int defStyle )
{
super( context, attrs, defStyle );
TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.MultiDirectionSlidingDrawer, defStyle, 0 );
int orientation = a.getInt( R.styleable.MultiDirectionSlidingDrawer_direction, ORIENTATION_BTT );
mVertical = ( orientation == ORIENTATION_BTT || orientation == ORIENTATION_TTB );
mBottomOffset = (int)a.getDimension( R.styleable.MultiDirectionSlidingDrawer_bottomOffset, 0.0f );
mTopOffset = (int)a.getDimension( R.styleable.MultiDirectionSlidingDrawer_topOffset, 0.0f );
mAllowSingleTap = a.getBoolean( R.styleable.MultiDirectionSlidingDrawer_allowSingleTap, true );
mAnimateOnClick = a.getBoolean( R.styleable.MultiDirectionSlidingDrawer_animateOnClick, true );
mInvert = ( orientation == ORIENTATION_TTB || orientation == ORIENTATION_LTR );
int handleId = a.getResourceId( R.styleable.MultiDirectionSlidingDrawer_handle, 0 );
if ( handleId == 0 ) { throw new IllegalArgumentException( "The handle attribute is required and must refer "
+ "to a valid child." ); }
int contentId = a.getResourceId( R.styleable.MultiDirectionSlidingDrawer_content, 0 );
if ( contentId == 0 ) { throw new IllegalArgumentException( "The content attribute is required and must refer "
+ "to a valid child." ); }
if ( handleId == contentId ) { throw new IllegalArgumentException( "The content and handle attributes must refer "
+ "to different children." ); }
mHandleId = handleId;
mContentId = contentId;
final float density = getResources().getDisplayMetrics().density;
mTapThreshold = (int)( TAP_THRESHOLD * density + 0.5f );
mMaximumTapVelocity = (int)( MAXIMUM_TAP_VELOCITY * density + 0.5f );
mMaximumMinorVelocity = (int)( MAXIMUM_MINOR_VELOCITY * density + 0.5f );
mMaximumMajorVelocity = (int)( MAXIMUM_MAJOR_VELOCITY * density + 0.5f );
mMaximumAcceleration = (int)( MAXIMUM_ACCELERATION * density + 0.5f );
mVelocityUnits = (int)( VELOCITY_UNITS * density + 0.5f );
if( mInvert ) {
mMaximumAcceleration = -mMaximumAcceleration;
mMaximumMajorVelocity = -mMaximumMajorVelocity;
mMaximumMinorVelocity = -mMaximumMinorVelocity;
}
a.recycle();
setAlwaysDrawnWithCacheEnabled( false );
}
@Override
protected void onFinishInflate()
{
mHandle = findViewById( mHandleId );
if ( mHandle == null ) { throw new IllegalArgumentException( "The handle attribute is must refer to an" + " existing child." ); }
mHandle.setOnClickListener( new DrawerToggler() );
mContent = findViewById( mContentId );
if ( mContent == null ) { throw new IllegalArgumentException( "The content attribute is must refer to an"
+ " existing child." ); }
mContent.setVisibility( View.GONE );
}
@Override
protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec )
{
int widthSpecMode = MeasureSpec.getMode( widthMeasureSpec );
int widthSpecSize = MeasureSpec.getSize( widthMeasureSpec
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Android 下拉通知效果源码.zip项目安卓应用源码下载Android 下拉通知效果源码.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
资源推荐
资源详情
资源评论
收起资源包目录
Android 下拉通知效果源码.zip (51个子文件)
Android 下拉通知效果源码
Android 下拉通知效果源码
1_130106135008_2.png 35KB
Android 下拉通知效果源码
DemoSlidingDrawer
bin
classes.dex 23KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
sliding_drawer_handle_bottom.png 730B
drawable
drawer_pattern.png 107B
drawable-mdpi
icon.png 2KB
classes
classes.dex 23KB
resources.ap_ 15KB
it
sephiroth
demo
slider
MainActivity.class 1KB
MainActivity$2.class 1KB
MainActivity$1.class 987B
R$layout.class 447B
R$id.class 902B
R$drawable.class 540B
R$attr.class 617B
R.class 635B
R$styleable.class 1KB
R$string.class 566B
widget
MultiDirectionSlidingDrawer$SlidingHandler.class 1KB
MultiDirectionSlidingDrawer$OnDrawerCloseListener.class 340B
MultiDirectionSlidingDrawer$OnDrawerOpenListener.class 338B
MultiDirectionSlidingDrawer$DrawerToggler.class 1KB
MultiDirectionSlidingDrawer$OnDrawerScrollListener.class 367B
MultiDirectionSlidingDrawer.class 21KB
DemoSlidingDrawer.apk 29KB
resources.ap_ 15KB
DemoSlidingDrawer.apk 29KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
sliding_drawer_handle_bottom.png 2KB
drawable
drawer_pattern.png 944B
pattern1.xml 176B
values
strings.xml 332B
attrs.xml 735B
drawable-mdpi
icon.png 3KB
layout
pen_content.xml 5KB
main.xml 1KB
default.properties 364B
gen
it
sephiroth
demo
slider
R.java 12KB
proguard.cfg 1KB
.settings
org.eclipse.core.resources.prefs 145B
org.eclipse.jdt.core.prefs 629B
src
it
sephiroth
demo
slider
MainActivity.java 1KB
widget
MultiDirectionSlidingDrawer.java 31KB
.project 820B
.classpath 364B
project.properties 360B
AndroidManifest.xml 690B
1-130106134U20-L.png 21KB
1_130106135008_1.png 36KB
共 51 条
- 1
资源评论
yxkfw
- 粉丝: 76
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- python-leetcode面试题解之第157题用Read4读取N个字符-题解.zip
- python-leetcode面试题解之第156题上下翻转二叉树-题解.zip
- python-leetcode面试题解之第155题最小栈-题解.zip
- python-leetcode面试题解之第153题寻找旋转排序数组中的最小值-题解.zip
- python-leetcode面试题解之第152题乘积最大子数组-题解.zip
- python-leetcode面试题解之第151题反转字符串中的单词-题解.zip
- python-leetcode面试题解之第150题逆波兰表达式求值-题解.zip
- python-leetcode面试题解之第149题直线上最多的点数-题解.zip
- python-leetcode面试题解之第148题排序链表-题解.zip
- python-leetcode面试题解之第147题对链表进行插入排序-题解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功