Android Open Source - DroidSweeper High Score Activity






From Project

Back to project page DroidSweeper.

License

The source code is released under:

MIT License

If you think the Android project DroidSweeper listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.nisble.droidsweeper.gui;
// w w w.  j av  a2s. co  m
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.WrapperListAdapter;
import de.nisble.droidsweeper.R;
import static de.nisble.droidsweeper.config.Constants.*;
import de.nisble.droidsweeper.config.Level;
import de.nisble.droidsweeper.game.database.DSDBAdapter;
import de.nisble.droidsweeper.game.database.DSDBGameEntry;
import de.nisble.droidsweeper.utilities.LogDog;

/** MultiListActivity for showing the highscores.<br>
 * @author Moritz Nisbl moritz.nisble@gmx.de */
public class HighScoreActivity extends Activity {
  private static final String CLASSNAME = HighScoreActivity.class.getSimpleName();

  private static final String[] POSTFIX = { "_easy", "_normal", "_hard" };
  private static final Level[] LEVELS = { Level.EASY, Level.NORMAL, Level.HARD };

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_timelist);

    try {
      for (int i = 0; i < 3; ++i) {
        ListView l = (ListView) findViewById(getResources().getIdentifier("lvTimeList" + POSTFIX[i], "id",
            getPackageName()));
        l.setEmptyView((TextView) findViewById(getResources().getIdentifier("tvTimeList_empty" + POSTFIX[i],
            "id", getPackageName())));

        /* Add header view */
        l.addHeaderView(getLayoutInflater().inflate(R.layout.layout_timelist_header, l, false), null, false);
        l.setHeaderDividersEnabled(true);

        /* Fetch list entries from database and put it into
         * HighScoreListAdapter. */
        l.setAdapter(new HighScoreListAdapter(getApplicationContext(), DSDBAdapter.INSTANCE.getGames(LEVELS[i])));

        l.setOnItemClickListener(onClickListener);
      }
    } catch (Exception e) {
      LogDog.e(CLASSNAME, "Unable to create HighScoreActivity", e);
    }
  }

  private AdapterView.OnItemClickListener onClickListener = new AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

      /* Get the HighScoreListAdapter back from parent view.
       * The Adapter is wrapped, so we need to cast it back.
       * Use the id to get the corresponding data base entry from the
       * adapter. */
      DSDBGameEntry entry = (DSDBGameEntry) ((HighScoreListAdapter) ((WrapperListAdapter) ((ListView) parent)
          .getAdapter()).getWrappedAdapter()).getItem((int) id);

      Intent intent = getIntent();
      // TODO: Use a constant!
      intent.putExtra("GAMEID", entry.GAMEID);

      setResult(INTENTRESULT_PLAY_REPLAY, intent);

      finish();
    }
  };
}




Java Source Code List

de.nisble.droidsweeper.config.ApplicationConfig.java
de.nisble.droidsweeper.config.Constants.java
de.nisble.droidsweeper.config.GameConfig.java
de.nisble.droidsweeper.config.Level.java
de.nisble.droidsweeper.game.Field.java
de.nisble.droidsweeper.game.GameObserver.java
de.nisble.droidsweeper.game.Game.java
de.nisble.droidsweeper.game.Position.java
de.nisble.droidsweeper.game.database.DSDBAdapter.java
de.nisble.droidsweeper.game.database.DSDBContract.java
de.nisble.droidsweeper.game.database.DSDBGameEntry.java
de.nisble.droidsweeper.game.database.DSDBHelper.java
de.nisble.droidsweeper.game.jni.FieldListener.java
de.nisble.droidsweeper.game.jni.FieldStatus.java
de.nisble.droidsweeper.game.jni.GameStatus.java
de.nisble.droidsweeper.game.jni.MatrixObserver.java
de.nisble.droidsweeper.game.jni.MineSweeperMatrix.java
de.nisble.droidsweeper.game.replay.PlayerObserver.java
de.nisble.droidsweeper.game.replay.Player.java
de.nisble.droidsweeper.game.replay.Recorder.java
de.nisble.droidsweeper.game.replay.Replay.java
de.nisble.droidsweeper.game.replay.TimeStep.java
de.nisble.droidsweeper.gui.DroidSweeperActivity.java
de.nisble.droidsweeper.gui.HighScoreActivity.java
de.nisble.droidsweeper.gui.HighScoreListAdapter.java
de.nisble.droidsweeper.gui.SettingsActivity.java
de.nisble.droidsweeper.gui.grid.FieldDrawables.java
de.nisble.droidsweeper.gui.grid.FieldView.java
de.nisble.droidsweeper.gui.grid.GameGridView.java
de.nisble.droidsweeper.utilities.LogDog.java
de.nisble.droidsweeper.utilities.Timer.java