Android Open Source - lostpets Take Picture Activity






From Project

Back to project page lostpets.

License

The source code is released under:

GNU General Public License

If you think the Android project lostpets listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fr.esiea.mobile.lostpets.activity;
// w  w w .  j a v  a  2 s . c  om
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.File;

import fr.esiea.mobile.lostpets.R;
import fr.esiea.mobile.lostpets.util.PictureFileManager;

//This class is the TakePictureActivity linked to activity_take_picture.xml
public class TakePictureActivity extends Activity implements View.OnClickListener {

    TextView m_txtOwnerPhone;
    ImageView m_imgLostPetPicture;
    Button m_btnSharePicture;
    Bitmap m_imageBitmap;

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

        m_btnSharePicture = (Button) findViewById(R.id.btn_sharePicture);
        m_imgLostPetPicture = (ImageView) findViewById(R.id.row_img_pet);
        m_txtOwnerPhone = (TextView) findViewById(R.id.txt_ownerPhone);

        m_btnSharePicture.setOnClickListener(this);

        //Set picture in the imageView
        setImgView();

        //Set the owner phone field if the argument is not null
        if (getIntent().getExtras().get("phone") != null) {
            m_txtOwnerPhone.setText((String) getIntent().getExtras().get("phone"));
        }
    }

    //Set the captured photo in the imageView
    private void setImgView() {
        File file = new File(PictureFileManager.getM_currentPhotoPath());
        Uri uri = Uri.fromFile(file);

        try {
            m_imageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
        }
        catch(Exception e) {
            Toast.makeText(this, R.string.err_pictureFile + ":" + e.getMessage(), Toast.LENGTH_LONG).show();
        }

        if (m_imageBitmap != null) {
            m_imgLostPetPicture.setImageBitmap(m_imageBitmap);
        }
    }

    @Override
    public void onClick(View view) {
        if (R.id.btn_sharePicture == view.getId()) {
            //Share picture with all applications which can handle pictures
            final Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("image/jpeg");
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(PictureFileManager.getM_currentPhotoPath())));
            startActivity(Intent.createChooser(shareIntent, "Partager avec..."));
        }
    }
}




Java Source Code List

fr.esiea.mobile.lostpets.ApplicationTest.java
fr.esiea.mobile.lostpets.activity.CreateLostPetActivity.java
fr.esiea.mobile.lostpets.activity.InfosActivity.java
fr.esiea.mobile.lostpets.activity.MainActivity.java
fr.esiea.mobile.lostpets.activity.MapsActivity.java
fr.esiea.mobile.lostpets.activity.PetActivity.java
fr.esiea.mobile.lostpets.activity.PetMarkerActivity.java
fr.esiea.mobile.lostpets.activity.TakePictureActivity.java
fr.esiea.mobile.lostpets.adapter.PetAdapter.java
fr.esiea.mobile.lostpets.dao.UserDataSource.java
fr.esiea.mobile.lostpets.dao.WebServiceDAO.java
fr.esiea.mobile.lostpets.fragment.PetFragment.java
fr.esiea.mobile.lostpets.fragment.PetListFragment.java
fr.esiea.mobile.lostpets.model.Pet.java
fr.esiea.mobile.lostpets.model.Pets.java
fr.esiea.mobile.lostpets.model.User.java
fr.esiea.mobile.lostpets.sql.MySQLiteHelper.java
fr.esiea.mobile.lostpets.util.PictureFileManager.java