Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Add support for pickUsing framework Fragments #43

Merged
merged 1 commit into from
Apr 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions scissors/src/main/java/com/lyft/android/scissors/CropView.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.lyft.android.scissors;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
Expand All @@ -32,8 +33,10 @@
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ImageView;

import com.lyft.android.scissors.CropViewExtensions.CropRequest;
import com.lyft.android.scissors.CropViewExtensions.LoadRequest;

import java.io.File;
import java.io.OutputStream;

Expand Down Expand Up @@ -317,5 +320,12 @@ public CropRequest crop() {
public void pickUsing(@NonNull Activity activity, int requestCode) {
CropViewExtensions.pickUsing(activity, requestCode);
}

/**
* Perform a pick image request using {@link Fragment#startActivityForResult(Intent, int)}.
*/
public void pickUsing(@NonNull Fragment fragment, int requestCode) {
CropViewExtensions.pickUsing(fragment, requestCode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,39 @@
package com.lyft.android.scissors;

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.ViewTreeObserver;

import java.io.File;
import java.io.OutputStream;
import java.util.concurrent.Future;

class CropViewExtensions {

static void pickUsing(Activity activity, int requestCode) {
activity.startActivityForResult(
createChooserIntent(),
requestCode);
}

static void pickUsing(Fragment fragment, int requestCode) {
fragment.startActivityForResult(
createChooserIntent(),
requestCode);
}

private static Intent createChooserIntent() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);

Intent chooserIntent = Intent.createChooser(intent, null);

activity.startActivityForResult(
chooserIntent,
requestCode);
return Intent.createChooser(intent, null);
}

public static class LoadRequest {
Expand Down