Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
RZulfikri committed Feb 13, 2019
2 parents 9039223 + 7ea2d4e commit 43c6810
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 54 deletions.
8 changes: 7 additions & 1 deletion Example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ export default class App extends Component<Props> {
"sticker10"
],
hiddenControls: [],
colors: undefined
colors: undefined,
onDone: () => {
console.log('on done')
},
onCancel: () => {
console.log('on cancel')
}
});
}

Expand Down
14 changes: 7 additions & 7 deletions Example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ android {
}
}
}
buildToolsVersion '27.0.3'
buildToolsVersion '28.0.3'
}

dependencies {
compile project(':rn-fetch-blob')
compile project(':react-native-fs')
compile project(':react-native-photo-editor')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
compile "com.facebook.react:react-native:+" // From node_modules
implementation project(':rn-fetch-blob')
implementation project(':react-native-fs')
implementation project(':react-native-photo-editor')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:28.0.0"
implementation "com.facebook.react:react-native:+" // From node_modules
}

// Run this once to be able to run the application with BUCK
Expand Down
5 changes: 4 additions & 1 deletion Example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
Expand Down
16 changes: 9 additions & 7 deletions Example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

buildscript {
repositories {
jcenter()
google()
maven { url 'https://jitpack.io' }
maven {
url 'https://maven.google.com/'
name 'Google'
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.2.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -19,8 +20,8 @@ buildscript {

allprojects {
repositories {
google()
mavenLocal()
jcenter()
maven { url 'https://jitpack.io' }
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
Expand All @@ -30,13 +31,14 @@ allprojects {
url 'https://maven.google.com/'
name 'Google'
}
jcenter()
}
}

ext {
buildToolsVersion = "26.0.3"
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 26
targetSdkVersion = 26
supportLibVersion = "26.1.0"
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.3"
}
4 changes: 2 additions & 2 deletions Example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Sep 09 19:41:28 IST 2018
#Sun Oct 14 12:20:52 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\:https://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\:https://services.gradle.org/distributions/gradle-4.6-all.zip
2 changes: 2 additions & 0 deletions Example/ios/Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSPhotoLibraryUsageDescription</key>
<string>iOS 10 needs permission to write photos...</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Our application needs permission to write photos...</string>
<key>UILaunchStoryboardName</key>
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ android {

`<activity android:name="com.ahmedadeltito.photoeditor.PhotoEditorActivity" />`

- To save image to the public external storage, you must request the WRITE_EXTERNAL_STORAGE permission in your manifest file:

`<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />`

> **Note:** Android SDK 27 > is supported
* iOS
Expand All @@ -92,6 +96,10 @@ android {
```
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Application needs permission to write photos...</string>
<!-- If you are targeting devices running on iOS 10 or later, you'll also need to add: -->
<key>NSPhotoLibraryUsageDescription</key>
<string>iOS 10 needs permission to write photos...</string>
```

* Now build your iOS app through Xcode
Expand Down
22 changes: 12 additions & 10 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@

buildscript {
repositories {
jcenter()
google()
maven { url 'https://jitpack.io' }
maven { url "https://maven.google.com" }
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.2.1'
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
buildToolsVersion '28.0.2'

defaultConfig {
minSdkVersion 16
Expand All @@ -29,17 +30,18 @@ android {
}

repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url "https://maven.google.com" }
}

dependencies {
compile 'com.facebook.react:react-native:+'
compile 'com.github.prscX:photo-editor-android:master-SNAPSHOT'
compile 'fr.avianey.com.viewpagerindicator:library:2.4.1@aar'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.android.support:design:27.1.1'
compile 'com.android.support:appcompat-v7:27.1.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.facebook.react:react-native:+'
implementation 'com.github.prscX:photo-editor-android:master-SNAPSHOT'
implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1@aar'
implementation 'com.nineoldandroids:library:2.4.0'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package com.ahmedadeltito.photoeditor;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.content.PermissionChecker;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
Expand All @@ -27,6 +34,7 @@
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ahmedadeltito.photoeditor.widget.SlidingUpPanelLayout;
import com.ahmedadeltito.photoeditorsdk.BrushDrawingView;
Expand All @@ -50,6 +58,8 @@ public class PhotoEditorActivity extends AppCompatActivity implements View.OnCli

public static Typeface emojiFont = null;

protected static final int MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE_GALLERY = 0x1;

private final String TAG = "PhotoEditorActivity";
private RelativeLayout parentImageRelativeLayout;
private RecyclerView drawingViewColorPickerRecyclerView;
Expand Down Expand Up @@ -355,25 +365,58 @@ public void onColorPickerClickListener(int colorCode) {
}

private void returnBackWithSavedImage() {
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) {
int permissionCheck = PermissionChecker.checkCallingOrSelfPermission(this,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE);

}
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
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";
Intent returnIntent = new Intent();
returnIntent.putExtra("imagePath", photoEditorSDK.saveImage("PhotoEditorSDK", imageName));
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
}.start();
}

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

if (isSDCARDMounted()) {
String folderName = "PhotoEditorSDK";
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), folderName);
if (!mediaStorageDir.exists() && !mediaStorageDir.mkdirs()) {
Log.d("PhotoEditorSDK", "Failed to create directory");
}

String selectedOutputPath = mediaStorageDir.getPath() + File.separator + imageName;
Log.d("PhotoEditorSDK", "selected camera path " + selectedOutputPath);
File file = new File(selectedOutputPath);

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();
}
}

Intent returnIntent = new Intent();
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
}.start();
Toast.makeText(this, getString(R.string.save_image_succeed), Toast.LENGTH_SHORT).show();
} else {
showPermissionRequest();
}
}


Expand Down Expand Up @@ -410,6 +453,8 @@ public void onFinish() {
var7.printStackTrace();
}

Intent returnIntent = new Intent();
setResult(Activity.RESULT_OK, returnIntent);

Intent returnIntent = new Intent();
returnIntent.putExtra("imagePath", newPath);
Expand All @@ -420,6 +465,47 @@ public void onFinish() {
}.start();
}

private boolean isSDCARDMounted() {
String status = Environment.getExternalStorageState();
return status.equals("mounted");
}

public void showPermissionRequest() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.access_media_permissions_msg));
builder.setPositiveButton(getString(R.string.continue_txt), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ActivityCompat.requestPermissions(PhotoEditorActivity.this,
new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE_GALLERY);
}
});
builder.setNegativeButton(getString(R.string.not_now), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(PhotoEditorActivity.this, getString(R.string.media_access_denied_msg), Toast.LENGTH_SHORT).show();
}
});
builder.show();
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE_GALLERY) {
// If request is cancelled, the result arrays are empty.
int permissionCheck = PermissionChecker.checkCallingOrSelfPermission(this,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
returnBackWithSavedImage();
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(this, getString(R.string.media_access_denied_msg), Toast.LENGTH_SHORT).show();
}
return;
}
}

@Override
public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ public void Edit(final ReadableMap props, final Callback onDone, final Callback

getCurrentActivity().startActivityForResult(intent, PHOTO_EDITOR_REQUEST);
}
}
}
1 change: 1 addition & 0 deletions android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string name="continue_txt">Continue</string>
<string name="not_now">NOT NOW</string>
<string name="media_access_denied_msg">You denied storage access, no photos will be added.</string>
<string name="save_image_succeed">Image saved</string>

<string name="ic_close">"\ue918"</string>
<string name="ic_text">"\ue945"</string>
Expand Down
Loading

0 comments on commit 43c6810

Please sign in to comment.