/*
* Copyright (C) 2007 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.
*/
package seker.mygallery.view;
import seker.mygallery.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.SoundEffectConstants;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.animation.Transformation;
import android.widget.Scroller;
/**
* A view that shows items in a center-locked, horizontally scrolling list.
* <p>
* The default values for the Gallery assume you will be using
* {@link android.R.styleable#Theme_galleryItemBackground} as the background for
* each View given to the Gallery from the Adapter. If you are not doing this,
* you may need to adjust some Gallery properties, such as the spacing.
* <p>
* Views given to the Gallery should use {@link MyGallery.LayoutParams} as their
* layout parameters type.
*
* @attr ref android.R.styleable#Gallery_animationDuration
* @attr ref android.R.styleable#Gallery_spacing
* @attr ref android.R.styleable#Gallery_gravity
*/
//@Widget
//mItemCount ---->getCount()
//mFirstPosition---->getFirstVisiblePosition()
public class MyGallery extends MyAbsSpinner implements GestureDetector.OnGestureListener {
//dynamic center
private int mDynamicCenter = -1;
// private boolean isSingleTapUp = false;
private static final byte RIGHT_DIRECTION = -1;
private static final byte INVALID_DIRECTION = 0;
private static final byte LEFT_DIRECTION = 1;
private byte m_GestureDirection = INVALID_DIRECTION;
/**
* Duration in milliseconds from the start of a scroll during which we're
* unsure whether the user is scrolling or flinging.
*/
private static final int SCROLL_TO_FLING_UNCERTAINTY_TIMEOUT = 250;
/**
* Horizontal spacing between items.
*/
private int mSpacing = 0;
/**
* How long the transition animation should run when a child view changes
* position, measured in milliseconds.
*/
private int mAnimationDuration = 400;
/**
* The alpha of items that are not selected.
*/
private float mUnselectedAlpha;
private int mGravity;
/**
* Helper for detecting touch gestures.
*/
private GestureDetector mGestureDetector;
/**
* The position of the item that received the user's down touch.
*/
private int mDownTouchPosition;
/**
* The view of the item that received the user's down touch.
*/
private View mDownTouchView;
/**
* Executes the delta scrolls from a fling or scroll movement.
*/
private FlingRunnable mFlingRunnable = new FlingRunnable();
/**
* Sets mSuppressSelectionChanged = false. This is used to set it to false
* in the future. It will also trigger a selection changed.
*/
private Runnable mDisableSuppressSelectionChangedRunnable = new Runnable() {
public void run() {
mSuppressSelectionChanged = false;
selectionChanged();
}
};
/**
* When fling runnable runs, it resets this to false. Any method along the
* path until the end of its run() can set this to true to abort any
* remaining fling. For example, if we've reached either the leftmost or
* rightmost item, we will set this to true.
*/
private boolean mShouldStopFling;
/**
* The currently selected item's child.
*/
private View mSelectedChild;
/**
* Whether to continuously callback on the item selected listener during a
* fling.
*/
private boolean mShouldCallbackDuringFling = true;
/**
* Whether to callback when an item that is not selected is clicked.
*/
private boolean mShouldCallbackOnUnselectedItemClick = true;
/**
* If true, do not callback to item selected listener.
*/
private boolean mSuppressSelectionChanged;
/**
* If true, we have received the "invoke" (center or enter buttons) key
* down. This is checked before we action on the "invoke" key up, and is
* subsequently cleared.
*/
private boolean mReceivedInvokeKeyDown;
private AdapterContextMenuInfo mContextMenuInfo;
/**
* If true, this onScroll is the first for this user's drag (remember, a
* drag sends many onScrolls).
*/
private boolean mIsFirstScroll;
public MyGallery(Context context) {
this(context, null);
}
public MyGallery(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.galleryStyle);
}
public MyGallery(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mGestureDetector = new GestureDetector(context, this);
mGestureDetector.setIsLongpressEnabled(true);
TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.MyGallery, defStyle, 0);
int index = a.getInt(R.styleable.MyGallery_gravity, -1);
if (index >= 0) {
setGravity(index);
}
int animationDuration =
a.getInt(R.styleable.MyGallery_animationDuration, -1);
if (animationDuration > 0) {
setAnimationDuration(animationDuration);
}
int spacing =
a.getDimensionPixelOffset(R.styleable.MyGallery_spacing, 0);
setSpacing(spacing);
float unselectedAlpha = a.getFloat(
R.styleable.MyGallery_unselectedAlpha, 0.5f);
setUnselectedAlpha(unselectedAlpha);
a.recycle();
/*
// We draw the selected item last (because otherwise the item to the
// right overlaps it)
mGroupFlags |= FLAG_USE_CHILD_DRAWING_ORDER;
mGroupFlags |= FLAG_SUPPORT_STATIC_TRANSFORMATIONS;
//*/
}
/**
* Whether or not to callback on any {@link #getOnItemSelectedListener()}
* while the items are being flinged. If false, only the final selected item
* will cause the callback. If true, all items between the first and the
* final will cause callbacks.
*
* @param shouldCallback Whether or not to callback on the listener while
* the items are being flinged.
*/
public void setCallbackDuringFling(boolean shouldCallback) {
mShouldCallbackDuringFling = shouldCallback;
}
/**
* Whether or not to callback when an item that is not selected is clicked.
* If false, the item will become selected (and re-centered). If true, the
* {@link #getOnItemClickListener()} will get the callback.
*
* @param shouldCallback Whether or not to callback on the listener when a
* item that is not selected is clicked.
* @hide
*/
public void setCallbackOnUnselectedItemClick(boolean shouldCallback) {
没有合适的资源?快使用搜索试试~ 我知道了~
自己重写Android下的拥有拖拽功能的Gallery
共70个文件
class:31个
png:15个
xml:10个
4星 · 超过85%的资源 需积分: 10 319 下载量 67 浏览量
2010-07-19
23:35:23
上传
评论 4
收藏 726KB ZIP 举报
温馨提示
1、自己重写了Android下的Gallery(比Android中现有的Gallery更有实用性)。 2、支持数据绑定,且支持绑定数据的动态更新。 3、拖拽效果的用户体验很好。 4、支持item选择效果,前提是item实现了View类的setSelected()方法。 5、点击测试用例1中第一个Item,即往Gallery中动态添加Item。 6、测试用例2中使用了多线程,取得当前Android系统中已安装的软件程序包。 7、点击测试用例2中的Gallery Item,则启动对应的软件程序。
资源推荐
资源详情
资源评论
收起资源包目录
MyGallery.zip (70个子文件)
MyGallery
.project 845B
default.properties 364B
bin
seker
mygallery
R$string.class 425B
R$layout.class 461B
MainActivity.class 5KB
R$drawable.class 917B
view
MyAdapterView.class 16KB
MyAdapterView$OnItemSelectedListener.class 544B
MyAdapterView$SelectionNotifier.class 952B
MyAdapterView$AdapterDataSetObserver.class 2KB
MyGallery$2.class 668B
MyAdapterView$OnItemClickListener.class 412B
GalleryChild.class 3KB
MyAbsSpinner$SavedState.class 2KB
MyGallery$LayoutParams.class 900B
MyAbsSpinner.class 9KB
GalleryAdapter.class 3KB
MyAbsSpinner$RecycleBin.class 2KB
MyAdapterView$OnItemLongClickListener.class 424B
MyAdapterView$AdapterContextMenuInfo.class 753B
MyGallery$1.class 703B
MyAbsSpinner$SavedState$1.class 1KB
MyGallery$FlingRunnable.class 3KB
MyGallery.class 20KB
R$styleable.class 1011B
R.class 653B
R$style.class 387B
R$color.class 800B
MainActivity$2.class 2KB
R$attr.class 596B
MainActivity$3.class 3KB
MainActivity$1.class 766B
R$id.class 1KB
MyGallery.apk 222KB
resources.ap_ 195KB
classes.dex 50KB
.settings
org.eclipse.jdt.core.prefs 629B
AndroidManifest.xml 663B
src
seker
mygallery
view
MyAbsSpinner.java 15KB
MyAdapterView.java 37KB
MyGallery.java 47KB
GalleryChild.java 2KB
GalleryAdapter.java 2KB
MainActivity.java 6KB
res
values
attrs.xml 3KB
styles.xml 332B
colors.xml 795B
strings.xml 159B
layout
gallerychild.xml 2KB
main.xml 1KB
gallerychild_box.xml 2KB
drawable-ldpi
icon.png 2KB
drawable-hdpi
img06.png 25KB
img08.png 25KB
img02.png 21KB
btn_bg_selector.xml 739B
img05.png 25KB
icon_base.png 5KB
focus.png 2KB
img01.png 20KB
img07.png 24KB
popup.png 5KB
img04.png 19KB
img03.png 24KB
icon.png 4KB
img00.png 9KB
drawable-mdpi
icon.png 3KB
color
bright_text_dark_focused.xml 553B
.classpath 280B
gen
seker
mygallery
R.java 21KB
assets
共 70 条
- 1
seker_xinjian
- 粉丝: 103
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页