Program: 172693
Project: 172693
Buggy source:
@Override protected 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.activity_main);
  prefs=PreferenceManager.getDefaultSharedPreferences(this);
  titleView=findViewById(R.id.title);
  highScoreView=findViewById(R.id.highScore);
  hintView=findViewById(R.id.hint);
  buttonLayout=findViewById(R.id.buttonLayout);
  musicView=findViewById(R.id.music);
  soundView=findViewById(R.id.sound);
  achievementsView=findViewById(R.id.achievements);
  rankView=findViewById(R.id.rank);
  gamesView=findViewById(R.id.games);
  aboutView=findViewById(R.id.about);
  pauseView=findViewById(R.id.pause);
  stopView=findViewById(R.id.stop);
  gameView=findViewById(R.id.game);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    soundPool=new SoundPool.Builder().setMaxStreams(2).setAudioAttributes(new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build()).build();
  }
 else   soundPool=new SoundPool(2,AudioManager.STREAM_MUSIC,0);
  explosionId=soundPool.load(this,R.raw.explosion,1);
  explosion2Id=soundPool.load(this,R.raw.explosion_two,1);
  buttonId=soundPool.load(this,R.raw.button,1);
  hissId=soundPool.load(this,R.raw.hiss,1);
  replenishId=soundPool.load(this,R.raw.replenish,1);
  upgradeId=soundPool.load(this,R.raw.upgrade,1);
  errorId=soundPool.load(this,R.raw.error,1);
  WeaponData.loadSounds(this,soundPool);
  Typeface typeface=FontUtils.getTypeface(this);
  int colorPrimary=ContextCompat.getColor(this,R.color.colorPrimary);
  int colorAccent=ContextCompat.getColor(this,R.color.colorAccent);
  titleView.setTypeface(typeface);
  titleView.setPaintFlags(titleView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
  titleView.getPaint().setShader(new LinearGradient(0,0,0,titleView.getLineHeight(),colorAccent,colorPrimary,Shader.TileMode.REPEAT));
  highScoreView.setTypeface(typeface);
  highScoreView.getPaint().setShader(new LinearGradient(0,0,0,hintView.getLineHeight(),colorAccent,colorPrimary,Shader.TileMode.REPEAT));
  hintView.setTypeface(typeface);
  hintView.getPaint().setShader(new LinearGradient(0,0,0,hintView.getLineHeight(),colorAccent,colorPrimary,Shader.TileMode.REPEAT));
  appName=getString(R.string.app_name);
  hintStart=getString(R.string.hint_start);
  isMusic=prefs.getBoolean(PreferenceUtils.PREF_MUSIC,true);
  musicEnabled=ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_music_enabled),colorAccent,colorPrimary);
  musicDisabled=ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_music_disabled),colorAccent,colorPrimary);
  musicView.setImageBitmap(isMusic ? musicEnabled : musicDisabled);
  musicView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      isMusic=!isMusic;
      prefs.edit().putBoolean(PreferenceUtils.PREF_MUSIC,isMusic).apply();
      musicView.setImageBitmap(isMusic ? musicEnabled : musicDisabled);
      if (isMusic)       player.start();
 else       player.pause();
      if (isSound)       soundPool.play(buttonId,1,1,0,0,1);
    }
  }
);
  isSound=prefs.getBoolean(PreferenceUtils.PREF_SOUND,true);
  soundEnabled=ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_sound_enabled),colorAccent,colorPrimary);
  soundDisabled=ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_sound_disabled),colorAccent,colorPrimary);
  soundView.setImageBitmap(isSound ? soundEnabled : soundDisabled);
  soundView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      isSound=!isSound;
      prefs.edit().putBoolean(PreferenceUtils.PREF_SOUND,isSound).apply();
      soundView.setImageBitmap(isSound ? soundEnabled : soundDisabled);
      if (isSound)       soundPool.play(buttonId,1,1,0,0,1);
    }
  }
);
  achievementsView.setImageBitmap(ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_achievements),colorAccent,colorPrimary));
  achievementsView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      startActivityForResult(Games.Achievements.getAchievementsIntent(apiClient),0);
      if (isSound)       soundPool.play(buttonId,1,1,0,0,1);
    }
  }
);
  rankView.setImageBitmap(ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_rank),colorAccent,colorPrimary));
  rankView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      startActivityForResult(Games.Leaderboards.getLeaderboardIntent(apiClient,getString(R.string.leaderboard_high_score)),0);
      if (isSound)       soundPool.play(buttonId,1,1,0,0,1);
    }
  }
);
  gamesView.setImageBitmap(ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_game),colorAccent,colorPrimary));
  gamesView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      if (apiClient != null) {
        if (apiClient.isConnected()) {
          new AlertDialog.Builder(MainActivity.this).setTitle(R.string.title_sign_out).setMessage(R.string.msg_sign_out).setPositiveButton(android.R.string.yes,new DialogInterface.OnClickListener(){
            @Override public void onClick(            DialogInterface dialogInterface,            int i){
              Games.signOut(apiClient);
              if (apiClient.isConnected())               apiClient.disconnect();
              achievementsView.setVisibility(View.GONE);
              rankView.setVisibility(View.GONE);
              dialogInterface.dismiss();
            }
          }
).setNegativeButton(android.R.string.no,new DialogInterface.OnClickListener(){
            @Override public void onClick(            DialogInterface dialogInterface,            int i){
              dialogInterface.dismiss();
            }
          }
).create().show();
        }
 else         apiClient.connect();
      }
    }
  }
);
  aboutView.setImageBitmap(ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_info),colorAccent,colorPrimary));
  aboutView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      if (!gameView.isPlaying() && (animator == null || !animator.isStarted())) {
        gameView.setOnClickListener(null);
        gameView.playTutorial();
        animateTitle(false);
        if (isSound)         soundPool.play(hissId,1,1,0,0,1);
      }
    }
  }
);
  play=ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_play),colorAccent,colorPrimary);
  pause=ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_pause),colorAccent,colorPrimary);
  stop=ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_stop),colorAccent,colorPrimary);
  pauseView.setImageBitmap(pause);
  pauseView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      isPaused=!isPaused;
      if (isPaused) {
        pauseView.setImageBitmap(play);
        stopView.setVisibility(View.VISIBLE);
        gameView.onPause();
      }
 else {
        pauseView.setImageBitmap(pause);
        pauseView.setAlpha(1f);
        stopView.setVisibility(View.GONE);
        gameView.onResume();
      }
    }
  }
);
  stopView.setImageBitmap(stop);
  stopView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      if (isPaused) {
        pauseView.setImageBitmap(pause);
        pauseView.setAlpha(1f);
        gameView.onResume();
        isPaused=false;
      }
      onStop(gameView.score);
      gameView.stop();
    }
  }
);
  int highScore=prefs.getInt(PreferenceUtils.PREF_HIGH_SCORE,0);
  if (highScore > 0)   highScoreView.setText(String.format(getString(R.string.score_high),highScore));
  player=MediaPlayer.create(this,R.raw.music);
  player.setLooping(true);
  if (isMusic)   player.start();
  handler.postDelayed(hintRunnable,1000);
  gameView.setListener(this);
  if (prefs.getBoolean(PreferenceUtils.PREF_TUTORIAL,true)) {
    gameView.playTutorial();
    buttonLayout.setVisibility(View.GONE);
    pauseView.setVisibility(View.VISIBLE);
    stopView.setVisibility(View.GONE);
  }
 else {
    gameView.setOnClickListener(this);
    animateTitle(true);
    apiClient=new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Games.API).addScope(Games.SCOPE_GAMES).build();
    apiClient.connect();
  }
}

Fixed version (ground truth):
@Override protected 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.activity_main);
  prefs=PreferenceManager.getDefaultSharedPreferences(this);
  titleView=findViewById(R.id.title);
  highScoreView=findViewById(R.id.highScore);
  hintView=findViewById(R.id.hint);
  buttonLayout=findViewById(R.id.buttonLayout);
  musicView=findViewById(R.id.music);
  soundView=findViewById(R.id.sound);
  achievementsView=findViewById(R.id.achievements);
  rankView=findViewById(R.id.rank);
  gamesView=findViewById(R.id.games);
  aboutView=findViewById(R.id.about);
  pauseView=findViewById(R.id.pause);
  stopView=findViewById(R.id.stop);
  gameView=findViewById(R.id.game);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    soundPool=new SoundPool.Builder().setMaxStreams(2).setAudioAttributes(new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build()).build();
  }
 else   soundPool=new SoundPool(2,AudioManager.STREAM_MUSIC,0);
  explosionId=soundPool.load(this,R.raw.explosion,1);
  explosion2Id=soundPool.load(this,R.raw.explosion_two,1);
  buttonId=soundPool.load(this,R.raw.button,1);
  hissId=soundPool.load(this,R.raw.hiss,1);
  replenishId=soundPool.load(this,R.raw.replenish,1);
  upgradeId=soundPool.load(this,R.raw.upgrade,1);
  errorId=soundPool.load(this,R.raw.error,1);
  WeaponData.loadSounds(this,soundPool);
  Typeface typeface=FontUtils.getTypeface(this);
  int colorPrimary=ContextCompat.getColor(this,R.color.colorPrimary);
  int colorAccent=ContextCompat.getColor(this,R.color.colorAccent);
  titleView.setTypeface(typeface);
  titleView.setPaintFlags(titleView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
  titleView.getPaint().setShader(new LinearGradient(0,0,0,titleView.getLineHeight(),colorAccent,colorPrimary,Shader.TileMode.REPEAT));
  highScoreView.setTypeface(typeface);
  highScoreView.getPaint().setShader(new LinearGradient(0,0,0,hintView.getLineHeight(),colorAccent,colorPrimary,Shader.TileMode.REPEAT));
  hintView.setTypeface(typeface);
  hintView.getPaint().setShader(new LinearGradient(0,0,0,hintView.getLineHeight(),colorAccent,colorPrimary,Shader.TileMode.REPEAT));
  appName=getString(R.string.app_name);
  hintStart=getString(R.string.hint_start);
  isMusic=prefs.getBoolean(PreferenceUtils.PREF_MUSIC,true);
  musicEnabled=ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_music_enabled),colorAccent,colorPrimary);
  musicDisabled=ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_music_disabled),colorAccent,colorPrimary);
  musicView.setImageBitmap(isMusic ? musicEnabled : musicDisabled);
  musicView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      isMusic=!isMusic;
      prefs.edit().putBoolean(PreferenceUtils.PREF_MUSIC,isMusic).apply();
      musicView.setImageBitmap(isMusic ? musicEnabled : musicDisabled);
      if (isMusic)       player.start();
 else       player.pause();
      if (isSound)       soundPool.play(buttonId,1,1,0,0,1);
    }
  }
);
  isSound=prefs.getBoolean(PreferenceUtils.PREF_SOUND,true);
  soundEnabled=ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_sound_enabled),colorAccent,colorPrimary);
  soundDisabled=ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_sound_disabled),colorAccent,colorPrimary);
  soundView.setImageBitmap(isSound ? soundEnabled : soundDisabled);
  soundView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      isSound=!isSound;
      prefs.edit().putBoolean(PreferenceUtils.PREF_SOUND,isSound).apply();
      soundView.setImageBitmap(isSound ? soundEnabled : soundDisabled);
      if (isSound)       soundPool.play(buttonId,1,1,0,0,1);
    }
  }
);
  achievementsView.setImageBitmap(ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_achievements),colorAccent,colorPrimary));
  achievementsView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      startActivityForResult(Games.Achievements.getAchievementsIntent(apiClient),0);
      if (isSound)       soundPool.play(buttonId,1,1,0,0,1);
    }
  }
);
  rankView.setImageBitmap(ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_rank),colorAccent,colorPrimary));
  rankView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      startActivityForResult(Games.Leaderboards.getLeaderboardIntent(apiClient,getString(R.string.leaderboard_high_score)),0);
      if (isSound)       soundPool.play(buttonId,1,1,0,0,1);
    }
  }
);
  gamesView.setImageBitmap(ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_game),colorAccent,colorPrimary));
  gamesView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      if (apiClient != null) {
        if (apiClient.isConnected()) {
          new AlertDialog.Builder(MainActivity.this).setTitle(R.string.title_sign_out).setMessage(R.string.msg_sign_out).setPositiveButton(android.R.string.yes,new DialogInterface.OnClickListener(){
            @Override public void onClick(            DialogInterface dialogInterface,            int i){
              Games.signOut(apiClient);
              if (apiClient.isConnected())               apiClient.disconnect();
              achievementsView.setVisibility(View.GONE);
              rankView.setVisibility(View.GONE);
              dialogInterface.dismiss();
            }
          }
).setNegativeButton(android.R.string.no,new DialogInterface.OnClickListener(){
            @Override public void onClick(            DialogInterface dialogInterface,            int i){
              dialogInterface.dismiss();
            }
          }
).create().show();
        }
 else         apiClient.connect();
      }
    }
  }
);
  aboutView.setImageBitmap(ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_info),colorAccent,colorPrimary));
  aboutView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      if (!gameView.isPlaying() && (animator == null || !animator.isStarted())) {
        gameView.setOnClickListener(null);
        gameView.playTutorial();
        animateTitle(false);
        if (isSound)         soundPool.play(hissId,1,1,0,0,1);
      }
    }
  }
);
  play=ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_play),colorAccent,colorPrimary);
  pause=ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_pause),colorAccent,colorPrimary);
  stop=ImageUtils.gradientBitmap(ImageUtils.getVectorBitmap(this,R.drawable.ic_stop),colorAccent,colorPrimary);
  pauseView.setImageBitmap(pause);
  pauseView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      isPaused=!isPaused;
      if (isPaused) {
        pauseView.setImageBitmap(play);
        if (!gameView.isTutorial())         stopView.setVisibility(View.VISIBLE);
        gameView.onPause();
      }
 else {
        pauseView.setImageBitmap(pause);
        pauseView.setAlpha(1f);
        stopView.setVisibility(View.GONE);
        gameView.onResume();
      }
    }
  }
);
  stopView.setImageBitmap(stop);
  stopView.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View view){
      if (isPaused) {
        pauseView.setImageBitmap(pause);
        pauseView.setAlpha(1f);
        gameView.onResume();
        isPaused=false;
      }
      onStop(gameView.score);
      gameView.stop();
    }
  }
);
  int highScore=prefs.getInt(PreferenceUtils.PREF_HIGH_SCORE,0);
  if (highScore > 0)   highScoreView.setText(String.format(getString(R.string.score_high),highScore));
  player=MediaPlayer.create(this,R.raw.music);
  player.setLooping(true);
  if (isMusic)   player.start();
  handler.postDelayed(hintRunnable,1000);
  gameView.setListener(this);
  if (prefs.getBoolean(PreferenceUtils.PREF_TUTORIAL,true)) {
    gameView.playTutorial();
    buttonLayout.setVisibility(View.GONE);
    pauseView.setVisibility(View.VISIBLE);
    stopView.setVisibility(View.GONE);
  }
 else {
    gameView.setOnClickListener(this);
    animateTitle(true);
    apiClient=new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Games.API).addScope(Games.SCOPE_GAMES).build();
    apiClient.connect();
  }
}