package org.miscwidgets.widget;
import org.miscwidgets.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.text.method.KeyListener;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.GestureDetector.OnGestureListener;
import android.view.animation.Animation;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.view.animation.Animation.AnimationListener;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
public class Panel extends LinearLayout {
private static final String TAG = "Panel";
/**
* Callback invoked when the panel is opened/closed.
*/
public static interface OnPanelListener {
/**
* Invoked when the panel becomes fully closed.
*/
public void onPanelClosed(Panel panel);
/**
* Invoked when the panel becomes fully opened.
*/
public void onPanelOpened(Panel panel);
}
private boolean mIsShrinking;
private int mPosition;
private int mDuration;
private boolean mLinearFlying;
private int mHandleId;
private int mContentId;
private View mHandle;
private View mContent;
private Drawable mOpenedHandle;
private Drawable mClosedHandle;
private float mTrackX;
private float mTrackY;
private float mVelocity;
private OnPanelListener panelListener;
public static final int TOP = 0;
public static final int BOTTOM = 1;
public static final int LEFT = 2;
public static final int RIGHT = 3;
private enum State {
ABOUT_TO_ANIMATE,
ANIMATING,
READY,
TRACKING,
FLYING,
};
private State mState;
private Interpolator mInterpolator;
private GestureDetector mGestureDetector;
private int mContentHeight;
private int mContentWidth;
private int mOrientation;
private float mWeight;
private PanelOnGestureListener mGestureListener;
private boolean mBringToFront;
public Panel(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Panel);
mDuration = a.getInteger(R.styleable.Panel_animationDuration, 750); // duration defaults to 750 ms
mPosition = a.getInteger(R.styleable.Panel_position, BOTTOM); // position defaults to BOTTOM
mLinearFlying = a.getBoolean(R.styleable.Panel_linearFlying, false); // linearFlying defaults to false
mWeight = a.getFraction(R.styleable.Panel_weight, 0, 1, 0.0f); // weight defaults to 0.0
if (mWeight < 0 || mWeight > 1) {
mWeight = 0.0f;
Log.w(TAG, a.getPositionDescription() + ": weight must be > 0 and <= 1");
}
mOpenedHandle = a.getDrawable(R.styleable.Panel_openedHandle);
mClosedHandle = a.getDrawable(R.styleable.Panel_closedHandle);
RuntimeException e = null;
mHandleId = a.getResourceId(R.styleable.Panel_handle, 0);
if (mHandleId == 0) {
e = new IllegalArgumentException(a.getPositionDescription() +
": The handle attribute is required and must refer to a valid child.");
}
mContentId = a.getResourceId(R.styleable.Panel_content, 0);
if (mContentId == 0) {
e = new IllegalArgumentException(a.getPositionDescription() +
": The content attribute is required and must refer to a valid child.");
}
a.recycle();
if (e != null) {
throw e;
}
mOrientation = (mPosition == TOP || mPosition == BOTTOM)? VERTICAL : HORIZONTAL;
setOrientation(mOrientation);
mState = State.READY;
mGestureListener = new PanelOnGestureListener();
mGestureDetector = new GestureDetector(mGestureListener);
mGestureDetector.setIsLongpressEnabled(false);
// i DON'T really know why i need this...
setBaselineAligned(false);
}
/**
* Sets the listener that receives a notification when the panel becomes open/close.
*
* @param onPanelListener The listener to be notified when the panel is opened/closed.
*/
public void setOnPanelListener(OnPanelListener onPanelListener) {
panelListener = onPanelListener;
}
/**
* Gets Panel's mHandle
*
* @return Panel's mHandle
*/
public View getHandle() {
return mHandle;
}
/**
* Gets Panel's mContent
*
* @return Panel's mContent
*/
public View getContent() {
return mContent;
}
/**
* Sets the acceleration curve for panel's animation.
*
* @param i The interpolator which defines the acceleration curve
*/
public void setInterpolator(Interpolator i) {
mInterpolator = i;
}
/**
* Set the opened state of Panel.
*
* @param open True if Panel is to be opened, false if Panel is to be closed.
* @param animate True if use animation, false otherwise.
*
* @return True if operation was performed, false otherwise.
*
*/
public boolean setOpen(boolean open, boolean animate) {
if (mState == State.READY && isOpen() ^ open) {
mIsShrinking = !open;
if (animate) {
mState = State.ABOUT_TO_ANIMATE;
if (!mIsShrinking) {
// this could make flicker so we test mState in dispatchDraw()
// to see if is equal to ABOUT_TO_ANIMATE
mContent.setVisibility(VISIBLE);
}
post(startAnimation);
} else {
mContent.setVisibility(open? VISIBLE : GONE);
postProcess();
}
return true;
}
return false;
}
/**
* Returns the opened status for Panel.
*
* @return True if Panel is opened, false otherwise.
*/
public boolean isOpen() {
return mContent.getVisibility() == VISIBLE;
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mHandle = findViewById(mHandleId);
if (mHandle == null) {
String name = getResources().getResourceEntryName(mHandleId);
throw new RuntimeException("Your Panel must have a child View whose id attribute is 'R.id." + name + "'");
}
mHandle.setOnTouchListener(touchListener);
mHandle.setOnClickListener(clickListener);
mContent = findViewById(mContentId);
if (mContent == null) {
String name = getResources().getResourceEntryName(mHandleId);
throw new RuntimeException("Your Panel must have a child View whose id attribute is 'R.id." + name + "'");
}
// reposition children
removeView(mHandle);
removeView(mContent);
if (mPosition == TOP || mPosition == LEFT) {
addView(mContent);
addView(mHandle);
} else {
addView(mHandle);
addView(mContent);
}
if (mClosedHandle != null) {
mHandle.setBackgroundDrawable(mClosedHandle);
}
mContent.setClickable(true);
mContent.setVisibility(GONE);
if (mWeight > 0) {
ViewGroup.LayoutParams params = mContent.getLayoutParams();
if (mOrientation == VERTICAL) {
params.height = ViewGroup.LayoutParams.FILL_PARENT;
} else {
params.width = ViewGroup.LayoutParams.FILL_PARENT;
}
mContent.setLayoutParams(params);
}
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
ViewParent parent = getParent();
if (parent != null && parent instanceof FrameLayout) {
mBringToFront = true;
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mWeight > 0 && mContent.getVisibility() == VISIBLE) {
View parent = (View) getParent();
if (parent != null) {
if (mOrientation == VERTICAL) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec((int) (parent.getHeight() * mWeight), MeasureSpec.EXACTLY);
} else {
widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) (parent.getWidth() * mWeight), MeasureSpec.EXACTLY);
}
}
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onLayout(boolean changed, int l, int t,
没有合适的资源?快使用搜索试试~ 我知道了~
android-misc-widgets.rar
共459个文件
svn-base:259个
png:84个
xml:45个
5星 · 超过95%的资源 需积分: 10 907 下载量 26 浏览量
2011-03-22
21:57:01
上传
评论 7
收藏 485KB RAR 举报
温馨提示
android-misc-widgets.rar
资源推荐
资源详情
资源评论
收起资源包目录
android-misc-widgets.rar (459个子文件)
all-wcprops 15KB
all-wcprops 3KB
all-wcprops 2KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1013B
all-wcprops 795B
all-wcprops 683B
all-wcprops 415B
all-wcprops 204B
all-wcprops 92B
all-wcprops 88B
all-wcprops 88B
.classpath 232B
entries 17KB
entries 3KB
entries 2KB
entries 2KB
entries 2KB
entries 1KB
entries 1KB
entries 864B
entries 705B
entries 379B
entries 292B
entries 252B
entries 240B
export_svg 858B
Panel.java 16KB
VirtualKeyboard.java 14KB
Switcher.java 11KB
TestInterpolators.java 5KB
SmoothButton.java 5KB
ElasticInterpolator.java 3KB
TestSwitcher.java 3KB
TestCustomTitle.java 3KB
BackInterpolator.java 3KB
BounceInterpolator.java 3KB
ExpoInterpolator.java 2KB
CircInterpolator.java 2KB
TestPanels.java 2KB
QuintInterpolator.java 2KB
QuartInterpolator.java 2KB
SineInterpolator.java 2KB
CubicInterpolator.java 2KB
QuadInterpolator.java 2KB
PlotView.java 1KB
Test.java 1KB
TestVirtualKeyboard.java 570B
TestSmoothButton.java 389B
TestTheme.java 290B
EasingType.java 107B
vk_zoom.png 11KB
top_switcher_collapsed.9.png 3KB
bottom_switcher_collapsed.9.png 3KB
icon.png 3KB
top_switcher_expanded.9.png 3KB
bottom_switcher_expanded.9.png 3KB
top_switcher_collapsed_selected.9.png 3KB
bottom_switcher_collapsed_selected.9.png 3KB
right_switcher_collapsed.9.png 3KB
left_switcher_collapsed.9.png 3KB
top_switcher_expanded_selected.9.png 3KB
right_switcher_expanded.9.png 3KB
bottom_switcher_expanded_selected.9.png 3KB
left_switcher_expanded.9.png 3KB
right_switcher_collapsed_selected.9.png 2KB
left_switcher_collapsed_selected.9.png 2KB
right_switcher_expanded_selected.9.png 2KB
left_switcher_expanded_selected.9.png 2KB
vk_zoom_handle.png 2KB
arrow_up_normal.png 2KB
arrow_down_normal.png 2KB
arrow_down_pressed.png 2KB
arrow_up_pressed.png 2KB
arrow_left_normal.png 2KB
arrow_right_normal.png 2KB
arrow_right_pressed.png 2KB
arrow_left_pressed.png 2KB
arrow_down_disabled.png 2KB
arrow_up_disabled.png 2KB
arrow_left_disabled.png 2KB
arrow_right_disabled.png 2KB
bottom_switcher_expanded_focused.9.png 2KB
bottom_switcher_collapsed_focused.9.png 2KB
top_switcher_expanded_focused.9.png 2KB
top_switcher_collapsed_focused.9.png 2KB
left_switcher_collapsed_focused.9.png 1KB
right_switcher_collapsed_focused.9.png 1KB
right_switcher_expanded_focused.9.png 1KB
left_switcher_expanded_focused.9.png 1KB
vk_button_ctrl.9.png 1KB
silver_button_selected.9.png 1016B
btn_dropdown_pressed.9.png 1009B
vk_button.9.png 994B
silver_button5.9.png 988B
silver_button2.9.png 979B
silver_button1.9.png 978B
btn_dropdown_normal.9.png 978B
silver_button6.9.png 971B
共 459 条
- 1
- 2
- 3
- 4
- 5
机械师2
- 粉丝: 7
- 资源: 28
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页