Android Open Source - Save-the-Planet Loading Screen Activity






From Project

Back to project page Save-the-Planet.

License

The source code is released under:

Copyright (c) 2002 JSON.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software ...

If you think the Android project Save-the-Planet 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.karolmajta.stp;
/* w  w  w  .  j  a  v  a 2 s.  c om*/
import com.karolmajta.procprox.FontManager;
import com.karolmajta.procprox.excepiton.FontNotCreatedException;
import com.karolmajta.stp.exception.NoTasksInProgressQueueException;
import com.karolmajta.stp.exception.UnboundViewException;
import com.karolmajta.stp.models.SyncProgress;
import com.karolmajta.stp.models.SyncTask;
import com.karolmajta.stp.views.FancyTextView;
import com.karolmajta.stp.views.ProgressView;

import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PImage;

public class LoadingScreenActivity extends PApplet {
  public static final String[] AVAILABLE_FONTS = {
    "Sansation_Bold.ttf"
  };
  
  private static final String BAR_NAME = "Loading...";
  private static final int BGCOLOR = 0xff000000;
  private static final int BAR_BG = 0xffffffff;
  private static final int BAR_EMPTY = 0xffffffff;
  private static final int BAR_LOADED = 0xffff0000;
  
  private static final String GAME_LOGO = "logo.png";
  private static final String STUDIO_LOGO = "303games.png";
  private static final String TAP_STRING = "Tap to continue";
  
  private static float MARGIN_W;
  private static float MARGIN_H;
  private static float BAR_X;
  private static float BAR_Y;
  private static float BAR_WIDTH;
  private static float BAR_OUT;
  private static float BAR_IN;
  private static float LOGO_X;
  private static float LOGO_Y;
  private static float SLOGO_X;
  private static float SLOGO_Y;
  
  public static float FONT_SMALL;
  public static float FONT_MEDIUM;
  public static float FONT_BIG;
  
  public static float[] FONT_SIZES;
  
  private FontManager fontManager;
  
  private SyncProgress progress;
  
  private ProgressView progressView;
  private PImage gameLogo;
  private PImage studioLogo;
  private FancyTextView tapScreenView;
  
  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
  
  @Override
  public void onPause() {
    super.onPause();
  }
  
    @Override
    public void setup() {
      gameLogo = loadImage(GAME_LOGO);
      studioLogo = loadImage(STUDIO_LOGO);
      
      MARGIN_W = width/10;
      MARGIN_H = MARGIN_W;
      LOGO_X = MARGIN_W;
      LOGO_Y = MARGIN_H;
      SLOGO_X = (width-studioLogo.width)/2;
      SLOGO_Y = height-MARGIN_H-studioLogo.height;
      BAR_X = 2*MARGIN_W;
      BAR_Y = LOGO_Y+gameLogo.width+MARGIN_H;
      BAR_WIDTH = width-4*MARGIN_W;
      BAR_OUT = height/50;
      BAR_IN = 0.5f*BAR_OUT;
      
      FONT_SMALL = height/40;
      FONT_MEDIUM = FONT_SMALL*2.5f;
      FONT_BIG = FONT_MEDIUM*2.0f;
      FONT_SIZES = new float[] {
          FONT_SMALL,
          FONT_MEDIUM,
          FONT_BIG
      };
      
      FontManager.getFontManager()
      .createFont(this, "Sansation_Bold.ttf", (int)FONT_SMALL);
      
      progress = new SyncProgress();
      for(final String fontName : AVAILABLE_FONTS){
        for(final float size : FONT_SIZES){
          SyncTask t = new SyncTask() {
          @Override
          public void then() {}
          @Override
          public void doIt() {
            FontManager fm = FontManager.getFontManager();
            fm.createFont
                (
                    LoadingScreenActivity.this,
                    fontName,
                    (int)size
                );
          }
        };
        progress.addTask(t, 1);
        }
      }
      
      PFont loadingBarPFont = null;
    try {
      loadingBarPFont = FontManager.getFontManager()
          .getFont("Sansation_Bold.ttf", (int)FONT_SMALL);
    } catch (FontNotCreatedException e) {
      loadingBarPFont = g.textFont;
    }
      
    tapScreenView = new FancyTextView
        (
            width/2,
            BAR_Y,
            loadingBarPFont,
            0xffffffff,
            FancyTextView.SHOW
        );
    tapScreenView.bindModel(TAP_STRING);
    
      progressView = new ProgressView
          (
              BAR_NAME,
              loadingBarPFont,
              BAR_X,
              BAR_Y,
              BAR_WIDTH,
              BAR_OUT,
              BAR_IN,
              BAR_BG,
              BAR_EMPTY,
              BAR_LOADED
          );
      progressView.bindModel(progress);
      
      smooth();
      background(BGCOLOR);
    }

    @Override
    public void draw() {
      background(BGCOLOR);
      
      image(gameLogo, LOGO_X, LOGO_Y);
      image(studioLogo, SLOGO_X, SLOGO_Y);
      
      try {
      progressView.draw(this);
    } catch (UnboundViewException e) {
      e.printStackTrace();
    }
      
      try {
        if(!progressView.isVisible()){
          tapScreenView.draw(this);
        }
    } catch (UnboundViewException e1) {
      e1.printStackTrace();
    }
      
      if(progress.hasNextTask()){
        try {
        progress.doNext();
      } catch (NoTasksInProgressQueueException e) {
        e.printStackTrace();
      }
      }
      
      if(mousePressed && !progressView.isVisible()){
        Intent i = new Intent(this, MainMenuActivity.class);
        startActivity(i);
        exit();
        finish();
      }
    }
    
    @Override
    public int sketchWidth() {
      Display display = getWindowManager().getDefaultDisplay(); 
      return display.getWidth();
    }
    
    @Override
    public int sketchHeight() {
      Display display = getWindowManager().getDefaultDisplay(); 
      return display.getHeight();
    }
    
    @Override
    public String sketchRenderer() {
        return P2D;
    }
}




Java Source Code List

com.karolmajta.procprox.DragDetector.java
com.karolmajta.procprox.Drag.java
com.karolmajta.procprox.FontManager.java
com.karolmajta.procprox.IEventFilter.java
com.karolmajta.procprox.TapDetector.java
com.karolmajta.procprox.Tap.java
com.karolmajta.procprox.excepiton.FontNotCreatedException.java
com.karolmajta.stp.LoadingScreenActivity.java
com.karolmajta.stp.MainMenuActivity.java
com.karolmajta.stp.exception.NoDeferredException.java
com.karolmajta.stp.exception.NoTasksInProgressQueueException.java
com.karolmajta.stp.exception.STPException.java
com.karolmajta.stp.exception.UnboundViewException.java
com.karolmajta.stp.models.ICanCollide.java
com.karolmajta.stp.models.IPConstants.java
com.karolmajta.stp.models.IProgress.java
com.karolmajta.stp.models.ITask.java
com.karolmajta.stp.models.ITickable.java
com.karolmajta.stp.models.MainMenuItemBall.java
com.karolmajta.stp.models.MainMenuObstacleBall.java
com.karolmajta.stp.models.ObstacleManager.java
com.karolmajta.stp.models.SyncProgress.java
com.karolmajta.stp.models.SyncTask.java
com.karolmajta.stp.models.Tickable.java
com.karolmajta.stp.models.Viewport.java
com.karolmajta.stp.views.FancyTextView.java
com.karolmajta.stp.views.IDrawable.java
com.karolmajta.stp.views.MainMenuItemBallDebugView.java
com.karolmajta.stp.views.MainMenuItemBallView.java
com.karolmajta.stp.views.MainMenuObstacleBallDebugView.java
com.karolmajta.stp.views.MainMenuObstacleBallView.java
com.karolmajta.stp.views.ObstacleManagerView.java
com.karolmajta.stp.views.ProgressDebugView.java
com.karolmajta.stp.views.ProgressView.java
com.karolmajta.stp.views.View.java