package com.starnet.android.pisces.compass;
import android.app.Activity;
import android.content.Intent;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Button;
import android.view.View.OnClickListener;
public class compass extends Activity implements SensorListener {
private static final String TAG = "Compass";
private ImageView ImgCompass;
private ImageView ImgCompass1;
// private TextView OrientText;
private SensorManager sm = null;
private RotateAnimation myAni = null;
private float DegressQuondam = 0.0f;
OnClickListener listener1 = null;
OnClickListener listener2 = null;
Button button1;
Button button2;
private AlphaAnimation myAnimation_Alpha;
private AlphaAnimation myAnimation_Alpha1;
private ImageView iv;
private ImageView iv1;
int i=0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Log.e(TAG, "Compass: onCreate");
super.onCreate(savedInstanceState);
//this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
iv = (ImageView) findViewById(R.id.ivStart);
myAnimation_Alpha=new AlphaAnimation(1.0f, 0.1f);
myAnimation_Alpha.setDuration(3000);
myAnimation_Alpha.setAnimationListener(new Animation.AnimationListener() {
//@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
//@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
//@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
listener1 = new OnClickListener() {
public void onClick(View v) {
AniRotateImage(DegressQuondam + 10.0f);}
};
listener2 = new OnClickListener() {
public void onClick(View v) {
AniRotateImage1(DegressQuondam + 10.0f);}
};
setContentView(R.layout.compass);
button1=(Button)findViewById(R.id.button1);
button1.setOnClickListener(listener1);
button2=(Button)findViewById(R.id.button2);
button2.setOnClickListener(listener2);
// OrientText = (TextView) findViewById(R.id.OrientText);
ImgCompass = (ImageView) findViewById(R.id.ivCompass);
ImgCompass1 = (ImageView) findViewById(R.id.ivCompass1);
}
});
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
@Override
public void onStart() {
Log.e(TAG, "Compass: onStart");
sm = (SensorManager) getSystemService(SENSOR_SERVICE);
super.onStart();
iv.startAnimation(myAnimation_Alpha);
}
@Override
protected void onResume() {
Log.e(TAG, "Compass: onResume");
super.onResume();
sm.registerListener(this, SensorManager.SENSOR_ORIENTATION
| SensorManager.SENSOR_ACCELEROMETER, SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
protected void onStop() {
Log.e(TAG, "Compass: onStop");
sm.unregisterListener(this);
super.onStop();
}
public void onPause() {
Log.e(TAG, "Compass: onPause");
super.onPause();
}
public void onDestroy() {
Log.e(TAG, "Compass: onDestroy");
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
menu.add(0, 1, 1, "旋转").setIcon(R.drawable.icon);
menu.add(0, 2, 2, "关于").setIcon(R.drawable.icon);
menu.add(0, 3, 3, "退出").setIcon(R.drawable.quit);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case 1:
AniRotateImage(DegressQuondam + 90.0f);
break;
case 2: {
Intent theActivity = new Intent(this, about.class);
startActivity(theActivity);
break;
}
case 3:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
private void AniRotateImage(float fDegress) {
Log.d(TAG, "Degress: " + DegressQuondam + ", " + fDegress);
myAni = new RotateAnimation(DegressQuondam, fDegress,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
myAni.setDuration(300);
//myAni.setDuration(300*2);
myAni.setInterpolator(new AccelerateDecelerateInterpolator());
myAni.setFillAfter(true);
ImgCompass.startAnimation(myAni);
DegressQuondam = fDegress;
}
private void AniRotateImage1(float fDegress) {
Log.d(TAG, "Degress: " + DegressQuondam + ", " + fDegress);
myAni = new RotateAnimation(DegressQuondam, fDegress,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
myAni.setDuration(300);
//myAni.setDuration(300*2);
myAni.setInterpolator(new AccelerateDecelerateInterpolator());
myAni.setFillAfter(true);
ImgCompass1.startAnimation(myAni);
DegressQuondam = fDegress;
}
public void onSensorChanged(int sensor, float[] values) {
synchronized (this) {
if (sensor == SensorManager.SENSOR_ORIENTATION) {
Log.d(TAG, "onSensorChanged: " + sensor + ", x: " + values[0]
+ ", y: " + values[1] + ", z: " + values[2]);
// OrientText.setText("--- NESW ---");
if (Math.abs(values[0] - DegressQuondam) < 1)
return;
/* switch ((int) values[0]) {
case 0: // North 北
OrientText.setText("正北");
break;
case 90: // East 东
OrientText.setText("正东");
break;
case 180: // South 南
OrientText.setText("正南");
break;
case 270: // West 西
OrientText.setText("正西");
break;
default: {
int v = (int) values[0];
if (v > 0 && v < 90) {
OrientText.setText("北偏东" + v);
}
if (v > 90 && v < 180) {
v = 180 - v;
OrientText.setText("南偏东" + v);
}
if (v > 180 && v < 270) {
v = v - 180;
OrientText.setText("南偏西" + v);
}
if (v > 270 && v < 360) {
v = 360 - v;
OrientText.setText("北偏西" + v);
}
}
}*/
// ((TextView) findViewById(R.id.OrientValue)).setText(String.valueOf(values[0]));
if (DegressQuondam != -values[0])
AniRotateImage(-values[0]);
}
// if (sensor == SensorManager.SENSOR_ACCELEROMETER) { // //}
}
}
public void onAccuracyChanged(int sensor, int accuracy) {
Log.d(TAG, "onAccuracyChanged: " + sensor + ", accuracy: " + accuracy);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Android_rotate--animation.zip_Android 动画_android_android animati
共39个文件
class:14个
xml:7个
png:7个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 199 浏览量
2022-09-21
08:33:46
上传
评论
收藏 1.63MB ZIP 举报
温馨提示
android 开发:动画旋转两图片,消除动画锯齿现象。
资源详情
资源评论
资源推荐
收起资源包目录
Android_rotate--animation.zip (39个子文件)
Android+动画旋转两图
bin
classes.dex 11KB
com
starnet
android
pisces
compass
R$layout.class 502B
R$id.class 1KB
R$drawable.class 912B
compass.class 6KB
compass$1$2.class 1KB
about.class 1KB
R$attr.class 388B
R.class 771B
about$1.class 837B
R$string.class 685B
compass$1.class 2KB
R$color.class 549B
compass$1$1.class 1KB
R$style.class 451B
resources.ap_ 496KB
compass.apk 504KB
res
drawable
panel.png 67KB
bg.png 76KB
quit.png 7KB
icon.png 8KB
Thumbs.db 28KB
compass_digree.png 66KB
pisces.png 11KB
compass.png 398KB
values
colors.xml 687B
strings.xml 492B
style.xml 369B
layout
compass.xml 2KB
about.xml 3KB
main.xml 277B
assets
default.properties 449B
gen
com
starnet
android
pisces
compass
R.java 4KB
.settings
org.eclipse.jdt.core.prefs 208B
src
com
starnet
android
pisces
compass
compass.java 7KB
about.java 955B
.project 843B
.classpath 280B
AndroidManifest.xml 902B
共 39 条
- 1
御道御小黑
- 粉丝: 58
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0