package com.example.mobapp_15;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends Activity {

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

	public void phoneme(View view)
	{
		Uri number = Uri.parse("tel:0190123456");
		Intent intent = new Intent(Intent.ACTION_DIAL, number);
		
		PackageManager packageManager = getPackageManager();
		List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
		if (activities.size() > 0)
		{
			startActivity(intent);
		}
	}

	static final int CAPTURE_REQUEST = 1;  // The request code

	public void cheese(View view)
	{
		Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
	    
		PackageManager packageManager = getPackageManager();
		List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
		if (activities.size() > 0)
		{
			startActivityForResult(intent, CAPTURE_REQUEST);
		}
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	    // Check which request we're responding to
	    if (requestCode == CAPTURE_REQUEST) {
	        if (resultCode == RESULT_OK) {
	        	Bundle extras = data.getExtras();
	            Bitmap mImageBitmap = (Bitmap) extras.get("data");
	            ImageView imageView = (ImageView)findViewById(R.id.imageView1);
	            imageView.setImageBitmap(mImageBitmap);
	        }
	    }
	}	
	@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;
	}

}
