Android Open Source - ubisoldiers Unit Customization Activity






From Project

Back to project page ubisoldiers.

License

The source code is released under:

MIT License

If you think the Android project ubisoldiers 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.github.gobbisanches.ubisoldiers.app;
/*ww w.j  a  va 2  s.  co  m*/
import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import com.github.gobbisanches.ubisoldiers.mechanics.General;
import com.github.gobbisanches.ubisoldiers.mechanics.Unit;

/**
 * Created by Sanches on 13/07/2014.
 */
public class UnitCustomizationActivity extends SingleFragmentActivity implements UnitCustomizationFragment.UnitCustomizationFragmentListener {
    private static final String UNIT_INDEX = "com.github.gobbisanches.ubisoldier.app.UnitCustomizationActivity.UnitIndex";
    private static final String GENERAL = "com.github.gobbisanches.ubisoldier.app.UnitCustomizationActivity.General";
    private General general;
    private int unitIndex;

    @Override
    protected Fragment createFragment() {
        general = (General) getIntent().getSerializableExtra(GENERAL);
        unitIndex = getIntent().getIntExtra(UNIT_INDEX, -1);

        if (general == null) {
            throw new RuntimeException("No General object was passed");
        }

        if ((unitIndex < 0) || (unitIndex > 2)) {
            if (unitIndex == -1) {
                throw new RuntimeException("No unit index parameter was passed");
            } else {
                throw new RuntimeException("Invalid Unit Index: " + unitIndex);
            }
        }

        return UnitCustomizationFragment.newInstance(unitIndex, general, unitIndex, this);
    }

    @Override
    public void onChangeUnit(int unitCustomizationId, Unit updatedUnit) {
//        general.getSquad().setUnit(unitIndex, updatedUnit);
        General.getPlayerGeneral().getSquad().setUnit(unitIndex, updatedUnit);
        setResult(unitIndex);
    }

    public static void startForUnit(General general, int unitIndex, Activity caller) {
        if(general == null) {
            throw new RuntimeException("Invalid General object");
        }
        if((unitIndex < 0) || (unitIndex > 2)) {
            throw new RuntimeException("Invalid unitIndex " + unitIndex);
        }

        Intent intent = new Intent(caller, UnitCustomizationActivity.class);

        intent.putExtra(GENERAL, general);
        intent.putExtra(UNIT_INDEX, unitIndex);

        caller.startActivityForResult(intent, unitIndex);
    }
}




Java Source Code List

com.github.gobbisanches.ubisoldiers.app.ArmyFragment.java
com.github.gobbisanches.ubisoldiers.app.BattleActivity.java
com.github.gobbisanches.ubisoldiers.app.BattleFragment.java
com.github.gobbisanches.ubisoldiers.app.ItemListFragment.java
com.github.gobbisanches.ubisoldiers.app.MainActivity.java
com.github.gobbisanches.ubisoldiers.app.ResourceManager.java
com.github.gobbisanches.ubisoldiers.app.SingleFragmentActivity.java
com.github.gobbisanches.ubisoldiers.app.UbisoldierUosApplication.java
com.github.gobbisanches.ubisoldiers.app.UbisoldiersDriver.java
com.github.gobbisanches.ubisoldiers.app.UnitCustomizationActivity.java
com.github.gobbisanches.ubisoldiers.app.UnitCustomizationFragment.java
com.github.gobbisanches.ubisoldiers.app.UnitFragment.java
com.github.gobbisanches.ubisoldiers.app.UosManager.java
com.github.gobbisanches.ubisoldiers.mechanics.Armor.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleLogEntry.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleLogParser.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleLog.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleSquad.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleUnit.java
com.github.gobbisanches.ubisoldiers.mechanics.Battle.java
com.github.gobbisanches.ubisoldiers.mechanics.DefaultGameRules.java
com.github.gobbisanches.ubisoldiers.mechanics.GameRules.java
com.github.gobbisanches.ubisoldiers.mechanics.General.java
com.github.gobbisanches.ubisoldiers.mechanics.ItemCollection.java
com.github.gobbisanches.ubisoldiers.mechanics.Item.java
com.github.gobbisanches.ubisoldiers.mechanics.MechanicsEngine.java
com.github.gobbisanches.ubisoldiers.mechanics.PolicyManager.java
com.github.gobbisanches.ubisoldiers.mechanics.SearchEngine.java
com.github.gobbisanches.ubisoldiers.mechanics.Soldier.java
com.github.gobbisanches.ubisoldiers.mechanics.Squad.java
com.github.gobbisanches.ubisoldiers.mechanics.Unit.java
com.github.gobbisanches.ubisoldiers.mechanics.Weapon.java