package com.espritmobile.sim.restocheck;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.print.PrintAttributes.Margins;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
import android.widget.RelativeLayout.LayoutParams;

public class TableActivity extends Activity {
	LinearLayout top, right, left, bottom;
	Button plate_top, plate_top2, plate_top3, plate_left, plate_left2,
			plate_right, plate_right2, plate_bottom, plate_bottom2,
			plate_bottom3, next;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_table);
		Intent i = getIntent();
		final int count = i.getIntExtra("count", 2);
		top = (LinearLayout) findViewById(R.id.top);
		left = (LinearLayout) findViewById(R.id.left);
		right = (LinearLayout) findViewById(R.id.right);
		bottom = (LinearLayout) findViewById(R.id.bottom);
		next = (Button) findViewById(R.id.next);
		
		next.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				startActivity(new Intent(TableActivity.this, BillActivity.class).putExtra("count", count));
				
			}
		});
		LayoutParams paramstop = new LayoutParams(LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT);
		paramstop.setMargins(0, 0, 2000, 0);
		paramstop.rightMargin = 2000;
		LayoutParams paramsleft = new LayoutParams(LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT);
		paramsleft.setMargins(0, 0, 0, 2000);

		switch (count) {
		case 2:
			plate_top = createButton(paramstop, "top");
			top.addView(plate_top);
			plate_bottom = createButton(paramstop, "bottom");
			bottom.addView(plate_bottom);
			break;
		case 3:
			plate_top = createButton(paramstop, "top");
			top.addView(plate_top);
			plate_bottom = createButton(paramstop, "bottom");
			bottom.addView(plate_bottom);
			plate_left = createButton(paramsleft, "left");
			left.addView(plate_left);

			break;
		case 4:
			plate_bottom = createButton(paramstop, "bottom");
			plate_top = createButton(paramstop, "top");
			plate_left = createButton(paramsleft, "left");
			plate_right = createButton(paramsleft, "right");
			top.addView(plate_top);
			bottom.addView(plate_bottom);
			left.addView(plate_left);
			right.addView(plate_right);
			break;
		case 5:
			plate_bottom = createButton(paramstop, "bottom");
			plate_bottom2 = createButton(paramstop, "bottom");
			plate_top = createButton(paramstop, "top");
			plate_left = createButton(paramsleft, "left");
			plate_right = createButton(paramsleft, "right");
			top.addView(plate_top);
			bottom.addView(plate_bottom);
			bottom.addView(plate_bottom2);
			left.addView(plate_left);
			right.addView(plate_right);
			break;
		case 6:
			plate_bottom = createButton(paramstop, "bottom");
			plate_bottom2 = createButton(paramstop, "bottom");
			plate_top = createButton(paramstop, "top");
			plate_top2 = createButton(paramstop, "top");
			plate_left = createButton(paramsleft, "left");
			plate_right = createButton(paramsleft, "right");
			top.addView(plate_top);
			top.addView(plate_top2);
			bottom.addView(plate_bottom);
			bottom.addView(plate_bottom2);
			left.addView(plate_left);
			right.addView(plate_right);
			break;
		case 7:
			plate_bottom = createButton(paramstop, "bottom");
			plate_bottom2 = createButton(paramstop, "bottom");
			plate_top = createButton(paramstop, "top");
			plate_top2 = createButton(paramstop, "top");
			plate_left = createButton(paramsleft, "left");
			plate_left2 = createButton(paramsleft, "left");
			plate_right = createButton(paramsleft, "right");
			top.addView(plate_top);
			top.addView(plate_top2);
			bottom.addView(plate_bottom);
			bottom.addView(plate_bottom2);
			left.addView(plate_left);
			left.addView(plate_left2);
			right.addView(plate_right);
			break;
		case 8:
			plate_bottom = createButton(paramstop, "bottom");
			plate_bottom2 = createButton(paramstop, "bottom");
			plate_top = createButton(paramstop, "top");
			plate_top2 = createButton(paramstop, "top");
			plate_left = createButton(paramsleft, "left");
			plate_left2 = createButton(paramsleft, "left");
			plate_right = createButton(paramsleft, "right");
			plate_right2 = createButton(paramsleft, "right");
			top.addView(plate_top);
			top.addView(plate_top2);
			bottom.addView(plate_bottom);
			bottom.addView(plate_bottom2);
			left.addView(plate_left);
			left.addView(plate_left2);
			right.addView(plate_right);
			right.addView(plate_right2);
			break;
		case 9:
			plate_bottom = createButton(paramstop, "bottom");
			plate_bottom2 = createButton(paramstop, "bottom");
			plate_bottom3 = createButton(paramstop, "bottom");
			plate_top = createButton(paramstop, "top");
			plate_top2 = createButton(paramstop, "top");
			plate_left = createButton(paramsleft, "left");
			plate_left2 = createButton(paramsleft, "left");
			plate_right = createButton(paramsleft, "right");
			plate_right2 = createButton(paramsleft, "right");
			top.addView(plate_top);
			top.addView(plate_top2);
			bottom.addView(plate_bottom);
			bottom.addView(plate_bottom2);
			bottom.addView(plate_bottom3);
			left.addView(plate_left);
			left.addView(plate_left2);
			right.addView(plate_right);
			right.addView(plate_right2);
			break;
		case 10:
			plate_top = createButton(paramstop, "top");
			plate_top2 = createButton(paramstop, "top");
			plate_top3 = createButton(paramstop, "top");
			plate_left = createButton(paramsleft, "left");
			plate_left2 = createButton(paramsleft, "left");
			plate_right = createButton(paramsleft, "right");
			plate_right2 = createButton(paramsleft, "right");
			plate_bottom = createButton(paramstop, "bottom");
			plate_bottom2 = createButton(paramstop, "bottom");
			plate_bottom3 = createButton(paramstop, "bottom");
			top.addView(plate_top);
			top.addView(plate_top2);
			top.addView(plate_top3);
			left.addView(plate_left);
			left.addView(plate_left2);
			right.addView(plate_right);
			right.addView(plate_right2);
			bottom.addView(plate_bottom);
			bottom.addView(plate_bottom2);
			bottom.addView(plate_bottom3);
			break;

		default:
			plate_top = createButton(paramstop, "top");
			top.addView(plate_top);
			plate_bottom = createButton(paramstop, "bottom");
			bottom.addView(plate_bottom);
			break;
		}

	}

	public Button createButton(android.widget.RelativeLayout.LayoutParams lp,
			String pos) {
		Button b = new Button(this);
		b.setLayoutParams(lp);
		b.setText("0 DT");
		b.setTextSize(70);
		b.setTextColor(getResources().getColor(R.color.vert));
		switch (pos) {
		case "top":
			b.setBackgroundResource(R.drawable.plate_top);
			return b;
		case "left":
			b.setBackgroundResource(R.drawable.plate_left);
			return b;
		case "right":
			b.setBackgroundResource(R.drawable.plate_right);
			return b;
		case "bottom":
			b.setBackgroundResource(R.drawable.plate_bottom);
			return b;
		default:
			return null;
		}
	}
}
