I am working with small application for display bubbles images on android screen.I have displayed all bubbles images from resource directory.I have implemented code as follows in view class.
onDraw method:
@Override
protected void onDraw(Canvas canvas)
{
super.dispatchDraw(canvas);
drawImages(canvas);
}
I have implemented drawImages() method as follows:
BitmapFactory.Options opts = new BitmapFactory.Options();
private void drawImages(Canvas canvas)
{
for(int i = 0; i<MAX_ROWS; i++){
for(int j=0; j<MAX_COLS; j++)
{
bmp = BitmapFactory.decodeResource(mContext.getResources(), items[i][j],opts);
canvas.drawBitmap(bmp,j*bmp.getWidth()+j*2,i*bmp.getHeight()+i*2,mBitmapPaint);
}
}
}
By using the above method i have drawn images from items[i][j]. I have implemented the initialize() override method as follows:
@Override
protected void initialize()
{
for(int i=0;i<MAX_ROWS;i++)
for(int j=0;j<MAX_COLS;j++)
{
items[i][j] = ImagesStore.ImageList.get(list_Indx);
list_Indx++;
if(list_Indx == ImagesStore.ImageList.size())
list_Indx = 0;
}
opts.inSampleSize = 4;
width = getWidth();
height = getHeight();
}
By using above code i have displayed all the bubble images on my emulator screen.
Here i would like to swap the bubbles which selects two bubbles by the user simultaneously.
I have implemented onTouchEvent method for check the bitmap image item position on screen as follows:
int x = 0;
int y = 0;
int tx = 0, ty = 0;
@Override
public boolean onTouchEvent(MotionEvent event)
{
tx = (int)event.getX();
ty = (int)event.getY();
int position;
x=tx;
y=ty;
row = (y) / bmp.getHeight();
col = x / bmp.getWidth();
position=row*MAX_COLS+(col+1);
Log.v("row", "=====>"+row);
Log.v("col", "=====>"+col);
Log.v("position", "=====>"+position);
count++;
if(count%4==0)
{
Log.v("count", "=====>"+count);
//I would like to implement swap code here
}
return true;
}
From the above code How can i swap(inter change the images) bitmap images implementation at onTouchEvent()
Please any body help me..............