Skip to content

Commit

Permalink
- Adding jitpack.yml
Browse files Browse the repository at this point in the history
- Reformatting code
- Organising imports
  • Loading branch information
tejpratap46 committed Aug 5, 2021
1 parent 9e3d8d8 commit b489809
Show file tree
Hide file tree
Showing 34 changed files with 519 additions and 549 deletions.
9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.application'
plugins {
id 'com.android.application'
}

android {
compileSdkVersion 30
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.tejpratapsingh.pdfcreatorandroid;

import static org.junit.Assert.assertEquals;

import android.content.Context;

import androidx.test.InstrumentationRegistry;
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<MainActivityTest> {

@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class PdfCreatorExampleActivityTest extends ScreenRobot<PdfCreatorExample

@Rule
public ActivityScenarioRule<PdfCreatorExampleActivity> activityRule =
new ActivityScenarioRule<>( PdfCreatorExampleActivity.class );
new ActivityScenarioRule<>(PdfCreatorExampleActivity.class);

@Test
public void canGeneratePdf() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<T extends ScreenRobot> {
private Activity activityContext; // Only required for some calls

public static <T extends ScreenRobot> T withRobot (Class<T> screenRobotClass) {
if ( screenRobotClass == null ) {
throw new IllegalArgumentException( "instance class == null" );
public static <T extends ScreenRobot> T withRobot(Class<T> 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;
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/assets/invoice.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta content="width=device-width, initial-scale=1.0" name="viewport">

<style type="text/css">
body{
Expand Down Expand Up @@ -42,6 +42,7 @@
h4, p{
margin:0px;
}

</style>

</head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
}
8 changes: 4 additions & 4 deletions app/src/main/res/drawable-anydpi/ic_focus.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:alpha="0.8"
android:tint="#000000"
android:alpha="0.8">
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
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"/>
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" />
</vector>
19 changes: 10 additions & 9 deletions app/src/main/res/drawable-anydpi/ic_pdf.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:alpha="0.8"
android:tint="#2B2B2B"
android:alpha="0.8">
<group android:scaleX="0.052287582"
android:scaleY="0.052287582">
<path
android:fillColor="#FF000000"
android:pathData="M211.65,142.8L211.65,142.8C214.2,142.8 214.2,142.8 211.65,142.8c2.55,-10.2 5.1,-15.3 5.1,-22.95v-5.1c2.55,-12.75 2.55,-22.95 0,-25.5c0,0 0,0 0,-2.55l-2.55,-2.55l0,0l0,0c0,0 0,2.55 -2.55,2.55C206.55,102 206.55,119.85 211.65,142.8L211.65,142.8zM135.15,318.75c-5.1,2.55 -10.2,5.1 -12.75,7.65c-17.85,15.3 -30.6,33.149 -33.15,40.8l0,0l0,0l0,0C104.55,364.65 119.85,349.35 135.15,318.75C137.7,318.75 137.7,318.75 135.15,318.75C137.7,318.75 135.15,318.75 135.15,318.75zM369.75,280.5c-2.55,-2.55 -12.75,-10.2 -48.45,-10.2c-2.55,0 -2.55,0 -5.1,0l0,0c0,0 0,0 0,2.55c17.85,7.65 35.7,12.75 48.45,12.75c2.55,0 2.55,0 5.1,0l0,0h2.55c0,0 0,0 0,-2.55l0,0C372.3,283.05 369.75,283.05 369.75,280.5zM408,0H51C22.95,0 0,22.95 0,51v357c0,28.05 22.95,51 51,51h357c28.05,0 51,-22.95 51,-51V51C459,22.95 436.05,0 408,0zM379.95,300.9c-5.101,2.55 -12.75,5.1 -22.95,5.1c-20.4,0 -51,-5.1 -76.5,-17.85c-43.35,5.1 -76.5,10.199 -102,20.399c-2.55,0 -2.55,0 -5.1,2.55c-30.6,53.551 -56.1,79.051 -76.5,79.051c-5.1,0 -7.65,0 -10.2,-2.551l-12.75,-7.649v-2.55c-2.55,-5.101 -2.55,-7.65 -2.55,-12.75c2.55,-12.75 17.85,-35.7 48.45,-53.551c5.1,-2.55 12.75,-7.649 22.95,-12.75c7.65,-12.75 15.3,-28.05 25.5,-45.899c12.75,-25.5 20.4,-51 28.05,-73.95l0,0c-10.2,-30.6 -15.3,-48.45 -5.1,-84.15c2.55,-10.2 10.2,-20.4 20.4,-20.4h5.1c5.1,0 10.2,2.55 15.3,5.1c17.851,17.85 10.2,58.65 0,91.8c0,2.55 0,2.55 0,2.55c10.2,28.05 25.5,51 40.8,66.3c7.65,5.1 12.75,10.2 22.95,15.3c12.75,0 22.95,-2.55 33.15,-2.55c30.6,0 51,5.1 58.649,17.85c2.551,5.101 2.551,10.2 2.551,15.3C387.6,288.15 385.05,295.8 379.95,300.9zM214.2,201.45c-5.1,17.85 -15.3,38.25 -25.5,61.2c-5.1,10.199 -10.2,17.85 -15.3,28.05h2.55h2.55l0,0c33.15,-12.75 63.75,-20.4 84.15,-22.95c-5.101,-2.55 -7.65,-5.1 -10.2,-7.65C239.7,244.8 224.4,224.4 214.2,201.45z"/>
</group>
android:viewportWidth="24"
android:viewportHeight="24">
<group
android:scaleX="0.052287582"
android:scaleY="0.052287582">
<path
android:fillColor="#FF000000"
android:pathData="M211.65,142.8L211.65,142.8C214.2,142.8 214.2,142.8 211.65,142.8c2.55,-10.2 5.1,-15.3 5.1,-22.95v-5.1c2.55,-12.75 2.55,-22.95 0,-25.5c0,0 0,0 0,-2.55l-2.55,-2.55l0,0l0,0c0,0 0,2.55 -2.55,2.55C206.55,102 206.55,119.85 211.65,142.8L211.65,142.8zM135.15,318.75c-5.1,2.55 -10.2,5.1 -12.75,7.65c-17.85,15.3 -30.6,33.149 -33.15,40.8l0,0l0,0l0,0C104.55,364.65 119.85,349.35 135.15,318.75C137.7,318.75 137.7,318.75 135.15,318.75C137.7,318.75 135.15,318.75 135.15,318.75zM369.75,280.5c-2.55,-2.55 -12.75,-10.2 -48.45,-10.2c-2.55,0 -2.55,0 -5.1,0l0,0c0,0 0,0 0,2.55c17.85,7.65 35.7,12.75 48.45,12.75c2.55,0 2.55,0 5.1,0l0,0h2.55c0,0 0,0 0,-2.55l0,0C372.3,283.05 369.75,283.05 369.75,280.5zM408,0H51C22.95,0 0,22.95 0,51v357c0,28.05 22.95,51 51,51h357c28.05,0 51,-22.95 51,-51V51C459,22.95 436.05,0 408,0zM379.95,300.9c-5.101,2.55 -12.75,5.1 -22.95,5.1c-20.4,0 -51,-5.1 -76.5,-17.85c-43.35,5.1 -76.5,10.199 -102,20.399c-2.55,0 -2.55,0 -5.1,2.55c-30.6,53.551 -56.1,79.051 -76.5,79.051c-5.1,0 -7.65,0 -10.2,-2.551l-12.75,-7.649v-2.55c-2.55,-5.101 -2.55,-7.65 -2.55,-12.75c2.55,-12.75 17.85,-35.7 48.45,-53.551c5.1,-2.55 12.75,-7.649 22.95,-12.75c7.65,-12.75 15.3,-28.05 25.5,-45.899c12.75,-25.5 20.4,-51 28.05,-73.95l0,0c-10.2,-30.6 -15.3,-48.45 -5.1,-84.15c2.55,-10.2 10.2,-20.4 20.4,-20.4h5.1c5.1,0 10.2,2.55 15.3,5.1c17.851,17.85 10.2,58.65 0,91.8c0,2.55 0,2.55 0,2.55c10.2,28.05 25.5,51 40.8,66.3c7.65,5.1 12.75,10.2 22.95,15.3c12.75,0 22.95,-2.55 33.15,-2.55c30.6,0 51,5.1 58.649,17.85c2.551,5.101 2.551,10.2 2.551,15.3C387.6,288.15 385.05,295.8 379.95,300.9zM214.2,201.45c-5.1,17.85 -15.3,38.25 -25.5,61.2c-5.1,10.199 -10.2,17.85 -15.3,28.05h2.55h2.55l0,0c33.15,-12.75 63.75,-20.4 84.15,-22.95c-5.101,-2.55 -7.65,-5.1 -10.2,-7.65C239.7,244.8 224.4,224.4 214.2,201.45z" />
</group>
</vector>
23 changes: 12 additions & 11 deletions app/src/main/res/drawable-anydpi/ic_print.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:alpha="0.8"
android:tint="#FFFFFF"
android:alpha="0.8">
<group android:scaleX="1.1111112"
android:scaleY="1.1111112"
android:translateX="-1.3333334"
android:translateY="-1.3333334">
<path
android:fillColor="@android:color/white"
android:pathData="M19,8L5,8c-1.66,0 -3,1.34 -3,3v6h4v4h12v-4h4v-6c0,-1.66 -1.34,-3 -3,-3zM16,19L8,19v-5h8v5zM19,12c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM18,3L6,3v4h12L18,3z"/>
</group>
android:viewportWidth="24"
android:viewportHeight="24">
<group
android:scaleX="1.1111112"
android:scaleY="1.1111112"
android:translateX="-1.3333334"
android:translateY="-1.3333334">
<path
android:fillColor="@android:color/white"
android:pathData="M19,8L5,8c-1.66,0 -3,1.34 -3,3v6h4v4h12v-4h4v-6c0,-1.66 -1.34,-3 -3,-3zM16,19L8,19v-5h8v5zM19,12c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM18,3L6,3v4h12L18,3z" />
</group>
</vector>
Loading

0 comments on commit b489809

Please sign in to comment.