diff --git a/.gitignore b/.gitignore index a8ffde9..ce847be 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,3 @@ proguard/ # Ignore gradle files .gradle/ build/ -gradle.properties diff --git a/build.gradle b/build.gradle index 7909bc8..b800852 100644 --- a/build.gradle +++ b/build.gradle @@ -5,9 +5,10 @@ buildscript { jcenter() google() } + dependencies { - classpath 'com.android.tools.build:gradle:3.1.4' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' + classpath 'com.android.tools.build:gradle:4.1.1' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' // NOTE: Do not place your application dependencies here; they belong @@ -19,13 +20,16 @@ allprojects { repositories { jcenter() google() + maven { url "https://jitpack.io" } } } ext { - permissionsDispatcherVersion = '2.4.0' + permissionsDispatcherVersion = '4.8.0' supportLibraryVersion = '28.0.0-rc02' - rxPermissionsVersion = '0.9.4@aar' - rxJavaVersion = '2.1.10' - rxAndroidVersion = '2.0.2' + rxPermissionsVersion = '0.12' + rxJavaVersion = '3.0.8' + rxAndroidVersion = '3.0.0' + androidAnnotation = '1.1.0' + androidAppCompat = '1.2.0-rc01' } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5db3f70..31ceb64 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Sep 17 15:51:05 JST 2018 +#Sun Dec 27 18:54:48 CET 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip diff --git a/simplecropview-sample/build.gradle b/simplecropview-sample/build.gradle index 112a90c..9ee9d7b 100644 --- a/simplecropview-sample/build.gradle +++ b/simplecropview-sample/build.gradle @@ -1,17 +1,22 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 28 - buildToolsVersion '28.0.2' + compileSdkVersion 30 + buildToolsVersion '30.0.3' defaultConfig { applicationId "com.example.simplecropviewsample" minSdkVersion 14 - targetSdkVersion 28 + targetSdkVersion 30 versionCode 1 versionName "1.0.0" } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + buildTypes { release { minifyEnabled false @@ -38,10 +43,12 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(':simplecropview') - implementation "com.github.hotchemi:permissionsdispatcher:$permissionsDispatcherVersion" - annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:$permissionsDispatcherVersion" - implementation "com.android.support:appcompat-v7:$supportLibraryVersion" - implementation "com.tbruyelle.rxpermissions2:rxpermissions:$rxPermissionsVersion" - implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion" - implementation "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion" -} + implementation "org.permissionsdispatcher:permissionsdispatcher:$permissionsDispatcherVersion" + annotationProcessor "org.permissionsdispatcher:permissionsdispatcher-processor:$permissionsDispatcherVersion" + + implementation "androidx.annotation:annotation:$androidAnnotation" + implementation "androidx.appcompat:appcompat:$androidAppCompat" + implementation "com.github.tbruyelle:rxpermissions:$rxPermissionsVersion" + implementation "io.reactivex.rxjava3:rxjava:$rxJavaVersion" + implementation "io.reactivex.rxjava3:rxandroid:$rxAndroidVersion" +} \ No newline at end of file diff --git a/simplecropview-sample/gradle.properties b/simplecropview-sample/gradle.properties new file mode 100644 index 0000000..5daef55 --- /dev/null +++ b/simplecropview-sample/gradle.properties @@ -0,0 +1,2 @@ +org.gradle.caching=true +android.useAndroidX=true \ No newline at end of file diff --git a/simplecropview-sample/src/main/AndroidManifest.xml b/simplecropview-sample/src/main/AndroidManifest.xml index 2d5964b..6b8d67f 100644 --- a/simplecropview-sample/src/main/AndroidManifest.xml +++ b/simplecropview-sample/src/main/AndroidManifest.xml @@ -8,6 +8,7 @@ () { - @Override public boolean test(@io.reactivex.annotations.NonNull Boolean granted) - throws Exception { - return granted; - } - }) - .flatMapCompletable(new Function() { - @Override - public CompletableSource apply(@io.reactivex.annotations.NonNull Boolean aBoolean) - throws Exception { - return mCropView.load(uri) - .useThumbnail(true) - .initialFrameRect(mFrameRect) - .executeAsCompletable(); - } - }) - .subscribeOn(Schedulers.newThread()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Action() { - @Override public void run() throws Exception { - } - }, new Consumer() { - @Override public void accept(@NonNull Throwable throwable) throws Exception { - } - }); + return new RxPermissions(this) // TODO according to https://github.com/tbruyelle/RxPermissions/issues/214#issuecomment-403970703 + .request(Manifest.permission.WRITE_EXTERNAL_STORAGE) + .filter(new Predicate() { + @Override + public boolean test(@NonNull Boolean granted) + throws Exception { + return granted; + } + }) + .flatMapCompletable(new Function() { + @Override + public CompletableSource apply(@NonNull Boolean aBoolean) + throws Exception { + return mCropView.load(uri) + .useThumbnail(true) + .initialFrameRect(mFrameRect) + .executeAsCompletable(); + } + }) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Action() { + @Override + public void run() throws Exception { + } + }, new Consumer() { + @Override + public void accept(@NonNull Throwable throwable) throws Exception { + } + }); } private Disposable cropImage() { return mCropView.crop(mSourceUri) - .executeAsSingle() - .flatMap(new Function>() { - @Override public SingleSource apply(@io.reactivex.annotations.NonNull Bitmap bitmap) - throws Exception { - return mCropView.save(bitmap) - .compressFormat(mCompressFormat) - .executeAsSingle(createSaveUri()); - } - }) - .doOnSubscribe(new Consumer() { - @Override public void accept(@io.reactivex.annotations.NonNull Disposable disposable) - throws Exception { - showProgress(); - } - }) - .doFinally(new Action() { - @Override public void run() throws Exception { - dismissProgress(); - } - }) - .subscribeOn(Schedulers.newThread()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Consumer() { - @Override public void accept(@io.reactivex.annotations.NonNull Uri uri) throws Exception { - ((RxActivity) getActivity()).startResultActivity(uri); - } - }, new Consumer() { - @Override public void accept(@io.reactivex.annotations.NonNull Throwable throwable) - throws Exception { - } - }); + .executeAsSingle() + .flatMap(new Function>() { + @Override + public SingleSource apply(@NonNull Bitmap bitmap) + throws Exception { + return mCropView.save(bitmap) + .compressFormat(mCompressFormat) + .executeAsSingle(createSaveUri()); + } + }) + .doOnSubscribe(new Consumer() { + @Override + public void accept(@NonNull Disposable disposable) + throws Exception { + showProgress(); + } + }) + .doFinally(new Action() { + @Override + public void run() throws Exception { + dismissProgress(); + } + }) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer() { + @Override + public void accept(@NonNull Uri uri) throws Exception { + ((RxActivity) getActivity()).startResultActivity(uri); + } + }, new Consumer() { + @Override + public void accept(@NonNull Throwable throwable) + throws Exception { + } + }); } // Bind views ////////////////////////////////////////////////////////////////////////////////// @@ -208,7 +231,7 @@ private void bindViews(View view) { public void pickImage() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT).setType("image/*"), - REQUEST_PICK_IMAGE); + REQUEST_PICK_IMAGE); } else { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); @@ -219,16 +242,17 @@ public void pickImage() { public void showProgress() { ProgressDialogFragment f = ProgressDialogFragment.getInstance(); - getFragmentManager().beginTransaction().add(f, PROGRESS_DIALOG).commitAllowingStateLoss(); + getParentFragmentManager().beginTransaction().add(f, PROGRESS_DIALOG).commitAllowingStateLoss(); } public void dismissProgress() { - if (!isResumed()) return; - android.support.v4.app.FragmentManager manager = getFragmentManager(); - if (manager == null) return; + if (!isResumed()) { + return; + } + FragmentManager manager = getParentFragmentManager(); ProgressDialogFragment f = (ProgressDialogFragment) manager.findFragmentByTag(PROGRESS_DIALOG); if (f != null) { - getFragmentManager().beginTransaction().remove(f).commitAllowingStateLoss(); + getParentFragmentManager().beginTransaction().remove(f).commitAllowingStateLoss(); } } @@ -256,12 +280,12 @@ public static String getDirPath() { public static Uri getUriFromDrawableResId(Context context, int drawableResId) { StringBuilder builder = new StringBuilder().append(ContentResolver.SCHEME_ANDROID_RESOURCE) - .append("://") - .append(context.getResources().getResourcePackageName(drawableResId)) - .append("/") - .append(context.getResources().getResourceTypeName(drawableResId)) - .append("/") - .append(context.getResources().getResourceEntryName(drawableResId)); + .append("://") + .append(context.getResources().getResourcePackageName(drawableResId)) + .append("/") + .append(context.getResources().getResourceTypeName(drawableResId)) + .append("/") + .append(context.getResources().getResourceEntryName(drawableResId)); return Uri.parse(builder.toString()); } @@ -305,7 +329,8 @@ public static String getMimeType(Bitmap.CompressFormat format) { // Handle button event ///////////////////////////////////////////////////////////////////////// private final View.OnClickListener btnListener = new View.OnClickListener() { - @Override public void onClick(View v) { + @Override + public void onClick(View v) { switch (v.getId()) { case R.id.buttonDone: mDisposable.add(cropImage()); diff --git a/simplecropview-sample/src/main/res/layout/activity_basic.xml b/simplecropview-sample/src/main/res/layout/activity_basic.xml index 88b100d..5016e7a 100644 --- a/simplecropview-sample/src/main/res/layout/activity_basic.xml +++ b/simplecropview-sample/src/main/res/layout/activity_basic.xml @@ -5,7 +5,7 @@ android:layout_height="match_parent" android:orientation="vertical"> - - -