package com.canvas.demo.view;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import com.canvas.demo.AnimationConfig;
import com.canvas.demo.R;
import com.canvas.demo.anim.CloseAppAnimation;
import com.canvas.demo.anim.NextAnimation;
import com.canvas.demo.anim.NextJitterAnimation;
import com.canvas.demo.anim.OpenAppAnimation;
import com.canvas.demo.anim.PrevAnimation;
import com.canvas.demo.anim.PrevJitterAnimation;
import com.canvas.demo.anim.RendererAnimation;
import com.canvas.demo.anim.RendererAnimation.AnimationNotification;
import com.canvas.demo.surface.RendererView;
import com.canvas.demo.util.CanvasUtil;
public class NavigationRendererView extends RendererView implements AnimationNotification {
private RendererAnimation mAnimation = null;
private int mFirstItemIndex = 0;
private int mCurrentIndex = 0;
private int mLastItemIndex = 0;
private List<NavigationItemView> mShowItems = new ArrayList<NavigationItemView>(AnimationConfig.SHOW_ITEM_COUNT) ;
private List<NavigationItemView> mAllItems = new ArrayList<NavigationItemView>() ;
private Bitmap mNavigationTitleBackground = null;
public NavigationRendererView(Context context) {
super(context);
mNavigationTitleBackground = BitmapFactory.decodeResource(getResources(),R.drawable.navigation_title_bg);
}
public void addNavigationItem(NavigationItem item)
{
mAllItems.add(new NavigationItemView(item));
}
public void doAnimation(RendererAnimation animation)
{
if(mShowItems.size() < 11)
{
mShowItems.clear();
for(int i=0;i< 11;i++)
{
int index = i % mAllItems.size();
NavigationItemView item = mAllItems.get(index);
item.setPosition(index);
mShowItems.add(item);
}
mFirstItemIndex = 0;
mCurrentIndex = mShowItems.size() / 2;
mLastItemIndex = mShowItems.size() - 1;
}
if(animation.getClass() == OpenAppAnimation.class) {
NavigationItemView item = mAllItems.get(mCurrentIndex);
((OpenAppAnimation)animation).setItemSize(item.getWidth(), item.getHeight());
}else if(animation.getClass() == CloseAppAnimation.class){
NavigationItemView item = mAllItems.get(mCurrentIndex);
((CloseAppAnimation)animation).setItemSize(item.getWidth(), item.getHeight());
}
mAnimation = animation;
mAnimation.setAnimationNotification(this);
this.startRenderer();
}
protected void onRenderer(Canvas canvas) {
if(mAnimation == null) return;
int saveCount = canvas.save();
//转换坐标
canvas.translate(0, getHeight() / 2.0f);
//绘制标题背景
drawTitleBackground(canvas);
//绘制上半部分
for(int index = 0;index < mCurrentIndex;index++)
{
mShowItems.get(index).draw(canvas, mAnimation);
}
//绘制下半部分
for(int index = mShowItems.size() - 1;index > mCurrentIndex;index--)
{
mShowItems.get(index).draw(canvas, mAnimation);
}
//绘制选中部分
mShowItems.get(mCurrentIndex).draw(canvas, mAnimation);
//还原Canvas
canvas.restoreToCount(saveCount);
if(mAnimation.isEnd())
{
this.stopRenderer();
}else{
mAnimation.nextFrame();
}
}
//----------------------绘制标题----------------------------------
private Paint mTitleBackgroundPaint = new Paint();
private void drawTitleBackground(Canvas canvas)
{
int saveCount = canvas.save();
mTitleBackgroundPaint.setAlpha(mAnimation.getTitleBackgroundAlpha());
canvas.translate(AnimationConfig.TITLE_LEFT, 0);
CanvasUtil.drawImage(canvas, mNavigationTitleBackground, 0, 0,
CanvasUtil.LEFT | CanvasUtil.VCENTER, mTitleBackgroundPaint);
canvas.restoreToCount(saveCount);
}
//-------------------------End------------------------------------
public void doAnimation(RendererAnimation animation, int step, int maxStep) {
if(animation.getClass() == NextAnimation.class){
if(step == maxStep / 2 + 1)
{
mShowItems.remove(mShowItems.size() - 1);
mCurrentIndex --;
}else if(step == maxStep){
mFirstItemIndex = ( mFirstItemIndex -1 + mAllItems.size() ) % mAllItems.size();
mLastItemIndex = ( mLastItemIndex -1 + mAllItems.size() ) % mAllItems.size();
mShowItems.add(0, mAllItems.get(mFirstItemIndex));
mCurrentIndex = mShowItems.size() / 2;
for(int i=0;i< mShowItems.size();i++)
{
mShowItems.get(i).setPosition(i);
}
this.doAnimation(new NextJitterAnimation());
}
}else if(animation.getClass() == PrevAnimation.class){
if(step == maxStep / 2)
{
mShowItems.remove(0);
}else if(step == maxStep){
mFirstItemIndex = ( mFirstItemIndex + 1 ) % mAllItems.size();
mLastItemIndex = ( mLastItemIndex + 1 ) % mAllItems.size();
mShowItems.add(mAllItems.get(mLastItemIndex));
mCurrentIndex = mShowItems.size() / 2;
for(int i=0;i< mShowItems.size();i++)
{
mShowItems.get(i).setPosition(i);
}
this.doAnimation(new PrevJitterAnimation());
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Widget炫酷特效 (宏基扇子型效果).zip (48个子文件)
Widget炫酷特效 (宏基扇子型效果)
CanvasDemo.rar 476KB
CanvasDemo
CanvasDemo
.classpath 280B
assets
Android.mk 2KB
src
com
canvas
demo
anim
NextJitterAnimation.java 838B
OpenAppAnimation.java 2KB
ShowAnimation.java 1005B
PrevJitterAnimation.java 838B
NextAnimation.java 1KB
CloseAppAnimation.java 2KB
PrevAnimation.java 1KB
RendererAnimation.java 3KB
AnimationConfig.java 774B
surface
IRendererInterface.java 142B
RendererView.java 1KB
view
NavigationItem.java 2KB
NavigationItemView.java 1KB
NavigationDataSource.java 240B
NavigationRendererView.java 6KB
BackgroundRendererView.java 2KB
MainActivity.java 3KB
util
Rectangle.java 665B
CanvasUtil.java 3KB
res
drawable-mdpi
icon.png 3KB
drawable-ldpi
icon.png 2KB
values
colors.xml 1KB
strings.xml 173B
styles.xml 1KB
layout
main.xml 382B
drawable
a2.jpg 35KB
a6.jpg 99KB
a8.jpg 52KB
a9.jpg 35KB
a1.jpg 38KB
navigation_title_bg.png 6KB
a3.jpg 33KB
round.png 78KB
a4.jpg 97KB
a7.jpg 35KB
a10.jpg 39KB
a0.jpg 41KB
a5.jpg 33KB
icon.png 3KB
drawable-hdpi
icon.png 4KB
default.properties 364B
.project 846B
AndroidManifest.xml 762B
gen
com
canvas
demo
R.java 2KB
说明.zip 17KB
共 48 条
- 1
资源评论
firepation
- 粉丝: 1755
- 资源: 950
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功