package com.lloydm.geosword.activities;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.lloydm.geosword1.R;
import com.lloydm.geosword.common.MyHandler;
import com.lloydm.geosword.common.StandardGameMenuActivity;
import com.lloydm.geosword.common.UploadCompleteBroadcastReceiver;
import com.lloydm.geosword.common.UploadService;

public class InspectFleetActivity extends StandardGameMenuActivity
{

     private final static String TAG = "com.lloydm.geosword.activities.InspectFleetActivity";
     private final static int UPDATETIMER = 0;

     private int gameid = -1;
     private int playerid = -1;
     private int teamid = -1;
     private int fleetid = -1;
     private int shipid = -1;
     private int shiptypeid = -1;

     private int[] fleetids = null;
     private String[] fleetnames = null;
     private int[] shipids = null;
     private int[] shiptypeids = null;
     private int[] currenthp = null;
     private float[] build = null;
     private int[] aigroupids = null;
     private int[] buildtimes = null;
     private String aisliders = "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555";

     private ArrayAdapter<String> fleetadapter = null;

     private Button btnlaunchattack = null;
     private Button[] btnshipdetail = null;
     private Button[] btngroupai = null;

     private TextView txtcapclock = null;
     private TextView txtcrsclock = null;
     private TextView txtbmbclock = null;
     private TextView txtfgtclock = null;

     private int bcaptime = 0;
     private int bcrstime = 0;
     private int bbmbtime = 0;
     private int bfgttime = 0;

     private ProgressBar progwheel = null;
     private TextView txtrepairs = null;

     private Button[] imgicons = null;

     private volatile boolean goingback = true;
     private volatile boolean waiting = false;

     private String currentfleetinfo = "";

     private volatile boolean anyshipsbeingrepaired = false;

     private UploadCompleteBroadcastReceiver receiver = null;

     @Override
     protected void onCreate(Bundle savedInstanceState)
     {
                     super.onCreate(savedInstanceState);
     }

     @Override
     public void setup()
     {
                     setContentView(R.layout.activity_inspectfleet);
                     mainview = (View) findViewById(R.layout.activity_inspectfleet);

                     worldcampaign = getIntent().getBooleanExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.worldcampaign", false);
                     if (!worldcampaign)
                     {
                                     setreceiver();
                     }
                     gameid = getIntent().getIntExtra("com.lloydm.geosword.common.UploadService.gameid", -1);
                     playerid = getIntent().getIntExtra("com.lloydm.geosword.common.UploadService.playerid", -1);
                     fleetid = getIntent().getIntExtra("com.lloydm.geosword.common.UploadService.fleetid", -1);
                     teamid = getIntent().getIntExtra("com.lloydm.geosword.common.UploadService.teamid", -1);

                     if (gameid != -1 && playerid != -1 && fleetid != -1 && teamid != -1)
                     {
                                     saveprefs("game_data_fleetids_" + Integer.toString(gameid) + "_" + Integer.toString(playerid) + "_" + Integer.toString(teamid) + "_" + Integer.toString(fleetid), "1");
                     }
                     if (gameid != -1 && playerid != -1 && teamid != -1 && fleetid == -1)
                     {
                                     String myfleetid = getprefs("game_data_ifleet_" + Integer.toString(gameid) + "_" + Integer.toString(playerid) + "_" + Integer.toString(teamid), "none");
                                     if (!myfleetid.equals("none"))

                                     {
                                                     fleetid = Integer.decode(myfleetid);
                                                     saveprefs("game_data_fleetids_" + Integer.toString(gameid) + "_" + Integer.toString(playerid) + "_" + Integer.toString(teamid) + "_" + Integer.toString(fleetid), "1");
                                     }

                     }

                     progwheel = (ProgressBar) findViewById(R.id.progressbar1);
                     if (!worldcampaign)
                     {
                                     progwheel.setVisibility(View.VISIBLE);
                     }
                     txtrepairs = (TextView) findViewById(R.id.txtrepairs);
                     txtrepairs.setTypeface(font);

                     txtcapclock = (TextView) findViewById(R.id.txtcapbuildtime);
                     txtcrsclock = (TextView) findViewById(R.id.txtcrsbuildtime);
                     txtbmbclock = (TextView) findViewById(R.id.txtbmbbuildtime);
                     txtfgtclock = (TextView) findViewById(R.id.txtfgtbuildtime);

                     btnback = (Button) findViewById(R.id.btnback4);
                     btnback.setOnClickListener(new View.OnClickListener()
                     {

                                     @Override
                                     public void
onClick(View v)
                                     {
                                                     goingback = true;
                                                     finish();
                                     }
                     })
;

                     handler = new MyHandler()
                     {
                                     public void handleMessage(Message msg)
                                     {
                                                     if (msg.what == UPDATETIMER)
                                                     {
                                                                     runOnUiThread(new Runnable()
                                                                     {
                                                                                     @Override
                                                                                     public void
run()
                                                                                     {
                                                                                                     if (bcaptime > 0)
                                                                                                     {
                                                                                                                     bcaptime--;
                                                                                                                     txtcapclock.setText(timetotext(bcaptime));
                                                                                                                     txtcapclock.setVisibility(View.VISIBLE);
                                                                                                                     txtcapclock.invalidate();
                                                                                                                     if (bcaptime == 0)
                                                                                                                     {
                                                                                                                                     // should work - we are simply trying to get the list again....
                                                                                                                                     if (!waiting)
                                                                                                                                     {
                                                                                                                                                     requestlist();
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     txtcapclock.setVisibility(View.INVISIBLE);
                                                                                                     }
                                                                                                     if (bcrstime > 0)
                                                                                                     {
                                                                                                                     bcrstime--;
                                                                                                                     txtcrsclock.setText(timetotext(bcrstime));
                                                                                                                     txtcrsclock.setVisibility(View.VISIBLE);
                                                                                                                     txtcrsclock.invalidate();
                                                                                                                     if (bcrstime == 0)
                                                                                                                     {
                                                                                                                                     // should work - we are simply trying to get the list again....
                                                                                                                                     if (!waiting)
                                                                                                                                     {
                                                                                                                                                     requestlist();
                                                                                                                                     }
                                                                                                                     }
                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     txtcrsclock.setVisibility(View.INVISIBLE);
                                                                                                     }
                                                                                                     if (bbmbtime > 0)
                                                                                                     {
                                                                                                                     bbmbtime--;
                                                                                                                     txtbmbclock.setText(timetotext(bbmbtime));
                                                                                                                     txtbmbclock.setVisibility(View.VISIBLE);
                                                                                                                     txtbmbclock.invalidate();
                                                                                                                     if (bbmbtime == 0)
                                                                                                                     {
                                                                                                                                     // should work - we are simply trying to get the list again....
                                                                                                                                     if (!waiting)
                                                                                                                                     {
                                                                                                                                                     requestlist();
                                                                                                                                     }
                                                                                                                     }
                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     txtbmbclock.setVisibility(View.INVISIBLE);
                                                                                                     }
                                                                                                     if (bfgttime > 0)
                                                                                                     {
                                                                                                                     bfgttime--;
                                                                                                                     txtfgtclock.setText(timetotext(bfgttime));
                                                                                                                     txtfgtclock.setVisibility(View.VISIBLE);
                                                                                                                     txtfgtclock.invalidate();
                                                                                                                     if (bfgttime == 0)
                                                                                                                     {
                                                                                                                                     // should work - we are simply trying to get the list again....
                                                                                                                                     if (!waiting)
                                                                                                                                     {
                                                                                                                                                     requestlist();
                                                                                                                                     }
                                                                                                                     }
                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     txtfgtclock.setVisibility(View.INVISIBLE);
                                                                                                     }
                                                                                                     try
                                                                                                     {
                                                                                                                     Message msg = new Message();
                                                                                                                     msg.what = UPDATETIMER;
                                                                                                                     handler.sendMessageDelayed(msg, 1000);
                                                                                                     }
                                                                                                     catch (Exception f)
                                                                                                     {

                                                                                                     }
                                                                                     }
                                                                     });
                                                     }
                                     }
                     };

                     // on click
                     btnlaunchattack = (Button) findViewById(R.id.btnattack);
                     if (!worldcampaign)
                     {
                                     btnlaunchattack.setEnabled(false);
                     }
                     btnlaunchattack.setTypeface(font);
                     btnlaunchattack.setOnClickListener(new View.OnClickListener()
                     {
                                     @Override
                                     public void
onClick(View v)
                                     {
                                                     if (fleetid != -1 && gameid != -1 && playerid != -1)
                                                     {
                                                                     onChangeActivity(1);
                                                     }
                                                     if (worldcampaign)
                                                     {
                                                                     onChangeActivity(11);
                                                     }
                                     }
                     });
                     // on click....

                     btnshipdetail = new Button[4];
                     btngroupai = new Button[4];

                     imgicons = new Button[16];

                     imgicons[0] = (Button) findViewById(R.id.imghpicon1);
                     imgicons[1] = (Button) findViewById(R.id.imghpicon2);
                     imgicons[2] = (Button) findViewById(R.id.imghpicon3);
                     imgicons[3] = (Button) findViewById(R.id.imghpicon4);
                     imgicons[4] = (Button) findViewById(R.id.imghpicon5);
                     imgicons[5] = (Button) findViewById(R.id.imghpicon6);
                     imgicons[6] = (Button) findViewById(R.id.imghpicon7);
                     imgicons[7] = (Button) findViewById(R.id.imghpicon8);
                     imgicons[8] = (Button) findViewById(R.id.imghpicon9);
                     imgicons[9] = (Button) findViewById(R.id.imghpicon10);
                     imgicons[10] = (Button) findViewById(R.id.imghpicon11);
                     imgicons[11] = (Button) findViewById(R.id.imghpicon12);
                     imgicons[12] = (Button) findViewById(R.id.imghpicon13);
                     imgicons[13] = (Button) findViewById(R.id.imghpicon14);
                     imgicons[14] = (Button) findViewById(R.id.imghpicon15);
                     imgicons[15] = (Button) findViewById(R.id.imghpicon16);

                     for (int i = 0; i < 16; i++)
                     {
                                     imgicons[i].setEnabled(false);
                     }

                     btnshipdetail[0] = (Button) findViewById(R.id.btnship1);
                     btnshipdetail[1] = (Button) findViewById(R.id.btnship2);
                     // btnshipdetail[2] = (Button) findViewById(R.id.btnship3);
                     // btnshipdetail[3] = (Button) findViewById(R.id.btnship4);
                     btnshipdetail[2] = (Button) findViewById(R.id.btnship5);
                     // btnshipdetail[5] = (Button) findViewById(R.id.btnship6);
                     // btnshipdetail[6] = (Button) findViewById(R.id.btnship7);
                     // btnshipdetail[7] = (Button) findViewById(R.id.btnship8);
                     btnshipdetail[3] = (Button) findViewById(R.id.btnship9);
                     // btnshipdetail[9] = (Button) findViewById(R.id.btnship10);
                     // btnshipdetail[10] = (Button) findViewById(R.id.btnship11);
                     // btnshipdetail[11] = (Button) findViewById(R.id.btnship12);
                     // btnshipdetail[12] = (Button) findViewById(R.id.btnship13);
                     // btnshipdetail[13] = (Button) findViewById(R.id.btnship14);
                     // btnshipdetail[14] = (Button) findViewById(R.id.btnship15);
                     // btnshipdetail[15] = (Button) findViewById(R.id.btnship16);

                     btngroupai[0] = (Button) findViewById(R.id.btnship1ai);

                     btngroupai[1] = (Button) findViewById(R.id.btnship2ai);
                     // btngroupai[2] = (Button) findViewById(R.id.btnship3ai);
                     // btngroupai[3] = (Button) findViewById(R.id.btnship4ai);
                     btngroupai[2] = (Button) findViewById(R.id.btnship5ai);
                     // btngroupai[5] = (Button) findViewById(R.id.btnship6ai);
                     // btngroupai[6] = (Button) findViewById(R.id.btnship7ai);
                     // btngroupai[7] = (Button) findViewById(R.id.btnship8ai);
                     btngroupai[3] = (Button) findViewById(R.id.btnship9ai);
                     // btngroupai[9] = (Button) findViewById(R.id.btnship10ai);
                     // btngroupai[10] = (Button) findViewById(R.id.btnship11ai);
                     // btngroupai[12] = (Button) findViewById(R.id.btnship13ai);
                     // btngroupai[13] = (Button) findViewById(R.id.btnship14ai);
                     // btngroupai[14] = (Button) findViewById(R.id.btnship15ai);
                     // btngroupai[15] = (Button) findViewById(R.id.btnship16ai);

                     for (int i = 0; i < 4; i++)
                     {
                                     if (!worldcampaign)
                                     {
                                                     btnshipdetail[i].setEnabled(false);
                                                     btngroupai[i].setEnabled(false);
                                     }
                                     btngroupai[i].setActivated(false);
                                     btnshipdetail[i].setId(i);
                                     btnshipdetail[i].setOnClickListener(new View.OnClickListener()
                                     {

                                                     @Override
                                                     public void
onClick(View v)
                                                     {
                                                                     // if (fleetid != -1 && playerid != -1 && gameid != -1)
                                                                     // {
                                                                     /*
                                                                         * int mid = 0; if(v.getId()>0 && v.getId()<4) { mid = 1; } if(v.getId()>4 && v.getId()<9) { mid = 2; } if(v.getId()>=9 ) { mid = 3; }
                                                                         *
/
                                                                     /*
                                                                         * int mid = v.getId(); if(mid==2) { mid= 4; } else { if(mid==3) { mid = 8; }
                                                                         *
                                                                         * }
                                                                         *
/
                                                                     int mid
=
v.getId();
                                                                     if (!worldcampaign)
                                                                     {
                                                                                     if (mid == 0)
                                                                                     {
                                                                                                     shipid = shipids[0];
                                                                                                     shiptypeid = 1;

                                                                                     }
                                                                                     if (mid == 1)
                                                                                     {
                                                                                                     shipid = shipids[1];
                                                                                                     shiptypeid = 2;
                                                                                     }
                                                                                     if (mid == 2)
                                                                                     {
                                                                                                     shipid = shipids[4];
                                                                                                     shiptypeid = 3;
                                                                                     }
                                                                                     if (mid == 3)
                                                                                     {
                                                                                                     shipid = shipids[8];
                                                                                                     shiptypeid = 4;
                                                                                     }
                                                                     }
                                                                     else
                                                                     {
                                                                                     shiptypeid = mid + 1;
                                                                     }

                                                                     if (worldcampaign)
                                                                     {
                                                                                     onChangeActivity(12);
                                                                     }
                                                                     else
                                                                     {
                                                                                     onChangeActivity(2);
                                                                     }
                                                                     // }
                                                     }
                                     });
                                     btngroupai[i].setId(i);
                                     btngroupai[i].setOnClickListener(new View.OnClickListener()
                                     {
                                                     @Override
                                                     public void
onClick(View v)
                                                     {
                                                                     // if (fleetid != -1 && playerid != -1 && gameid != -1)
                                                                     // {
                                                                     int mid = v.getId();
                                                                     if (!worldcampaign)
                                                                     {
                                                                                     if (mid == 0)
                                                                                     {
                                                                                                     shipid = shipids[0];
                                                                                                     shiptypeid = 1;

                                                                                     }
                                                                                     if (mid == 1)
                                                                                     {
                                                                                                     shipid = shipids[1];
                                                                                                     shiptypeid = 2;
                                                                                     }
                                                                                     if (mid == 2)
                                                                                     {
                                                                                                     shipid = shipids[4];
                                                                                                     shiptypeid = 3;
                                                                                     }
                                                                                     if (mid == 3)
                                                                                     {
                                                                                                     shipid = shipids[8];
                                                                                                     shiptypeid = 4;
                                                                                     }
                                                                     }
                                                                     else
                                                                     {
                                                                                     shiptypeid = mid + 1;
                                                                     }
                                                                     if (worldcampaign)
                                                                     {
                                                                                     onChangeActivity(13);
                                                                     }
                                                                     else
                                                                     {
                                                                                     onChangeActivity(3);
                                                                     }
                                                                     // }
                                                     }
                                     });
                     }
                     final String fleetinfo = getprefs("game_data_shipdata_" + Integer.toString(gameid) + "_" + Integer.toString(playerid) + "_" + Integer.toString(teamid) + "_" + Integer.toString(fleetid), "none");
                     currentfleetinfo = fleetinfo;
                     if (!fleetinfo.equals("none"))

                     {
                                     String[] rows = fleetinfo.substring(0, fleetinfo.length() - 1).split(":");
                                     int fi = 0;
                                     int si = 0;
                                     int numfleets = rows.length / 16;
                                     Log.d(TAG, "RowsLength:" + rows.length);
                                     Log.d(TAG, "Num Fleets:" + numfleets);
                                     if (rows.length > 0)
                                     {
                                                     fleetids = new int[numfleets]; // never changes
                                                     fleetnames = new String[numfleets]; // never changes
                                                     shipids = new int[numfleets * 16]; // never changes
                                                     shiptypeids = new int[numfleets * 16]; // never changes
                                                     currenthp = new int[numfleets * 16]; // ignore this one.....
                                                     aigroupids = new int[numfleets * 16]; // never changes
                                                     build = new float[numfleets * 16]; // ignore this one....
                                                     buildtimes = new int[numfleets * 16];
                                                     for (int i = 0; i < rows.length; i++)
                                                     {
                                                                     String[] fields = rows[i].split("\\|");

                                                                     if (fields.length > 0)
                                                                     {
                                                                                     if (i % 16 == 0)
                                                                                     {
                                                                                                     fleetids[fi] = Integer.decode(fields[0]);
                                                                                                     fleetnames[fi] = fields[1];
                                                                                                     aisliders = fields[2];

                                                                                                     shipids[fi * 16 + si] = Integer.decode(fields[3]);
                                                                                                     shiptypeids[fi * 16 + si] = Integer.decode(fields[4]);
                                                                                                     currenthp[fi * 16 + si] = Integer.decode(fields[5]); // most
                                                                                                                                                                                                                                                                                                                         // likely
                                                                                                                                                                                                                                                                                                                         // inaccurate
                                                                                                     build[fi * 16 + si] = Float.parseFloat(fields[6]); // most
                                                                                                                                                                                                                                                                                                                 // likely
                                                                                                                                                                                                                                                                                                                 // inaccurate
                                                                                                     aigroupids[fi * 16 + si] = Integer.decode(fields[7]);

                                                                                                     buildtimes[fi * 16 + si] = Integer.decode(fields[8]); // added 29-june-2015

                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     shipids[fi * 16 + si] = Integer.decode(fields[0]);
                                                                                                     shiptypeids[fi * 16 + si] = Integer.decode(fields[1]);
                                                                                                     currenthp[fi * 16 + si] = Integer.decode(fields[2]); // most
                                                                                                                                                                                                                                                                                                                         // likely
                                                                                                                                                                                                                                                                                                                         // inaccurate
                                                                                                     build[fi * 16 + si] = Float.parseFloat(fields[3]); // most
                                                                                                                                                                                                                                                                                                                 // likely
                                                                                                                                                                                                                                                                                                                 // inaccurate
                                                                                                     aigroupids[fi * 16 + si] = Integer.decode(fields[4]);
                                                                                                     buildtimes[fi * 16 + si] = Integer.decode(fields[5]);
                                                                                     }
                                                                     }
                                                                     if (i % 16 == 15)
                                                                     {
                                                                                     fi++;
                                                                                     si = 0;
                                                                     }
                                                                     else
                                                                     {
                                                                                     si++;
                                                                     }

                                                     }
                                                     boolean tmp = false;
                                                     // progwheel.setVisibility(View.INVISIBLE);
                                                     for (int i = 0; i < 4; i++)
                                                     {
                                                                     btnshipdetail[i].setEnabled(true);
                                                                     btngroupai[i].setEnabled(true);
                                                                     String ss = getprefs("game_data_aiset_" + Integer.toString(gameid) + "_" + Integer.toString(playerid) + "_" + Integer.toString(teamid) + "_" + Integer.toString(fleetid) + "_" + Integer.toString(i + 1), "0");
                                                                     if (ss != null)
                                                                     {
                                                                                     if (ss.equals("0"))

                                                                                     {
                                                                                                     btngroupai[i].setActivated(true);
                                                                                     }
                                                                     }
                                                     }
                                                     if (tmp)
                                                     {
                                                                     btnlaunchattack.setEnabled(true);
                                                     }
                                                     if (fleetadapter == null)
                                                     {
                                                                     fleetadapter = new ArrayAdapter<String>(InspectFleetActivity.this, android.R.layout.simple_spinner_dropdown_item, fleetnames);
                                                     }

                                                     int mcaptime
= 0;
                                                     int mcrstime = 0;
                                                     int mbmbtime = 0;
                                                     int mfgttime = 0;

                                                     for (int i = 0; i < 16; i++)
                                                     {
                                                                     fleetid = fleetids[0];

                                                                     // set clocks....
                                                                     if (shiptypeids[i] == 1)
                                                                     {
                                                                                     if (buildtimes[i] > mcaptime)
                                                                                     {
                                                                                                     mcaptime = buildtimes[i];

                                                                                     }
                                                                     }
                                                                     if (shiptypeids[i] == 2)
                                                                     {
                                                                                     if (buildtimes[i] > mcrstime)
                                                                                     {
                                                                                                     mcrstime = buildtimes[i];

                                                                                     }
                                                                     }
                                                                     if (shiptypeids[i] == 3)
                                                                     {
                                                                                     if (buildtimes[i] > mbmbtime)
                                                                                     {
                                                                                                     mbmbtime = buildtimes[i];

                                                                                     }
                                                                     }
                                                                     if (shiptypeids[i] == 4)
                                                                     {
                                                                                     if (buildtimes[i] > mfgttime)
                                                                                     {
                                                                                                     mfgttime = buildtimes[i];

                                                                                     }
                                                                     }
                                                                     if (teamid == 1)
                                                                     {
                                                                                     if (shiptypeids[i] == 1)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_1_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_1_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_1_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_1_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }
                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_1_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 2)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_2_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_2_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_2_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_2_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_2_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 3)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_3_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_3_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_3_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_3_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_3_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 4)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_4_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_4_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_4_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_4_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_4_1);
                                                                                                     }
                                                                                     }
                                                                     }
                                                                     if (teamid == 2)
                                                                     {
                                                                                     if (shiptypeids[i] == 1)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {

                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_1_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_1_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_1_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_1_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_1_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 2)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_2_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_2_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_2_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_2_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_2_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 3)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_3_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_3_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_3_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_3_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_3_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 4)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_4_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_4_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_4_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_4_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_4_1);
                                                                                                     }
                                                                                     }
                                                                     }
                                                                     if (teamid == 3)
                                                                     {
                                                                                     if (shiptypeids[i] == 1)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_1_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_1_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_1_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_1_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_1_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 2)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_2_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_2_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_2_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_2_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_2_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 3)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_3_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_3_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_3_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_3_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_3_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 4)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_4_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_4_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_4_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_4_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_4_1);
                                                                                                     }
                                                                                     }
                                                                     }
                                                                     if (teamid == 4)
                                                                     {
                                                                                     if (shiptypeids[i] == 1)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_1_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_1_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_1_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_1_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_1_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 2)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_2_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_2_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_2_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_2_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_2_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 3)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_3_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_3_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_3_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_3_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_3_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 4)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_4_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_4_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_4_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_4_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_4_1);
                                                                                                     }
                                                                                     }
                                                                     }
                                                                     if (teamid == 5)
                                                                     {
                                                                                     if (shiptypeids[i] == 1)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_1_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_1_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_1_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_1_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_1_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 2)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_2_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_2_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_2_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_2_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_2_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 3)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_3_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_3_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_3_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_3_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_3_1);
                                                                                                     }
                                                                                     }
                                                                                     if (shiptypeids[i] == 4)
                                                                                     {
                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                     {
                                                                                                                     if (build[i] < 0.25)
                                                                                                                     {
                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_4_2);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                     {
                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_4_2_3);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_4_2_2);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_4_2_1);
                                                                                                                                                     }
                                                                                                                                     }
                                                                                                                     }

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_4_1);
                                                                                                     }
                                                                                     }
                                                                     }
                                                                     imgicons[i].setVisibility(View.VISIBLE);
                                                                     imgicons[i].invalidate();
                                                     }

                                                     bcaptime = mcaptime;
                                                     bcrstime = mcrstime;
                                                     bbmbtime = mbmbtime;
                                                     bfgttime = mfgttime;

                                     }
                     }
                     else
                     {
                                     if (!worldcampaign)
                                     {
                                                     if (teamid == 1)
                                                     {
                                                                     bvidresid = R.raw.fltmovt1;
                                                     }
                                                     if (teamid == 2)
                                                     {
                                                                     bvidresid = R.raw.fltmovt2;
                                                     }
                                                     if (teamid == 3)
                                                     {
                                                                     bvidresid = R.raw.fltmovt3;
                                                     }
                                                     if (teamid == 4)
                                                     {
                                                                     bvidresid = R.raw.fltmovt4;
                                                     }
                                                     if (teamid == 5)
                                                     { // change this when Brandie sends it through....
                                                                     bvidresid = R.raw.fltmovt5;
                                                     }
                                                     bhidevidonfinish = true;
                                                     bvideo = (SurfaceView) findViewById(R.id.surfacevidfleet);
                                                     bvideo.setVisibility(View.VISIBLE);
                                                     txtwait = (TextView) findViewById(R.id.txtpleasewait1);
                                                     txtwait.setTypeface(font);
                                                     txtwait.setVisibility(View.VISIBLE);

                                     }

                                     if (worldcampaign)
                                     {
                                                     for (int i = 0; i < 16; i++)
                                                     {
                                                                     if (teamid == 1)
                                                                     {
                                                                                     if (i == 0)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_1_1);
                                                                                     }
                                                                                     if (i > 0 && i < 4)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_2_1);
                                                                                     }
                                                                                     if (i > 3 && i < 8)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_3_1);
                                                                                     }
                                                                                     if (i > 7)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_4_1);
                                                                                     }
                                                                     }
                                                                     if (teamid == 2)
                                                                     {
                                                                                     if (i == 0)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_1_1);
                                                                                     }
                                                                                     if (i > 0 && i < 4)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_2_1);
                                                                                     }
                                                                                     if (i > 3 && i < 8)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_3_1);
                                                                                     }
                                                                                     if (i > 7)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_2_4_1);
                                                                                     }
                                                                     }
                                                                     if (teamid == 3)
                                                                     {
                                                                                     if (i == 0)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_1_1);
                                                                                     }
                                                                                     if (i > 0 && i < 4)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_2_1);
                                                                                     }
                                                                                     if (i > 3 && i < 8)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_3_1);
                                                                                     }
                                                                                     if (i > 7)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_3_4_1);
                                                                                     }
                                                                     }
                                                                     if (teamid == 4)
                                                                     {
                                                                                     if (i == 0)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_1_1);
                                                                                     }
                                                                                     if (i > 0 && i < 4)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_2_1);
                                                                                     }
                                                                                     if (i > 3 && i < 8)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_3_1);
                                                                                     }
                                                                                     if (i > 7)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_4_4_1);
                                                                                     }
                                                                     }
                                                                     if (teamid == 5)
                                                                     {
                                                                                     if (i == 0)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_1_1);
                                                                                     }
                                                                                     if (i > 0 && i < 4)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_2_1);
                                                                                     }
                                                                                     if (i > 3 && i < 8)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_3_1);
                                                                                     }
                                                                                     if (i > 7)
                                                                                     {
                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_5_4_1);
                                                                                     }
                                                                     }
                                                                     imgicons[i].setVisibility(View.VISIBLE);
                                                                     imgicons[i].invalidate();
                                                     }

                                     }
                     }
                     if (!worldcampaign)
                     {
                                     requestlist();
                     }
     }

     @SuppressLint("InlinedApi")

     private void requestlist()
     {
                     if (waiting)
                     {
                                     newtoast("Please wait....trying to talk to database");
                                     return;
                     }
                     waiting = true;

                     Intent serviceintent = new Intent(InspectFleetActivity.this, UploadService.class);
                     if (Build.VERSION.SDK_INT >= 12)
                     {
                                     serviceintent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
                     }
                     serviceintent.setAction("com.lloydm.geosword.common.UploadService.inspectfleet.load");

                     serviceintent.putExtra("com.lloydm.geosword.common.UploadService.playerid", playerid);
                     serviceintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                     startService(serviceintent);

     }

     @Override
     protected void onResume()
     {
                     super.onResume();
                     if (!worldcampaign)
                     {
                                     setreceiver();
                                     // there is a chance that we have just returned from the login screen -
                                     // in which case....
                                     // if we are logged in then we most likely want to attempt to redownload
                                     // stuff....
                                     if (isloggedin() && loginstatuschanged())
                                     {
                                                     requestlist();
                                     }
                     }
                     Message msg = new Message();
                     msg.what = UPDATETIMER;
                     handler.sendMessageDelayed(msg, 1000);
                     setuphelp(R.string.htt_fleet, R.string.htxt_fleet, R.string.htt_fleet);
     }

     @Override
     protected void onPause()
     {
                     super.onPause();
                     if (receiver != null)
                     {
                                     unregisterReceiver(receiver);
                     }
                     receiver = null;
                     handler.removeCallbacksAndMessages(null);

                     if (isFinishing())
                     {
                                     if (goingback)
                                     {
                                                     // we want to start the first ingame menu...
                                                     if (worldcampaign)
                                                     {
                                                                     onChangeActivity(10);
                                                     }
                                                     else
                                                     {
                                                                     onChangeActivity(0);
                                                     }

                                     }
                     }
     }

     @Override
     public void onChangeActivity(int id)
     {
                     super.onChangeActivity(id);
                     if (id == 1)
                     {
                                     goingback = false;
                                     startActivity(new Intent(this, LaunchAttackActivity.class).putExtra("com.lloydm.geosword.common.UploadService.gameid", gameid).putExtra("com.lloydm.geosword.common.UploadService.playerid", playerid).putExtra("com.lloydm.geosword.common.UploadService.fleetid", fleetid).putExtra("com.lloydm.geosword.common.UploadService.teamid", teamid));
                                     finish();
                     }
                     if (id == 2)
                     {
                                     goingback = false;
                                     Log.d(TAG, "ShipTypeID:" + shiptypeid);

                                     startActivity(new Intent(this, ShipActivity.class).putExtra("com.lloydm.geosword.common.UploadService.gameid", gameid).putExtra("com.lloydm.geosword.common.UploadService.playerid", playerid).putExtra("com.lloydm.geosword.common.UploadService.shipid", shipid).putExtra("com.lloydm.geosword.common.UploadService.shiptypeid", shiptypeid).putExtra("com.lloydm.geosword.common.UploadService.fleetid", fleetid).putExtra("com.lloydm.geosword.common.UploadService.teamid", teamid).putExtra("com.lloydm.geosword.common.UploadService.fromai", 0));
                                     finish();
                     }
                     if (id == 3)
                     {
                                     goingback = false;
                                     startActivity(new Intent(this, ModifyAIActivity.class).putExtra("com.lloydm.geosword.common.UploadService.gameid", gameid).putExtra("com.lloydm.geosword.common.UploadService.playerid", playerid).putExtra("com.lloydm.geosword.common.UploadService.shipid", shipid).putExtra("com.lloydm.geosword.common.UploadService.fleetid", fleetid).putExtra("com.lloydm.geosword.common.UploadService.teamid", teamid).putExtra("com.lloydm.geosword.common.UploadService.shiptypeid", shiptypeid));
                                     saveprefs("game_data_aiset_" + Integer.toString(gameid) + "_" + Integer.toString(playerid) + "_" + Integer.toString(teamid) + "_" + Integer.toString(fleetid) + "_" + Integer.toString(shiptypeid), "1");
                                     finish();
                     }
                     if (id == 0)
                     {
                                     goingback = false;
                                     startActivity(new Intent(this, InGameFrontMenuActivity.class).putExtra("com.lloydm.geosword.common.UploadService.gameid", gameid).putExtra("com.lloydm.geosword.common.UploadService.playerid", playerid).putExtra("com.lloydm.geosword.common.UploadService.teamid", teamid));
                                     finish();
                     }
                     if (id == 10)
                     {
                                     goingback = false;
                                     startActivity(new Intent(this, MainMenuActivity.class));
                                     finish();
                     }

                     if (id == 11)
                     {
                                     goingback = false;
                                     startActivity(new Intent(this, Map3DActivity.class).putExtra("com.lloydm.geosword.common.UploadService.teamid", teamid));

                                     finish();
                     }
                     if (id == 12)
                     {
                                     goingback = false;
                                     Log.d(TAG, "ShipTypeID:" + shiptypeid);

                                     startActivity(new Intent(this, ShipActivity.class).putExtra("com.lloydm.geosword.common.UploadService.shiptypeid", shiptypeid).putExtra("com.lloydm.geosword.common.UploadService.fleetid", fleetid).putExtra("com.lloydm.geosword.common.UploadService.teamid", teamid).putExtra("com.lloydm.geosword.common.UploadService.fromai", 0).putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.worldcampaign", true));
                                     finish();
                     }
                     if (id == 13)
                     {
                                     goingback = false;
                                     startActivity(new Intent(this, ModifyAIActivity.class).putExtra("com.lloydm.geosword.common.UploadService.teamid", teamid).putExtra("com.lloydm.geosword.common.UploadService.shiptypeid", shiptypeid).putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.worldcampaign", true));
                                     finish();
                     }
     }

     private void
setreceiver()
     {
                     if (receiver == null)
                     {
                                     receiver = new UploadCompleteBroadcastReceiver()
                                     {
                                                     @Override
                                                     public void
onReceive(Context context, Intent intent)
                                                     {

                                                                     // the intent will contain the response from the
                                                                     // server.....either true or false....very simple - that's
                                                                     // all we care
                                                                     // about when we send information to the server...and
                                                                     // possibly an error code...
                                                                     Log.d(TAG, "Fleet Info Receiver Received");

                                                                     boolean success = intent.getBooleanExtra("com.lloydm.geosword.activities.InspectFleetActivity.resultcode", false);

                                                                     long tuid = intent.getLongExtra("com.lloydm.geosword.common.UploadService.uniqueid", -1);
                                                                     if (tuid != uid)
                                                                     {
                                                                                     // ignore this one and try again.....
                                                                                     Log.i(TAG, "uid does not match");
                                                                                     success = false;

                                                                     }

                                                                     if (success)
                                                                     {
                                                                                     runOnUiThread(new Runnable()
                                                                                     {
                                                                                                     @Override
                                                                                                     public void
run()
                                                                                                     {
                                                                                                                     progwheel.setVisibility(View.INVISIBLE);
                                                                                                     }
                                                                                     });
                                                                                     Log.d(TAG, "Fleet Info Success");
                                                                                     final String fleetinfo = intent.getStringExtra("com.lloydm.geosword.activities.InspectFleetActivity.fleetinfo");

                                                                                     // if there is absolutely no difference between the
                                                                                     // currentfleetinfo and the
                                                                                     // one here then behave a little differently....

                                                                                     if (fleetinfo.equals(currentfleetinfo))
                                                                                     {
                                                                                                     // only thing we may do is enable the attack
                                                                                                     // button....if we can......
                                                                                                     for (int i = 0; i < 16; i++)
                                                                                                     {
                                                                                                                     if (currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f))
                                                                                                                     {

                                                                                                                                     runOnUiThread(new Runnable()
                                                                                                                                     {

                                                                                                                                                     @Override
                                                                                                                                                     public void
run()
                                                                                                                                                     {
                                                                                                                                                                     btnlaunchattack.setEnabled(true);
                                                                                                                                                     }
                                                                                                                                     })
;
                                                                                                                                     break;
                                                                                                                     }
                                                                                                     }
                                                                                                     /*
                                                                                                         * runOnUiThread(new Runnable() {
                                                                                                         *
                                                                                                         * @Override public void run() {
                                                                                                         *
                                                                                                         * } })
;
                                                                                                         *
/
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     // load everything as normal......
                                                                                                     Log.d(TAG, "Fleet Info - Inspect Fleet Receiver:" + fleetinfo);
                                                                                                     runOnUiThread(new Runnable()
                                                                                                     {

                                                                                                                     @Override
                                                                                                                     public void
run()
                                                                                                                     {
                                                                                                                                     // 21|Goodblokes
                                                                                                                                     // Fleet|257|1|2500|0|1:258|2|750|0|2:259|2|750|0|3:260|2|750|0|4:261|3|25|0|5:262|3|25|0|6:263|3|25|0|7:264|3|25|0|8:265|4|12|0|9:266|4|12|0|10:267|4|12|0|11:268|4|12|0|12:269|4|12|0|13:270|4|12|0|14:271|4|12|0|15:272|4|12|0|0:
                                                                                                                                     String[] rows = fleetinfo.substring(0, fleetinfo.length() - 1).split(":");
                                                                                                                                     int fi = 0;
                                                                                                                                     int si = 0;
                                                                                                                                     int numfleets = rows.length / 16;
                                                                                                                                     Log.d(TAG, "RowsLength:" + rows.length);
                                                                                                                                     Log.d(TAG, "Num Fleets:" + numfleets);
                                                                                                                                     if (rows.length > 0)
                                                                                                                                     {
                                                                                                                                                     fleetids = new int[numfleets];
                                                                                                                                                     fleetnames = new String[numfleets];
                                                                                                                                                     shipids = new int[numfleets * 16];
                                                                                                                                                     shiptypeids = new int[numfleets * 16];
                                                                                                                                                     currenthp = new int[numfleets * 16];
                                                                                                                                                     aigroupids = new int[numfleets * 16];
                                                                                                                                                     build = new float[numfleets * 16];
                                                                                                                                                     buildtimes = new int[numfleets * 16];
                                                                                                                                                     for (int i = 0; i < rows.length; i++)
                                                                                                                                                     {
                                                                                                                                                                     String[] fields = rows[i].split("\\|");

                                                                                                                                                                     if (fields.length > 0)
                                                                                                                                                                     {
                                                                                                                                                                                     if (i % 16 == 0)
                                                                                                                                                                                     {
                                                                                                                                                                                                     fleetids[fi] = Integer.decode(fields[0]);
                                                                                                                                                                                                     fleetnames[fi] = fields[1];
                                                                                                                                                                                                     aisliders = fields[2];
                                                                                                                                                                                                     shipids[fi * 16 + si] = Integer.decode(fields[3]);
                                                                                                                                                                                                     shiptypeids[fi * 16 + si] = Integer.decode(fields[4]);
                                                                                                                                                                                                     currenthp[fi * 16 + si] = Integer.decode(fields[5]);
                                                                                                                                                                                                     build[fi * 16 + si] = Float.parseFloat(fields[6]);
                                                                                                                                                                                                     aigroupids[fi * 16 + si] = Integer.decode(fields[7]);
                                                                                                                                                                                                     buildtimes[fi * 16 + si] = Integer.decode(fields[8]);

                                                                                                                                                                                     }
                                                                                                                                                                                     else
                                                                                                                                                                                     {
                                                                                                                                                                                                     shipids[fi * 16 + si] = Integer.decode(fields[0]);
                                                                                                                                                                                                     shiptypeids[fi * 16 + si] = Integer.decode(fields[1]);
                                                                                                                                                                                                     currenthp[fi * 16 + si] = Integer.decode(fields[2]);
                                                                                                                                                                                                     build[fi * 16 + si] = Float.parseFloat(fields[3]);
                                                                                                                                                                                                     aigroupids[fi * 16 + si] = Integer.decode(fields[4]);
                                                                                                                                                                                                     buildtimes[fi * 16 + si] = Integer.decode(fields[5]);
                                                                                                                                                                                     }
                                                                                                                                                                     }
                                                                                                                                                                     if (i % 16 == 15)
                                                                                                                                                                     {
                                                                                                                                                                                     fi++;
                                                                                                                                                                                     si = 0;
                                                                                                                                                                     }
                                                                                                                                                                     else
                                                                                                                                                                     {
                                                                                                                                                                                     si++;
                                                                                                                                                                     }
                                                                                                                                                     }
                                                                                                                                                     boolean tmp = false;
                                                                                                                                                     for (int i = 0; i < 16; i++)
                                                                                                                                                     {
                                                                                                                                                                     if (currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f))
                                                                                                                                                                     {
                                                                                                                                                                                     tmp = true;
                                                                                                                                                                     }
                                                                                                                                                     }
                                                                                                                                                     for (int i = 0; i < 4; i++)
                                                                                                                                                     {
                                                                                                                                                                     btnshipdetail[i].setEnabled(true);
                                                                                                                                                                     btngroupai[i].setEnabled(true);
                                                                                                                                                                     String ss = getprefs("game_data_aiset_" + Integer.toString(gameid) + "_" + Integer.toString(playerid) + "_" + Integer.toString(teamid) + "_" + Integer.toString(fleetid) + "_" + Integer.toString(i + 1), "0");
                                                                                                                                                                     if (ss != null)
                                                                                                                                                                     {
                                                                                                                                                                                     if (ss.equals("0"))

                                                                                                                                                                                     {
                                                                                                                                                                                                     btngroupai[i].setActivated(true);
                                                                                                                                                                                     }
                                                                                                                                                                     }
                                                                                                                                                     }
                                                                                                                                                     if (tmp)
                                                                                                                                                     {
                                                                                                                                                                     btnlaunchattack.setEnabled(true);
                                                                                                                                                     }

                                                                                                                                                     if (fleetadapter == null)
                                                                                                                                                     {
                                                                                                                                                                     fleetadapter = new ArrayAdapter<String>(InspectFleetActivity.this, android.R.layout.simple_spinner_dropdown_item, fleetnames);
                                                                                                                                                     }
                                                                                                                                                     else
                                                                                                                                                     {
                                                                                                                                                                     // fleetadapter.clear();
                                                                                                                                                                     // for(int
                                                                                                                                                                     // i=0;i<fleetnames.length;i++)
                                                                                                                                                                     // {
                                                                                                                                                                     // fleetadapter.add(fleetnames[i]);
                                                                                                                                                                     // }
                                                                                                                                                                     // fleetadapter.notifyDataSetChanged();
                                                                                                                                                     }

                                                                                                                                                     int mcaptime
=
0;
                                                                                                                                                     int mcrstime = 0;
                                                                                                                                                     int mbmbtime = 0;
                                                                                                                                                     int mfgttime = 0;

                                                                                                                                                     for (int i = 0; i < 16; i++)
                                                                                                                                                     {
                                                                                                                                                                     fleetid = fleetids[0];

                                                                                                                                                                     if (shiptypeids[i] == 1)
                                                                                                                                                                     {
                                                                                                                                                                                     if (buildtimes[i] > mcaptime)
                                                                                                                                                                                     {
                                                                                                                                                                                                     mcaptime = buildtimes[i];

                                                                                                                                                                                     }
                                                                                                                                                                     }
                                                                                                                                                                     if (shiptypeids[i] == 2)
                                                                                                                                                                     {
                                                                                                                                                                                     if (buildtimes[i] > mcrstime)
                                                                                                                                                                                     {
                                                                                                                                                                                                     mcrstime = buildtimes[i];

                                                                                                                                                                                     }
                                                                                                                                                                     }
                                                                                                                                                                     if (shiptypeids[i] == 3)
                                                                                                                                                                     {
                                                                                                                                                                                     if (buildtimes[i] > mbmbtime)
                                                                                                                                                                                     {
                                                                                                                                                                                                     mbmbtime = buildtimes[i];

                                                                                                                                                                                     }
                                                                                                                                                                     }
                                                                                                                                                                     if (shiptypeids[i] == 4)
                                                                                                                                                                     {
                                                                                                                                                                                     if (buildtimes[i] > mfgttime)
                                                                                                                                                                                     {
                                                                                                                                                                                                     mfgttime = buildtimes[i];

                                                                                                                                                                                     }
                                                                                                                                                                     }

                                                                                                                                                                     if (teamid == 1)
                                                                                                                                                                     {
                                                                                                                                                                                     if (shiptypeids[i] == 1)
                                                                                                                                                                                     {
                                                                                                                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                                                                                                                     {
                                                                                                                                                                                                                     anyshipsbeingrepaired = true;
                                                                                                                                                                                                                     if (build[i] < 0.25)
                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_1_2);
                                                                                                                                                                                                                     }
                                                                                                                                                                                                                     else
                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_1_2_3);
                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                     else
                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_1_2_2);
                                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                                     else
                                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_1_2_1);
                                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                     }
                                                                                                                                                                                                     }
                                                                                                                                                                                                     else
                                                                                                                                                                                                     {
                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_1_1);
                                                                                                                                                                                                     }
                                                                                                                                                                                     }
                                                                                                                                                                                     if (shiptypeids[i] == 2)
                                                                                                                                                                                     {
                                                                                                                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                                                                                                                     {
                                                                                                                                                                                                                     anyshipsbeingrepaired = true;
                                                                                                                                                                                                                     if (build[i] < 0.25)
                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_2_2);
                                                                                                                                                                                                                     }
                                                                                                                                                                                                                     else
                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_2_2_3);
                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                     else
                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_2_2_2);
                                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                                     else
                                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_2_2_1);
                                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                     }

                                                                                                                                                                                                     }
                                                                                                                                                                                                     else
                                                                                                                                                                                                     {
                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_2_1);
                                                                                                                                                                                                     }
                                                                                                                                                                                     }
                                                                                                                                                                                     if (shiptypeids[i] == 3)
                                                                                                                                                                                     {
                                                                                                                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                                                                                                                     {
                                                                                                                                                                                                                     anyshipsbeingrepaired = true;
                                                                                                                                                                                                                     if (build[i] < 0.25)
                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_3_2);
                                                                                                                                                                                                                     }
                                                                                                                                                                                                                     else
                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                     if (build[i] < 0.5)
                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_3_2_3);
                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                     else
                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                     if (build[i] < 0.75)
                                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_3_2_2);
                                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                                     else
                                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_3_2_1);
                                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                     }

                                                                                                                                                                                                     }
                                                                                                                                                                                                     else
                                                                                                                                                                                                     {
                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_3_1);
                                                                                                                                                                                                     }
                                                                                                                                                                                     }
                                                                                                                                                                                     if (shiptypeids[i] == 4)
                                                                                                                                                                                     {
                                                                                                                                                                                                     if (!(currenthp[i] > 0 && (build[i] == 0 || build[i] >= 1.0f)))
                                                                                                                                                                                                     {
                                                                                                                                                                                                                     anyshipsbeingrepaired = true;
                                                                                                                                                                                                                     if (build[i] < 0.25)
                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                     imgicons[i].setBackgroundResource(R.drawable.ship_1_4_2);
                                                                                                                                                                                                                     }
                                                                                                                                                                                                                     else
                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                     if (build[i] < 0.5)
                                                                                                &nb