Page 456 - 3-2
P. 456
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.sound) {
if (item.isChecked()) {
music.setImageDrawable(getResources().getDrawable(play));
hoeDongSong.stop();
try {
hoeDongSong.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
hoeDongSong.seekTo(0);
seekbar.setProgress(0);
sound = false;
item.setChecked(false);
findViewById(R.id.fab).setVisibility(View.GONE);
Toast.makeText(this, "Check out", Toast.LENGTH_SHORT).show();
} else {
sound = true;
item.setChecked(true);
Toast.makeText(this, "Check", Toast.LENGTH_SHORT).show();
if (fabView) {
findViewById(R.id.fab).setVisibility(View.VISIBLE);
}
}
}
return true;
}
@Override
public void onBackPressed() {
new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Closing Activity")
.setMessage("Are you sure you want to close this activity?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
}).setNegativeButton("No", null).show();
- 456 -