<commit_before>package au.com.codeka.warworlds.game.solarsystem;

import java.util.Locale;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import au.com.codeka.RomanNumeralFormatter;
import au.com.codeka.common.Log;
import au.com.codeka.common.Vector2;
import au.com.codeka.common.model.BaseColony;
import au.com.codeka.common.model.BaseEmpirePresence;
import au.com.codeka.common.model.BasePlanet;
import au.com.codeka.common.protobuf.Messages;
import au.com.codeka.warworlds.R;
import au.com.codeka.warworlds.ctrl.ColonyFocusView;
import au.com.codeka.warworlds.ctrl.FleetListSimple;
import au.com.codeka.warworlds.ctrl.SelectionView;
import au.com.codeka.warworlds.eventbus.EventHandler;
import au.com.codeka.warworlds.game.CombatReportDialog;
import au.com.codeka.warworlds.game.ScoutReportDialog;
import au.com.codeka.warworlds.game.SitrepActivity;
import au.com.codeka.warworlds.game.build.BuildActivity;
import au.com.codeka.warworlds.model.Colony;
import au.com.codeka.warworlds.model.Empire;
import au.com.codeka.warworlds.model.EmpireManager;
import au.com.codeka.warworlds.model.EmpireShieldManager;
import au.com.codeka.warworlds.model.Fleet;
import au.com.codeka.warworlds.model.Planet;
import au.com.codeka.warworlds.model.ShieldManager;
import au.com.codeka.warworlds.model.Star;
import au.com.codeka.warworlds.model.StarManager;
import au.com.codeka.warworlds.model.StarSimulationQueue;

/**
 * This is a fragment which displays details about a single solar system.
 */
public class SolarSystemFragment extends Fragment {
    private static final Log log = new Log("SolarSystemFragment");
    private SolarSystemSurfaceView mSolarSystemSurfaceView;
    private ProgressBar mProgressBar;
    private Star mStar;
    private Planet mPlanet;
    private Colony mColony;
    private boolean mIsFirstRefresh;
    private View mView;
    private int starID;

    // needs to be Object so we can do a version check before instantiating the class
    Object mSolarSystemSurfaceViewOnLayoutChangedListener;

    private static final int BUILD_REQUEST = 3000;

    public Star getStar() {
        return mStar;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.solarsystem, container, false);

        mSolarSystemSurfaceView = (SolarSystemSurfaceView) mView.findViewById(R.id.solarsystem_view);
        mProgressBar = (ProgressBar) mView.findViewById(R.id.progress_bar);
        final Button buildButton = (Button) mView.findViewById(R.id.solarsystem_colony_build);
        final Button focusButton = (Button) mView.findViewById(R.id.solarsystem_colony_focus);
        final Button sitrepButton = (Button) mView.findViewById(R.id.sitrep_btn);
        final Button planetViewButton = (Button) mView.findViewById(R.id.enemy_empire_view);
        final Button emptyViewButton = (Button) mView.findViewById(R.id.empty_view_btn);
        final FleetListSimple fleetList = (FleetListSimple) mView.findViewById(R.id.fleet_list);
        final SelectionView selectionView = (SelectionView) mView.findViewById(R.id.selection);
        mSolarSystemSurfaceView.setSelectionView(selectionView);

        mIsFirstRefresh = true;
        if (savedInstanceState != null) {
            mIsFirstRefresh = savedInstanceState.getBoolean("au.com.codeka.warworlds.IsFirstRefresh");
        }

        mSolarSystemSurfaceView.addPlanetSelectedListener(
                new SolarSystemSurfaceView.OnPlanetSelectedListener() {
            @Override
            public void onPlanetSelected(Planet planet) {
                mPlanet = planet;
                refreshSelectedPlanet();
            }
        });

        buildButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mStar == null) {
                    return; // can happen before the star loads
                }

                Intent intent = new Intent(getActivity(), BuildActivity.class);
                intent.putExtra("au.com.codeka.warworlds.StarKey", mStar.getKey());

                Messages.Colony.Builder colony_pb = Messages.Colony.newBuilder();
                mColony.toProtocolBuffer(colony_pb);
                intent.putExtra("au.com.codeka.warworlds.Colony", colony_pb.build().toByteArray());

                startActivityForResult(intent, BUILD_REQUEST);
            }
        });

        focusButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mStar == null || mStar.getPlanets() == null) {
                    return;
                }

                FocusDialog dialog = new FocusDialog();
                dialog.setColony(mStar, mColony);
                dialog.show(getActivity().getSupportFragmentManager(), "");
            }
        });

        sitrepButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mStar == null) {
                    return; // can happen before the star loads
                }
<commit_msg>Fixed a potential NPE in FocusDialog.setColony.<commit_after>package au.com.codeka.warworlds.game.solarsystem;

import java.util.Locale;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import au.com.codeka.RomanNumeralFormatter;
import au.com.codeka.common.Log;
import au.com.codeka.common.Vector2;
import au.com.codeka.common.model.BaseColony;
import au.com.codeka.common.model.BaseEmpirePresence;
import au.com.codeka.common.model.BasePlanet;
import au.com.codeka.common.protobuf.Messages;
import au.com.codeka.warworlds.R;
import au.com.codeka.warworlds.ctrl.ColonyFocusView;
import au.com.codeka.warworlds.ctrl.FleetListSimple;
import au.com.codeka.warworlds.ctrl.SelectionView;
import au.com.codeka.warworlds.eventbus.EventHandler;
import au.com.codeka.warworlds.game.CombatReportDialog;
import au.com.codeka.warworlds.game.ScoutReportDialog;
import au.com.codeka.warworlds.game.SitrepActivity;
import au.com.codeka.warworlds.game.build.BuildActivity;
import au.com.codeka.warworlds.model.Colony;
import au.com.codeka.warworlds.model.Empire;
import au.com.codeka.warworlds.model.EmpireManager;
import au.com.codeka.warworlds.model.EmpireShieldManager;
import au.com.codeka.warworlds.model.Fleet;
import au.com.codeka.warworlds.model.Planet;
import au.com.codeka.warworlds.model.ShieldManager;
import au.com.codeka.warworlds.model.Star;
import au.com.codeka.warworlds.model.StarManager;
import au.com.codeka.warworlds.model.StarSimulationQueue;

/**
 * This is a fragment which displays details about a single solar system.
 */
public class SolarSystemFragment extends Fragment {
    private static final Log log = new Log("SolarSystemFragment");
    private SolarSystemSurfaceView mSolarSystemSurfaceView;
    private ProgressBar mProgressBar;
    private Star mStar;
    private Planet mPlanet;
    private Colony mColony;
    private boolean mIsFirstRefresh;
    private View mView;
    private int starID;

    // needs to be Object so we can do a version check before instantiating the class
    Object mSolarSystemSurfaceViewOnLayoutChangedListener;

    private static final int BUILD_REQUEST = 3000;

    public Star getStar() {
        return mStar;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.solarsystem, container, false);

        mSolarSystemSurfaceView = (SolarSystemSurfaceView) mView.findViewById(R.id.solarsystem_view);
        mProgressBar = (ProgressBar) mView.findViewById(R.id.progress_bar);
        final Button buildButton = (Button) mView.findViewById(R.id.solarsystem_colony_build);
        final Button focusButton = (Button) mView.findViewById(R.id.solarsystem_colony_focus);
        final Button sitrepButton = (Button) mView.findViewById(R.id.sitrep_btn);
        final Button planetViewButton = (Button) mView.findViewById(R.id.enemy_empire_view);
        final Button emptyViewButton = (Button) mView.findViewById(R.id.empty_view_btn);
        final FleetListSimple fleetList = (FleetListSimple) mView.findViewById(R.id.fleet_list);
        final SelectionView selectionView = (SelectionView) mView.findViewById(R.id.selection);
        mSolarSystemSurfaceView.setSelectionView(selectionView);

        mIsFirstRefresh = true;
        if (savedInstanceState != null) {
            mIsFirstRefresh = savedInstanceState.getBoolean("au.com.codeka.warworlds.IsFirstRefresh");
        }

        mSolarSystemSurfaceView.addPlanetSelectedListener(
                new SolarSystemSurfaceView.OnPlanetSelectedListener() {
            @Override
            public void onPlanetSelected(Planet planet) {
                mPlanet = planet;
                refreshSelectedPlanet();
            }
        });

        buildButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mStar == null) {
                    return; // can happen before the star loads
                }

                Intent intent = new Intent(getActivity(), BuildActivity.class);
                intent.putExtra("au.com.codeka.warworlds.StarKey", mStar.getKey());

                Messages.Colony.Builder colony_pb = Messages.Colony.newBuilder();
                mColony.toProtocolBuffer(colony_pb);
                intent.putExtra("au.com.codeka.warworlds.Colony", colony_pb.build().toByteArray());

                startActivityForResult(intent, BUILD_REQUEST);
            }
        });

        focusButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mStar == null || mStar.getPlanets() == null || mColony == null) {
                    return;
                }

                FocusDialog dialog = new FocusDialog();
                dialog.setColony(mStar, mColony);
                dialog.show(getActivity().getSupportFragmentManager(), "");
            }
        });

        sitrepButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mStar == null) {
                    return; // can happen before the star loads
                }

{'fraction_non_alphanumeric': 0.09391522537861816, 'fraction_numerical': 0.0010753651760910476, 'mean_word_length': 3.130273871206514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3024942', 'n_tokens_mistral': 3278, 'n_tokens_neox': 3139, 'n_words': 607}