From b48980957c3a2859290b6a9ff2a2ba7eae354cdc Mon Sep 17 00:00:00 2001 From: Tej Pratap Singh Date: Thu, 5 Aug 2021 13:24:00 +0530 Subject: [PATCH] - Adding jitpack.yml - Reformatting code - Organising imports --- app/build.gradle | 9 +- .../ExampleInstrumentedTest.java | 4 +- .../pdfcreatorandroid/MainActivityTest.java | 18 +- .../PdfCreatorExampleActivityTest.java | 2 +- .../pdfcreatorandroid/ScreenRobot.java | 73 ++-- app/src/main/assets/invoice.html | 5 +- .../PdfCreatorExampleActivity.java | 2 +- .../PdfEditorExampleActivity.java | 54 +-- app/src/main/res/drawable-anydpi/ic_focus.xml | 8 +- app/src/main/res/drawable-anydpi/ic_pdf.xml | 19 +- app/src/main/res/drawable-anydpi/ic_print.xml | 23 +- app/src/main/res/drawable-anydpi/ic_share.xml | 23 +- .../main/res/layout/activity_pdf_editor.xml | 1 - .../res/mipmap-anydpi-v26/ic_launcher.xml | 4 +- .../mipmap-anydpi-v26/ic_launcher_round.xml | 4 +- app/src/main/res/values-v21/styles.xml | 2 +- app/src/main/res/xml/file_provider_paths.xml | 2 +- .../pdfcreatorandroid/ExampleUnitTest.java | 4 +- jitpack.yml | 2 + .../src/main/java/android/print/PDFPrint.java | 12 +- .../activity/PDFCreatorActivity.java | 12 +- .../activity/PDFViewerActivity.java | 7 +- .../pdfcreator/custom/TouchImageView.java | 83 ++-- .../custom/TouchImageViewFling.java | 368 +++++++++--------- .../custom/ViewPagerForPhotoView.java | 13 +- .../pdfcreator/custom/ZoomLayout.java | 20 +- .../pdfcreator/utils/FileManager.java | 41 +- .../pdfcreator/utils/PDFUtil.java | 148 +++---- .../pdfcreator/views/PDFTableView.java | 7 +- .../pdfcreator/views/basic/PDFTextView.java | 53 ++- .../pdfcreator/views/basic/PDFView.java | 19 +- .../src/main/res/drawable-anydpi/ic_left.xml | 6 +- .../src/main/res/drawable-anydpi/ic_right.xml | 6 +- .../res/drawable/layout_rounded_corner.xml | 14 +- 34 files changed, 519 insertions(+), 549 deletions(-) create mode 100644 jitpack.yml diff --git a/app/build.gradle b/app/build.gradle index ec6072b..5e5a757 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,6 @@ -apply plugin: 'com.android.application' +plugins { + id 'com.android.application' +} android { compileSdkVersion 30 @@ -17,10 +19,9 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } - buildToolsVersion '30.0.2' } dependencies { diff --git a/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/ExampleInstrumentedTest.java index 0ba3200..9f8ca9c 100644 --- a/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/ExampleInstrumentedTest.java @@ -1,5 +1,7 @@ package com.tejpratapsingh.pdfcreatorandroid; +import static org.junit.Assert.assertEquals; + import android.content.Context; import androidx.test.InstrumentationRegistry; @@ -8,8 +10,6 @@ import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.assertEquals; - /** * Instrumented test, which will execute on an Android device. * diff --git a/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/MainActivityTest.java b/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/MainActivityTest.java index 53e8700..ea4f086 100644 --- a/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/MainActivityTest.java +++ b/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/MainActivityTest.java @@ -1,14 +1,5 @@ package com.tejpratapsingh.pdfcreatorandroid; -import android.view.View; - -import androidx.test.espresso.ViewInteraction; -import androidx.test.ext.junit.rules.ActivityScenarioRule; - -import org.hamcrest.core.IsInstanceOf; -import org.junit.Rule; -import org.junit.Test; - import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.assertion.ViewAssertions.matches; @@ -19,6 +10,15 @@ import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.anyOf; +import android.view.View; + +import androidx.test.espresso.ViewInteraction; +import androidx.test.ext.junit.rules.ActivityScenarioRule; + +import org.hamcrest.core.IsInstanceOf; +import org.junit.Rule; +import org.junit.Test; + public class MainActivityTest extends ScreenRobot { @Rule diff --git a/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/PdfCreatorExampleActivityTest.java b/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/PdfCreatorExampleActivityTest.java index a41e591..1693f82 100644 --- a/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/PdfCreatorExampleActivityTest.java +++ b/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/PdfCreatorExampleActivityTest.java @@ -10,7 +10,7 @@ public class PdfCreatorExampleActivityTest extends ScreenRobot activityRule = - new ActivityScenarioRule<>( PdfCreatorExampleActivity.class ); + new ActivityScenarioRule<>(PdfCreatorExampleActivity.class); @Test public void canGeneratePdf() { diff --git a/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/ScreenRobot.java b/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/ScreenRobot.java index 6e93eac..290cf47 100644 --- a/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/ScreenRobot.java +++ b/app/src/androidTest/java/com/tejpratapsingh/pdfcreatorandroid/ScreenRobot.java @@ -1,9 +1,5 @@ package com.tejpratapsingh.pdfcreatorandroid; -import android.app.Activity; -import androidx.annotation.IdRes; -import androidx.annotation.StringRes; - import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.Espresso.pressBack; import static androidx.test.espresso.action.ViewActions.click; @@ -17,84 +13,87 @@ import static androidx.test.espresso.matcher.ViewMatchers.withText; import static org.hamcrest.Matchers.not; +import android.app.Activity; + +import androidx.annotation.IdRes; +import androidx.annotation.StringRes; + // URL: https://gist.github.com/adavis/f35c12bdafbf2e20f66485235f9d423f public abstract class ScreenRobot { private Activity activityContext; // Only required for some calls - public static T withRobot (Class screenRobotClass) { - if ( screenRobotClass == null ) { - throw new IllegalArgumentException( "instance class == null" ); + public static T withRobot(Class screenRobotClass) { + if (screenRobotClass == null) { + throw new IllegalArgumentException("instance class == null"); } try { return screenRobotClass.newInstance(); - } - catch ( IllegalAccessException iae ) { - throw new RuntimeException( "IllegalAccessException", iae ); - } - catch ( InstantiationException ie ) { - throw new RuntimeException( "InstantiationException", ie ); + } catch (IllegalAccessException iae) { + throw new RuntimeException("IllegalAccessException", iae); + } catch (InstantiationException ie) { + throw new RuntimeException("InstantiationException", ie); } } - public T checkIsDisplayed (@IdRes int... viewIds) { - for ( int viewId : viewIds ) { - onView( withId( viewId ) ).check( matches( isDisplayed() ) ); + public T checkIsDisplayed(@IdRes int... viewIds) { + for (int viewId : viewIds) { + onView(withId(viewId)).check(matches(isDisplayed())); } return (T) this; } - public T checkIsHidden (@IdRes int... viewIds) { - for ( int viewId : viewIds ) { - onView( withId( viewId ) ).check( matches( not( isDisplayed() ) ) ); + public T checkIsHidden(@IdRes int... viewIds) { + for (int viewId : viewIds) { + onView(withId(viewId)).check(matches(not(isDisplayed()))); } return (T) this; } - public T checkViewHasText (@IdRes int viewId, String expected) { - onView( withId( viewId ) ).check( matches( withText( expected ) ) ); + public T checkViewHasText(@IdRes int viewId, String expected) { + onView(withId(viewId)).check(matches(withText(expected))); return (T) this; } - public T checkViewHasText (@IdRes int viewId, @StringRes int messageResId) { - onView( withId( viewId ) ).check( matches( withText( messageResId ) ) ); + public T checkViewHasText(@IdRes int viewId, @StringRes int messageResId) { + onView(withId(viewId)).check(matches(withText(messageResId))); return (T) this; } - public T checkViewHasHint (@IdRes int viewId, @StringRes int messageResId) { - onView( withId( viewId ) ).check( matches( withHint( messageResId ) ) ); + public T checkViewHasHint(@IdRes int viewId, @StringRes int messageResId) { + onView(withId(viewId)).check(matches(withHint(messageResId))); return (T) this; } - public T clickOkOnView (@IdRes int viewId) { - onView( withId( viewId ) ).perform( click() ); + public T clickOkOnView(@IdRes int viewId) { + onView(withId(viewId)).perform(click()); return (T) this; } - public T enterTextIntoView (@IdRes int viewId, String text) { - onView( withId( viewId ) ).perform( typeText( text ) ); + public T enterTextIntoView(@IdRes int viewId, String text) { + onView(withId(viewId)).perform(typeText(text)); return (T) this; } - public T provideActivityContext (Activity activityContext) { + public T provideActivityContext(Activity activityContext) { this.activityContext = activityContext; return (T) this; } - public T checkDialogWithTextIsDisplayed (@StringRes int messageResId) { - onView( withText( messageResId ) ) - .inRoot( withDecorView( not( activityContext.getWindow().getDecorView() ) ) ) - .check( matches( isDisplayed() ) ); + public T checkDialogWithTextIsDisplayed(@StringRes int messageResId) { + onView(withText(messageResId)) + .inRoot(withDecorView(not(activityContext.getWindow().getDecorView()))) + .check(matches(isDisplayed())); return (T) this; } - public T swipeLeftOnView (@IdRes int viewId) { - onView( withId( viewId ) ).perform( swipeLeft() ); + public T swipeLeftOnView(@IdRes int viewId) { + onView(withId(viewId)).perform(swipeLeft()); return (T) this; } - public T goBack () { + public T goBack() { pressBack(); return (T) this; } diff --git a/app/src/main/assets/invoice.html b/app/src/main/assets/invoice.html index 39b4642..bb9a863 100644 --- a/app/src/main/assets/invoice.html +++ b/app/src/main/assets/invoice.html @@ -1,8 +1,8 @@ - + - + diff --git a/app/src/main/java/com/tejpratapsingh/pdfcreatorandroid/PdfCreatorExampleActivity.java b/app/src/main/java/com/tejpratapsingh/pdfcreatorandroid/PdfCreatorExampleActivity.java index 1ce38a4..3ce95a6 100644 --- a/app/src/main/java/com/tejpratapsingh/pdfcreatorandroid/PdfCreatorExampleActivity.java +++ b/app/src/main/java/com/tejpratapsingh/pdfcreatorandroid/PdfCreatorExampleActivity.java @@ -25,10 +25,10 @@ import com.tejpratapsingh.pdfcreator.views.PDFFooterView; import com.tejpratapsingh.pdfcreator.views.PDFHeaderView; import com.tejpratapsingh.pdfcreator.views.PDFTableView; -import com.tejpratapsingh.pdfcreator.views.basic.PDFPageBreakView; import com.tejpratapsingh.pdfcreator.views.basic.PDFHorizontalView; import com.tejpratapsingh.pdfcreator.views.basic.PDFImageView; import com.tejpratapsingh.pdfcreator.views.basic.PDFLineSeparatorView; +import com.tejpratapsingh.pdfcreator.views.basic.PDFPageBreakView; import com.tejpratapsingh.pdfcreator.views.basic.PDFTextView; import java.io.File; diff --git a/app/src/main/java/com/tejpratapsingh/pdfcreatorandroid/PdfEditorExampleActivity.java b/app/src/main/java/com/tejpratapsingh/pdfcreatorandroid/PdfEditorExampleActivity.java index e3547a3..064110c 100644 --- a/app/src/main/java/com/tejpratapsingh/pdfcreatorandroid/PdfEditorExampleActivity.java +++ b/app/src/main/java/com/tejpratapsingh/pdfcreatorandroid/PdfEditorExampleActivity.java @@ -28,33 +28,6 @@ public class PdfEditorExampleActivity extends AppCompatActivity { private WebView webView; - public static class MyWebViewClient extends WebViewClient { - - public interface OnSourceReceived { - void success(String html); - } - - private final OnSourceReceived onSourceReceived; - - public MyWebViewClient(OnSourceReceived onSourceReceived) { - this.onSourceReceived = onSourceReceived; - } - - public boolean shouldOverrideUrlLoading(WebView view, String url) { - if (url.startsWith("source://")) { - try { - String html = URLDecoder.decode(url, "UTF-8").substring(9); - onSourceReceived.success(html); - } catch (UnsupportedEncodingException e) { - Log.e("example", "failed to decode source", e); - } - return true; - } - // For all other links, let the WebView do it's normal thing - return false; - } - } - @SuppressLint("SetJavaScriptEnabled") @Override protected void onCreate(Bundle savedInstanceState) { @@ -129,4 +102,31 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { } return super.onOptionsItemSelected(item); } + + public static class MyWebViewClient extends WebViewClient { + + private final OnSourceReceived onSourceReceived; + + public MyWebViewClient(OnSourceReceived onSourceReceived) { + this.onSourceReceived = onSourceReceived; + } + + public boolean shouldOverrideUrlLoading(WebView view, String url) { + if (url.startsWith("source://")) { + try { + String html = URLDecoder.decode(url, "UTF-8").substring(9); + onSourceReceived.success(html); + } catch (UnsupportedEncodingException e) { + Log.e("example", "failed to decode source", e); + } + return true; + } + // For all other links, let the WebView do it's normal thing + return false; + } + + public interface OnSourceReceived { + void success(String html); + } + } } \ No newline at end of file diff --git a/app/src/main/res/drawable-anydpi/ic_focus.xml b/app/src/main/res/drawable-anydpi/ic_focus.xml index dfca8dc..97d0db4 100644 --- a/app/src/main/res/drawable-anydpi/ic_focus.xml +++ b/app/src/main/res/drawable-anydpi/ic_focus.xml @@ -1,11 +1,11 @@ + android:viewportWidth="24" + android:viewportHeight="24"> + android:pathData="M5,15L3,15v4c0,1.1 0.9,2 2,2h4v-2L5,19v-4zM5,5h4L9,3L5,3c-1.1,0 -2,0.9 -2,2v4h2L5,5zM19,3h-4v2h4v4h2L21,5c0,-1.1 -0.9,-2 -2,-2zM19,19h-4v2h4c1.1,0 2,-0.9 2,-2v-4h-2v4zM12,8c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM12,14c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z" /> diff --git a/app/src/main/res/drawable-anydpi/ic_pdf.xml b/app/src/main/res/drawable-anydpi/ic_pdf.xml index 37c7606..3425294 100644 --- a/app/src/main/res/drawable-anydpi/ic_pdf.xml +++ b/app/src/main/res/drawable-anydpi/ic_pdf.xml @@ -1,14 +1,15 @@ - - - + android:viewportWidth="24" + android:viewportHeight="24"> + + + diff --git a/app/src/main/res/drawable-anydpi/ic_print.xml b/app/src/main/res/drawable-anydpi/ic_print.xml index 3e2fef7..04eb9f6 100644 --- a/app/src/main/res/drawable-anydpi/ic_print.xml +++ b/app/src/main/res/drawable-anydpi/ic_print.xml @@ -1,16 +1,17 @@ - - - + android:viewportWidth="24" + android:viewportHeight="24"> + + + diff --git a/app/src/main/res/drawable-anydpi/ic_share.xml b/app/src/main/res/drawable-anydpi/ic_share.xml index f67ec46..cc11daf 100644 --- a/app/src/main/res/drawable-anydpi/ic_share.xml +++ b/app/src/main/res/drawable-anydpi/ic_share.xml @@ -1,16 +1,17 @@ - - - + android:viewportWidth="24" + android:viewportHeight="24"> + + + diff --git a/app/src/main/res/layout/activity_pdf_editor.xml b/app/src/main/res/layout/activity_pdf_editor.xml index 0b3094a..f90a348 100644 --- a/app/src/main/res/layout/activity_pdf_editor.xml +++ b/app/src/main/res/layout/activity_pdf_editor.xml @@ -1,6 +1,5 @@ - - + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml index 036d09b..c9ad5f9 100644 --- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml index 13eb58b..d69c0ec 100644 --- a/app/src/main/res/values-v21/styles.xml +++ b/app/src/main/res/values-v21/styles.xml @@ -7,7 +7,7 @@ @color/colorPrimaryDark -