Android Open Source - GhostStories Title Activity






From Project

Back to project page GhostStories.

License

The source code is released under:

GNU General Public License

If you think the Android project GhostStories 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 games.ghoststories.activities;
/*w w  w.  j  a  v a  2 s .c o  m*/
import games.ghoststories.R;
import games.ghoststories.data.GhostStoriesBitmaps;
import games.ghoststories.data.GhostStoriesConstants;
import games.ghoststories.data.GhostStoriesGameManager;
import games.ghoststories.enums.EDifficulty;

import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

/**
 * Activity for the title screen of the game
 */
public class TitleActivity extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.title);

      mLoadingTextView = (TextView)findViewById(R.id.loading);
      Typeface face = Typeface.createFromAsset(getAssets(),
            GhostStoriesConstants.sFont);
      mLoadingTextView.setTypeface(face);
      mLoadText = mLoadingTextView.getText().toString();
   }

   /*
    * (non-Javadoc)
    * @see android.app.Activity#onStart()
    */
   @Override
   protected void onStart() {
      mLoadingTextView.setVisibility(View.GONE);
      mLoadingTextView.setText(mLoadText);
      mLoadCounter = 0;

      findViewById(R.id.new_game).setVisibility(View.VISIBLE);
      findViewById(R.id.continue_game).setVisibility(View.VISIBLE);
      findViewById(R.id.settings).setVisibility(View.VISIBLE);
      super.onStart();
   }

   public void newGameSelected(View pView) {
      Log.d("TitleActivity", "NewGame");

      mLoadingTextView.setVisibility(View.VISIBLE);
      findViewById(R.id.new_game).setVisibility(View.GONE);
      findViewById(R.id.continue_game).setVisibility(View.GONE);
      findViewById(R.id.settings).setVisibility(View.GONE);

      final Future<?> future = mLoadingThread.scheduleAtFixedRate(new Runnable() {
         public void run() {
            String text = mLoadText;
            for(int i = 0; i < mLoadCounter; ++i) {
               text += ".";
            }
            mLoadCounter++;
            if(mLoadCounter > sMaxDots) {
               mLoadCounter = 0;
            }
            final String newLabel = text;
            TitleActivity.this.runOnUiThread(new Runnable() {
               public void run() {
                  mLoadingTextView.setText(newLabel);
               }
            });
         }
      }, 0, 500, TimeUnit.MILLISECONDS);

      //Initialize the game on a background thread
      new AsyncTask<Void, Void, Void>() {
         @Override
         protected Void doInBackground(Void... params) {
            GhostStoriesBitmaps.initBitmaps(getResources());
            GhostStoriesGameManager.getInstance().initializeGame(
                  EDifficulty.INITIATE, TitleActivity.this);
            return null;
         }

         @Override
         protected void onPostExecute(Void result) {
            future.cancel(true);
            //Switch to the game activity
            Intent intent = new Intent(TitleActivity.this, GameScreenActivity.class);
            startActivity(intent);
         }
      }.execute();

   }

   public void continueGameSelected(View pView) {
      Log.d("TitleActivity", "ContinueGame");
   }

   public void settingsSelected(View pView) {
      Log.d("TitleActivity", "Settings");
   }

   /** Maximum number of dots for the loading text **/
   private static int sMaxDots = 3;

   /** Counter used for the loading text **/
   private int mLoadCounter = 0;
   /** The initial loading text **/
   private String mLoadText;
   /** Thread used to update the loading text **/
   private final ScheduledExecutorService mLoadingThread =
         Executors.newSingleThreadScheduledExecutor();
   /** The loading text view **/
   private TextView mLoadingTextView;
}




Java Source Code List

com.drawable.shapes.GradientRectangle.java
com.interfaces.IDraggable.java
com.utils.AndroidUtils.java
com.utils.AnimationUtils2.java
com.utils.ImageLoadingTask.java
com.utils.ImageRotationTask.java
com.utils.ImageViewUtils.java
com.views.NumberedImageView.java
com.views.ToggledImageView.java
com.views.layouts.ScaledLinearLayout.java
com.views.layouts.ScaledRelativeLayout.java
com.views.layouts.SquareGridLayout.java
com.views.layouts.SquareLinearLayout.java
com.views.layouts.SquareTableLayout.java
com.views.layouts.ZoomableRelativeLayout.java
com.views.listeners.DragTouchListener.java
games.ghoststories.activities.GameLoadingActivity.java
games.ghoststories.activities.GameScreenActivity.java
games.ghoststories.activities.TitleActivity.java
games.ghoststories.controllers.GhostDeckController.java
games.ghoststories.controllers.HaunterController.java
games.ghoststories.controllers.PlayerBoardCardController.java
games.ghoststories.controllers.VillageTileController.java
games.ghoststories.controllers.combat.CombatAreaController.java
games.ghoststories.controllers.combat.DiceDragListener.java
games.ghoststories.controllers.combat.GhostDragListener.java
games.ghoststories.controllers.combat.TaoTokenDragListener.java
games.ghoststories.data.DragData.java
games.ghoststories.data.GameBoardData.java
games.ghoststories.data.GhostData.java
games.ghoststories.data.GhostDeckData.java
games.ghoststories.data.GhostGraveyardData.java
games.ghoststories.data.GhostStoriesBitmaps.java
games.ghoststories.data.GhostStoriesConstants.java
games.ghoststories.data.GhostStoriesGameManager.java
games.ghoststories.data.PlayerData.java
games.ghoststories.data.TokenSupplyData.java
games.ghoststories.data.interfaces.IGameBoardListener.java
games.ghoststories.data.interfaces.IGamePhaseListener.java
games.ghoststories.data.interfaces.IGameTokenListener.java
games.ghoststories.data.interfaces.IGhostDeckListener.java
games.ghoststories.data.interfaces.IGhostListener.java
games.ghoststories.data.interfaces.ITokenListener.java
games.ghoststories.data.interfaces.IVillageTileListener.java
games.ghoststories.data.village.BuddhistTempleTileData.java
games.ghoststories.data.village.CircleOfPrayerTileData.java
games.ghoststories.data.village.VillageTileDataFactory.java
games.ghoststories.data.village.VillageTileData.java
games.ghoststories.enums.EBoardLocation.java
games.ghoststories.enums.ECardLocation.java
games.ghoststories.enums.EColor.java
games.ghoststories.enums.ECombatPhase.java
games.ghoststories.enums.EDiceSide.java
games.ghoststories.enums.EDice.java
games.ghoststories.enums.EDifficulty.java
games.ghoststories.enums.EDragItem.java
games.ghoststories.enums.EGamePhase.java
games.ghoststories.enums.EGhostAbility.java
games.ghoststories.enums.EHaunterLocation.java
games.ghoststories.enums.EPlayerAbility.java
games.ghoststories.enums.ETileLocation.java
games.ghoststories.enums.EVillageTile.java
games.ghoststories.fragments.AuxAreaFragment.java
games.ghoststories.fragments.GameboardFragment.java
games.ghoststories.utils.BitmapUtils.java
games.ghoststories.utils.GameUtils.java
games.ghoststories.utils.XmlUtils.java
games.ghoststories.views.GameScreen.java
games.ghoststories.views.aux_area.CardInfoView.java
games.ghoststories.views.aux_area.GamePhaseDetailsView.java
games.ghoststories.views.aux_area.GamePhaseView.java
games.ghoststories.views.aux_area.GhostDeckView.java
games.ghoststories.views.aux_area.GhostGraveyardCardView.java
games.ghoststories.views.aux_area.PlayerInfoView.java
games.ghoststories.views.combat.CombatDamageView.java
games.ghoststories.views.combat.CombatDiceAreaView.java
games.ghoststories.views.combat.CombatDiceView.java
games.ghoststories.views.combat.CombatGhostView.java
games.ghoststories.views.combat.CombatInstructionsView.java
games.ghoststories.views.combat.CombatRollView.java
games.ghoststories.views.combat.CombatView.java
games.ghoststories.views.combat.ExtraCombatDiceView.java
games.ghoststories.views.combat.GhostHealthView.java
games.ghoststories.views.common.AbstractNumberedTokenView.java
games.ghoststories.views.common.BuddhaTokenView.java
games.ghoststories.views.common.QiTokenView.java
games.ghoststories.views.common.TaoTokenView.java
games.ghoststories.views.common.YinYangTokenView.java
games.ghoststories.views.gameboard.PlayerAreaView.java
games.ghoststories.views.gameboard.PlayerBoardCardView.java
games.ghoststories.views.gameboard.PlayerBoardView.java
games.ghoststories.views.gameboard.PlayerTokenAreaView.java
games.ghoststories.views.gameboard.VillageTileView.java
games.ghoststories.views.graveyard.GraveyardScrollView.java
games.ghoststories.views.graveyard.GraveyardView.java
games.ghoststories.views.title.TitleButton.java
games.ghoststories.views.title.TitleScreen.java
games.ghoststories.views.village.CircleOfPrayerView.java