Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

Commit

Permalink
Fix demo app (#94)
Browse files Browse the repository at this point in the history
* Update gradle wrapper

* Picker updated

* Improved image picker

* Fix first time image blank bug

* Disable user interaction until image loads successfully

* Remove dead code
  • Loading branch information
iamutkarshtiwari authored Jun 22, 2021
1 parent b78725e commit 0ff32f4
Show file tree
Hide file tree
Showing 39 changed files with 947 additions and 949 deletions.
2 changes: 0 additions & 2 deletions ananas/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ dependencies {
api "com.theartofdev.edmodo:android-image-cropper:${cropper_version}"
implementation "io.reactivex.rxjava2:rxjava:${rxjava_version}"
implementation "io.reactivex.rxjava2:rxandroid:${rxandroid_version}"
implementation "com.github.bumptech.glide:glide:${glide_version}"
kapt "com.github.bumptech.glide:compiler:${glide_version}"
implementation "androidx.core:core-ktx:${core_ktx_version}"
implementation "com.android.support.constraint:constraint-layout:${constraint_layout_version}"
}
Expand Down
2 changes: 1 addition & 1 deletion ananas/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:label="@string/iamutkarshtiwari_github_io_ananas_library_name"
android:exported="true" />

<activity android:name=".picchooser.SelectPictureActivity" />
<activity android:name="iamutkarshtiwari.github.io.imageeditorsample.picchooser.SelectPictureActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package iamutkarshtiwari.github.io.ananas.editimage;

import android.Manifest;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
Expand All @@ -11,13 +11,15 @@
import android.os.Bundle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Surface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;

import androidx.activity.result.ActivityResultLauncher;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
Expand Down Expand Up @@ -109,18 +111,17 @@ public class EditImageActivity extends BaseActivity implements OnLoadingDialogLi
private int imageWidth, imageHeight;
private Bitmap mainBitmap;
private Dialog loadingDialog;
private TextView titleView;
private MainMenuFragment mainMenuFragment;
private RedoUndoController redoUndoController;
private OnMainBitmapChangeListener onMainBitmapChangeListener;
private CompositeDisposable compositeDisposable = new CompositeDisposable();
private final CompositeDisposable compositeDisposable = new CompositeDisposable();

public static void start(Activity activity, Intent intent, int requestCode) {
public static void start(ActivityResultLauncher<Intent> launcher, Intent intent, Context context) {
if (TextUtils.isEmpty(intent.getStringExtra(ImageEditorIntentBuilder.SOURCE_PATH))) {
Toast.makeText(activity, R.string.iamutkarshtiwari_github_io_ananas_not_selected, Toast.LENGTH_SHORT).show();
Toast.makeText(context, R.string.iamutkarshtiwari_github_io_ananas_not_selected, Toast.LENGTH_SHORT).show();
return;
}
activity.startActivityForResult(intent, requestCode);
launcher.launch(intent);
}

@Override
Expand All @@ -131,12 +132,6 @@ public void onCreate(Bundle savedInstanceState) {
initView();
}

@Override
protected void onPause() {
compositeDisposable.clear();
super.onPause();
}

@Override
public void showLoadingDialog() {
loadingDialog.show();
Expand All @@ -157,7 +152,7 @@ private void getData() {
}

private void initView() {
titleView = findViewById(R.id.title);
TextView titleView = findViewById(R.id.title);
if (editorTitle != null) {
titleView.setText(editorTitle);
}
Expand Down Expand Up @@ -238,16 +233,13 @@ private void setOnMainBitmapChangeListener(OnMainBitmapChangeListener listener)
@Override
public void onRequestPermissionsResult(int requestCode,
@NotNull String permissions[], @NotNull int[] grantResults) {
switch (requestCode) {
case PERMISSIONS_REQUEST_CODE: {
// If request is cancelled, the result arrays are empty.
if (!(grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
finish();
}
break;
if (requestCode == PERMISSIONS_REQUEST_CODE) {
if (!(grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
finish();
}
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

@Override
Expand All @@ -268,8 +260,7 @@ private void closeInputMethod() {
}

@Override
public void onPointerCaptureChanged(boolean hasCapture) {
}
public void onPointerCaptureChanged(boolean hasCapture) { }

@Override
public void onBackPressed() {
Expand Down Expand Up @@ -349,8 +340,6 @@ protected void doSaveImage() {
if (numberOfOperations <= 0)
return;

compositeDisposable.clear();

Disposable saveImageDisposable = saveImage(mainBitmap)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
Expand Down Expand Up @@ -378,14 +367,21 @@ private Single<Boolean> saveImage(Bitmap finalBitmap) {
}

private void loadImageFromFile(String filePath) {
compositeDisposable.clear();

Disposable loadImageDisposable = loadImage(filePath)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe(subscriber -> loadingDialog.show())
.doOnSubscribe(subscriber -> {
loadingDialog.show();
mainMenuFragment.setMenuOptionsClickable(false);
})
.doOnSuccess(bitmap -> {
mainMenuFragment.setMenuOptionsClickable(true);
})
.doFinally(() -> loadingDialog.dismiss())
.subscribe(processedBitmap -> changeMainBitmap(processedBitmap, false), e -> showToast(R.string.iamutkarshtiwari_github_io_ananas_load_error));
.subscribe(processedBitmap -> changeMainBitmap(processedBitmap, false), e -> {
showToast(R.string.iamutkarshtiwari_github_io_ananas_load_error);
Log.wtf("Error", e.getMessage());
});

compositeDisposable.add(loadImageDisposable);
}
Expand Down Expand Up @@ -459,9 +455,6 @@ public Bitmap getMainBit() {
return mainBitmap;
}

/**
* @author panyi
*/
private final class BottomGalleryAdapter extends FragmentPagerAdapter {
BottomGalleryAdapter(FragmentManager fm) {
super(fm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ImageEditorIntentBuilder @JvmOverloads constructor(private val context: Co
fun build(): Intent {

if (sourcePath.isNullOrBlank()) {
throw Exception("Output image path required. Use withOutputPath(path) to provide the output image path.")
throw Exception("Source image path required. Use withSourcePath(path) to provide the output image path.")
} else {
intent.putExtra(SOURCE_PATH, sourcePath)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ private void scaleImage() {
public void applyTextImage() {
// Hide borders of all stickers before save
updateViewsBordersVisibilityExcept(null);
compositeDisposable.clear();
Disposable applyTextDisposable = Observable.fromCallable(() -> getFinalBitmapFromView(textStickersParentView))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
Expand Down Expand Up @@ -239,12 +238,6 @@ private Bitmap getFinalBitmapFromView(View view) {
return Bitmap.createBitmap(resultBitmap, textStickerWidthCenterX - (imageViewWidth / 2), textStickerHeightCenterY - (imageViewHeight / 2), imageViewWidth, imageViewHeight);
}

@Override
public void onPause() {
compositeDisposable.clear();
super.onPause();
}

@Override
public void onDestroy() {
compositeDisposable.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,4 @@ public void onDestroy() {
super.onDestroy();
disposable.dispose();
}

@Override
public void onPause() {
super.onPause();
disposable.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ public void applyFilterImage() {
}
}

@Override
public void onPause() {
compositeDisposable.clear();
super.onPause();
}

@Override
public void onDestroy() {
tryRecycleFilterBitmap();
Expand All @@ -124,8 +118,6 @@ public void enableFilter(int filterIndex) {
return;
}

compositeDisposable.clear();

Disposable applyFilterDisposable = applyFilter(filterIndex)
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
Expand Down
Loading

0 comments on commit 0ff32f4

Please sign in to comment.