package com.example.mobapp_l_dialogs;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.app.AlertDialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Build;


public class MainActivity extends ActionBarActivity 
	implements DatePickerFragment.DatePickerResult,
	CustomDialogFragment.LoginResult {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	public void doDialogDatePicker(View v) {
		DatePickerFragment newFragment = new DatePickerFragment();
	    newFragment.setOnDatePickerResultListener(this);
		newFragment.show(getFragmentManager(), "datePicker");
	}

	@Override
	public void onDatePickerResult(Boolean canceled, int year, int month, int day) {
 		//Toast.makeText(this,"result cancel "+canceled+" day "+day, Toast.LENGTH_SHORT).show();
 		TextView text = (TextView)findViewById(R.id.textView12);
 		if (!canceled)
 			text.setText("OK "+day+"."+month+"."+year);
 		else
 			text.setText("Canceled");
	}
	
	public void doDialogAlert(View v) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);

		builder.setMessage("Was nun?")
			   .setTitle("Zucker oder Suessstoff?")
		       .setCancelable(false)
			   .setPositiveButton("Zucker",new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog,int id) {
					TextView text = (TextView)findViewById(R.id.textView22);
					text.setText("Zucker");

					}
				  })
				.setNegativeButton("Suessstoff",new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog,int id) {
					TextView text = (TextView)findViewById(R.id.textView22);
					text.setText("Suessstoff");
					}
				})
				.setNeutralButton("Hmmm...",new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog,int id) {
					TextView text = (TextView)findViewById(R.id.textView22);
					text.setText("Beides");
					}
				});
		AlertDialog dialog = builder.create();
		dialog.show();
	}
	public void doDialogCustom(View v) {
		CustomDialogFragment newFragment = new CustomDialogFragment();
		newFragment.setCancelable(false);
		newFragment.show(getFragmentManager(), "customDlg");
	}

	@Override
	public void Login() {
 		TextView text = (TextView)findViewById(R.id.TextView32);
		text.setText("login");
 		//Toast.makeText(this,"login", Toast.LENGTH_SHORT).show();
	}

	@Override
	public void Logout() {
 		TextView text = (TextView)findViewById(R.id.TextView32);
		text.setText("logout");
 		//Toast.makeText(this,"logout", Toast.LENGTH_SHORT).show();
	}
}
