Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 5.96 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package asd.r;
  2.  
  3. import java.util.Random;
  4. import java.util.concurrent.BrokenBarrierException;
  5.  
  6. import android.R.integer;
  7. import android.app.Activity;
  8. import android.graphics.Bitmap;
  9. import android.graphics.BitmapFactory;
  10. import android.graphics.Color;
  11. import android.graphics.Matrix.ScaleToFit;
  12. import android.graphics.drawable.BitmapDrawable;
  13. import android.os.Bundle;
  14. import android.os.Handler;
  15. import android.view.View;
  16. import android.view.ViewGroup;
  17. import android.view.View.OnClickListener;
  18. import android.view.Window;
  19. import android.view.WindowManager;
  20. import android.widget.Button;
  21. import android.widget.ImageButton;
  22. import android.widget.ImageView;
  23. import android.widget.TableRow;
  24. import android.widget.ImageView.ScaleType;
  25. import android.widget.TableLayout;
  26. import android.widget.TextView;
  27. import android.widget.Toast;
  28.  
  29. public class AsdActivity extends Activity {
  30.         int [] niz;
  31.         int [] pamti;
  32.         ImageButton [] dugme;
  33.         TextView skor;
  34.         TableRow red;
  35.         int a=0;int pom=0;
  36.         int i,n;
  37.         int prva=0,druga=0;
  38.         int broj_pokusaja=0;
  39.        
  40.         //treba mi niz da ubacim u njega identifikatore slika koji odgovaraju idovima dugmica
  41.         //treba mi niz da pamti koji su sve prosli da ne moze njih da izabere.
  42.        
  43.     /** Called when the activity is first created. */
  44.     @Override
  45.     public void onCreate(Bundle savedInstanceState) {
  46.         super.onCreate(savedInstanceState);
  47.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  48.         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  49.         WindowManager.LayoutParams.FLAG_FULLSCREEN);
  50.         setContentView(R.layout.main);
  51.        
  52.         TableLayout lay=(TableLayout)findViewById(R.id.TableLayout1);
  53.      
  54.         TableLayout.LayoutParams rowLp = new TableLayout.LayoutParams(
  55.                 ViewGroup.LayoutParams.MATCH_PARENT,
  56.                 ViewGroup.LayoutParams.MATCH_PARENT,
  57.                 1.0f);
  58.         TableRow.LayoutParams cellLp = new TableRow.LayoutParams(
  59.                 ViewGroup.LayoutParams.MATCH_PARENT,
  60.                 ViewGroup.LayoutParams.MATCH_PARENT,
  61.                 1.0f);cellLp.bottomMargin=10;cellLp.rightMargin=10;
  62.                
  63.         TableRow.LayoutParams skorLp = new TableRow.LayoutParams(
  64.                 ViewGroup.LayoutParams.MATCH_PARENT,
  65.                 22,
  66.                 1.0f);
  67.        
  68.  
  69.                
  70.              
  71.                
  72.        
  73.   OnClickListener listen= new OnClickListener() {
  74.                        
  75.                         @Override
  76.                         public void onClick(View v) {
  77.                                 broj_pokusaja++;
  78.                                 skor.setText("MaG"+"  " + Integer.toString(broj_pokusaja));
  79.                                
  80.                                 // TODO Auto-generated method stub                             
  81.                                
  82.                                 //Toast.makeText(v.getContext(), Integer.toString(pom), Toast.LENGTH_SHORT).show();
  83.                                 if(pom<2)
  84.                                 {
  85.                                         if(pamti[v.getId()]==0){v.setBackgroundResource(R.drawable.a);}
  86.                                         if(pamti[v.getId()]==1){v.setBackgroundResource(R.drawable.ww);}
  87.                                         if(pamti[v.getId()]==2){v.setBackgroundResource(R.drawable.kornjaca);}
  88.                                         if(pamti[v.getId()]==3){v.setBackgroundResource(R.drawable.zaba);}
  89.                                         if(pamti[v.getId()]==4){v.setBackgroundResource(R.drawable.macka);}
  90.                                         if(pamti[v.getId()]==5){v.setBackgroundResource(R.drawable.riba);}
  91.                                         pom++;
  92.                                         if(a==0){prva=v.getId();a++;return;}
  93.                                         if(a==1)
  94.                                                
  95.                                         {
  96.                                                 druga=v.getId();
  97.                                        
  98.                                                 Handler handler=new Handler();
  99.                                         handler.postDelayed(new Runnable() {
  100.                                                
  101.                                                 @Override
  102.                                                 public void run() {
  103.                                                         if(pamti[prva]!=pamti[druga])
  104.                                                         {
  105.                                                                 dugme[prva].setBackgroundResource(R.drawable.e);
  106.                                                                 dugme[druga].setBackgroundResource(R.drawable.e);
  107.                                                                
  108.                                                                
  109.                                                         }
  110.                                                         pom=0;
  111.                                                        
  112.                                                 }
  113.                                         }, 1500);
  114.                                         a=0;
  115.                                        
  116.                                         }
  117.                                        
  118.                                        
  119.                                 }
  120.                         }
  121.   };
  122.                
  123.      
  124.  
  125.   skor=new TextView(this);
  126.   skor.setBackgroundResource(R.drawable.belo);
  127.   skor.setText("MaG"+"  " + Integer.toString(broj_pokusaja));
  128.   skor.setTextColor(Color.RED);
  129.  
  130.  
  131.  
  132.         dugme=new ImageButton[12];
  133.      for(i=0,n=0;i<3;i++)
  134.         {
  135.                 if(i==0){TableRow red=new TableRow(this);red.addView(skor,skorLp);lay.addView(red,skorLp);}
  136.                 TableRow red=new TableRow(this);
  137.                
  138.                 dugme[n]=new ImageButton(this);
  139.                 dugme[n].setScaleType(ScaleType.FIT_CENTER);
  140.                 dugme[n].setBackgroundResource(R.drawable.e);
  141.             dugme[n].setOnClickListener(listen);
  142.             dugme[n].setId(n);
  143.            
  144.             red.addView(dugme[n],cellLp);
  145.             n++;
  146.             dugme[n]=new ImageButton(this);
  147.             dugme[n].setScaleType(ScaleType.FIT_CENTER);
  148.             dugme[n].setBackgroundResource(R.drawable.e);        
  149.             dugme[n].setOnClickListener(listen);
  150.             dugme[n].setId(n);
  151.            
  152.             red.addView(dugme[n],cellLp);
  153.             n++;
  154.             dugme[n]=new ImageButton(this);
  155.             dugme[n].setScaleType(ScaleType.FIT_CENTER);
  156.             dugme[n].setBackgroundResource(R.drawable.e);        
  157.             dugme[n].setOnClickListener(listen);
  158.             dugme[n].setId(n);
  159.            
  160.             red.addView(dugme[n],cellLp);
  161.             n++;
  162.             dugme[n]=new ImageButton(this);
  163.             dugme[n].setScaleType(ScaleType.FIT_CENTER);
  164.             dugme[n].setBackgroundResource(R.drawable.e);        
  165.             dugme[n].setOnClickListener(listen);
  166.             dugme[n].setId(n);
  167.            
  168.             red.addView(dugme[n],cellLp);
  169.             n++;
  170.            
  171.             lay.addView(red,rowLp);
  172.            
  173.          
  174.            
  175.            
  176.            
  177.            
  178.     }
  179.      
  180.      niz=new int[12];
  181.      pamti=new int[12];n=0;
  182.     Random rand=new Random();
  183.     for(i=0;i<12;i++){pamti[i]=-1;}
  184.      
  185.     for(i=0;i<12;)
  186.     {
  187.         n=rand.nextInt(12);
  188.         if(pamti[n]==-1)
  189.         {
  190.                 if(i%2==0)
  191.                 {
  192.                                        
  193.                                 pamti[n]=i/2;
  194.                                 }
  195.                        
  196.        
  197.         else {
  198.                         pamti[n]=(i-1)/2;
  199.              }
  200.         i++;}
  201.     }
  202.  
  203.        
  204.        
  205.        
  206.        
  207.        
  208.          
  209.        
  210.      
  211.                
  212.     }
  213. }