Skip to content

Commit

Permalink
- android: adding stickers support
Browse files Browse the repository at this point in the history
  • Loading branch information
prscms committed Sep 11, 2018
1 parent d13923f commit 4f072ee
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 18 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,19 @@ public void onCreate(@Nullable Bundle savedInstanceState) {

TypedArray images = getResources().obtainTypedArray(R.array.photo_editor_photos);

stickerBitmaps = new ArrayList<>();
for (int i = 0; i < images.length(); i++) {
stickerBitmaps.add(decodeSampledBitmapFromResource(photoEditorActivity.getResources(), images.getResourceId(i, -1), 120, 120));
ArrayList<Integer> stickers = (ArrayList<Integer>) getActivity().getIntent().getExtras().getSerializable("stickers");

if (stickers != null && stickers.size() > 0) {
stickerBitmaps = new ArrayList<>();

for (int i = 0;i < stickers.size();i++) {
stickerBitmaps.add(decodeSampledBitmapFromResource(getActivity().getResources(), stickers.get(i), 120, 120));
}
} else {
stickerBitmaps = new ArrayList<>();
for (int i = 0; i < images.length(); i++) {
stickerBitmaps.add(decodeSampledBitmapFromResource(photoEditorActivity.getResources(), images.getResourceId(i, -1), 120, 120));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.ahmedadeltito.photoeditorsdk.ViewType;
import com.viewpagerindicator.PageIndicator;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -110,8 +112,20 @@ protected void onCreate(Bundle savedInstanceState) {
deleteTextView.setTypeface(newFont);

final List<Fragment> fragmentsList = new ArrayList<>();
fragmentsList.add(new ImageFragment());
fragmentsList.add(new EmojiFragment());

ImageFragment imageFragment = new ImageFragment();
ArrayList stickers = (ArrayList<Integer>) getIntent().getExtras().getSerializable("stickers");
if (stickers != null && stickers.size() > 0) {
Bundle bundle = new Bundle();
bundle.putSerializable("stickers", stickers);

imageFragment.setArguments(bundle);
}

fragmentsList.add(imageFragment);

EmojiFragment emojiFragment = new EmojiFragment();
fragmentsList.add(emojiFragment);

PreviewSlidePagerAdapter adapter = new PreviewSlidePagerAdapter(getSupportFragmentManager(), fragmentsList);
pager.setAdapter(adapter);
Expand Down Expand Up @@ -356,6 +370,45 @@ public void onFinish() {
}.start();
}


private void returnBackWithUpdateImage() {
updateView(View.GONE);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
parentImageRelativeLayout.setLayoutParams(layoutParams);
new CountDownTimer(1000, 500) {
public void onTick(long millisUntilFinished) {

}

public void onFinish() {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageName = "IMG_" + timeStamp + ".jpg";

String selectedImagePath = getIntent().getExtras().getString("selectedImagePath");
File file = new File(selectedImagePath);

try {
FileOutputStream out = new FileOutputStream(file);
if (parentImageRelativeLayout != null) {
parentImageRelativeLayout.setDrawingCacheEnabled(true);
parentImageRelativeLayout.getDrawingCache().compress(Bitmap.CompressFormat.JPEG, 80, out);
}

out.flush();
out.close();
} catch (Exception var7) {
var7.printStackTrace();
}


finish();
}
}.start();
}


@Override
public void onClick(View v) {
if (v.getId() == R.id.close_tv) {
Expand All @@ -377,7 +430,7 @@ public void onClick(View v) {
} else if (v.getId() == R.id.erase_drawing_tv) {
eraseDrawing();
} else if (v.getId() == R.id.go_to_next_screen_tv) {
returnBackWithSavedImage();
returnBackWithUpdateImage();
}
}

Expand Down
31 changes: 19 additions & 12 deletions android/src/main/java/ui/photoeditor/RNPhotoEditorModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
package ui.photoeditor;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
Expand Down Expand Up @@ -33,36 +37,39 @@ public String getName() {
public void Edit(final ReadableMap props, final Callback onDone, final Callback onCancel) {
String path = props.getString("path");

//Process Stickers
ReadableArray stickers = props.getArray("stickers");
ArrayList<Integer> stickersIntent = new ArrayList<Integer>();

for (int i = 0;i < stickers.size();i++) {
int drawableId = getReactApplicationContext().getResources().getIdentifier(stickers.getString(i), "drawable", getReactApplicationContext().getPackageName());

stickersIntent.add(drawableId);
}

//Process Hidden Controls
ReadableArray hiddenControls = props.getArray("hiddenControls");
ArrayList hiddenControlsIntent = new ArrayList<>();

for (int i = 0;i < hiddenControls.size();i++) {
hiddenControlsIntent.add(hiddenControls.getString(i));
}

//Process Colors
ReadableArray colors = props.getArray("colors");
ArrayList colorPickerColors = new ArrayList<>();

for (int i = 0;i < colors.size();i++) {
colorPickerColors.add(Color.parseColor(colors.getString(i)));
}


Intent intent = new Intent(getCurrentActivity(), PhotoEditorActivity.class);
intent.putExtra("selectedImagePath", path);
intent.putExtra("colorPickerColors", colorPickerColors);
intent.putExtra("hiddenControls", hiddenControlsIntent);
intent.putExtra("stickers", stickersIntent);

getCurrentActivity().startActivity(intent);

// if (mActivity != null) {
// mActivity.startActivityForResult(intent, mRequestCode);
// } else if (mFragment != null) {
// mFragment.startActivityForResult(intent, mRequestCode);
// } else {
// mSupportFragment.startActivityForResult(intent, mRequestCode);
// }

// PhotoEditorSDK photoEditorSDK = new PhotoEditorSDK.PhotoEditorSDKBuilder(PhotoEditorActivity.this)
// .buildPhotoEditorSDK();
getCurrentActivity().startActivityForResult(intent, 1);
}
}

0 comments on commit 4f072ee

Please sign in to comment.