// 获取状态栏的高度
private int getStatusHeight() {
Class<?> c = null;
Object obj = null;
Field field = null;
int x = 0;
int height = 0;
try {
c = Class.forName("com.android.internal.R$dimen");
obj = c.newInstance();
field = c.getField("status_bar_height");
x = Integer.parseInt(field.get(obj).toString());
height = getResources().getDimensionPixelSize(x);
} catch (Exception e) {
e.printStackTrace();
}
return height;
}
// 主页面跳动
private void jump(float delta) {
if (thisDelta - 0.03f < 0.001f) {
thisDelta = 0.05f;
return;
}
thisDelta = delta;
if (hasEverPulled) {
return;
}
playJumpAnimation(thisDelta);
}
// 上拉/下拉主页面
private void pull(boolean upward) {
if (upward && pulled) {
return;
}
if (!upward && !pulled) {
return;
}
float originalY;
float finalY;
if (!pulled) {
originalY = 0;
finalY = (float) (0 - height + 0.4 * height);
} else {
originalY = (float) (0 - height + 0.4 * height);
finalY = 0;
}
pulled = !pulled;
AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(new TranslateAnimation(0, 0, originalY,
finalY));
animationSet.setDuration(300);
animationSet.setInterpolator(new AccelerateDecelerateInterpolator());
animationSet.setFillAfter(true);
animationSet.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
if (!pulled) {