0

i am trying to do a flipcard app in which there is gridview of images showing a same image ,say a card_back .

On clicking each image,it flips showing another image which is different for every item of gridview,say a card_front.

if 2 cards are showing their card_front image,aftr 1 second both gets automatically flipped to show the card_back.

what i am trying to do is that in this 1-2 seconds,the user should not be able to click any of the other items.or even if he clicks,no card should be flipped in those 2 seconds.How can i do this.Is it possible to use a transparent view that covers the whole of the gridview and make it visible only for those 2 seconds.Can someone please help me out.

   gridview.setOnItemClickListener(new OnItemClickListener()
        {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id)
            {   
                 pos=position;

               findViewById(R.id.view1).setBackgroundColor(getResources().getColor(android.R.color.transparent));


                 switch(flippedCardCounter)
                 {

                 case 0:
                     flippedCardCounter++;    //increase counter
                     v1=v;
                     startFlipAnimation(imageView,v1);
                     break;
                 //flippedCardCounter = 1 -> one card flipped
                 case 1:
                     flippedCardCounter++;    //increase counter
                     v2=v;
                     startFlipAnimation(imageView,v2);
                     im1=((ViewHolder) v1.getTag()).img;
                     im2=((ViewHolder) v2.getTag()).img;

                      Handler handler = new Handler(); 
                      handler.postDelayed(new Runnable() { 
                           public void run() { 
                                startUnflipAnimation(im1,v1);
                            startUnflipAnimation(im2,v2);
                           } 
                      },1000); 
                      break;
                 //flippedCardCounter = 2 -> hide two flipped card, flip one card
                 case 2:
                     flippedCardCounter = 0;  
                     flippedCardCounter++;   //increase counter
                     startFlipAnimation(imageView,v);
                     v1=v2=v;
                     break;
            }
                 }

              }); 
mmBs
  • 8,421
  • 6
  • 38
  • 46
jincy abraham
  • 579
  • 2
  • 9
  • 21
  • thanks for editing(improving/debugging) the answer :), I own you a coffee. –  Oct 13 '13 at 18:12

1 Answers1

1

Maybe this help

public class MyClass{
....
private volatile boolean isLock=false;


gridview.setOnItemClickListener(new OnItemClickListener()
        {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id)
            {  
if(isLock){return;} 
                 pos=position;

               findViewById(R.id.view1).setBackgroundColor(getResources().getColor(android.R.color.transparent));


                 switch(flippedCardCounter)
                 {

                 case 0:
                     flippedCardCounter++;    //increase counter
                     v1=v;
                     startFlipAnimation(imageView,v1);
                     break;
                 //flippedCardCounter = 1 -> one card flipped
                 case 1:
                     flippedCardCounter++;    //increase counter
                     isLock=true;
                     v2=v;
                     startFlipAnimation(imageView,v2);
                     im1=((ViewHolder) v1.getTag()).img;
                     im2=((ViewHolder) v2.getTag()).img;

                      Handler handler = new Handler(); 
                      handler.postDelayed(new Runnable() { 
                           public void run() { 
                            ////////////////////////

                            ////////////////////////
                                startUnflipAnimation(im1,v1);
                            startUnflipAnimation(im2,v2);
                               isLock=false; 
                           } 
                      },1000);

                      break;
                 //flippedCardCounter = 2 -> hide two flipped card, flip one card
                 case 2:
                     flippedCardCounter = 0;  
                     flippedCardCounter++;   //increase counter
                     startFlipAnimation(imageView,v);
                     v1=v2=v;
                     break;
            }
                 }

              }); 

....
}

You may set the isLock variable anywhere you like to disable clocking. I hope I could give some hand!

jincy abraham
  • 579
  • 2
  • 9
  • 21
  • Can you help me out with how to shuffle these images randomly. – jincy abraham Oct 13 '13 at 18:22
  • how many images does it have? and does it keep them in some variable like `List`?! –  Oct 13 '13 at 18:24
  • it has 12 total images .ie. 6 of them repeating twice.Its declared inside the imageadapter activity as public static Integer[] mThumbSelected = { R.drawable.a,R.drawable.b, R.drawable.c,R.drawable.d, R.drawable.e,R.drawable.f, R.drawable.a,R.drawable.b, R.drawable.c,R.drawable.d, R.drawable.e,R.drawable.f }; – jincy abraham Oct 13 '13 at 18:36
  • so you may need to generate a random image (via `Math.random()` or `Random` class), and just load the image and show it. –  Oct 13 '13 at 19:27
  • Is there any way we can animate the shuffling? – Harikrishnan Oct 14 '13 at 13:35
  • well dude I am weak in GUI related subjects, but all I know it's possible, you may search and try something(code), then if you face with errors, come back and share the code to talk about it. –  Oct 14 '13 at 16:19