File comparison in Android

You can visually compare pages. This resolution independent comparison allows you to quickly spot differences between pages.

There are two main ways to integrate the out-of-box UI components in your application:

  1. Standalone activity
  2. Comparison options dialog

Standalone activity

The DiffActivity is a standalone component that handles from picking two files to generating the comparison result.

Apryse Docs Image
  1. Define the activity

Storage Permission

Please follow the latest Android best practices and guidelines outlined here

XML

1<activity android:name="com.pdftron.pdf.controls.DiffActivity" android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize" android:theme="@style/PDFTronAppTheme" android:windowSoftInputMode="adjustPan" />
  1. Show the activity
1DiffActivity.open(this);

Comparison options dialog

If you have your own viewer already and only want to show the comparison options in your application, the DiffOptionsDialogFragment can be used.

Apryse Docs Image
1public void show(final Context context, FragmentManager fragmentManager, final ArrayList<Uri> files) {
2 DiffOptionsDialogFragment fragment = DiffOptionsDialogFragment.newInstance(
3 files.get(0), files.get(1)
4 );
5 fragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.PDFTronAppTheme);
6 fragment.setDiffOptionsDialogListener(new DiffOptionsDialogFragment.DiffOptionsDialogListener() {
7 @Override
8 public void onDiffOptionsConfirmed(int color1, int color2, int blendMode) {
9 compareFiles(context, files, color1, color2, blendMode);
10 }
11 });
12 fragment.show(fragmentManager, DiffOptionsDialogFragment.TAG);
13}

where compareFile is:

1private final CompositeDisposable mDisposable = new CompositeDisposable();
2
3private void compareFiles(Context context, ArrayList<Uri> files, int color1, int color2, int blendMode) {
4 mDisposable.add(DiffUtils.compareFiles(context, files, color1, color2, blendMode)
5 .subscribeOn(Schedulers.io())
6 .observeOn(AndroidSchedulers.mainThread())
7 .subscribe(new Consumer<Uri>() {
8 @Override
9 public void accept(Uri uri) throws Exception {
10 // do something with the output
11 }
12 }, new Consumer<Throwable>() {
13 @Override
14 public void accept(Throwable throwable) throws Exception {
15
16 }
17 }));
18}

AsyncTask pattern can be used instead of Disposable pattern if desired.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales