package android.view.ext;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
public class SatelliteMenu extends FrameLayout {
private static final int DEFAULT_SATELLITE_DISTANCE = 200;
private static final float DEFAULT_TOTAL_SPACING_DEGREES = 90f;
private static final boolean DEFAULT_CLOSE_ON_CLICK = true;
private static final int DEFAULT_EXPAND_DURATION = 400;
private Animation mainRotateRight;
private Animation mainRotateLeft;
private ImageView imgMain;
private SateliteClickedListener itemClickedListener;
private InternalSatelliteOnClickListener internalItemClickListener;
private List<SatelliteMenuItem> menuItems = new ArrayList<SatelliteMenuItem>();
private Map<View, SatelliteMenuItem> viewToItemMap = new HashMap<View, SatelliteMenuItem>();
private AtomicBoolean plusAnimationActive = new AtomicBoolean(false);
//States of these variables are saved
private boolean rotated = false;
private int measureDiff = 0;
//States of these variables are saved - Also configured from XML
private float totalSpacingDegree = 90f;
private int satelliteDistance = DEFAULT_SATELLITE_DISTANCE;
private int expandDuration = DEFAULT_EXPAND_DURATION;
private boolean closeItemsOnClick = DEFAULT_CLOSE_ON_CLICK;
public SatelliteMenu(Context context) {
super(context);
init(context, null, 0);
}
public SatelliteMenu(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0);
}
public SatelliteMenu(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs, defStyle);
}
private void init(Context context, AttributeSet attrs, int defStyle) {
inflate(context, R.layout.sat_main, this);
imgMain = (ImageView) findViewById(R.id.sat_main);
if(attrs != null){
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SatelliteMenu, defStyle, 0);
satelliteDistance = typedArray.getDimensionPixelSize(R.styleable.SatelliteMenu_satelliteDistance, DEFAULT_SATELLITE_DISTANCE);
totalSpacingDegree = typedArray.getFloat(R.styleable.SatelliteMenu_totalSpacingDegree, DEFAULT_TOTAL_SPACING_DEGREES);
closeItemsOnClick = typedArray.getBoolean(R.styleable.SatelliteMenu_closeOnClick, DEFAULT_CLOSE_ON_CLICK);
expandDuration = typedArray.getInt(R.styleable.SatelliteMenu_expandDuration, DEFAULT_EXPAND_DURATION);
//float satelliteDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 170, getResources().getDisplayMetrics());
typedArray.recycle();
}
mainRotateLeft = SatelliteAnimationCreator.createMainButtonAnimation(context);
mainRotateRight = SatelliteAnimationCreator.createMainButtonInverseAnimation(context);
Animation.AnimationListener plusAnimationListener = new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
plusAnimationActive.set(false);
}
};
mainRotateLeft.setAnimationListener(plusAnimationListener);
mainRotateRight.setAnimationListener(plusAnimationListener);
imgMain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SatelliteMenu.this.onClick();
}
});
internalItemClickListener = new InternalSatelliteOnClickListener(this);
}
private void onClick() {
if (plusAnimationActive.compareAndSet(false, true)) {
if (!rotated) {
imgMain.startAnimation(mainRotateLeft);
for (SatelliteMenuItem item : menuItems) {
item.getView().startAnimation(item.getOutAnimation());
}
} else {
imgMain.startAnimation(mainRotateRight);
for (SatelliteMenuItem item : menuItems) {
item.getView().startAnimation(item.getInAnimation());
}
}
rotated = !rotated;
}
}
private void openItems() {
if (plusAnimationActive.compareAndSet(false, true)) {
if (!rotated) {
imgMain.startAnimation(mainRotateLeft);
for (SatelliteMenuItem item : menuItems) {
item.getView().startAnimation(item.getOutAnimation());
}
}
rotated = !rotated;
}
}
private void closeItems() {
if (plusAnimationActive.compareAndSet(false, true)) {
if (rotated) {
imgMain.startAnimation(mainRotateRight);
for (SatelliteMenuItem item : menuItems) {
item.getView().startAnimation(item.getInAnimation());
}
}
rotated = !rotated;
}
}
public void addItems(List<SatelliteMenuItem> items) {
menuItems.addAll(items);
this.removeView(imgMain);
TextView tmpView = new TextView(getContext());
tmpView.setLayoutParams(new FrameLayout.LayoutParams(0, 0));
float[] degrees = getDegrees(menuItems.size());
int index = 0;
for (SatelliteMenuItem menuItem : menuItems) {
int finalX = SatelliteAnimationCreator.getTranslateX(
degrees[index], satelliteDistance);
int finalY = SatelliteAnimationCreator.getTranslateY(
degrees[index], satelliteDistance);
ImageView itemView = (ImageView) LayoutInflater.from(getContext())
.inflate(R.layout.sat_item_cr, this, false);
ImageView cloneView = (ImageView) LayoutInflater.from(getContext())
.inflate(R.layout.sat_item_cr, this, false);
itemView.setTag(menuItem.getId());
cloneView.setVisibility(View.GONE);
itemView.setVisibility(View.GONE);
cloneView.setOnClickListener(internalItemClickListener);
cloneView.setTag(Integer.valueOf(menuItem.getId()));
FrameLayout.LayoutParams layoutParams = getLayoutParams(cloneView);
layoutParams.bottomMargin = Math.abs(finalY);
layoutParams.leftMargin = Math.abs(finalX);
cloneView.setLayoutParams(layoutParams);
if (menuItem.getImgResourceId() > 0) {
itemView.setImageResource(menuItem.getImgResourceId());
cloneView.setImageResource(menuItem.getImgResourceId());
} else if (menuItem.getImgDrawable() != null) {
itemView.setImageDrawable(menuItem.getImgDrawable());
cloneView.setImageDrawable(menuItem.getImgDrawable());
}
Animation itemOut = SatelliteAnimationCreator.createItemOutAnimation(getContext(), index,expandDuration, finalX, finalY);
Animation itemIn = SatelliteAnimationCreator.createItemInAnimation(getContext(), index, expandDuration, finalX, finalY);
Animation itemClick = SatelliteAnimationCreator.createItemClickAnimation(getContext());
menuItem.setView(itemView);
menuItem.setCloneView(cloneView);
menuItem.setInAnimation(itemIn);
menuItem.setOutAnimation(itemOut);
menuItem.setClickAnimation(itemClick);
menuItem.setFinalX(finalX);
menuItem.setFinalY(finalY);
itemIn.setAnimationListener(new SatelliteAnimationListener(itemView, true, viewToItemMap));
itemOut.setAnimationListener(new SatelliteAnimationListener(itemView, false, viewToItemMap));
itemClick.setAnimationListener(new SatelliteItemClickAnimationListener(this, menuItem.getId()));
this.addView(itemView);
this.addView(cloneView);
viewToItemMap.put(itemView, menuItem);
viewToItemMap.put(cloneView, menuItem);
index++;
}
this.addView(imgMain);
}
private float[] getDegrees(int count) {
float[] result = null;
int tmpCount = count - 1;
result = new float[count];
float delta = totalSpacingDegree / tmpCount;
for (int index = 0; index < count; index++) {
int tmpIndex = index;
System.out.println("=====index=" + index + "tmpIndex=" + tmpIndex);
if (count < 4) {
tmpIndex = tmpIndex + 1
没有合适的资源?快使用搜索试试~ 我知道了~
android菜单展开的动画效果
共85个文件
png:32个
class:22个
xml:15个
5星 · 超过95%的资源 需积分: 49 517 下载量 18 浏览量
2014-08-08
16:16:54
上传
评论 4
收藏 424KB ZIP 举报
温馨提示
见博客:http://blog.csdn.net/baidu_nod/article/details/38404531
资源推荐
资源详情
资源评论
收起资源包目录
satellite-menu-sample.zip (85个子文件)
satellite-menu-sample
.project 825B
project.properties 407B
proguard.cfg 1KB
src
android
view
ext
SatelliteMenuActivity.java 1KB
SatelliteMenuItem.java 2KB
SatelliteMenu.java 16KB
SatelliteAnimationCreator.java 5KB
AndroidManifest.xml 742B
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
searchable_video.png 5KB
ic_launcher.png 4KB
ic_4.png 8KB
ic_5.png 8KB
sat_main.png 8KB
searchable_web.png 5KB
ic_3.png 8KB
main.png 8KB
searchable_zhidao.png 4KB
ic_1.png 8KB
searchable_mp3.png 4KB
ic_6.png 8KB
searchable_map.png 4KB
ic_2.png 8KB
drawable-mdpi
ic_launcher.png 3KB
layout
sat_main.xml 364B
sat_item_cr.xml 308B
main.xml 745B
anim
sat_item_anim_click.xml 632B
sat_item_in_rotate_interpolator.xml 144B
sat_main_rotate_right.xml 358B
sat_item_anticipate_interpolator.xml 145B
sat_item_overshoot_interpolator.xml 144B
sat_item_out_rotate_interpolator.xml 144B
sat_item_click_interpolator.xml 144B
sat_main_rotate_left.xml 358B
values
sat_attrs.xml 381B
strings.xml 189B
pom.notworking 1KB
gen
android
view
ext
BuildConfig.java 158B
R.java 9KB
.classpath 475B
bin
resources.ap_ 100KB
satellite-menu-sample.apk 114KB
classes
android
view
ext
R$layout.class 455B
SatelliteMenuItem.class 3KB
SatelliteAnimationCreator.class 3KB
BuildConfig.class 341B
R$drawable.class 824B
R$attr.class 544B
SatelliteMenu$SatelliteAnimationListener.class 2KB
SatelliteMenuActivity.class 1KB
R$id.class 440B
SatelliteMenu$SateliteClickedListener.class 271B
SatelliteMenu$InternalSatelliteOnClickListener.class 1KB
SatelliteMenu$SavedState$1.class 1KB
R$anim.class 759B
R.class 615B
R$string.class 421B
SatelliteMenu$1.class 1KB
SatelliteMenu$SavedState.class 3KB
SatelliteMenu$2.class 827B
SatelliteMenu$SatelliteItemClickAnimationListener.class 2KB
SatelliteMenuActivity$1.class 1KB
R$styleable.class 798B
SatelliteMenu.class 13KB
AndroidManifest.xml 742B
dexedLibs
annotations-7e69f838eed6b034d25a77417c4e635e.jar 910B
jarlist.cache 120B
res
crunch
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
searchable_video.png 5KB
ic_launcher.png 4KB
ic_4.png 8KB
ic_5.png 8KB
sat_main.png 8KB
searchable_web.png 4KB
ic_3.png 7KB
main.png 8KB
searchable_zhidao.png 3KB
ic_1.png 8KB
searchable_mp3.png 3KB
ic_6.png 7KB
searchable_map.png 3KB
ic_2.png 7KB
drawable-mdpi
ic_launcher.png 2KB
classes.dex 27KB
共 85 条
- 1
移动爱好者
- 粉丝: 70
- 资源: 69
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于yolov5识别算法实现的DNF自动脚本源码.zip
- 基于Python实现的自动化办公项目.zip
- 基于python实现的基于PyQt5和爬虫的小说阅读系统.zip
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页