package cy.test.rotate3d;
import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
public class RotateActivity extends Activity implements OnTouchListener {
private ViewGroup layoutmain;
private ViewGroup layoutnext;
private ViewGroup layoutlast;
private Rotate3D rotate3d;
private Rotate3D rotate3d2;
private Rotate3D rotate3d3;
private int mCenterX ;
private int mCenterY ;
private float degree = (float) 0.0;
private int currentTab = 0;
private float perDegree;
private VelocityTracker mVelocityTracker;
private boolean areButtonsShowing;
private RelativeLayout composerButtonsWrapper;
private ImageView composerButtonsShowHideButtonIcon;
private RelativeLayout composerButtonsShowHideButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initMain();
MyAnimations.initOffset(this);
// 加号的动画
composerButtonsShowHideButton.startAnimation(MyAnimations.getRotateAnimation(0, 360, 200));
DisplayMetrics dm = new DisplayMetrics();
dm = getResources().getDisplayMetrics();
mCenterX = dm.widthPixels / 2;
mCenterY = dm.heightPixels / 2;
perDegree = (float) (90.0 / dm.widthPixels);
}
private void setListener() {
// 给大按钮设置点击事件
composerButtonsShowHideButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (!areButtonsShowing) {
// 图标的动画
MyAnimations.startAnimationsIn(composerButtonsWrapper, 300);
// 加号的动画
composerButtonsShowHideButtonIcon.startAnimation(MyAnimations.getRotateAnimation(0, -225, 300));
} else {
// 图标的动画
MyAnimations.startAnimationsOut(composerButtonsWrapper, 300);
// 加号的动画
composerButtonsShowHideButtonIcon.startAnimation(MyAnimations.getRotateAnimation(-225, 0, 300));
}
areButtonsShowing = !areButtonsShowing;
}
});
// 给小图标设置点击事件
for (int i = 0; i < composerButtonsWrapper.getChildCount(); i++) {
final ImageView smallIcon = (ImageView) composerButtonsWrapper.getChildAt(i);
final int position = i;
smallIcon.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// 这里写各个item的点击事件
// 1.加号按钮缩小后消失 缩小的animation
// 2.其他按钮缩小后消失 缩小的animation
// 3.被点击按钮放大后消失 透明度渐变 放大渐变的animation
//composerButtonsShowHideButton.startAnimation(MyAnimations.getMiniAnimation(300));
if(areButtonsShowing){
composerButtonsShowHideButtonIcon.startAnimation(MyAnimations.getRotateAnimation(-225, 0, 300));
smallIcon.startAnimation(MyAnimations.getMaxAnimation(400));
for (int j = 0; j < composerButtonsWrapper.getChildCount(); j++) {
if (j != position) {
final ImageView smallIcon = (ImageView) composerButtonsWrapper.getChildAt(j);
smallIcon.startAnimation(MyAnimations.getMiniAnimation(300));
//MyAnimations.getMiniAnimation(300).setFillAfter(true);
}
}
areButtonsShowing = !areButtonsShowing;
}
}
});
}
}
private void initMain(){
setContentView(R.layout.main);
composerButtonsWrapper = (RelativeLayout) findViewById(R.id.composer_buttons_wrapper);
composerButtonsShowHideButton = (RelativeLayout) findViewById(R.id.composer_buttons_show_hide_button);
composerButtonsShowHideButtonIcon = (ImageView) findViewById(R.id.composer_buttons_show_hide_button_icon);
layoutnext = (ViewGroup) findViewById(R.id.layout_next);
layoutnext.setOnTouchListener(this);
layoutlast = (ViewGroup) findViewById(R.id.layout_last);
layoutlast.setOnTouchListener(this);
layoutmain = (ViewGroup)findViewById(R.id.layout_main);
layoutmain.setOnTouchListener(this);
setListener();
}
private int mLastMotionX;
public boolean onTouch(View arg0, MotionEvent event) {
int x = (int) event.getX();
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();//获得VelocityTracker类实例
}
mVelocityTracker.addMovement(event);//将事件加入到VelocityTracker类实例中
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mLastMotionX = x;
break;
case MotionEvent.ACTION_MOVE:
mVelocityTracker.computeCurrentVelocity(1000, 1000);
Log.i("test","velocityTraker :"+mVelocityTracker.getXVelocity());
int dx = x - mLastMotionX;
if(dx != 0){
doRotate(dx);
if(degree > 90){
degree = 0;
break;
}
}else{
return false;
}
mLastMotionX = x;
break;
case MotionEvent.ACTION_UP:
//设置units的值为1000,意思为一秒时间内运动了多少个像素
mVelocityTracker.computeCurrentVelocity(1000);
float VelocityX = mVelocityTracker.getXVelocity();
Log.i("test","velocityTraker2:"+mVelocityTracker.getXVelocity());
if(VelocityX > 500 || VelocityX < -500 ){
endRotateByVelocity();
}else{
endRotate();
}
releaseVelocityTracker();
break;
case MotionEvent.ACTION_CANCEL:
releaseVelocityTracker();
break;
}
return true;
}
private void releaseVelocityTracker() {
if(null != mVelocityTracker) {
mVelocityTracker.clear();
mVelocityTracker.recycle();
mVelocityTracker = null;
}
}
private void endRotateByVelocity(){
if(degree > 0){
rotate3d = new Rotate3D(degree , 90 , 0, mCenterX, mCenterY);
rotate3d3 = new Rotate3D( - 90 + degree,0,0, mCenterX, mCenterY);
rotate3d.setDuration(300);
rotate3d3.setDuration(300);
if(currentTab == 0){
layoutmain.startAnimation(rotate3d);
layoutlast.startAnimation(rotate3d3);
}else if(currentTab == 2){
layoutlast.startAnimation(rotate3d);
layoutnext.startAnimation(rotate3d3);
}else if(currentTab == 1){
layoutnext.startAnimation(rotate3d);
layoutmain.startAnimation(rotate3d3);
}
currentTab =(currentTab - 1)%3;
if(currentTab < 0){
currentTab = 2;
}
}else if(degree < 0){
rotate3d = new Rotate3D(degree , -90 , 0, mCenterX, mCenterY);
rotate3d2 = new Rotate3D( 90 + degree,0,0, mCenterX, mCenterY);
rotate3d.setDuration(300);
rotate3d2.setDuration(300);
if(currentTab == 0){
layoutmain.startAnimation(rotate3d);
layoutnext.startAnimation(rotate3d2);
}else if(currentTab == 1){
layoutnext.startAnimation(rotate3d);
layoutlast.startAnimation(rotate3d2);
}else if(currentTab == 2){
layoutlast.startAnimation(rotate3d);
layoutmain.startAnimation(rotate3d2);
}
currentTab = (currentTab + 1)%3;
}
System.out.println(">>>>>>>>degree:"+degree +" currentTab:" + currentTab);
setViewVisibile();
degree = 0;
}
private void endRotate() {
if(degree > 45){
rotate3d = new Rotate3D(degree , 90 , 0, mCenterX, mCenterY);
rotate3d3 = new Rotate3D( - 90 + degree,0,0, mCenterX, mCenterY);
rotate3d.setDuration(300);
rotate3d3.setDuration(300);
if(currentTab == 0){
layoutmain.startAnimation(rotate3d);
layoutlast.startAnimation(rotate3d3);
}else if(currentTab == 2){
layoutlast.startAnimation(rotate3d);
layoutnext.startAnimation(rotate3d3);
}else if(currentTab == 1){
layoutnext.startAnimation(rota
没有合适的资源?快使用搜索试试~ 我知道了~
Android 随手势进行3D旋转
共60个文件
png:20个
class:14个
xml:7个
5星 · 超过95%的资源 需积分: 10 16 下载量 38 浏览量
2013-05-12
00:37:46
上传
评论
收藏 545KB RAR 举报
温馨提示
Android 随手势进行3D旋转,内含源码导入Eclipse直接即可使用
资源推荐
资源详情
资源评论
收起资源包目录
Android 随手势进行3D旋转.rar (60个子文件)
Rotate3D
.project 844B
project.properties 360B
proguard.cfg 1KB
src
cy
test
rotate3d
Rotate3D.java 2KB
RotateActivity.java 11KB
MyAnimations.java 4KB
AndroidManifest.xml 743B
hs_err_pid3916.log 5KB
res
drawable-hdpi
user_wizard_3.jpg 17KB
user_wizard_2.jpg 26KB
composer_sun.png 4KB
composer_button.png 3KB
icon.png 63KB
composer_place.png 3KB
composer_thought.png 2KB
composer_sleep.png 3KB
composer_camera.png 2KB
composer_with.png 3KB
composer_icn_plus.png 164B
user_wizard_1.jpg 26KB
composer_music.png 3KB
layout
bottom_button.xml 4KB
main.xml 1KB
anim
rotate_in.xml 364B
rotate_out.xml 364B
values
strings.xml 256B
.settings
org.eclipse.jdt.core.prefs 177B
org.eclipse.core.resources.prefs 110B
gen
cy
test
rotate3d
BuildConfig.java 158B
R.java 2KB
.classpath 364B
bin
resources.ap_ 155KB
classes
cy
test
rotate3d
R$layout.class 425B
RotateActivity$1.class 1KB
BuildConfig.class 341B
R$drawable.class 851B
Rotate3D.class 2KB
R$attr.class 334B
RotateActivity$2.class 2KB
R$id.class 893B
R$anim.class 421B
RotateActivity.class 8KB
R.class 561B
R$string.class 488B
MyAnimations.class 4KB
MyAnimations$1.class 1KB
AndroidManifest.xml 743B
jarlist.cache 119B
res
drawable-hdpi
composer_sun.png 1KB
composer_button.png 3KB
icon.png 60KB
composer_place.png 3KB
composer_thought.png 2KB
composer_sleep.png 3KB
composer_camera.png 2KB
composer_with.png 3KB
composer_icn_plus.png 164B
composer_music.png 3KB
classes.dex 16KB
Rotate3D.apk 166KB
共 60 条
- 1
资源评论
- 这个名字不太长2014-07-02UI是很前卫的设计,非常好,直接拿来用了
- qdrzwd22013-06-16效果不错,再修改一下就完美了。不过要是opengl实现的就好了
囧_囧
- 粉丝: 0
- 资源: 44
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功