Skip to content

Commit

Permalink
Merge branch 'feature_filter'
Browse files Browse the repository at this point in the history
  • Loading branch information
burhanrashid52 committed May 29, 2018
2 parents 4b29f2a + 1e554f5 commit b32e40c
Show file tree
Hide file tree
Showing 56 changed files with 1,674 additions and 164 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A Photo Editor library with simple, easy support for image editing using paints,
## Features

- [**Drawing**](#drawing) on image with option to change its Brush's Color,Size,Opacity and Erasing.
- Apply [**Filter**](#filter) on image using MediaEffect
- Adding/Editing [**Text**](#text) with option to change its Color with Custom Fonts.
- Adding [**Emoji**](#emoji) with Custom Emoji Fonts.
- Adding [**Images/Stickers**](#adding-imagesstickers)
Expand All @@ -30,7 +31,7 @@ A Photo Editor library with simple, easy support for image editing using paints,
## Getting Started
To start with this , you need to just simply add the dependencies in gradle file of app module like this
```
implementation 'ja.burhanrashid52:photoeditor:0.1.1'
implementation 'ja.burhanrashid52:photoeditor:0.2.0'
```
or your can also import the :photoeditor module from sample for customization

Expand Down Expand Up @@ -101,6 +102,24 @@ We can customize our brush and paint with diffrent set of property.To start draw



## Filter
You can apply inbuild filter to the sourc images using

`mPhotoEditor.setFilterEffect(PhotoFilter.BRIGHTNESS);`

![](https://i.imgur.com/xXTGcVC.gif)

You can also apply custom effect using `Custom.Builder` paramater

```
CustomEffect customEffect = new CustomEffect.Builder(EffectFactory.EFFECT_BRIGHTNESS)
.setParameter("brightness", 0.5f)
.build();
mPhotoEditor.setFilterEffect(customEffect);
```
For more details go to wiki



## Text

Expand Down Expand Up @@ -174,7 +193,7 @@ It will take default fonts provided in the builder,If you want diffrent Emoji fo
You need provide a file with callback method when edited image is saved

```
mPhotoEditor.saveImage(filePath, new PhotoEditor.OnSaveListener() {
mPhotoEditor.saveAsFile(filePath, new PhotoEditor.OnSaveListener() {
@Override
public void onSuccess(@NonNull String imagePath) {
Log.e("PhotoEditor","Image Saved Successfully");
Expand All @@ -186,6 +205,7 @@ It will take default fonts provided in the builder,If you want diffrent Emoji fo
}
});
```
For more detail go to wiki

## How to contribute?
* Check out contribution guidelines 👉[CONTRIBUTING.md](https://github.com/burhanrashid52/PhotoEditor/blob/master/CONTRIBUTING.md)
Expand Down
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:27.1.0'
implementation 'ja.burhanrashid52:photoeditor:0.1.1'
//implementation project(':photoeditor')
implementation 'com.android.support:cardview-v7:27.1.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:design:27.1.1'
//implementation 'ja.burhanrashid52:photoeditor:0.1.1'
implementation project(':photoeditor')
implementation 'com.android.support:cardview-v7:27.1.1'
}

// make sure this line comes *after* you apply the Android plugin
Expand Down
Binary file added app/src/main/assets/filters/auto_fix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/b_n_w.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/brightness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/contrast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/cross_process.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/documentary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/dual_tone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/fill_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/fish_eye.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/flip_horizental.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/flip_vertical.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/grain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/gray_scale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/lomish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/negative.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/original.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/posterize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/rotate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/saturate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/sepia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/sharpen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/temprature.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/tint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/filters/vignette.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
198 changes: 116 additions & 82 deletions app/src/main/java/com/burhanrashid52/imageeditor/EditImageActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
Expand All @@ -12,27 +11,39 @@
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.content.res.ResourcesCompat;
import android.support.constraint.ConstraintLayout;
import android.support.constraint.ConstraintSet;
import android.support.transition.ChangeBounds;
import android.support.transition.TransitionManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.animation.AnticipateOvershootInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.burhanrashid52.imageeditor.base.BaseActivity;
import com.burhanrashid52.imageeditor.filters.FilterListener;
import com.burhanrashid52.imageeditor.filters.FilterViewAdapter;
import com.burhanrashid52.imageeditor.tools.EditingToolsAdapter;
import com.burhanrashid52.imageeditor.tools.ToolType;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import ja.burhanrashid52.photoeditor.OnPhotoEditorListener;
import ja.burhanrashid52.photoeditor.PhotoEditor;
import ja.burhanrashid52.photoeditor.PhotoEditorView;
import ja.burhanrashid52.photoeditor.ViewType;
import ja.burhanrashid52.photoeditor.PhotoFilter;

public class EditImageActivity extends BaseActivity implements OnPhotoEditorListener,
View.OnClickListener,
PropertiesBSFragment.Properties,
EmojiBSFragment.EmojiListener,
StickerBSFragment.StickerListener {
StickerBSFragment.StickerListener, EditingToolsAdapter.OnItemSelected, FilterListener {

private static final String TAG = EditImageActivity.class.getSimpleName();
public static final String EXTRA_IMAGE_PATHS = "extra_image_paths";
Expand All @@ -45,32 +56,14 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
private StickerBSFragment mStickerBSFragment;
private TextView mTxtCurrentTool;
private Typeface mWonderFont;
private RecyclerView mRvTools, mRvFilters;
private EditingToolsAdapter mEditingToolsAdapter = new EditingToolsAdapter(this);
private FilterViewAdapter mFilterViewAdapter = new FilterViewAdapter(this);
private ConstraintLayout mRootView;
private ConstraintSet mConstraintSet = new ConstraintSet();
private boolean mIsFilterVisible;


/**
* launch editor with multiple image
*
* @param context
* @param imagesPath
*/
public static void launch(Context context, ArrayList<String> imagesPath) {
Intent starter = new Intent(context, EditImageActivity.class);
starter.putExtra(EXTRA_IMAGE_PATHS, imagesPath);
context.startActivity(starter);
}

/**
* launch editor with single image
*
* @param context
* @param imagePath
*/
public static void launch(Context context, String imagePath) {
ArrayList<String> imagePaths = new ArrayList<>();
imagePaths.add(imagePath);
launch(context, imagePaths);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -88,6 +81,15 @@ protected void onCreate(Bundle savedInstanceState) {
mEmojiBSFragment.setEmojiListener(this);
mPropertiesBSFragment.setPropertiesChangeListener(this);

LinearLayoutManager llmTools = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
mRvTools.setLayoutManager(llmTools);
mRvTools.setAdapter(mEditingToolsAdapter);

LinearLayoutManager llmFilters = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
mRvFilters.setLayoutManager(llmFilters);
mRvFilters.setAdapter(mFilterViewAdapter);


//Typeface mTextRobotoTf = ResourcesCompat.getFont(this, R.font.roboto_medium);
//Typeface mEmojiTypeFace = Typeface.createFromAsset(getAssets(), "emojione-android.ttf");

Expand All @@ -100,39 +102,22 @@ protected void onCreate(Bundle savedInstanceState) {
mPhotoEditor.setOnPhotoEditorListener(this);

//Set Image Dynamically
//mPhotoEditorView.getSource().setImageResource(R.drawable.got);
// mPhotoEditorView.getSource().setImageResource(R.drawable.color_palette);
}

private void initViews() {
ImageView imgPencil;
ImageView imgEraser;
ImageView imgUndo;
ImageView imgRedo;
ImageView imgText;
ImageView imgCamera;
ImageView imgGallery;
ImageView imgSticker;
ImageView imgEmo;
ImageView imgSave;
ImageView imgClose;

mPhotoEditorView = findViewById(R.id.photoEditorView);
mTxtCurrentTool = findViewById(R.id.txtCurrentTool);

imgEmo = findViewById(R.id.imgEmoji);
imgEmo.setOnClickListener(this);

imgSticker = findViewById(R.id.imgSticker);
imgSticker.setOnClickListener(this);

imgPencil = findViewById(R.id.imgPencil);
imgPencil.setOnClickListener(this);

imgText = findViewById(R.id.imgText);
imgText.setOnClickListener(this);

imgEraser = findViewById(R.id.btnEraser);
imgEraser.setOnClickListener(this);
mRvTools = findViewById(R.id.rvConstraintTools);
mRvFilters = findViewById(R.id.rvFilterView);
mRootView = findViewById(R.id.rootView);

imgUndo = findViewById(R.id.imgUndo);
imgUndo.setOnClickListener(this);
Expand All @@ -151,6 +136,7 @@ private void initViews() {

imgClose = findViewById(R.id.imgClose);
imgClose.setOnClickListener(this);

}

@Override
Expand Down Expand Up @@ -189,25 +175,6 @@ public void onStopViewChangeListener(ViewType viewType) {
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.imgPencil:
mPhotoEditor.setBrushDrawingMode(true);
mTxtCurrentTool.setText(R.string.label_brush);
mPropertiesBSFragment.show(getSupportFragmentManager(), mPropertiesBSFragment.getTag());
break;
case R.id.btnEraser:
mPhotoEditor.brushEraser();
mTxtCurrentTool.setText(R.string.label_eraser);
break;
case R.id.imgText:
TextEditorDialogFragment textEditorDialogFragment = TextEditorDialogFragment.show(this);
textEditorDialogFragment.setOnTextEditorListener(new TextEditorDialogFragment.TextEditor() {
@Override
public void onDone(String inputText, int colorCode) {
mPhotoEditor.addText(inputText, colorCode);
mTxtCurrentTool.setText(R.string.label_text);
}
});
break;

case R.id.imgUndo:
mPhotoEditor.undo();
Expand All @@ -222,19 +189,7 @@ public void onDone(String inputText, int colorCode) {
break;

case R.id.imgClose:
if (!mPhotoEditor.isCacheEmpty()) {
showSaveDialog();
} else {
finish();
}
break;

case R.id.imgSticker:
mStickerBSFragment.show(getSupportFragmentManager(), mStickerBSFragment.getTag());
break;

case R.id.imgEmoji:
mEmojiBSFragment.show(getSupportFragmentManager(), mEmojiBSFragment.getTag());
onBackPressed();
break;

case R.id.imgCamera:
Expand All @@ -260,7 +215,7 @@ private void saveImage() {
+ System.currentTimeMillis() + ".png");
try {
file.createNewFile();
mPhotoEditor.saveImage(file.getAbsolutePath(), new PhotoEditor.OnSaveListener() {
mPhotoEditor.saveAsFile(file.getAbsolutePath(), new PhotoEditor.OnSaveListener() {
@Override
public void onSuccess(@NonNull String imagePath) {
hideLoading();
Expand All @@ -276,6 +231,8 @@ public void onFailure(@NonNull Exception exception) {
});
} catch (IOException e) {
e.printStackTrace();
hideLoading();
showSnackbar(e.getMessage());
}
}
}
Expand Down Expand Up @@ -366,4 +323,81 @@ public void onClick(DialogInterface dialog, int which) {
builder.create().show();

}

@Override
public void onFilterSelected(PhotoFilter photoFilter) {
mPhotoEditor.setFilterEffect(photoFilter);
}

@Override
public void onToolSelected(ToolType toolType) {
switch (toolType) {
case BRUSH:
mPhotoEditor.setBrushDrawingMode(true);
mTxtCurrentTool.setText(R.string.label_brush);
mPropertiesBSFragment.show(getSupportFragmentManager(), mPropertiesBSFragment.getTag());
break;
case TEXT:
TextEditorDialogFragment textEditorDialogFragment = TextEditorDialogFragment.show(this);
textEditorDialogFragment.setOnTextEditorListener(new TextEditorDialogFragment.TextEditor() {
@Override
public void onDone(String inputText, int colorCode) {
mPhotoEditor.addText(inputText, colorCode);
mTxtCurrentTool.setText(R.string.label_text);
}
});
break;
case ERASER:
mPhotoEditor.brushEraser();
mTxtCurrentTool.setText(R.string.label_eraser);
break;
case FILTER:
mTxtCurrentTool.setText(R.string.label_filter);
showFilter(true);
break;
case EMOJI:
mEmojiBSFragment.show(getSupportFragmentManager(), mEmojiBSFragment.getTag());
break;
case STICKER:
mStickerBSFragment.show(getSupportFragmentManager(), mStickerBSFragment.getTag());
break;
}
}


void showFilter(boolean isVisible) {
mIsFilterVisible = isVisible;
mConstraintSet.clone(mRootView);

if (isVisible) {
mConstraintSet.clear(mRvFilters.getId(), ConstraintSet.START);
mConstraintSet.connect(mRvFilters.getId(), ConstraintSet.START,
ConstraintSet.PARENT_ID, ConstraintSet.START);
mConstraintSet.connect(mRvFilters.getId(), ConstraintSet.END,
ConstraintSet.PARENT_ID, ConstraintSet.END);
} else {
mConstraintSet.connect(mRvFilters.getId(), ConstraintSet.START,
ConstraintSet.PARENT_ID, ConstraintSet.END);
mConstraintSet.clear(mRvFilters.getId(), ConstraintSet.END);
}

ChangeBounds changeBounds = new ChangeBounds();
changeBounds.setDuration(350);
changeBounds.setInterpolator(new AnticipateOvershootInterpolator(1.0f));
TransitionManager.beginDelayedTransition(mRootView, changeBounds);

mConstraintSet.applyTo(mRootView);
}

@Override
public void onBackPressed() {
if (mIsFilterVisible) {
showFilter(false);
mTxtCurrentTool.setText(R.string.app_name);
} else if (!mPhotoEditor.isCacheEmpty()) {
showSaveDialog();
} else {
super.onBackPressed();
}
}
}
Loading

0 comments on commit b32e40c

Please sign in to comment.