Back to project page PowerGridCompanion.
The source code is released under:
Apache License
If you think the Android project PowerGridCompanion listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.mintcode.kris.powergridhelper.Activities; /* w w w . j a v a 2 s.c om*/ import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import com.mintcode.kris.powergridhelper.Adapters.PlayerOrderAdapter; import com.mintcode.kris.powergridhelper.Adapters.PowerPlantAdapter; import com.mintcode.kris.powergridhelper.Models.Player; import com.mintcode.kris.powergridhelper.R; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; public class PowerPlantAuctionActivity extends Activity { public ArrayList<Player> playerList; public HashMap<String,Integer> resourceList; int stage; Context mContext; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_power_plant_auction); mContext = this; Bundle extras = getIntent().getExtras(); resourceList = new HashMap<String, Integer>(); playerList = extras.getParcelableArrayList("PlayerList"); resourceList.put("Coal",extras.getInt("Coal")); resourceList.put("Oil",extras.getInt("Oil")); resourceList.put("Garbage",extras.getInt("Garbage")); resourceList.put("Uranium",extras.getInt("Uranium")); stage = extras.getInt("Stage"); this.getActionBar().setTitle("Power Plant Auction"); ListView lv = (ListView)findViewById(R.id.PlantAuctionListView); lv.setAdapter(new PowerPlantAdapter(this,R.id.PlantAuctionListView,playerList)); //ResourceBar LinearLayout resourceLayout = (LinearLayout)findViewById(R.id.Resources); //Coal int coalCost = (9 - (resourceList.get("Coal") / 3)); int coalAvil = (3 - (resourceList.get("Coal") % 3)); LinearLayout coalLayout = (LinearLayout)findViewById(R.id.CoalLayout); TextView coalCostTv = (TextView)coalLayout.findViewById(R.id.CoalCostAuction); TextView coalAvilTv = (TextView)coalLayout.findViewById(R.id.CoalAvailableAuction); if(resourceList.get("Coal") > 0) { coalCostTv.setText("$" + coalCost); coalAvilTv.setText(coalAvil + " Left"); }else{ coalCostTv.setText(""); coalAvilTv.setText("SOLD OUT"); } //Oil int oilCost = (9 - (resourceList.get("Oil") / 3)); int oilAvil = (3 - (resourceList.get("Oil") % 3)); LinearLayout oilLayout = (LinearLayout)findViewById(R.id.OilLayout); TextView oilCostTv = (TextView)oilLayout.findViewById(R.id.OilCostAuction); TextView oilAvilTv = (TextView)oilLayout.findViewById(R.id.OilAvailableAuction); if(resourceList.get("Oil") > 0) { oilCostTv.setText("$" + oilCost); oilAvilTv.setText(oilAvil + " Left"); }else{ oilCostTv.setText(""); oilAvilTv.setText("SOLD OUT"); } //Garbage int garbageCost = (9 - (resourceList.get("Garbage") / 3)); int garbageAvil = (3 - (resourceList.get("Garbage") % 3)); LinearLayout garbageLayout = (LinearLayout)findViewById(R.id.GarbageLayout); TextView garbageCostTv = (TextView)garbageLayout.findViewById(R.id.GarbageCostAuction); TextView garbageAvilTv = (TextView)garbageLayout.findViewById(R.id.GarbageAvailableAuction); if(resourceList.get("Garbage") > 0) { garbageCostTv.setText("$" + garbageCost); garbageAvilTv.setText(garbageAvil + " Left"); }else{ garbageCostTv.setText(""); garbageAvilTv.setText("SOLD OUT"); } //Uranium int uraniumCost = (17 - (resourceList.get("Uranium"))); if(resourceList.get("Uranium") <= 4){ uraniumCost = (18 - (resourceList.get("Uranium") * 2)); }else{ uraniumCost = (12 - resourceList.get("Uranium")); } int uraniumAvil = 1; LinearLayout uraniumLayout = (LinearLayout)findViewById(R.id.UraniumLayout); TextView uraniumCostTv = (TextView)uraniumLayout.findViewById(R.id.UraniumCostAuction); TextView uraniumAvilTv = (TextView)uraniumLayout.findViewById(R.id.UraniumAvailableAuction); if(resourceList.get("Uranium") > 0) { uraniumCostTv.setText("$" + uraniumCost); uraniumAvilTv.setText(uraniumAvil + " Left"); }else{ uraniumCostTv.setText(""); uraniumAvilTv.setText("SOLD OUT"); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. if(stage == 2){ getMenuInflater().inflate(R.menu.power_plant_auction_stage_two, menu); }else{ getMenuInflater().inflate(R.menu.power_plant_auction, menu); } return true; } public void FinishedAuction(final View v){ Intent mainIntent = new Intent(v.getContext(), ResourcePurchaseActivity.class); Bundle extras = new Bundle(); extras.putInt("Coal",resourceList.get("Coal")); extras.putInt("Oil",resourceList.get("Oil")); extras.putInt("Garbage",resourceList.get("Garbage")); extras.putInt("Uranium",resourceList.get("Uranium")); extras.putInt("Stage",stage); extras.putParcelableArrayList("PlayerList", playerList); mainIntent.putExtras(extras); startActivity(mainIntent); } public void BeginStageThree(MenuItem item) { item.setVisible(false); stage = 3; } @Override public void onBackPressed(){ LayoutInflater inflater = LayoutInflater.from(mContext); final View dialoglayout = inflater.inflate(R.layout.back_dialog, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext); alertDialogBuilder.setView(dialoglayout); //set buttons alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialogBuilder.setPositiveButton("Continue", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); closeActivity(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } public void closeActivity(){ this.finish(); } }