import android.view.*;
import android.graphics.*;
public class 對(duì)象容器 extends 對(duì)象{
private int downx=0,downy=0;
private int[] dxX,dxY;
public boolean w=true,h=true;
public Bitmap 背景=null;
public int 背景顏色=Color.argb(255,100,100,100);
public int 對(duì)象間距=10;
public Paint 邊框=null;
public 對(duì)象容器(int x,int y,int width,int height){
super(x,y,width,height);
類名="對(duì)象容器";
}
public void 顯示(Canvas c){
if(顯示)行為(c);
};
public void 事件(MotionEvent e){
if(事件){
行為(e);
運(yùn)行內(nèi)部對(duì)象(e);
if(e.getAction()==MotionEvent.ACTION_UP){
移動(dòng)=false;
按下=false;
}
}
}
public void 行為(MotionEvent e){
if(e.getAction()==MotionEvent.ACTION_DOWN){
按下=計(jì)算.如果在某個(gè)矩形范圍(this,e);
if(按下){
記錄內(nèi)部對(duì)象位置();
downx=(int)e.getX();
downy=(int)e.getY();
}
}
if(e.getAction()==MotionEvent.ACTION_MOVE){
if(按下){
if(計(jì)算.絕對(duì)值((int)e.getX(),downx)>10||計(jì)算.絕對(duì)值((int)e.getY(),downy)>10)
移動(dòng)=true;
if(內(nèi)部對(duì)象!=null){
int x=(int)e.getX()-downx;
int y=(int)e.getY()-downy;
移動(dòng)內(nèi)部對(duì)象(x,y);
}
}
}
if(e.getAction()==MotionEvent.ACTION_UP){
if(按下){
dxX=null;
dxY=null;
}
}
}
public void 行為(Canvas c){
drawbeijing(c,背景顏色);
}
public void drawbeijing(Canvas c,int color){
Bitmap bj=Bitmap.createBitmap(寬,高,Bitmap.Config.ARGB_8888);
Canvas cc=new Canvas(bj);
if(背景!=null)cc.drawBitmap(背景,0,0,null);
cc.drawColor(color);
if(內(nèi)部對(duì)象!=null&&內(nèi)部對(duì)象顯示)運(yùn)行內(nèi)部對(duì)象(cc);
if(邊框!=null)圖形.畫矩形(0,0,寬-1,高-1,cc,邊框);
c.drawBitmap(bj,x,y,null);
}
public void 移動(dòng)內(nèi)部對(duì)象(int x,int y){
int i=0;
if(內(nèi)部對(duì)象!=null&&dxX!=null&&dxY!=null)
while(i<內(nèi)部對(duì)象.length){
if(w)內(nèi)部對(duì)象[i].x=dxX[i]+x;
if(h)內(nèi)部對(duì)象[i].y=dxY[i]+y;
i++;
}
}
public void 記錄內(nèi)部對(duì)象位置(){
int i=0;
if(內(nèi)部對(duì)象!=null)
while(i<內(nèi)部對(duì)象.length){
dxX=合并.合并(dxX,內(nèi)部對(duì)象[i].x);
dxY=合并.合并(dxY,內(nèi)部對(duì)象[i].y);
i++;
}
}
public void 運(yùn)行內(nèi)部對(duì)象(MotionEvent e){
e.setLocation(e.getX()-x,e.getY()-y);
if(按下)super.運(yùn)行內(nèi)部對(duì)象(e);
e.setLocation(e.getX()+x,e.getY()+y);
}
public void X方向裝入對(duì)象(對(duì)象 dx){
if(內(nèi)部對(duì)象==null){
dx.x=0;
裝入對(duì)象(dx);
}else{
dx.x=內(nèi)部對(duì)象[內(nèi)部對(duì)象.length-1].x+內(nèi)部對(duì)象[內(nèi)部對(duì)象.length-1].寬+對(duì)象間距;
裝入對(duì)象(dx);
}
}
public void Y方向裝入對(duì)象(對(duì)象 dx){
if(內(nèi)部對(duì)象==null){
dx.y=0;
裝入對(duì)象(dx);
}else{
dx.y=內(nèi)部對(duì)象[內(nèi)部對(duì)象.length-1].y+內(nèi)部對(duì)象[內(nèi)部對(duì)象.length-1].高+對(duì)象間距;
裝入對(duì)象(dx);
}
}
public void 設(shè)置邊框(int 寬度,int 顏色){
邊框=new Paint();
邊框.setStyle(Paint.Style.STROKE);
邊框.setTextSize(寬度);
邊框.setColor(顏色);
}
}
顧名思義這個(gè)類是一個(gè)對(duì)象的容器,一個(gè)對(duì)象通過裝入對(duì)象這個(gè)方法裝入這個(gè)容器,可以通過觸控移動(dòng)容器里的所有對(duì)象,容器里的對(duì)象坐標(biāo)保持相對(duì)不變。