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 75 下载量 182 浏览量
2013-10-23
08:40:20
上传
评论 1
收藏 545KB RAR 举报
温馨提示
android+随首饰进行3D旋转的源码,里面有几个小控件,可以下载下来看下
资源推荐
资源详情
资源评论
收起资源包目录
Android+随手势进行3D旋转的源码.rar (60个子文件)
Rotate3D
AndroidManifest.xml 743B
res
anim
rotate_out.xml 364B
rotate_in.xml 364B
layout
bottom_button.xml 4KB
main.xml 1KB
drawable-hdpi
composer_with.png 3KB
user_wizard_1.jpg 26KB
user_wizard_3.jpg 17KB
composer_camera.png 2KB
composer_thought.png 2KB
user_wizard_2.jpg 26KB
composer_sun.png 4KB
composer_icn_plus.png 164B
composer_place.png 3KB
composer_music.png 3KB
icon.png 63KB
composer_sleep.png 3KB
composer_button.png 3KB
values
strings.xml 256B
proguard.cfg 1KB
src
cy
test
rotate3d
Rotate3D.java 2KB
MyAnimations.java 4KB
RotateActivity.java 11KB
hs_err_pid3916.log 5KB
bin
classes
cy
test
rotate3d
RotateActivity$2.class 2KB
MyAnimations.class 4KB
BuildConfig.class 341B
R.class 561B
R$anim.class 421B
R$layout.class 425B
R$attr.class 334B
Rotate3D.class 2KB
R$id.class 893B
R$string.class 488B
MyAnimations$1.class 1KB
R$drawable.class 851B
RotateActivity.class 8KB
RotateActivity$1.class 1KB
AndroidManifest.xml 743B
Rotate3D.apk 166KB
res
drawable-hdpi
composer_with.png 3KB
composer_camera.png 2KB
composer_thought.png 2KB
composer_sun.png 1KB
composer_icn_plus.png 164B
composer_place.png 3KB
composer_music.png 3KB
icon.png 60KB
composer_sleep.png 3KB
composer_button.png 3KB
jarlist.cache 119B
classes.dex 16KB
resources.ap_ 155KB
.classpath 364B
project.properties 360B
.settings
org.eclipse.core.resources.prefs 110B
org.eclipse.jdt.core.prefs 177B
.project 844B
gen
cy
test
rotate3d
R.java 2KB
BuildConfig.java 158B
共 60 条
- 1
shinobu59
- 粉丝: 5
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页