package com.movashah.talee;

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.*;
import android.net.*;
import android.graphics.drawable.*;
import java.util.zip.*;
import android.widget.GridLayout.*;

public class resultActivity extends Activity
{
		@Override
		protected void onCreate(Bundle savedInstanceState)
		{
				super.onCreate(savedInstanceState);
				setContentView(R.layout.result);


		}

		@Override
		public boolean onCreateOptionsMenu(Menu menu)
		{
				// TODO: Implement this method
				getMenuInflater().inflate(R.menu.next_menu, menu);
				return true;
		}

		@Override
		public boolean onOptionsItemSelected(MenuItem item)
		{
				// TODO: Implement this method
				switch (item.getItemId())
				{
						case(R.id.main_menuitem2):

								finish();
				}

				return true;
		}

		public void addBut(View v)
		{
				//LayoutInflater inf = resultActivity.getLayoutInflater();
				//View l = inf.inflate(R.layout.result,(ViewGroup) getView(),false);
				LinearLayout L = (LinearLayout) findViewById(R.id.resultLinearLayout);
				//LayoutParams l = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
				Button tBut = new Button(this);
				tBut.setTextAppearance(this, android.R.style.TextAppearance_Large);
				tBut.setText("۷. علیرضا (۴۵۶)");
				//tBut.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.MATCH_PARENT));
				tBut.setOnClickListener(new OnClickListener(){
						@Override
						public void onClick(View view){
								shoDg(view);
						}
				});
				L.addView(tBut);
		}


    public void shoDg(View view)
    {
				MyDialogFragment f = new MyDialogFragment();
				Bundle args = new Bundle();
				Button b = (Button) view;
				String naam = (String) b.getText();
				args.putString("Nam", naam);
				f.setArguments(args);
				f.show(getFragmentManager(), "mydialog");
    }
}

class MyDialogFragment extends DialogFragment
{
		String Naam;

		@Override
		public Dialog onCreateDialog(Bundle savedInstanceState)
		{
				AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
				Naam = getArguments().getString("Nam");
				builder.setTitle("ارسال نام");
				builder.setMessage("آیا نام انتخاب شده به نرم‌افزار پیامک ارسال شود؟");
				builder.setPositiveButton("بله", new DialogInterface.OnClickListener() {

								@Override
								public void onClick(DialogInterface p1, int p2)
								{
										// TODO: Implement this method
										//Button b = (Button) view;
										String naam = ""; //(String) b.getText();
										naam = "نام پیشنهادی: " + Naam + "\n";
										Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:"));
										intent.putExtra("sms_body", naam);
										startActivity(intent);
								}
						});
				builder.setNegativeButton("خیر", new DialogInterface.OnClickListener(){
								@Override
								public void onClick(DialogInterface p1, int p2)
								{

								}
						});
				return builder.create();
		}


}
