博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android小代码
阅读量:7168 次
发布时间:2019-06-29

本文共 8267 字,大约阅读时间需要 27 分钟。

hot3.png

public class FanShapedView extends View {

 
private static final String TAG = FanShapedView.class.getSimpleName(); 
Context context; 
private Paint paint; 
private Resources resources; 
private Rect allBgRect; 
private Rect firstImgRect; 
private Rect secondImgRect; 
private Rect thirdImgRect; 
private Rect fourImgRect; 
private Rect fiveImgRect; 
private Rect sixtImgRect; 
private Rect onfirstImgRect; 
private Bitmap fanshapedBitmap; 
private static int screenWidth = -1; 
private static int screenHeight = -1; 
private static int size = 16; 
private int downX = -1; 
private int downY = -1; 
public static int orient = 1; 
private boolean initPass; 
private boolean autoInitRes = true; 
private boolean actionPass; 
private boolean startActivity; 
private PaddlingAction paddlingAction = PaddlingAction.no; 
private SoundManager soundManager; 
private static LinkedList<Bitmap> menuBitmaps = new LinkedList<Bitmap>(); 
private static LinkedList<String> homeItem = new LinkedList<String>(); 
public FanShapedView(Context context) {
 
super(context); 
this.context = context; 
init(); 
public FanShapedView(Context context, AttributeSet attrs) {
 
super(context, attrs); 
this.context = context; 
init(); 
/** 
* <p>Title: </p> 
* <p>Description: You can use the constructor to initialize the pictures and text</p> 
* context 
* paddlingBitmaps Shown in the picture 
* homeItem Shown in the text 
*/ 
public FanShapedView(Context context, LinkedList<Bitmap> menuBitmaps, LinkedList<String> homeItem){
 
this(context); 
FanShapedView.menuBitmaps = menuBitmaps; 
FanShapedView.homeItem = homeItem; 
autoInitRes = false; 
private void init(){
 
initPass = true; 
resources = context.getResources(); 
paint = new Paint(Paint.ANTI_ALIAS_FLAG); 
fanshapedBitmap = BitmapFactory.decodeResource(resources, R.drawable.fanshaped); 
if (autoInitRes) {
 
Bitmap temp = BitmapFactory.decodeResource(resources, R.drawable.home_tab_contact_selected); 
menuBitmaps.add(temp); 
temp = BitmapFactory.decodeResource(resources, R.drawable.home_tab_im); 
menuBitmaps.add(temp); 
temp = BitmapFactory.decodeResource(resources, R.drawable.home_tab_call); 
menuBitmaps.add(temp); 
temp = BitmapFactory.decodeResource(resources, R.drawable.home_tab_im_selected); 
menuBitmaps.add(temp); 
temp = BitmapFactory.decodeResource(resources, R.drawable.home_tab_dial_selected); 
menuBitmaps.add(temp); 
temp = BitmapFactory.decodeResource(resources, R.drawable.home_tab_mail_selected); 
menuBitmaps.add(temp); 
temp = BitmapFactory.decodeResource(resources, R.drawable.home_tab_sns); 
menuBitmaps.add(temp); 
temp = BitmapFactory.decodeResource(resources, R.drawable.home_tab_setting_selected); 
menuBitmaps.add(temp); 
homeItem.add("contact"); 
homeItem.add("im"); 
homeItem.add("call"); 
homeItem.add("message"); 
homeItem.add("usage"); 
homeItem.add("money"); 
homeItem.add("sns"); 
homeItem.add("more"); 
soundManager = new SoundManager(context); 
soundManager.initSounds(); 
soundManager.addSound(1, R.raw.dudu); 
private void initOnDraw(boolean initPass){
 
screenWidth = this.getWidth(); 
screenHeight = this.getHeight(); 
Log.i(TAG, "screenWidth="+screenWidth+" screenHeight="+screenHeight); 
screenWidth = screenWidth < screenHeight ? screenWidth:screenHeight; 
size = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, screenWidth/12f, resources.getDisplayMetrics()); 
allBgRect = new Rect(0, 0, screenWidth, screenWidth); 
firstImgRect = new Rect((int)(0.81 * screenWidth), (int)(0.78 * screenWidth), (int)(0.95 * screenWidth), (int)(0.93 * screenWidth)); 
onfirstImgRect = new Rect((int)(0.78 * screenWidth), (int)(0.76 * screenWidth), (int)(screenWidth), (int)(screenWidth)); 
secondImgRect = new Rect((int)(0.045 * screenWidth), (int)(0.76 * screenWidth), (int)(0.2 * screenWidth), (int)(0.93 * screenWidth)); 
thirdImgRect = new Rect((int)(0.14 * screenWidth), (int)(0.48 * screenWidth), (int)(0.29 * screenWidth), (int)(0.66 * screenWidth)); 
fourImgRect = new Rect((int)(0.31 * screenWidth), (int)(0.26 * screenWidth), (int)(0.46 * screenWidth), (int)(0.44 * screenWidth)); 
fiveImgRect = new Rect((int)(0.53 * screenWidth), (int)(0.11 * screenWidth), (int)(0.675 * screenWidth), (int)(0.285 * screenWidth)); 
sixtImgRect = new Rect((int)(0.79 * screenWidth), (int)(0.02 * screenWidth), (int)(0.94 * screenWidth), (int)(0.19 * screenWidth)); 
initPass = false; 
@Override 
protected void onDraw(Canvas canvas) {
 
super.onDraw(canvas); 
initOnDraw(initPass); 
canvas.drawColor(0x00000000); 
canvas.drawBitmap(fanshapedBitmap, null, allBgRect, null); 
canvas.drawBitmap(menuBitmaps.getFirst(), null, firstImgRect, null); 
canvas.save(); 
canvas.rotate(-80); 
canvas.translate(-(0.927f *screenWidth), -(0.6f *screenWidth)); 
canvas.drawBitmap(menuBitmaps.get(1), null, secondImgRect, null); 
canvas.restore(); 
canvas.save(); 
canvas.rotate(-60); 
canvas.translate(-(0.61f *screenWidth), -(0.11f *screenWidth)); 
canvas.drawBitmap(menuBitmaps.get(2), null, thirdImgRect, null); 
canvas.restore(); 
canvas.save(); 
canvas.rotate(-45); 
canvas.translate(-(0.37f *screenWidth), (0.165f *screenWidth)); 
canvas.drawBitmap(menuBitmaps.get(3), null, fourImgRect, null); 
canvas.restore(); 
canvas.save(); 
canvas.rotate(-30); 
canvas.translate(-(0.18f *screenWidth), (0.27f *screenWidth)); 
canvas.drawBitmap(menuBitmaps.get(4), null, fiveImgRect, null); 
canvas.restore(); 
canvas.save(); 
canvas.rotate(-10); 
canvas.translate(-(0.04f *screenWidth), (0.14f *screenWidth)); 
canvas.drawBitmap(menuBitmaps.get(5), null, sixtImgRect, null); 
canvas.restore(); 
@Override 
public boolean onTouchEvent(MotionEvent event) {
 
int action = event.getAction(); 
int x = (int) event.getX(); 
int y = (int) event.getY(); 
switch (action) {
 
case MotionEvent.ACTION_DOWN: 
if (onfirstImgRect.contains(x, y)) {//闅愯棌 
Log.i(TAG, "闅愯棌"); 
// this.setVisibility(GONE); 
downX = -1; 
downY = -1; 
actionPass = false; 
paddlingAction = PaddlingAction.no; 
return this.performClick(); 
if (secondImgRect.contains(x, y)) {
 
moveDownHandle(); 
if (thirdImgRect.contains(x, x)) {
 
moveDownHandle(); 
moveDownHandle(); 
if (fourImgRect.contains(x, x)) {
 
moveDownHandle(); 
moveDownHandle(); 
moveDownHandle(); 
if (fiveImgRect.contains(x, x)) {
 
moveDownHandle(); 
moveDownHandle(); 
moveDownHandle(); 
moveDownHandle(); 
if (sixtImgRect.contains(x, x)) {
 
moveDownHandle(); 
moveDownHandle(); 
moveDownHandle(); 
moveDownHandle(); 
moveDownHandle(); 
if (allBgRect.contains(x, y)) {
 
Log.i(TAG, "ACTION_DOWN"); 
downX = x; 
downY = y; 
actionPass = true; 
break; 
case MotionEvent.ACTION_MOVE: 
if(actionPass){
 
if (downX + screenWidth/10 < x || downY - screenWidth/10 > y) {//寰�笂杞竴涓�
Log.i(TAG, "寰�笂杞竴涓�"); 
paddlingAction = PaddlingAction.up; 
}else if (downX - screenWidth/10 > x || downY + screenWidth/10 < y) {
 
Log.i(TAG, "寰�笅杞竴涓�---------"); 
paddlingAction = PaddlingAction.down; 
break; 
case MotionEvent.ACTION_UP: 
if (paddlingAction != PaddlingAction.no) {
 
if (paddlingAction == PaddlingAction.up) {
 
orient = 1; 
moveUpHandle(); 
}else if (paddlingAction == PaddlingAction.down) {
 
orient = 2; 
moveDownHandle(); 
refreshView(); 
downX = -1; 
downY = -1; 
actionPass = false; 
paddlingAction = PaddlingAction.no; 
startActivity = true; 
refreshView(); 
return this.performClick(); 
// break; 
default: 
break; 
return true; 
public void moveDownHandle(){
 
Bitmap temp = menuBitmaps.getFirst(); 
menuBitmaps.removeFirst(); 
menuBitmaps.addLast(temp); 
String str = homeItem.getFirst(); 
homeItem.removeFirst(); 
homeItem.addLast(str); 
soundManager.playSound(1); 
public void moveUpHandle(){
 
Bitmap temp = menuBitmaps.getLast(); 
menuBitmaps.removeLast(); 
menuBitmaps.addFirst(temp); 
String str = homeItem.getLast(); 
homeItem.removeLast(); 
homeItem.addFirst(str); 
soundManager.playSound(1); 
public Bitmap getFirstBitmap(){
 
return menuBitmaps.getFirst(); 
public String getFirstItem(){
 
return homeItem.getFirst(); 
public boolean isStartActivity() {
 
boolean temp = startActivity; 
startActivity = false; 
return temp; 
private Handler handler = new Handler(); 
private void refreshView() {
 
handler.post(new Runnable() {
 
@Override 
public void run() {
 
Log.i(TAG, "refreshView"); 
invalidate(); 
}); 
public void recycle() {
 
menuBitmaps.remove(); 
homeItem.remove(); 
menuBitmaps = null; 
homeItem = null; 
soundManager.removeAll(); 
screenWidth = -1; 
screenHeight = -1; 
enum PaddlingAction{
 
no,up,down; 

转载于:https://my.oschina.net/u/1994482/blog/401900

你可能感兴趣的文章
安卓开发_浅谈Android动画(一)
查看>>
SharePoint 2013 开启访问请求 链接丢失
查看>>
WebView入门
查看>>
textarea字数限制方法一例
查看>>
基于jquery tool实现的windows桌面效果
查看>>
ORA-01012: not logged on
查看>>
百度富文本编辑器UEditor1.3上传图片附件等
查看>>
Universal Image Loader_图片异步加载
查看>>
unity3d assetbundle打包策略
查看>>
JSONObject与JSONArray的使用
查看>>
管道(Pipe)/createPipe
查看>>
Windows下搭建Eclipse+Android4.0开发环境
查看>>
TCP segment of a reassembled PDU
查看>>
swift百度地图api
查看>>
sql server 排序规则
查看>>
CCNA2.0笔记_OSPF v3
查看>>
测试工程师应该知道的数据库基本操作(增删改查)
查看>>
求二叉树中的节点个数、求二叉树的深度(高度)
查看>>
看到一些前端面试题没答案,自己做了一下如果有错请指出
查看>>
Selenium2(WebDriver)总结(四)---基本元素操作
查看>>