Android Open Source - Gamework Game Service






From Project

Back to project page Gamework.

License

The source code is released under:

Apache License

If you think the Android project Gamework 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 cz.robyer.gamework.app.game;
//  w w  w . j a v  a  2  s  .co  m
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Intent;
import android.location.Location;
import android.support.v4.app.NotificationCompat;
import android.widget.Toast;
import cz.robyer.gamework.game.GameEvent;
import cz.robyer.gamework.game.GameEvent.EventType;
import cz.robyer.gamework.game.GameStatus;
import cz.robyer.gamework.app.R;
import cz.robyer.gamework.app.activity.GameMapActivity;

public class GameService extends cz.robyer.gamework.game.GameService {

  /* (non-Javadoc)
   * @see cz.robyer.gamework.game.GameService#getGameNotification()
   */
  @SuppressLint("DefaultLocale")
  @Override
  protected Notification getGameNotification() {
      Intent notificationIntent = new Intent(this, GameMapActivity.class)
          .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

      // location
      Location loc = getLocation();
      String gps = "-";
      if (loc != null)
        gps = String.format("%s, %s", loc.getLatitude(), loc.getLongitude());
      
    // time
      int seconds = (int) (getTime() / 1000);
    int minutes = seconds / 60;
    seconds     = seconds % 60;
    String time = String.format("%d:%02d", minutes, seconds);
    
      String summary = null;
      String text = null;
      
      switch (getStatus()) {
      case GAME_LOADING:
        summary = "Loading...";
        break;
      case GAME_LOST:
        summary = "You lost this game!";
        break;
      case GAME_NONE:
        summary = "No game loaded";
        break;
      case GAME_PAUSED:
        summary = "Game is paused";
        break;
      case GAME_RUNNING:
        summary = "Game is running";
        text = String.format("Game time: %s\nGame location: %s", time, gps);
        break;
      case GAME_WAITING:
        summary = "Waiting for start...";
        break;
      case GAME_WON:
        summary = "You won this game!";
        break;
      }

      NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
          .setWhen(getStartTime())
              .setSmallIcon(R.drawable.ic_stat_game)
              .setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0))
              .setContentTitle(getScenario().getInfo().title)
              .setContentText(summary);
      
      if (text != null)
        mBuilder.setStyle(new NotificationCompat.BigTextStyle()
              .bigText(text)
        .setSummaryText(summary));
      
      return mBuilder.build();
  }

  /* (non-Javadoc)
   * @see cz.robyer.gamework.game.GameService#onGameStart(boolean, android.content.Intent)
   */
  @Override
  protected void onGameStart(boolean starting, Intent intent) {
    if (starting) {
        Intent gameIntent = new Intent(this, GameMapActivity.class);
        gameIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(gameIntent);
      } else {
        Toast.makeText(getApplicationContext(), "Game is already running.", Toast.LENGTH_LONG).show();
      }
  }

  /* (non-Javadoc)
   * @see cz.robyer.gamework.game.GameService#onEvent(cz.robyer.gamework.game.GameEvent)
   */
  @Override
  protected void onEvent(GameEvent event) {

      switch (event.type) {
      case UPDATED_LOCATION:
         if (getStatus() == GameStatus.GAME_WAITING) {
           gameHandler.broadcastEvent(EventType.GAME_START);
         }
         
      case GAME_QUIT:
      case GAME_START:
      case GAME_PAUSE:
      case GAME_WIN:
      case GAME_LOSE:
      case UPDATED_TIME:
        refreshNotification(false);
        break;

      default:
        break;
      }

  }

}




Java Source Code List

cz.robyer.gamework.app.activity.BaseActivity.java
cz.robyer.gamework.app.activity.BaseGameActivity.java
cz.robyer.gamework.app.activity.GameInventoryActivity.java
cz.robyer.gamework.app.activity.GameMapActivity.java
cz.robyer.gamework.app.activity.GameMessagesActivity.java
cz.robyer.gamework.app.activity.GameObjectivesActivity.java
cz.robyer.gamework.app.activity.GameToolsActivity.java
cz.robyer.gamework.app.activity.HelpActivity.java
cz.robyer.gamework.app.activity.MainActivity.java
cz.robyer.gamework.app.activity.MessageActivity.java
cz.robyer.gamework.app.game.GameService.java
cz.robyer.gamework.app.service.JavaScriptHandler.java
cz.robyer.gamework.app.service.MessageAdapter.java
cz.robyer.gamework.constants.Constants.java
cz.robyer.gamework.game.GameEventBroadcaster.java
cz.robyer.gamework.game.GameEventListener.java
cz.robyer.gamework.game.GameEvent.java
cz.robyer.gamework.game.GameHandler.java
cz.robyer.gamework.game.GameService.java
cz.robyer.gamework.game.GameStatus.java
cz.robyer.gamework.scenario.BaseObject.java
cz.robyer.gamework.scenario.HookableObject.java
cz.robyer.gamework.scenario.IdentificableObject.java
cz.robyer.gamework.scenario.ScenarioInfo.java
cz.robyer.gamework.scenario.Scenario.java
cz.robyer.gamework.scenario.area.Area.java
cz.robyer.gamework.scenario.area.MultiPointArea.java
cz.robyer.gamework.scenario.area.PointArea.java
cz.robyer.gamework.scenario.area.SoundArea.java
cz.robyer.gamework.scenario.helper.EventHookable.java
cz.robyer.gamework.scenario.helper.ScannerHookable.java
cz.robyer.gamework.scenario.helper.TimeHookable.java
cz.robyer.gamework.scenario.hook.Condition.java
cz.robyer.gamework.scenario.hook.Hook.java
cz.robyer.gamework.scenario.message.Message.java
cz.robyer.gamework.scenario.parser.XmlScenarioParser.java
cz.robyer.gamework.scenario.reaction.ActivityReaction.java
cz.robyer.gamework.scenario.reaction.EventReaction.java
cz.robyer.gamework.scenario.reaction.MessageReaction.java
cz.robyer.gamework.scenario.reaction.MultiReaction.java
cz.robyer.gamework.scenario.reaction.Reaction.java
cz.robyer.gamework.scenario.reaction.ReferenceReaction.java
cz.robyer.gamework.scenario.reaction.SoundReaction.java
cz.robyer.gamework.scenario.reaction.VariableReaction.java
cz.robyer.gamework.scenario.reaction.VibrateReaction.java
cz.robyer.gamework.scenario.variable.BooleanVariable.java
cz.robyer.gamework.scenario.variable.DecimalVariable.java
cz.robyer.gamework.scenario.variable.Variable.java
cz.robyer.gamework.utils.GPoint.java
cz.robyer.gamework.utils.Log.java
cz.robyer.gamework.utils.Utils.java