继续上篇的animation,本篇用到的是AnimationListener,参考自iteye上的一个朋友的翻牌动画。AnimationListener主要是用来监听animation的,它接受animation的通知,每个通知声明了一个相关的事件。话不多说,上代码:
package com.kevin.animation; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; import android.widget.ImageView; public class AnimationDemo extends Activity { private ImageView img; private boolean isFront = false; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); img = (ImageView)findViewById(R.id.imageView1); // bind onclick event img.setOnClickListener(new ImgOnClickListener()); } class ImgOnClickListener implements OnClickListener{ @Override public void onClick(View v) { // load back animation config Animation animation = AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.back_scale); // bind AnimationListener animation.setAnimationListener(new AnimationListener() { // Notifies the start of the animation. @Override public void onAnimationStart(Animation animation) { System.out.println("onAnimationStart."); } // Notifies the repetition of the animation. @Override public void onAnimationRepeat(Animation animation) { System.out.println("onAnimationRepeat"); } // Notifies the end of the animation. @Override public void onAnimationEnd(Animation animation) { System.out.println("onAnimationEnd"); if(isFront){ img.setImageResource(R.drawable.back); isFront = false; }else{ img.setImageResource(R.drawable.front); isFront = true; } // load front animation config img.setAnimation(AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.front_scale)); } }); // invoke animation immediately img.startAnimation(animation); } } }
public class TestAppPageThread extends Thread {
private static GameCenterService gameCenterService;
public TestAppPageThread() {
}
public static void main(String[] args) throws IOException {
int threadCount = 10;
ServiceFactory fact = ServiceFactories.getFactory();
gameCenterService = fact.getService(GameCenterService.class);
System.out.println("threadCount:" + threadCount);
testMutiThread(threadCount);
}
public static void testMutiThread(int threadCount)
throws IOException {
read();
//循环调用线程
for(int i=0; i< threadCount; i++){
//必须调用Thread的start()函数,该函数再调用run()
Thread t = new TestAppPageThread();
t.start();
}
}
@Override
//必须覆盖Thread的run()函数来完成有用的工作
public void run(){
try {
System.out.println("offset:" );
System.out.println("limit:");
//ServiceFuture<AppPage> f = gameCenterService.getPage(1, 2);
//ServiceFuture<AppPage[]> f = gameCenterService.getAppPageListByKeyword("僵尸", 0, 10);
//ServiceFuture<AppPage[]> f = gameCenterService.getAppPageListByStatus(1, 10);
ServiceFuture<AppPage[]> f = gameCenterService.getAppPageCategoryList(1, 2, 1,10);
System.out.println(f);
System.out.println(11);
f.submit();
if (f.await(2300)) {
if (f.isSuccess()) {
System.out.println(14);
System.out.println(f.getContent());
AppPage[] pagelist = f.getContent();
System.out.print(pagelist.length);
for(AppPage page : pagelist){
long start = System.currentTimeMillis();
System.out.println(page.getId()+" "+page.getPageName() + " " + page.getAddTime()
+" time used:" + (System.currentTimeMillis()- start) + "ms");
}
} else {
System.out.println("not success");
}
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
public static void read() throws IOException {
System.out.println(9);
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="/blog_article/<%=basePath%>/index.html">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" href="/blog_article/jquerymobile/jquery.mobile-1.0b1.min.css" />
<script src="/blog_article/jquerymobile/jquery-1.6.1.js"></script>
<script src="/blog_article/jquerymobile/jquery.mobile-1.0b1.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
---
</div>
<div data-role="content">
<div data-role="fieldcontain">
<label for="name">Text Input:</label>
<input type="text" name="name" id="name" value="" />
</div>
<a href="/blog_article/index.html" data-role="button" data-icon="delete">Delete</a>
</div>
<div data-role="button">
<input type="text" name="name" id="name2" value="" />
<a id="cha" data-role="button" data-icon="arrow-d" data-iconpos="notext"></a>
<select name="selectchoice" id="selectchoice" data-native-menu="false">
<option value="standard">Standard: 7 day</option>
<option value="rush">Rush: 3 days</option>
<option value="express">Express: next day</option>
<option value="overnight">Overnight</option>
</select>
</div>
<div data-role="footer">...</div>
</div>
<script type="text/javascript">
setTimeout(function (){
$("#cha").click(function (){
$(".ui-select").find("a").trigger("click");
var position =$("#cha").offset();
$(".ui-selectmenu").css("top",""+position.top);
$(".ui-selectmenu").css("left",""+position.left-($("#name").width()/2));
$(".ui-selectmenu").find("ul").find("li").find("div").find("div").append("xxx");
$(".ui-selectmenu").click(function (){
$("#name2").val($("#selectchoice").val());
});
});
$(".ui-select").hide();
},100);
</script>
</body>
</html>