Search in sources :

Example 1 with CropImageView

use of com.theartofdev.edmodo.cropper.CropImageView in project Alphago by Onedelay.

the class SendImageActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_send_image);
    imageFile = (File) getIntent().getSerializableExtra("sendImage");
    cropImageView = findViewById(R.id.cropImageView);
    cropImageView.setImageUriAsync(Uri.fromFile(imageFile));
    cropImageView.setAspectRatio(1, 1);
    cropImageView.setFixedAspectRatio(true);
    cropImageView.setCropShape(CropImageView.CropShape.RECTANGLE);
    cropImageView.setAutoZoomEnabled(false);
    cropImageView.setCropRect(new Rect(1000, 1000, 1000, 1000));
    cropImageView.setOnCropImageCompleteListener(new CropImageView.OnCropImageCompleteListener() {

        @Override
        public void onCropImageComplete(CropImageView view, CropImageView.CropResult result) {
            Bitmap bitmap = result.getBitmap();
            if (bitmap != null) {
                try {
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
                    byte[] bitmapData = bos.toByteArray();
                    FileOutputStream fos = new FileOutputStream(imageFile);
                    fos.write(bitmapData);
                    fos.flush();
                    fos.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            // onComplete(imageFile);
            // new BitmapToFileTask(imageFile, SendImageActivity.this)
            // .execute(bitmap);
            AlphagoServer.getInstance().sendImage(getBaseContext(), imageFile, new Callback<ResponeImageLabel>() {

                @Override
                public void onResponse(Call<ResponeImageLabel> call, Response<ResponeImageLabel> response) {
                    if (response.body() != null) {
                        category = response.body().getCategory();
                        max_label = response.body().getResponseLabel();
                        ID = response.body().getID();
                        cate_ID = response.body().getCate_ID();
                        Intent intent = new Intent(getBaseContext(), ImageRecognitionActivity.class);
                        intent.putExtra("imageFile", imageFile);
                        intent.putExtra("category", category);
                        intent.putExtra("max_label", max_label);
                        intent.putExtra("ID", ID);
                        intent.putExtra("cate_ID", cate_ID);
                        frameLoading.setVisibility(View.GONE);
                        startActivity(intent);
                        finish();
                    }
                }

                @Override
                public void onFailure(Call<ResponeImageLabel> call, Throwable t) {
                    frameLoading.setVisibility(View.GONE);
                    Toast.makeText(SendImageActivity.this, "서버 연결 안됨", Toast.LENGTH_SHORT).show();
                    t.printStackTrace();
                }
            });
        }
    });
    findViewById(R.id.crop_image_menu_rotate_right).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            cropImageView.rotateImage(90);
        }
    });
    findViewById(R.id.btn_retry).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new ImageSelectionMethodDialog().show(getSupportFragmentManager(), "dialog");
        }
    });
    findViewById(R.id.btn_send).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            frameLoading.setVisibility(View.VISIBLE);
            cropImageView.getCroppedImageAsync();
        }
    });
    frameLoading = (FrameLayout) findViewById(R.id.frame_loading);
}
Also used : Call(retrofit2.Call) Rect(android.graphics.Rect) Intent(android.content.Intent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImageView(android.widget.ImageView) CropImageView(com.theartofdev.edmodo.cropper.CropImageView) View(android.view.View) Response(retrofit2.Response) Bitmap(android.graphics.Bitmap) Callback(retrofit2.Callback) FileOutputStream(java.io.FileOutputStream) CropImageView(com.theartofdev.edmodo.cropper.CropImageView) ImageSelectionMethodDialog(com.alphago.alphago.fragment.ImageSelectionMethodDialog)

Example 2 with CropImageView

use of com.theartofdev.edmodo.cropper.CropImageView in project Zom-Android by zom.

the class AccountFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK && requestCode == 200) {
        Uri imageUri = getPickImageResultUri(data);
        if (imageUri == null)
            return;
        // (CropImageView)view.findViewById(R.id.CropImageView);
        mCropImageView = new CropImageView(getActivity());
        mCropImageView.setAspectRatio(1, 1);
        mCropImageView.setFixedAspectRatio(true);
        mCropImageView.setCropShape(CropImageView.CropShape.OVAL);
        try {
            Bitmap bmpThumbnail = SecureMediaStore.getThumbnailFile(getActivity(), imageUri, 512);
            mCropImageView.setImageBitmap(bmpThumbnail);
            // Use the Builder class for convenient dialog construction
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setView(mCropImageView).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    setAvatar(mCropImageView.getCroppedImage());
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                // User cancelled the dialog
                }
            });
            // Create the AlertDialog object and return it
            AlertDialog dialog = builder.create();
            dialog.show();
            ;
        } catch (IOException ioe) {
            Log.e(ImApp.LOG_TAG, "couldn't load avatar", ioe);
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Bitmap(android.graphics.Bitmap) DialogInterface(android.content.DialogInterface) IOException(java.io.IOException) CropImageView(com.theartofdev.edmodo.cropper.CropImageView) Uri(android.net.Uri)

Example 3 with CropImageView

use of com.theartofdev.edmodo.cropper.CropImageView in project Zom-Android by zom.

the class OnboardingActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    ImApp mApp = (ImApp) getApplication();
    mApp.initAccountInfo();
    if (resultCode == RESULT_OK) {
        if (requestCode == OnboardingManager.REQUEST_SCAN) {
            showInviteScreen();
            ArrayList<String> resultScans = data.getStringArrayListExtra("result");
            for (String resultScan : resultScans) {
                try {
                    // parse each string and if they are for a new user then add the user
                    OnboardingManager.DecodedInviteLink diLink = OnboardingManager.decodeInviteLink(resultScan);
                    new AddContactAsyncTask(mNewAccount.providerId, mNewAccount.accountId, mApp).execute(diLink.username, diLink.fingerprint, diLink.nickname);
                // if they are for a group chat, then add the group
                } catch (Exception e) {
                    Log.w(ImApp.LOG_TAG, "error parsing QR invite link", e);
                }
            }
            if (resultScans.size() > 0) {
                showMainScreen();
            }
        } else if (requestCode == OnboardingManager.REQUEST_CHOOSE_AVATAR) {
            Uri imageUri = getPickImageResultUri(data);
            if (imageUri == null)
                return;
            // (CropImageView)view.findViewById(R.id.CropImageView);
            mCropImageView = new CropImageView(OnboardingActivity.this);
            mCropImageView.setAspectRatio(1, 1);
            mCropImageView.setFixedAspectRatio(true);
            mCropImageView.setCropShape(CropImageView.CropShape.OVAL);
            try {
                Bitmap bmpThumbnail = SecureMediaStore.getThumbnailFile(OnboardingActivity.this, imageUri, 512);
                mCropImageView.setImageBitmap(bmpThumbnail);
                // Use the Builder class for convenient dialog construction
                android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(OnboardingActivity.this);
                builder.setView(mCropImageView).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int id) {
                        setAvatar(mCropImageView.getCroppedImage(), mNewAccount);
                        showInviteScreen();
                        delete(mOutputFileUri);
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int id) {
                        // User cancelled the dialog
                        delete(mOutputFileUri);
                    }
                });
                // Create the AlertDialog object and return it
                android.support.v7.app.AlertDialog dialog = builder.create();
                dialog.show();
                ;
            } catch (IOException ioe) {
                Log.e(ImApp.LOG_TAG, "couldn't load avatar", ioe);
            }
        }
    }
}
Also used : AlertDialog(android.app.AlertDialog) AddContactAsyncTask(org.awesomeapp.messenger.tasks.AddContactAsyncTask) DialogInterface(android.content.DialogInterface) ImApp(org.awesomeapp.messenger.ImApp) IOException(java.io.IOException) Uri(android.net.Uri) IOException(java.io.IOException) Bitmap(android.graphics.Bitmap) OnClickListener(android.view.View.OnClickListener) CropImageView(com.theartofdev.edmodo.cropper.CropImageView)

Example 4 with CropImageView

use of com.theartofdev.edmodo.cropper.CropImageView in project android by testpress.

the class CropImageActivity method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.crop_image_layout);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    cropImageView = (CropImageView) findViewById(R.id.CropImageView);
    cropImageView.setImageBitmap(ImageUtils.decodeImage(getIntent().getStringExtra("picturePath"), 500, 500));
    ((TextView) findViewById(R.id.done)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // get the cropped coordinates
            Rect rect = cropImageView.getCropRect();
            // details to crop in server
            int[] croppedImageDetails = new int[] { rect.left, rect.top, rect.width(), rect.height() };
            Intent intent = new Intent();
            intent.putExtra("croppedImageDetails", croppedImageDetails);
            intent.putExtra("rotatedDegree", rotatedDegree);
            setResult(RESULT_OK, intent);
            finish();
        }
    });
    ((TextView) findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
}
Also used : Rect(android.graphics.Rect) TextView(android.widget.TextView) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) CropImageView(com.theartofdev.edmodo.cropper.CropImageView)

Aggregations

CropImageView (com.theartofdev.edmodo.cropper.CropImageView)4 Bitmap (android.graphics.Bitmap)3 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 Rect (android.graphics.Rect)2 Uri (android.net.Uri)2 View (android.view.View)2 IOException (java.io.IOException)2 AlertDialog (android.app.AlertDialog)1 AlertDialog (android.support.v7.app.AlertDialog)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ImageSelectionMethodDialog (com.alphago.alphago.fragment.ImageSelectionMethodDialog)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 ImApp (org.awesomeapp.messenger.ImApp)1 AddContactAsyncTask (org.awesomeapp.messenger.tasks.AddContactAsyncTask)1 Call (retrofit2.Call)1 Callback (retrofit2.Callback)1