package com.sample;
import java.util.ArrayList;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AbsoluteLayout;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AbsoluteLayout.LayoutParams;
public class test extends Activity {
/** Called when the activity is first created. */
//**调整屏幕宽度和高度
int width=480;
int height=854;
//
PageConner pageconner;
ConnerDown connerdown;
ConnerUp connerup;
Handler handler;
ArrayList<Integer> booklist;
int index=0;
int flag;
float preview_x;
float preview_y;
Bitmap bitmap;
Bitmap reversebitmap;
AbsoluteLayout booklayout;
ImageView imageview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags
(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
);
setContentView(R.layout.main);
//定义一个自动翻页的handler
handler=new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch(msg.what)
{
case 1:
if(msg.arg1==1)
{
pageview pv=new pageview(test.this,bitmap,reversebitmap,pageconner,connerup,connerdown,flag,width,height);
imageview.setBackgroundDrawable(getResources().getDrawable(booklist.get(index+1)));
booklayout.removeAllViews();
booklayout.addView(imageview, new LayoutParams(width,height,0,0));
booklayout.addView(pv,new LayoutParams(width,height,0,0));
}
if(msg.arg1==2)
{
pageview pv=new pageview(test.this,bitmap,reversebitmap,pageconner,connerup,connerdown,flag,width,height);
imageview.setBackgroundDrawable(getResources().getDrawable(booklist.get(index-1)));
booklayout.removeAllViews();
booklayout.addView(imageview, new LayoutParams(width,height,0,0));
booklayout.addView(pv,new LayoutParams(width,height,0,0));
}
if(msg.arg1==3)
{
pageview pv=new pageview(test.this,bitmap,reversebitmap,pageconner,connerup,connerdown,flag,width,height);
imageview.setBackgroundDrawable(getResources().getDrawable(booklist.get(index-1)));
booklayout.removeAllViews();
booklayout.addView(imageview, new LayoutParams(width,height,0,0));
booklayout.addView(pv,new LayoutParams(width,height,0,0));
}
if(msg.arg1==4)
{
pageview pv=new pageview(test.this,bitmap,reversebitmap,pageconner,connerup,connerdown,flag,width,height);
imageview.setBackgroundDrawable(getResources().getDrawable(booklist.get(index+1)));
booklayout.removeAllViews();
booklayout.addView(imageview, new LayoutParams(width,height,0,0));
booklayout.addView(pv,new LayoutParams(width,height,0,0));
}
break;
case 2:
imageview.setBackgroundDrawable(getResources().getDrawable(booklist.get(index)));
booklayout.removeAllViews();
booklayout.addView(imageview, new LayoutParams(width,height,0,0));
break;
}
}
};
//
booklayout=(AbsoluteLayout)findViewById(R.id.booklayout);
imageview=new ImageView(this);
booklist=new ArrayList<Integer>();
booklist.add(R.drawable.c);
booklist.add(R.drawable.b);
booklist.add(R.drawable.a);
imageview.setBackgroundDrawable(getResources().getDrawable(booklist.get(0)));
booklayout.addView(imageview,new LayoutParams(width,height,0,0));
booklayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction())
{
case MotionEvent.ACTION_MOVE:
float x=event.getX();
float y=event.getY();
float dif_x=x-preview_x;
float dif_y=y-preview_y;
if(index!=(booklist.size()-1))
{
if(preview_x>(width-30)&&preview_y<30)
{
if(dif_x<0&&dif_y>0)
{
flag=1;
pageconner=new PageConner();
connerup=new ConnerUp();
connerdown=new ConnerDown();
pageconner.x=x;
pageconner.y=y;
connerup.x=(float)(Math.pow(y, 2)-Math.pow(width, 2)+Math.pow(x, 2))/(2*x-2*width);
connerup.y=0;
connerdown.x=(float)(2*height*y-Math.pow(y, 2)+Math.pow(width, 2)-Math.pow(x, 2))/(2*width-2*x);
connerdown.y=height;
pageview pv=new pageview(test.this,bitmap,reversebitmap,pageconner,connerup,connerdown,flag,width,height);
imageview.setBackgroundDrawable(getResources().getDrawable(booklist.get(index+1)));
booklayout.removeAllViews();
booklayout.addView(imageview, new LayoutParams(width,height,0,0));
booklayout.addView(pv,new LayoutParams(width,height,0,0));
}
}
}
if(index!=0)
{
if(preview_x<30&&preview_y<30)
{
if(dif_x>0&&dif_y>0)
{
flag=2;
pageconner=new PageConner();
connerup=new ConnerUp();
connerdown=new ConnerDown();
pageconner.x=x;
pageconner.y=y;
connerup.x=(float)(Math.pow(y, 2)/2/x+x/2);
connerup.y=0;
connerdown.x=(float)((x*x+y*y-2*height*y)/2/x);
connerdown.y=height;
pageview pv=new pageview(test.this,bitmap,reversebitmap,pageconner,connerup,connerdown,flag,width,height);
imageview.setBackgroundDrawable(getResources().getDrawable(booklist.get(index-1)));
booklayout.removeAllViews();
booklayout.addView(imageview, new LayoutParams(width,height,0,0));
booklayout.addView(pv,new LayoutParams(width,height,0,0));
}
}
}
if(index!=0)
{
if(preview_x<30&&preview_y>(height-30))
{
if(dif_x>0&&dif_y<0)
{
flag=3;
pageconner=new PageConner();
connerup=new ConnerUp();
connerdown=new ConnerDown();
pageconner.x=x;
pageconner.y=y;
connerup.x=(x*x+y*y-height*height)/2/x;
connerup.y=0;
connerdown.x=(2*height*height-2*height*y-height*height+y*y+x*x)/2/x;
connerdown.y=height;
pageview pv=new pageview(test.this,bitmap,reversebitmap,pageconner,connerup,connerdown,flag,width,height);
imageview.setBackgroundDrawable(getResources().getDrawable(booklist.get(index-1)));
booklayout.removeAllViews();
booklayout.addView(imageview, new LayoutParams(width,height,0,0));
booklayout.addView(pv,new LayoutParams(width,height,0,0));
}
}
}
if(index!=(booklist.size()-1))
{
if(preview_x>(width-30)&&preview_y>(height-30))
{
if(dif_x<0&&dif_y<0)
{
flag=4;
pageconner=new PageConner();
connerup=new ConnerUp();
connerdown=new ConnerDown();
pageconner.x=x;
pageconner.y=y;
connerup.x=(y*y-height*height-width*width+x*x)/2/(x-width);
connerup.y=0;
connerdown.x=(2*height*y-height*height*2-y*y+height*height+width*width-x*x)/2/(width-x);
connerdown.y=height;
pageview pv=new pageview(test.this,bitmap,reversebitmap,pageconner,connerup,connerdown,flag,width,height);
imageview.setBackgroundDrawable(getResources().getDrawable(booklist.get(index+1)));
booklayout.removeAllViews();
booklayout.addView(imageview, new LayoutParams(width,height,0,0));
booklayout.addView(pv,new LayoutParams(width,height,0,0));
}
}
}
break;
case MotionEvent.ACTION_DOWN:
preview_x=event.getX();
preview_y=event.getY();
getImage(bookla
android模拟真实翻页(单页版,不是apk额,是源码,呵呵,你们想要的)
3星 · 超过75%的资源 需积分: 9 101 浏览量
2011-03-30
17:00:37
上传
评论 2
收藏 460KB ZIP 举报
Colder
- 粉丝: 281
- 资源: 1
最新资源
- 转载使用许可协议范本(互联网行业)模版.doc
- 软件产业运行情况调研问卷模版.doc
- 软件产品发布管理流程.doc
- 软件仿真多机串行通信.doc
- Python大作业:音乐播放软件(爬虫+可视化+数据分析+数据库)
- 课程设计-python爬虫-爬取日报,爬取日报文章后存储到本地,附带源代码+课程设计报告
- 软件和信息技术服务行业投资与前景预测.pptx
- 课程设计-基于SpringBoot + Mybatis+python爬虫NBA球员数据爬取可视化+源代码+文档+sql+效果图
- 软件品质管理系列二项目策划规范.doc
- 基于TensorFlow+PyQt+GUI的酒店评论情感分析,支持分析本地数据文件和网络爬取数据分析+源代码+文档说明+安装教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈