Android Open Source - GameTimer Player






From Project

Back to project page GameTimer.

License

The source code is released under:

Apache License

If you think the Android project GameTimer 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 com.solidnw.gametimer.model;
/*from w w  w  . j  a v  a  2 s .  c  o m*/
import android.os.Handler;
import android.os.SystemClock;

import com.solidnw.gametimer.activities.GameActivity;

/**
 * 
 * @author  SickSta
 * @since   21:21:51 - 21.01.2013
 * @project AndroidGameTimer
 */
public class Player
{
//  private final String mName;
  private String mName;
  private String mColor;
  private Time mPlayerTime;
  private Time mInitialTime;
  private long mStartTime;
  private Handler mHandler;
  private Runnable mUpdateTask;
//  private final String mRingtoneUri;
  private String mRingtoneUri;
  private String mGameMode;
  
  // ===========================================================
  // Constructors
  // ===========================================================
  public Player(String playerName, String color, String ringtone) {
    mName  = playerName;
    mColor  = color;
    mRingtoneUri = ringtone;
    mPlayerTime = new Time(1,23,42);
//    handler = new Handler();
//    playerTime = new Time(GameActivity.getTime().getHours(), GameActivity.getTime().getMinutes(), GameActivity.getTime().getSeconds());
//    initialTime = new Time(playerTime);
//    
//    // TODO: Maybe put this as an extra class (or at least method)
//    updateTask = new Runnable()
//    {
//      public void run()
//      {        
//        long millis = SystemClock.uptimeMillis() - startTime;
//        int seconds = (int) (millis / 1000);
//        int minutes = seconds / 60;
//        seconds     = seconds % 60;
//        
//        if(playerTime.decreaseOneSecond() != true)
//        {
//          handler.removeCallbacks(updateTask);
//        }
//        
//        // Call this again in 1 second
//        handler.postAtTime(updateTask, startTime + (((minutes * 60) + seconds + 1) * 1000));
//      }
//    };
  }
  
  public void initializeTime(Time initialTime) {
    mInitialTime = initialTime;
    mPlayerTime = initialTime;
    mHandler = new Handler();
    
    mUpdateTask = new Runnable() {
      public void run() {
        long millis = SystemClock.uptimeMillis() - mStartTime;
        int seconds = (int) (millis / 1000);
        int minutes = seconds / 60;
        seconds     = seconds % 60;
        
        if(mPlayerTime.decreaseOneSecond() != true) {
          mHandler.removeCallbacks(mUpdateTask);
        }
        
        mHandler.postAtTime(mUpdateTask, mStartTime + (((minutes * 60) + seconds + 1) * 1000));
      }
    };
  }
  
  public void initializeMode(String gameMode) {
    mGameMode = gameMode;
  }
  
  public void start() {
    mStartTime = SystemClock.uptimeMillis();

    if(GameModeConstants.FIXED_TURN_TIME.equals(mGameMode))
    {
      mPlayerTime = new Time(mInitialTime);
    }
  
    mHandler.removeCallbacks(mUpdateTask);
    mHandler.postDelayed(mUpdateTask, 100);
  }
  
  public void stop() {
    mHandler.removeCallbacks(mUpdateTask);
  }
  
  public String getTimeString() {
    return mPlayerTime.toString();
  }
  
  /**
   * @return the name of the player
   */
  public String getName() {
    return mName;
  }
  
  /**
   * @return the color of the player as hex-string of the form 'AARRGGBB'
   */
  public String getColor() {
    return mColor;
  }
  
  public String getRingtone() {
    return mRingtoneUri;
  }

  /**
   * @param name the name of the player to set
   */
  public void setName(String name) {
    mName = name;
  }

  /**
   * @param color the color of the player to set
   */
  public void setColor(String color) {
    mColor = color;
  }
}




Java Source Code List

com.solidnw.gametimer.activities.GameActivity.java
com.solidnw.gametimer.activities.GroupActivity.java
com.solidnw.gametimer.activities.GroupManagementActivity.java
com.solidnw.gametimer.activities.MainActivity.java
com.solidnw.gametimer.activities.PlayerActivity.java
com.solidnw.gametimer.activities.PlayerManagementActivity.java
com.solidnw.gametimer.adapter.AbstractRemoveItemAdapter.java
com.solidnw.gametimer.adapter.ColorAdapter.java
com.solidnw.gametimer.adapter.DrawerListAdapter.java
com.solidnw.gametimer.adapter.GameModePagerAdapter.java
com.solidnw.gametimer.adapter.GroupAdapter.java
com.solidnw.gametimer.adapter.RemoveGroupListAdapter.java
com.solidnw.gametimer.adapter.RemoveMemberListAdapter.java
com.solidnw.gametimer.adapter.RemovePlayerListAdapter.java
com.solidnw.gametimer.database.DatabaseHelper.java
com.solidnw.gametimer.database.DatabaseLayer.java
com.solidnw.gametimer.fragments.GameFragment.java
com.solidnw.gametimer.fragments.GameModeFragment.java
com.solidnw.gametimer.fragments.GameModePagerFragment.java
com.solidnw.gametimer.fragments.GroupFragment.java
com.solidnw.gametimer.fragments.GroupManagementFragment.java
com.solidnw.gametimer.fragments.PlayerFragment.java
com.solidnw.gametimer.fragments.PlayerManagementFragment.java
com.solidnw.gametimer.listener.DrawerItemClickListener.java
com.solidnw.gametimer.model.DrawerConstants.java
com.solidnw.gametimer.model.GameModeConstants.java
com.solidnw.gametimer.model.GradientHelper.java
com.solidnw.gametimer.model.Gradient.java
com.solidnw.gametimer.model.Group.java
com.solidnw.gametimer.model.IntentConstants.java
com.solidnw.gametimer.model.Player.java
com.solidnw.gametimer.model.PreferencesConstants.java
com.solidnw.gametimer.model.Time.java