- package asd.r;
- import java.util.Random;
- import java.util.concurrent.BrokenBarrierException;
- import android.R.integer;
- import android.app.Activity;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.Color;
- import android.graphics.Matrix.ScaleToFit;
- import android.graphics.drawable.BitmapDrawable;
- import android.os.Bundle;
- import android.os.Handler;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.View.OnClickListener;
- import android.view.Window;
- import android.view.WindowManager;
- import android.widget.Button;
- import android.widget.ImageButton;
- import android.widget.ImageView;
- import android.widget.TableRow;
- import android.widget.ImageView.ScaleType;
- import android.widget.TableLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- public class AsdActivity extends Activity {
- int [] niz;
- int [] pamti;
- ImageButton [] dugme;
- TextView skor;
- TableRow red;
- int a=0;int pom=0;
- int i,n;
- int prva=0,druga=0;
- int broj_pokusaja=0;
- //treba mi niz da ubacim u njega identifikatore slika koji odgovaraju idovima dugmica
- //treba mi niz da pamti koji su sve prosli da ne moze njih da izabere.
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.main);
- TableLayout lay=(TableLayout)findViewById(R.id.TableLayout1);
- TableLayout.LayoutParams rowLp = new TableLayout.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT,
- 1.0f);
- TableRow.LayoutParams cellLp = new TableRow.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT,
- 1.0f);cellLp.bottomMargin=10;cellLp.rightMargin=10;
- TableRow.LayoutParams skorLp = new TableRow.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- 22,
- 1.0f);
- OnClickListener listen= new OnClickListener() {
- @Override
- public void onClick(View v) {
- broj_pokusaja++;
- skor.setText("MaG"+" " + Integer.toString(broj_pokusaja));
- // TODO Auto-generated method stub
- //Toast.makeText(v.getContext(), Integer.toString(pom), Toast.LENGTH_SHORT).show();
- if(pom<2)
- {
- if(pamti[v.getId()]==0){v.setBackgroundResource(R.drawable.a);}
- if(pamti[v.getId()]==1){v.setBackgroundResource(R.drawable.ww);}
- if(pamti[v.getId()]==2){v.setBackgroundResource(R.drawable.kornjaca);}
- if(pamti[v.getId()]==3){v.setBackgroundResource(R.drawable.zaba);}
- if(pamti[v.getId()]==4){v.setBackgroundResource(R.drawable.macka);}
- if(pamti[v.getId()]==5){v.setBackgroundResource(R.drawable.riba);}
- pom++;
- if(a==0){prva=v.getId();a++;return;}
- if(a==1)
- {
- druga=v.getId();
- Handler handler=new Handler();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- if(pamti[prva]!=pamti[druga])
- {
- dugme[prva].setBackgroundResource(R.drawable.e);
- dugme[druga].setBackgroundResource(R.drawable.e);
- }
- pom=0;
- }
- }, 1500);
- a=0;
- }
- }
- }
- };
- skor=new TextView(this);
- skor.setBackgroundResource(R.drawable.belo);
- skor.setText("MaG"+" " + Integer.toString(broj_pokusaja));
- skor.setTextColor(Color.RED);
- dugme=new ImageButton[12];
- for(i=0,n=0;i<3;i++)
- {
- if(i==0){TableRow red=new TableRow(this);red.addView(skor,skorLp);lay.addView(red,skorLp);}
- TableRow red=new TableRow(this);
- dugme[n]=new ImageButton(this);
- dugme[n].setScaleType(ScaleType.FIT_CENTER);
- dugme[n].setBackgroundResource(R.drawable.e);
- dugme[n].setOnClickListener(listen);
- dugme[n].setId(n);
- red.addView(dugme[n],cellLp);
- n++;
- dugme[n]=new ImageButton(this);
- dugme[n].setScaleType(ScaleType.FIT_CENTER);
- dugme[n].setBackgroundResource(R.drawable.e);
- dugme[n].setOnClickListener(listen);
- dugme[n].setId(n);
- red.addView(dugme[n],cellLp);
- n++;
- dugme[n]=new ImageButton(this);
- dugme[n].setScaleType(ScaleType.FIT_CENTER);
- dugme[n].setBackgroundResource(R.drawable.e);
- dugme[n].setOnClickListener(listen);
- dugme[n].setId(n);
- red.addView(dugme[n],cellLp);
- n++;
- dugme[n]=new ImageButton(this);
- dugme[n].setScaleType(ScaleType.FIT_CENTER);
- dugme[n].setBackgroundResource(R.drawable.e);
- dugme[n].setOnClickListener(listen);
- dugme[n].setId(n);
- red.addView(dugme[n],cellLp);
- n++;
- lay.addView(red,rowLp);
- }
- niz=new int[12];
- pamti=new int[12];n=0;
- Random rand=new Random();
- for(i=0;i<12;i++){pamti[i]=-1;}
- for(i=0;i<12;)
- {
- n=rand.nextInt(12);
- if(pamti[n]==-1)
- {
- if(i%2==0)
- {
- pamti[n]=i/2;
- }
- else {
- pamti[n]=(i-1)/2;
- }
- i++;}
- }
- }
- }