Android Open Source - miner Screen Manager






From Project

Back to project page miner.

License

The source code is released under:

Apache License

If you think the Android project miner 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.kolomiyets.miner.screen;
/*from   w ww  .  j a v a 2s .c  o m*/
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.SparseArray;

public class ScreenManager {
  
  public final static String ARG_CONNECT_METHOD = "CONNECT_METHOD";
  public final static String ARG_GAME_NAME = "GAME_NAME";
  public final static String ARG_DEVICE = "GAME_DEVICE";
  
  public enum ScreenType {
    START, DEVICES, CONNECTING, SELECT, MINER, SAPPER
  }
  
  private SparseArray<ScreenType> scenarium;
  private FragmentManager fragmentManager;
  private int defaultContainerResId;
  private int curPos;
  private ScreenBase curScr;
  
  public ScreenManager(FragmentManager fragmentManager, int defaultContainerResId) {
    this.fragmentManager = fragmentManager;
    this.defaultContainerResId = defaultContainerResId;
    initDefaultScenarium();
  }
  
  public void initDefaultScenarium(){
    curPos = 0;
    
    scenarium = new SparseArray<ScreenManager.ScreenType>(1);
    scenarium.put(0, ScreenType.START);
    scenarium.put(1, ScreenType.DEVICES);
    scenarium.put(2, ScreenType.CONNECTING);
    scenarium.put(3, ScreenType.SELECT);
    scenarium.put(4, ScreenType.MINER);
    scenarium.put(5, ScreenType.SAPPER);
    
    goTo(curPos);
//    goTo(5);
  }
  
  public void next(int containerResId, Bundle args){
    goTo(containerResId, curPos+1, args);
  }
  
  public void next(){
    next(defaultContainerResId, null);
  }
  
  public void next(Bundle args){
    next(defaultContainerResId, args);
  }
  
  public void previous(int containerResId, Bundle args){
    goTo(containerResId, curPos-1, args);
  }
  
  public void previous(){
    previous(defaultContainerResId, null);
  }
  
  public void previous(Bundle args){
    previous(defaultContainerResId, args);
  }
  
  public void goTo(int containerResId, int position, Bundle args){
    if(position<0) {
      curPos = 0;
    } else if(position>=scenarium.size()){
      curPos = scenarium.size()-1;
    } else {
      curPos = position;
    }
    
    curScr = getScreen(scenarium.get(curPos));
    curScr.setArguments(args);
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(containerResId, curScr, getScreenTag(curScr.getClass()))
    .commit();
  }
  
  public void goTo(int position, Bundle args){
    goTo(defaultContainerResId, position, args);
  }
  
  public void goTo(int position){
    goTo(defaultContainerResId, position, null);
  }
  
  public void goTo(int containerResId, ScreenType type, Bundle args){
    for(int i=0; i<scenarium.size(); i++){
      if(scenarium.get(i).equals(type)) {
        goTo(containerResId, i, args);
        return;
      }
    }
  }
  
  public void goTo(ScreenType type, Bundle args){
    goTo(defaultContainerResId, type, args);
  }
  
  public void goTo(ScreenType type){
    goTo(defaultContainerResId, type, null);
  }
  
  private ScreenBase getScreen(ScreenType type){
    ScreenBase result;
    switch (type) {
    case START:
      result = new ScreenCreateGame();
      break;
    case CONNECTING:
      result = new ScreenConnectingGame();
      break;
    case DEVICES:
      result = new ScreenDevices();
      break;
    case SELECT:
      result = new ScreenSelectPlayer();
      break;
    case MINER:
      result = new PlayGroundMiner();
      break;
    case SAPPER:
      result = new PlayGroundSapper();
      break;
    default:
      result = null;
      break;
    }
    
    return result;
  }
  
  public static <T extends ScreenBase> String getScreenTag(Class<T> cls){
    return cls.getName();
  }
  
  public ScreenBase getCurrentScreen(){
    return curScr;
  }
}




Java Source Code List

com.kolomiyets.miner.MinerActivity.java
com.kolomiyets.miner.Miner.java
com.kolomiyets.miner.bt.BtStateMonitor.java
com.kolomiyets.miner.bt.ConnectionBase.java
com.kolomiyets.miner.bt.ConnectionManager.java
com.kolomiyets.miner.bt.ConnectionMaster.java
com.kolomiyets.miner.bt.ConnectionProcessor.java
com.kolomiyets.miner.bt.ConnectionSlave.java
com.kolomiyets.miner.bt.EConnectMethod.java
com.kolomiyets.miner.bt.IBtEnableCallback.java
com.kolomiyets.miner.bt.IRequestBtResult.java
com.kolomiyets.miner.bt.notification.BtListener.java
com.kolomiyets.miner.bt.notification.BtNotificationCmd.java
com.kolomiyets.miner.bt.notification.BtNotificationConnect.java
com.kolomiyets.miner.bt.notification.BtNotificationDiscoveryDevice.java
com.kolomiyets.miner.bt.notification.BtNotificationDiscoveryState.java
com.kolomiyets.miner.bt.notification.BtNotificationDiscovery.java
com.kolomiyets.miner.bt.notification.BtNotificationHandshake.java
com.kolomiyets.miner.bt.notification.BtNotificationPower.java
com.kolomiyets.miner.bt.notification.BtNotificationState.java
com.kolomiyets.miner.bt.notification.BtNotification.java
com.kolomiyets.miner.bt.notification.EConnectionSate.java
com.kolomiyets.miner.bt.notification.NotificationManager.java
com.kolomiyets.miner.bt.protocol.CmdBase.java
com.kolomiyets.miner.bt.protocol.CmdFactory.java
com.kolomiyets.miner.bt.protocol.CmdFieldState.java
com.kolomiyets.miner.bt.protocol.CmdGameState.java
com.kolomiyets.miner.bt.protocol.CmdGameTeam.java
com.kolomiyets.miner.bt.protocol.CmdHandshake.java
com.kolomiyets.miner.bt.protocol.CmdPing.java
com.kolomiyets.miner.bt.protocol.CmdResponse.java
com.kolomiyets.miner.bt.protocol.ECmdName.java
com.kolomiyets.miner.bt.protocol.EGameState.java
com.kolomiyets.miner.dialog.DialogProvider.java
com.kolomiyets.miner.dialog.EDialogType.java
com.kolomiyets.miner.dialog.IDialogResult.java
com.kolomiyets.miner.screen.PlayGroundBase.java
com.kolomiyets.miner.screen.PlayGroundMiner.java
com.kolomiyets.miner.screen.PlayGroundSapper.java
com.kolomiyets.miner.screen.ScreenBase.java
com.kolomiyets.miner.screen.ScreenConnectingGame.java
com.kolomiyets.miner.screen.ScreenCreateGame.java
com.kolomiyets.miner.screen.ScreenDevices.java
com.kolomiyets.miner.screen.ScreenManager.java
com.kolomiyets.miner.screen.ScreenSelectPlayer.java
com.kolomiyets.miner.view.GridCell.java