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; //from w w w.j a va 2 s . com import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; 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.ResourceAdapter; import com.mintcode.kris.powergridhelper.Models.Player; import com.mintcode.kris.powergridhelper.R; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; public class ResourcePurchaseActivity 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_resource_purchase); 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("Purchase Resources"); ListView lv = (ListView) findViewById(R.id.ResourcePurchaseListView); Collections.reverse(playerList); lv.setAdapter(new ResourceAdapter(this, R.id.ResourcePurchaseListView, playerList, resourceList, this)); setupResource(); } public void setupResource() { //ResourceBar //Coal int coalCost = (8 - ((resourceList.get("Coal") - 1) / 3)); int coalAvil = (resourceList.get("Coal") % 3); if (coalAvil == 0) { coalAvil = 3; } TextView coalCostTv = (TextView) findViewById(R.id.CoalCostResource); TextView coalAvilTv = (TextView) findViewById(R.id.CoalAvailableResource); if (resourceList.get("Coal") > 0) { coalCostTv.setText("$" + coalCost); coalAvilTv.setText(coalAvil + " Left"); } else { coalCostTv.setText(""); coalAvilTv.setText("SOLD OUT"); } //Oil int oilCost = (8 - ((resourceList.get("Oil") - 1) / 3)); int oilAvil = ((resourceList.get("Oil") % 3)); if (oilAvil == 0) { oilAvil = 3; } TextView oilCostTv = (TextView) findViewById(R.id.OilCostResource); TextView oilAvilTv = (TextView) findViewById(R.id.OilAvailableResource); if (resourceList.get("Oil") > 0) { oilCostTv.setText("$" + oilCost); oilAvilTv.setText(oilAvil + " Left"); } else { oilCostTv.setText(""); oilAvilTv.setText("SOLD OUT"); } //Garbage int garbageCost = (8 - ((resourceList.get("Garbage") - 1) / 3)); int garbageAvil = ((resourceList.get("Garbage") % 3)); if (garbageAvil == 0) { garbageAvil = 3; } TextView garbageCostTv = (TextView) findViewById(R.id.GarbageCostResource); TextView garbageAvilTv = (TextView) findViewById(R.id.GarbageAvailableResource); 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 = (16 - ((resourceList.get("Uranium") - 1) * 2)); } else { uraniumCost = (8 - ((resourceList.get("Uranium") - 1) - 4)); } int uraniumAvil = 1; TextView uraniumCostTv = (TextView) findViewById(R.id.UraniumCostResource); TextView uraniumAvilTv = (TextView) findViewById(R.id.UraniumAvailableResource); 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. getMenuInflater().inflate(R.menu.resource_purchase, menu); return true; } public void FinishedResource(final View v) { Intent mainIntent = new Intent(v.getContext(), BuildingActivity.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); } @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(); } }