package com.sagarapp; import java.io.IOException; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; public class Camera extends Activity implements View.OnClickListener{ ImageView img; ImageButton takepic; Button setdp; Intent i; final static int cameraData = 0; Bitmap bmp; final Context context = this; boolean taken = false; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.photo); initialize(); takepic.setOnClickListener(this); setdp.setOnClickListener(this); } private void initialize() { // TODO Auto-generated method stub img = (ImageView)findViewById(R.id.Ivpic); takepic = (ImageButton)findViewById(R.id.Ibcapture); setdp = (Button)findViewById(R.id.Bsetdp); } @SuppressWarnings("deprecation") @Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()) { case R.id.Ibcapture: i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); taken = true; startActivityForResult(i,cameraData); break; case R.id.Bsetdp: try { if(taken) getApplicationContext().setWallpaper(bmp); else{ AlertDialog.Builder alertDialogBulider = new AlerDialog.Builder(context); alertDialogBulider.setTitle("Warning!"); alertDialogBulider.setMessage("No Image Is Available"); alertDialogBulider.setCancelable(false); alertDialogBulider.setNeutralButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // TODO Auto-generated method stub dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBulider.create(); alertDialog.show(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(resultCode == RESULT_OK) { Bundle extras = data.getExtras(); bmp = (Bitmap)extras.get("data"); img.setImageBitmap(bmp); } else { AlertDialog.Builder alertDialogBulider = new AlertDialog.Builder(context); alertDialogBulider.setTitle("Warning!"); alertDialogBulider.setMessage("No Photo Is Taken"); alertDialogBulider.setCancelable(false); alertDialogBulider.setNeutralButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // TODO Auto-generated method stub dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBulider.create(); alertDialog.show(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)