Skip to content

Commit

Permalink
add image pick component
Browse files Browse the repository at this point in the history
  • Loading branch information
heaven7 committed Nov 25, 2019
1 parent 9b9d079 commit 2ea7bd6
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.heaven7.android.component.gallery;

import android.app.Activity;
import android.content.Intent;

import com.heaven7.android.component.AppComponentContext;

import java.util.List;

/**
* the image pick delegate
* @author heaven7
* @since 1.1.4
*/
public interface ImagePickComponent extends AppComponentContext {

/**
* start pick image from camera. you should start with startActivityForResult and setResult for callback
* @param activity the activity
* @param op the pick option
* @param callback the callback of pick
*/
void startPickFromCamera(Activity activity, PickOption op, Callback callback);

/**
* start pick from gallery.
* @param activity the activity
* @param op the pick option
* @param callback the callback of pick
*/
void startPickFromGallery(Activity activity, PickOption op, Callback callback);

/**
* often we handle data from activity onActivityResult.
* @param requestCode the request code
* @param resultCode the result code
* @param data the intent data.
*/
void onActivityResult(int requestCode, int resultCode, Intent data);

/**
* the callback of pick
*/
interface Callback{
/**
* called on pick result
* @param activity the activity
* @param files the files.
*/
void onPickResult(Activity activity, List<String> files);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.heaven7.android.component.gallery;

/**
* the pick option
* @author heaven7
* @since 1.1.4
*/
public class PickOption {

private int minCount;
private int maxCount;
private boolean crop;
private int aspectX;
private int aspectY;
private int outputX;
private int outputY;
private String outputFormat; //png ,jpeg and etc.

protected PickOption(PickOption.Builder builder) {
this.minCount = builder.minCount;
this.maxCount = builder.maxCount;
this.crop = builder.crop;
this.aspectX = builder.aspectX;
this.aspectY = builder.aspectY;
this.outputX = builder.outputX;
this.outputY = builder.outputY;
this.outputFormat = builder.outputFormat;
}

public int getMinCount() {
return this.minCount;
}

public int getMaxCount() {
return this.maxCount;
}

public boolean isCrop() {
return this.crop;
}

public int getAspectX() {
return this.aspectX;
}

public int getAspectY() {
return this.aspectY;
}

public int getOutputX() {
return this.outputX;
}

public int getOutputY() {
return this.outputY;
}

public String getOutputFormat() {
return this.outputFormat;
}

public static class Builder {
private int minCount;
private int maxCount;
private boolean crop;
private int aspectX;
private int aspectY;
private int outputX;
private int outputY;
private String outputFormat; //png ,jpeg and etc.

public Builder setMinCount(int minCount) {
this.minCount = minCount;
return this;
}

public Builder setMaxCount(int maxCount) {
this.maxCount = maxCount;
return this;
}

public Builder setCrop(boolean crop) {
this.crop = crop;
return this;
}

public Builder setAspectX(int aspectX) {
this.aspectX = aspectX;
return this;
}

public Builder setAspectY(int aspectY) {
this.aspectY = aspectY;
return this;
}

public Builder setOutputX(int outputX) {
this.outputX = outputX;
return this;
}

public Builder setOutputY(int outputY) {
this.outputY = outputY;
return this;
}

public Builder setOutputFormat(String outputFormat) {
this.outputFormat = outputFormat;
return this;
}

public PickOption build() {
return new PickOption(this);
}
}
}

0 comments on commit 2ea7bd6

Please sign in to comment.