/*
* 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);
int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
if (widthSpecMode == MeasureSpec.UNSPECIFIED
|| heightSpecMode == MeasureSpec.UNSPECIFIED) {
throw new R
没有合适的资源?快使用搜索试试~ 我知道了~
下拉抽屉菜单加上横向gridview的实现
共57个文件
class:17个
png:15个
xml:8个
需积分: 9 117 下载量 194 浏览量
2015-09-07
11:47:03
上传
评论
收藏 118KB RAR 举报
温馨提示
各种抽屉菜单越来越来多,需求各种奇葩,这是帮别人实现的一个下拉抽屉菜单,抽屉里面的布局是可以横向滚动的gridview。需要的朋友可以参考下。
资源推荐
资源详情
资源评论
收起资源包目录
下拉抽屉+横向gridview菜单.rar (57个子文件)
DemoSlidingDrawer
.project 820B
default.properties 364B
bin
DemoSlidingDrawer.apk 31KB
AndroidManifest.xml 714B
jarlist.cache 120B
dexedLibs
annotations-cd10ad8c83e2e68ee326c1a50de2107e.jar 1KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
sliding_drawer_handle_bottom.png 730B
icon.png 4KB
drawable
drawer_pattern.png 107B
drawable-mdpi
icon.png 2KB
crunch
drawable-ldpi
icon.png 2KB
drawable-hdpi
sliding_drawer_handle_bottom.png 730B
icon.png 4KB
drawable
drawer_pattern.png 107B
drawable-mdpi
icon.png 2KB
resources.ap_ 15KB
classes
it
sephiroth
demo
slider
R$string.class 566B
R$layout.class 479B
MyGridViewAdapter$ViewHolder.class 652B
MainActivity.class 3KB
R$drawable.class 540B
widget
MultiDirectionSlidingDrawer$OnDrawerOpenListener.class 338B
MultiDirectionSlidingDrawer$DrawerToggler.class 1KB
MultiDirectionSlidingDrawer.class 22KB
MultiDirectionSlidingDrawer$SlidingHandler.class 1KB
MultiDirectionSlidingDrawer$OnDrawerCloseListener.class 340B
MultiDirectionSlidingDrawer$OnDrawerScrollListener.class 367B
R$styleable.class 1KB
R.class 635B
BuildConfig.class 357B
R$attr.class 617B
MyGridViewAdapter.class 2KB
R$id.class 774B
classes.dex 31KB
proguard.cfg 1KB
.settings
org.eclipse.core.resources.prefs 145B
org.eclipse.jdt.core.prefs 629B
AndroidManifest.xml 714B
src
it
sephiroth
demo
slider
widget
MultiDirectionSlidingDrawer.java 31KB
MainActivity.java 2KB
MyGridViewAdapter.java 1KB
project.properties 360B
res
values
attrs.xml 735B
strings.xml 332B
layout
pen_content.xml 863B
listitem.xml 660B
main.xml 1KB
drawable-ldpi
icon.png 2KB
drawable-hdpi
sliding_drawer_handle_bottom.png 2KB
icon.png 4KB
drawable
drawer_pattern.png 944B
pattern1.xml 176B
drawable-mdpi
icon.png 3KB
drawable-xhdpi
.classpath 475B
gen
it
sephiroth
demo
slider
R.java 12KB
BuildConfig.java 166B
assets
共 57 条
- 1
资源评论
山寨戴王
- 粉丝: 163
- 资源: 23
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功