@Override public boolean onCreateOptionsMenu(Menu menu) { getSupportMenuInflater().inflate(R.menu.global, menu); MenuItem menuRestart = menu.findItem(R.id.menuRestart); menuRestart.setOnMenuItemClickListener( new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { BrandManager.restart(); return false; } }); getSupportActionBar().setDisplayHomeAsUpEnabled(true); menuGuessed = menu.findItem(R.id.menuGuessed); menuScore = menu.findItem(R.id.menuScore); updateScore(); int total = BrandManager.size(); int totalGuessed = BrandManager.sizeGuessed(); menuGuessed.setTitle("Guessed: " + String.valueOf(totalGuessed) + "/" + String.valueOf(total)); return true; }
public void guessed() { BrandManager.guessed(brandIndex); brandName.setVisibility(View.VISIBLE); variants.setVisibility(View.GONE); setTitle(res.getString(R.string.guessed)); if (BrandManager.allGuessed()) { nextButton.setVisibility(View.GONE); restartButton.setVisibility(View.VISIBLE); } if (menuGuessed != null) { int total = BrandManager.size(); int totalGuessed = BrandManager.sizeGuessed(); menuGuessed.setTitle("Guessed " + String.valueOf(totalGuessed) + "/" + String.valueOf(total)); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); res = getResources(); logoImage = (ImageView) findViewById(R.id.logoImage); variant1 = (Button) findViewById(R.id.variant1); variant2 = (Button) findViewById(R.id.variant2); variant3 = (Button) findViewById(R.id.variant3); variant4 = (Button) findViewById(R.id.variant4); nextButton = (Button) findViewById(R.id.nextButton); restartButton = (Button) findViewById(R.id.restartButton); brandName = (TextView) findViewById(R.id.brandName); variants = findViewById(R.id.variants); if (BrandManager.allGuessed() || BrandManager.size() - BrandManager.sizeGuessed() == 1) { nextButton.setVisibility(View.GONE); restartButton.setVisibility(View.VISIBLE); } variant1.setOnClickListener( new OnClickListener() { public void onClick(View v) { checkGuess(1, v); } }); variant2.setOnClickListener( new OnClickListener() { public void onClick(View v) { checkGuess(2, v); } }); variant3.setOnClickListener( new OnClickListener() { public void onClick(View v) { checkGuess(3, v); } }); variant4.setOnClickListener( new OnClickListener() { public void onClick(View v) { checkGuess(4, v); } }); nextButton.setOnClickListener( new OnClickListener() { public void onClick(View v) { next(); } }); restartButton.setOnClickListener( new OnClickListener() { public void onClick(View v) { restart(); } }); int intentBrand = getIntent().getIntExtra("brand", -1); if (intentBrand != -1) { startGuessing(intentBrand); } }