package com.zhaoyan;
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.animation.Interpolator;
import android.widget.Scroller;
/**
*Workspace是有数个屏幕宽的一个“桌面”,每屏都有用户可以交互的图标,目录或者widget。
*/
public class Workspace extends ViewGroup {
private static final String TAG = "MyLauncher.Workspace";
private static final int INVALID_SCREEN = -1;
/**
* The velocity at which a fling gesture will cause us to snap to the next screen
*/
private static final int SNAP_VELOCITY = 600; //fling手势速度,超过该值切换到下一屏幕
private final WallpaperManager mWallpaperManager;
private int mDefaultScreen;
private boolean mFirstLayout = true;
private int mCurrentScreen;
private int mNextScreen = INVALID_SCREEN;
private Scroller mScroller;
private VelocityTracker mVelocityTracker;
/**
* Target drop area calculated during last acceptDrop call.
*/
private int[] mTargetCell = null;
private float mLastMotionX;
private float mLastMotionY;
private final static int TOUCH_STATE_REST = 0;
private final static int TOUCH_STATE_SCROLLING = 1;
private int mTouchState = TOUCH_STATE_REST;
private OnLongClickListener mLongClickListener;
private int[] mTempCell = new int[2];
private int[] mTempEstimate = new int[2];
private boolean mAllowLongPress = true;
private int mTouchSlop;
private int mMaximumVelocity;
private static final int INVALID_POINTER = -1;
private int mActivePointerId = INVALID_POINTER;
private Drawable mPreviousIndicator;
private Drawable mNextIndicator;
private static final float NANOTIME_DIV = 1000000000.0f;
private static final float SMOOTHING_SPEED = 0.75f;
private static final float SMOOTHING_CONSTANT = (float) (0.016 / Math.log(SMOOTHING_SPEED));
private float mSmoothingTime;
private float mTouchX;
private WorkspaceOvershootInterpolator mScrollInterpolator;
private static final float BASELINE_FLING_VELOCITY = 2500.f;
private static final float FLING_VELOCITY_INFLUENCE = 0.4f;
private static class WorkspaceOvershootInterpolator implements Interpolator {
private static final float DEFAULT_TENSION = 1.3f;
private float mTension;
public WorkspaceOvershootInterpolator() {
mTension = DEFAULT_TENSION;
}
public void setDistance(int distance) {
mTension = distance > 0 ? DEFAULT_TENSION / distance : DEFAULT_TENSION;
}
public void disableSettle() {
mTension = 0.f;
}
public float getInterpolation(float t) {
// _o(t) = t * t * ((tension + 1) * t + tension)
// o(t) = _o(t - 1) + 1
t -= 1.0f;
return t * t * ((mTension + 1) * t + mTension) + 1.0f;
}
}
/**
* Used to inflate the Workspace from XML.
*
* @param context The application's context.
* @param attrs The attribtues set containing the Workspace's customization values.
*/
public Workspace(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
/**
* Used to inflate the Workspace from XML.
*
* @param context The application's context.
* @param attrs The attribtues set containing the Workspace's customization values.
* @param defStyle Unused.
*/
public Workspace(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mWallpaperManager = WallpaperManager.getInstance(context);
mDefaultScreen=0;
/*
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0);
mDefaultScreen = a.getInt(R.styleable.Workspace_defaultScreen, 1);
a.recycle(); */
setHapticFeedbackEnabled(false);
initWorkspace();
}
/**
* Initializes various states for this workspace.
*/
private void initWorkspace() {
Context context = getContext();
mScrollInterpolator = new WorkspaceOvershootInterpolator();
mScroller = new Scroller(context, mScrollInterpolator);
mCurrentScreen = mDefaultScreen;
final ViewConfiguration configuration = ViewConfiguration.get(getContext());
mTouchSlop = configuration.getScaledTouchSlop();
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}
boolean isDefaultScreenShowing() {
return mCurrentScreen == mDefaultScreen;
}
int getCurrentScreen() {
return mCurrentScreen;
}
void setCurrentScreen(int currentScreen) {
if (!mScroller.isFinished()) mScroller.abortAnimation();
mCurrentScreen = Math.max(0, Math.min(currentScreen, getChildCount() - 1));
scrollTo(mCurrentScreen * getWidth(), 0);
invalidate();
}
/**
* Registers the specified listener on each screen contained in this workspace.
*
* @param l The listener used to respond to long clicks.
*/
@Override
public void setOnLongClickListener(OnLongClickListener l) {
mLongClickListener = l;
final int count = getChildCount();
for (int i = 0; i < count; i++) {
getChildAt(i).setOnLongClickListener(l);
}
}
private void updateWallpaperOffset(int scrollRange) {
IBinder token = getWindowToken();
if (token != null) {
mWallpaperManager.setWallpaperOffsetSteps(1.0f / (getChildCount() - 1), 0 );
mWallpaperManager.setWallpaperOffsets(getWindowToken(),
Math.max(0.f, Math.min(mScrollX/(float)scrollRange, 1.f)), 0);
}
}
@Override
public void scrollTo(int x, int y) {
super.scrollTo(x, y);
mTouchX = x;
mSmoothingTime = System.nanoTime() / NANOTIME_DIV;
}
@Override
public void computeScroll() {
if (mScroller.computeScrollOffset()) {
mTouchX = mScrollX = mScroller.getCurrX();
mSmoothingTime = System.nanoTime() / NANOTIME_DIV;
mScrollY = mScroller.getCurrY();
postInvalidate();
} else if (mNextScreen != INVALID_SCREEN) {
mCurrentScreen = Math.max(0, Math.min(mNextScreen, getChildCount() - 1));
//mPreviousIndicator.setLevel(mCurrentScreen);
//mNextIndicator.setLevel(mCurrentScreen);
mNextScreen = INVALID_SCREEN;
//clearChildrenCache();
} else if (mTouchState == TOUCH_STATE_SCROLLING) {
final float now = System.nanoTime() / NANOTIME_DIV;
final float e = (float) Math.exp((now - mSmoothingTime) / SMOOTHING_CONSTANT);
final float dx = mTouchX - mScrollX;
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
搭建步骤: 1 下载代码,导入到myEclipse项目里,发现很多错误。 2 在myEclipse的Android项目中,选择项目属性->Java Build Path->Libraries->Add Library->User Library->Next-> UserLibraries进入到User Libraries管理界面,点击New新建一个User Library,比如android_framework,点击Add Jars把Jar包加入到建立的User Library中,最后点击OK。为了访问因此成员,需要改变类搜索顺序,选择项目属性->Java Build Path->Order and Export,把所建立的User Libraries移到Android SDK的上面。 3 编译运行。如果发现myEclipse因内存小编译不了,修改myeclipse.ini,把数字改大点。
资源推荐
资源详情
资源评论
收起资源包目录
Workspace.rar (35个子文件)
Workspace
AndroidManifest.xml 734B
res
layout
main.xml 3KB
drawable-ldpi
ic_launcher.png 2KB
drawable-mdpi
ic_launcher.png 3KB
drawable-hdpi
ic_launcher.png 4KB
values
strings.xml 184B
attrs.xml 2KB
proguard.cfg 1KB
src
com
zhaoyan
WorkspaceActivity.java 340B
CellLayout.java 887B
Workspace.java 31KB
bin
classes
com
zhaoyan
Workspace$SavedState.class 1KB
R$styleable.class 1KB
R.class 531B
R$layout.class 373B
Workspace.class 15KB
R$attr.class 692B
CellLayout.class 1KB
R$id.class 453B
R$string.class 406B
Workspace$SavedState$1.class 1KB
Workspace$WorkspaceOvershootInterpolator.class 948B
WorkspaceActivity.class 518B
R$drawable.class 386B
res
drawable-ldpi
ic_launcher.png 2KB
drawable-mdpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
classes.dex 6.07MB
Workspace.apk 2.59MB
resources.ap_ 11KB
.classpath 481B
assets
project.properties 361B
classes.jar 6.02MB
.project 845B
gen
com
zhaoyan
R.java 15KB
共 35 条
- 1
avlgood2010
- 粉丝: 5
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页