Android Open Source - android-cropimage Main Activity






From Project

Back to project page android-cropimage.

License

The source code is released under:

Apache License

If you think the Android project android-cropimage 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 com.android.camera.example;
/*from w w  w . j a v  a  2  s  .co  m*/
import android.app.Activity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.android.camera.CropImageIntentBuilder;

import java.io.File;

public class MainActivity extends Activity implements View.OnClickListener {
    private static int REQUEST_PICTURE = 1;
    private static int REQUEST_CROP_PICTURE = 2;

    private Button button;
    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(this);

        imageView = (ImageView) findViewById(R.id.imageView);
    }

    @Override
    public void onClick(View view) {
        if (view.equals(button)) {
            startActivityForResult(MediaStoreUtils.getPickImageIntent(this), REQUEST_PICTURE);
        }
    }

    @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
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        File croppedImageFile = new File(getFilesDir(), "test.jpg");

        if ((requestCode == REQUEST_PICTURE) && (resultCode == RESULT_OK)) {
            // When the user is done picking a picture, let's start the CropImage Activity,
            // setting the output image file and size to 200x200 pixels square.
            Uri croppedImage = Uri.fromFile(croppedImageFile);

            CropImageIntentBuilder cropImage = new CropImageIntentBuilder(200, 200, croppedImage);
            cropImage.setSourceImage(data.getData());

            startActivityForResult(cropImage.getIntent(this), REQUEST_CROP_PICTURE);
        } else if ((requestCode == REQUEST_CROP_PICTURE) && (resultCode == RESULT_OK)) {
            // When we are done cropping, display it in the ImageView.
            imageView.setImageBitmap(BitmapFactory.decodeFile(croppedImageFile.getAbsolutePath()));
        }
    }
}




Java Source Code List

com.android.camera.BitmapManager.java
com.android.camera.CropImageIntentBuilder.java
com.android.camera.CropImage.java
com.android.camera.HighlightView.java
com.android.camera.ImageManager.java
com.android.camera.ImageViewTouchBase.java
com.android.camera.MonitoredActivity.java
com.android.camera.NoSearchActivity.java
com.android.camera.RotateBitmap.java
com.android.camera.Util.java
com.android.camera.example.MainActivity.java
com.android.camera.example.MediaStoreUtils.java
com.android.camera.gallery.BaseImageList.java
com.android.camera.gallery.BaseImage.java
com.android.camera.gallery.IImageList.java
com.android.camera.gallery.IImage.java
com.android.camera.gallery.ImageListUber.java
com.android.camera.gallery.ImageList.java
com.android.camera.gallery.Image.java
com.android.camera.gallery.LruCache.java
com.android.camera.gallery.SingleImageList.java
com.android.camera.gallery.UriImage.java
com.android.camera.gallery.VideoList.java
com.android.camera.gallery.VideoObject.java