├── library
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── attrs.xml
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_app.png
│ │ │ └── layout
│ │ │ │ └── view_pdf_page.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── es
│ │ │ └── voghdev
│ │ │ └── pdfviewpager
│ │ │ └── library
│ │ │ ├── asset
│ │ │ ├── CopyAsset.java
│ │ │ ├── CopyAssetServiceImpl.java
│ │ │ └── CopyAssetThreadImpl.java
│ │ │ ├── remote
│ │ │ ├── DownloadFile.java
│ │ │ ├── RemotePDFViewPager.java
│ │ │ └── DownloadFileUrlConnectionImpl.java
│ │ │ ├── util
│ │ │ └── FileUtil.java
│ │ │ ├── PDFViewPager.java
│ │ │ ├── service
│ │ │ └── CopyAssetService.java
│ │ │ └── adapter
│ │ │ └── PDFPagerAdapter.java
│ └── androidTest
│ │ └── java
│ │ └── es
│ │ └── voghdev
│ │ └── pdfviewpager
│ │ └── library
│ │ └── ApplicationTest.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── screenshots
├── local.gif
├── remote.gif
└── sdcard.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── sample
├── src
│ └── main
│ │ ├── assets
│ │ ├── adobe.pdf
│ │ └── sample.pdf
│ │ ├── res
│ │ ├── drawable-hdpi
│ │ │ └── ic_app.png
│ │ ├── drawable-xxhdpi
│ │ │ └── ic_app.png
│ │ ├── layout
│ │ │ ├── activity_asset_on_sd.xml
│ │ │ ├── activity_remote_pdf.xml
│ │ │ ├── activity_asset_on_xml.xml
│ │ │ ├── activity_legacy.xml
│ │ │ └── activity_main.xml
│ │ └── values
│ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── es
│ │ └── voghdev
│ │ └── pdfviewpager
│ │ ├── SampleApplication.java
│ │ ├── AssetOnXMLActivity.java
│ │ ├── MainActivity.java
│ │ ├── AssetOnSDActivity.java
│ │ ├── LegacyPDFActivity.java
│ │ └── RemotePDFActivity.java
└── build.gradle
├── .gitignore
├── gradlew.bat
├── gradlew
├── README.md
└── LICENSE
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':library'
2 |
--------------------------------------------------------------------------------
/screenshots/local.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/PdfViewPager/master/screenshots/local.gif
--------------------------------------------------------------------------------
/screenshots/remote.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/PdfViewPager/master/screenshots/remote.gif
--------------------------------------------------------------------------------
/screenshots/sdcard.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/PdfViewPager/master/screenshots/sdcard.gif
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/PdfViewPager/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | pdfviewpager
3 |
4 |
--------------------------------------------------------------------------------
/sample/src/main/assets/adobe.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/PdfViewPager/master/sample/src/main/assets/adobe.pdf
--------------------------------------------------------------------------------
/sample/src/main/assets/sample.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/PdfViewPager/master/sample/src/main/assets/sample.pdf
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/ic_app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/PdfViewPager/master/sample/src/main/res/drawable-hdpi/ic_app.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/ic_app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/PdfViewPager/master/sample/src/main/res/drawable-xxhdpi/ic_app.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PDDStudio/PdfViewPager/master/library/src/main/res/drawable-xxhdpi/ic_app.png
--------------------------------------------------------------------------------
/library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | @android:color/white
4 |
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | TODO.txt
2 | import-summary.txt
3 | .gradle
4 | bin/
5 | gen/
6 | local.properties
7 | /.idea
8 | .DS_Store
9 | build/
10 | .gradle/
11 | *.apk
12 | *.ap_
13 | *.dex
14 | *.class
15 | proguard/
16 | .idea
17 | *.iml
18 | *.yml
19 | target
20 | Thumbs.db
21 | *.swp
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_asset_on_sd.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/es/voghdev/pdfviewpager/library/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package es.voghdev.pdfviewpager.library;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/library/src/main/res/layout/view_pdf_page.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile 'com.android.support:appcompat-v7:23.1.1'
24 | }
25 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "es.voghdev.pdfviewpager"
9 | minSdkVersion 15
10 | }
11 |
12 | buildTypes {
13 | release {
14 | minifyEnabled false
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
16 | }
17 | }
18 | }
19 |
20 | dependencies{
21 | compile fileTree(dir: 'libs', include: ['*.jar'])
22 | compile 'com.android.support:appcompat-v7:23.0.1'
23 | compile project(":library")
24 | }
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/appandweb/android-sdks/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_remote_pdf.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_asset_on_xml.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/library/src/main/java/es/voghdev/pdfviewpager/library/asset/CopyAsset.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager.library.asset;
17 |
18 | public interface CopyAsset {
19 | public void copy(String assetName, String destinationPath);
20 |
21 | public interface Listener{
22 | public void success(String assetName, String destinationPath);
23 | public void failure(Exception e);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_legacy.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
21 |
22 |
28 |
29 |
--------------------------------------------------------------------------------
/library/src/main/java/es/voghdev/pdfviewpager/library/remote/DownloadFile.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager.library.remote;
17 |
18 | public interface DownloadFile {
19 | public void download(String url, String destinationPath);
20 |
21 | public interface Listener{
22 | public void onSuccess(String url, String destinationPath);
23 | public void onFailure(Exception e);
24 | public void onProgressUpdate(int progress, int total);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/java/es/voghdev/pdfviewpager/library/asset/CopyAssetServiceImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager.library.asset;
17 |
18 | import android.content.Context;
19 |
20 | import es.voghdev.pdfviewpager.library.service.CopyAssetService;
21 |
22 | public class CopyAssetServiceImpl implements CopyAsset {
23 | private Context context;
24 |
25 | public CopyAssetServiceImpl(Context context) {
26 | this.context = context;
27 | }
28 |
29 | @Override
30 | public void copy(String assetName, String destinationPath) {
31 | CopyAssetService.startCopyAction(context, assetName, destinationPath);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sample/src/main/java/es/voghdev/pdfviewpager/SampleApplication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager;
17 |
18 | import android.app.Application;
19 | import android.os.Handler;
20 |
21 | import java.io.File;
22 |
23 | import es.voghdev.pdfviewpager.library.asset.CopyAsset;
24 | import es.voghdev.pdfviewpager.library.asset.CopyAssetThreadImpl;
25 |
26 | public class SampleApplication extends Application{
27 | final String[] sampleAssets = {"adobe.pdf","sample.pdf"};
28 |
29 | @Override
30 | public void onCreate() {
31 | super.onCreate();
32 |
33 | initSampleAssets();
34 | }
35 |
36 | private void initSampleAssets() {
37 | CopyAsset copyAsset = new CopyAssetThreadImpl(this, new Handler());
38 | for(String asset : sampleAssets){
39 | copyAsset.copy(asset, new File(getCacheDir(), asset).getAbsolutePath());
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PdfViewPager samples
4 | Remote PDF URL
5 | http://partners.adobe.com/public/developer/en/xml/AdobeXMLFormsSamples.pdf
6 | Tap to start download
7 | Asset on SD card example
8 | Asset on XML example
9 | Remote PDF Example
10 | PdfViewPager examples
11 | Ready to download
12 | Legacy PDF Example (Pre-Lollipop)
13 | Downloading...
14 | Download Complete. Now opening PDF, Wait a moment please...
15 | BTW, all icons are from www.flaticon.com
16 | This is a PDF document, declared on XML, set up by code.
17 | Remote PDF sample
18 | PDF on your SD sample
19 | PDF as asset (code) sample
20 | PDF as asset (XML) sample
21 | Pre-lollipop PDF download and launch
22 | This sample PDF here >>\nis declared by code
23 |
24 |
--------------------------------------------------------------------------------
/sample/src/main/java/es/voghdev/pdfviewpager/AssetOnXMLActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager;
17 |
18 | import android.content.Context;
19 | import android.content.Intent;
20 | import android.os.Bundle;
21 | import android.support.v7.app.AppCompatActivity;
22 |
23 | import es.voghdev.pdfviewpager.library.PDFViewPager;
24 | import es.voghdev.pdfviewpager.library.adapter.PDFPagerAdapter;
25 |
26 | public class AssetOnXMLActivity extends AppCompatActivity{
27 | PDFViewPager pdfViewPager;
28 |
29 | @Override
30 | public void onCreate(Bundle savedInstanceState){
31 | super.onCreate(savedInstanceState);
32 | setTitle(R.string.asset_on_xml);
33 | setContentView(R.layout.activity_asset_on_xml);
34 |
35 | pdfViewPager = (PDFViewPager) findViewById(R.id.pdfViewPager);
36 | }
37 |
38 | @Override
39 | protected void onDestroy() {
40 | super.onDestroy();
41 |
42 | ((PDFPagerAdapter) pdfViewPager.getAdapter()).close();
43 | }
44 |
45 | public static void open(Context context){
46 | Intent i = new Intent(context, AssetOnXMLActivity.class);
47 | context.startActivity(i);
48 | }
49 | }
--------------------------------------------------------------------------------
/library/src/main/java/es/voghdev/pdfviewpager/library/util/FileUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager.library.util;
17 |
18 | import android.content.Context;
19 | import android.util.Log;
20 |
21 | import java.io.File;
22 | import java.io.FileOutputStream;
23 | import java.io.IOException;
24 | import java.io.InputStream;
25 | import java.io.OutputStream;
26 |
27 | import es.voghdev.pdfviewpager.library.BuildConfig;
28 |
29 | public class FileUtil {
30 | public static boolean copyAsset(Context ctx, String assetName, String destinationPath) throws IOException{
31 | InputStream in = ctx.getAssets().open(assetName);
32 | File f = new File(destinationPath);
33 | f.createNewFile();
34 | OutputStream out = new FileOutputStream(new File(destinationPath));
35 |
36 | byte[] buffer = new byte[1024];
37 | int read;
38 | while((read = in.read(buffer)) != -1){
39 | out.write(buffer, 0, read);
40 | }
41 | in.close();
42 | out.close();
43 |
44 | return true;
45 | }
46 |
47 | public static String extractFileNameFromURL(String url){
48 | return url.substring(url.lastIndexOf('/') + 1);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/library/src/main/java/es/voghdev/pdfviewpager/library/PDFViewPager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager.library;
17 |
18 | import android.content.Context;
19 | import android.content.res.TypedArray;
20 | import android.support.v4.view.ViewPager;
21 | import android.util.AttributeSet;
22 |
23 | import es.voghdev.pdfviewpager.library.adapter.PDFPagerAdapter;
24 |
25 | public class PDFViewPager extends ViewPager {
26 | protected Context context;
27 |
28 | public PDFViewPager(Context context, String pdfPath) {
29 | super(context);
30 | this.context = context;
31 | init(pdfPath);
32 | }
33 |
34 | public PDFViewPager(Context context, AttributeSet attrs) {
35 | super(context, attrs);
36 | this.context = context;
37 | init(attrs);
38 | }
39 |
40 | private void init(String pdfPath) {
41 | setAdapter(new PDFPagerAdapter(context, pdfPath));
42 | }
43 |
44 | private void init(AttributeSet attrs){
45 | if(attrs != null){
46 | TypedArray a;
47 |
48 | a = context.obtainStyledAttributes(attrs, R.styleable.PDFViewPager);
49 | String assetFileName = a.getString(R.styleable.PDFViewPager_assetFileName);
50 |
51 | if( assetFileName != null && assetFileName.length() > 0)
52 | setAdapter(new PDFPagerAdapter(context, assetFileName));
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/sample/src/main/java/es/voghdev/pdfviewpager/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager;
17 |
18 | import android.os.Build;
19 | import android.os.Bundle;
20 | import android.support.v7.app.AppCompatActivity;
21 | import android.view.View;
22 | import android.widget.Toast;
23 |
24 | import es.voghdev.pdfviewpager.library.PDFViewPager;
25 | import es.voghdev.pdfviewpager.library.adapter.PDFPagerAdapter;
26 |
27 | public class MainActivity extends AppCompatActivity {
28 | PDFViewPager pdfViewPager;
29 | PDFPagerAdapter adapter;
30 |
31 | @Override
32 | public void onCreate(Bundle savedInstanceState)
33 | {
34 | super.onCreate(savedInstanceState);
35 | setTitle(R.string.std_example);
36 | setContentView(R.layout.activity_main);
37 |
38 | pdfViewPager = (PDFViewPager) findViewById(R.id.pdfViewPager);
39 |
40 | adapter = new PDFPagerAdapter(this, "sample.pdf");
41 | pdfViewPager.setAdapter(adapter);
42 | }
43 |
44 | @Override
45 | protected void onDestroy() {
46 | super.onDestroy();
47 |
48 | if(adapter != null) {
49 | adapter.close();
50 | adapter = null;
51 | }
52 | }
53 |
54 | // region OnClick handlers
55 | public void onClickSample2(View v){
56 | RemotePDFActivity.open(this);
57 | }
58 |
59 | public void onClickSample3(View v){
60 | AssetOnSDActivity.open(this);
61 | }
62 |
63 | public void onClickSample4(View v){
64 | Toast.makeText(this, R.string.dummy_msg, Toast.LENGTH_LONG).show();
65 | }
66 |
67 | public void onClickSample5(View v){
68 | AssetOnXMLActivity.open(this);
69 | }
70 |
71 | public void onClickSample6(View v){
72 | LegacyPDFActivity.open(this);
73 | }
74 | // endregion
75 | }
76 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
11 |
16 |
17 |
23 |
24 |
30 |
31 |
37 |
38 |
44 |
45 |
51 |
52 |
58 |
59 |
63 |
64 |
--------------------------------------------------------------------------------
/library/src/main/java/es/voghdev/pdfviewpager/library/service/CopyAssetService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager.library.service;
17 |
18 | import android.app.IntentService;
19 | import android.content.Context;
20 | import android.content.Intent;
21 |
22 | import java.io.IOException;
23 |
24 | import es.voghdev.pdfviewpager.library.BuildConfig;
25 | import es.voghdev.pdfviewpager.library.util.FileUtil;
26 |
27 | public class CopyAssetService extends IntentService {
28 | private static final String ACTION_COPY_ASSET = BuildConfig.APPLICATION_ID + ".copy_asset";
29 |
30 | private static final String EXTRA_ASSET = BuildConfig.APPLICATION_ID +".asset";
31 | private static final String EXTRA_DESTINATION = BuildConfig.APPLICATION_ID +".destination_path";
32 |
33 | public CopyAssetService() {
34 | super("CopyAssetService");
35 | }
36 |
37 | public static void startCopyAction(Context context, String asset, String destinationPath) {
38 | Intent intent = new Intent(context, CopyAssetService.class);
39 | intent.setAction(ACTION_COPY_ASSET);
40 | intent.putExtra(EXTRA_ASSET, asset);
41 | intent.putExtra(EXTRA_DESTINATION, destinationPath);
42 | context.startService(intent);
43 | }
44 |
45 | @Override
46 | protected void onHandleIntent(Intent intent) {
47 | if (intent != null) {
48 | final String action = intent.getAction();
49 | if (ACTION_COPY_ASSET.equals(action)) {
50 | final String param1 = intent.getStringExtra(EXTRA_ASSET);
51 | final String param2 = intent.getStringExtra(EXTRA_DESTINATION);
52 | handleActionCopyAsset(param1, param2);
53 | }
54 | }
55 | }
56 |
57 | private void handleActionCopyAsset(String asset, String destinationPath) {
58 | try {
59 | FileUtil.copyAsset(this, asset, destinationPath);
60 | } catch (IOException e) {
61 | e.printStackTrace();
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/src/main/java/es/voghdev/pdfviewpager/library/asset/CopyAssetThreadImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager.library.asset;
17 |
18 | import android.content.Context;
19 | import android.os.Handler;
20 |
21 | import java.io.IOException;
22 |
23 | import es.voghdev.pdfviewpager.library.util.FileUtil;
24 |
25 | public class CopyAssetThreadImpl implements CopyAsset {
26 | Context context;
27 | Handler uiThread;
28 | CopyAsset.Listener listener = new NullListener();
29 |
30 | public CopyAssetThreadImpl(Context context, Handler uiThread, Listener listener) {
31 | this.context = context;
32 | this.uiThread = uiThread;
33 | if(listener != null)
34 | this.listener = listener;
35 | }
36 |
37 | public CopyAssetThreadImpl(Context context, Handler uiThread) {
38 | this.context = context;
39 | this.uiThread = uiThread;
40 | }
41 |
42 | @Override
43 | public void copy(final String assetName, final String destinationPath) {
44 | new Thread(new Runnable() {
45 | @Override
46 | public void run() {
47 | try {
48 | FileUtil.copyAsset(context, assetName, destinationPath);
49 | notifySuccess(assetName, destinationPath);
50 | }catch(IOException e) {
51 | notifyError(e);
52 | }
53 | }
54 | }).start();
55 | }
56 |
57 | private void notifySuccess(final String assetName, final String destinationPath) {
58 | if(uiThread == null)
59 | return;
60 |
61 | uiThread.post(new Runnable() {
62 | @Override
63 | public void run() {
64 | listener.success(assetName, destinationPath);
65 | }
66 | });
67 | }
68 |
69 | private void notifyError(final IOException e) {
70 | if(uiThread == null)
71 | return;
72 |
73 | uiThread.post(new Runnable() {
74 | @Override
75 | public void run() {
76 | listener.failure(e);
77 | }
78 | });
79 | }
80 |
81 | protected class NullListener implements Listener{
82 | public void success(String assetName, String destinationPath) {}
83 | public void failure(Exception e) {}
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/library/src/main/java/es/voghdev/pdfviewpager/library/remote/RemotePDFViewPager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager.library.remote;
17 |
18 | import android.content.Context;
19 | import android.content.res.TypedArray;
20 | import android.os.Handler;
21 | import android.support.v4.view.ViewPager;
22 | import android.util.AttributeSet;
23 |
24 | import java.io.File;
25 |
26 | import es.voghdev.pdfviewpager.library.R;
27 | import es.voghdev.pdfviewpager.library.util.FileUtil;
28 |
29 | public class RemotePDFViewPager extends ViewPager implements DownloadFile.Listener {
30 | protected Context context;
31 | protected DownloadFile.Listener listener;
32 |
33 | public RemotePDFViewPager(Context context, String pdfUrl, DownloadFile.Listener listener) {
34 | super(context);
35 | this.context = context;
36 | this.listener = listener;
37 | init(pdfUrl);
38 | }
39 |
40 | public RemotePDFViewPager(Context context, AttributeSet attrs) {
41 | super(context, attrs);
42 | this.context = context;
43 | init(attrs);
44 | }
45 |
46 | private void init(String pdfUrl) {
47 | DownloadFile downloadFile = new DownloadFileUrlConnectionImpl(context, new Handler(), this);
48 | downloadFile.download(pdfUrl, new File(context.getCacheDir(), FileUtil.extractFileNameFromURL(pdfUrl)).getAbsolutePath());
49 | }
50 |
51 | private void init(AttributeSet attrs){
52 | if(attrs != null){
53 | TypedArray a;
54 |
55 | a = context.obtainStyledAttributes(attrs, R.styleable.PDFViewPager);
56 | String pdfUrl = a.getString(R.styleable.PDFViewPager_pdfUrl);
57 |
58 | if( pdfUrl != null && pdfUrl.length() > 0)
59 | init(pdfUrl);
60 | }
61 | }
62 |
63 | @Override
64 | public void onSuccess(String url, String destinationPath) {
65 | listener.onSuccess(url, destinationPath);
66 | }
67 |
68 | @Override
69 | public void onFailure(Exception e) {
70 | listener.onFailure(e);
71 | }
72 |
73 | @Override
74 | public void onProgressUpdate(int progress, int total) {
75 | listener.onProgressUpdate(progress, total);
76 | }
77 |
78 | public class NullListener implements DownloadFile.Listener{
79 | public void onSuccess(String url, String destinationPath) {}
80 | public void onFailure(Exception e) {}
81 | public void onProgressUpdate(int progress, int total) {}
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/sample/src/main/java/es/voghdev/pdfviewpager/AssetOnSDActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager;
17 |
18 | import android.content.Context;
19 | import android.content.Intent;
20 | import android.os.Bundle;
21 | import android.os.Environment;
22 | import android.os.Handler;
23 | import android.support.v7.app.AppCompatActivity;
24 | import android.widget.Toast;
25 |
26 | import java.io.File;
27 |
28 | import es.voghdev.pdfviewpager.library.PDFViewPager;
29 | import es.voghdev.pdfviewpager.library.adapter.PDFPagerAdapter;
30 | import es.voghdev.pdfviewpager.library.asset.CopyAsset;
31 | import es.voghdev.pdfviewpager.library.asset.CopyAssetThreadImpl;
32 |
33 | public class AssetOnSDActivity extends AppCompatActivity{
34 | final String[] sampleAssets = {"adobe.pdf","sample.pdf"};
35 |
36 | PDFViewPager pdfViewPager;
37 | File pdfFolder;
38 |
39 | @Override
40 | public void onCreate(Bundle savedInstanceState){
41 | super.onCreate(savedInstanceState);
42 | setTitle(R.string.asset_on_sd);
43 | setContentView(R.layout.activity_asset_on_sd);
44 |
45 | pdfFolder = Environment.getExternalStorageDirectory();
46 | copyAssetsOnSDCard();
47 | }
48 |
49 | protected void copyAssetsOnSDCard() {
50 | final Context context = this;
51 | CopyAsset copyAsset = new CopyAssetThreadImpl(getApplicationContext(), new Handler(), new CopyAsset.Listener() {
52 | @Override
53 | public void success(String assetName, String destinationPath) {
54 | pdfViewPager = new PDFViewPager(context, getPdfPathOnSDCard());
55 | setContentView(pdfViewPager);
56 | }
57 |
58 | @Override
59 | public void failure(Exception e) {
60 | e.printStackTrace();
61 | Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
62 | }
63 | });
64 |
65 | for(String asset : sampleAssets){
66 | copyAsset.copy(asset, new File(pdfFolder, asset).getAbsolutePath());
67 | }
68 | }
69 |
70 | protected String getPdfPathOnSDCard() {
71 | File f = new File(pdfFolder, "adobe.pdf");
72 | return f.getAbsolutePath();
73 | }
74 |
75 | @Override
76 | protected void onDestroy() {
77 | super.onDestroy();
78 |
79 | ((PDFPagerAdapter) pdfViewPager.getAdapter()).close();
80 | }
81 |
82 | public static void open(Context context){
83 | Intent i = new Intent(context, AssetOnSDActivity.class);
84 | context.startActivity(i);
85 | }
86 | }
--------------------------------------------------------------------------------
/sample/src/main/java/es/voghdev/pdfviewpager/LegacyPDFActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager;
17 |
18 | import android.content.Context;
19 | import android.content.Intent;
20 | import android.net.Uri;
21 | import android.os.Build;
22 | import android.os.Bundle;
23 | import android.os.Handler;
24 | import android.support.v7.app.AppCompatActivity;
25 | import android.view.View;
26 | import android.widget.Button;
27 | import android.widget.ProgressBar;
28 | import android.widget.TextView;
29 |
30 | import java.io.File;
31 |
32 | import es.voghdev.pdfviewpager.library.remote.DownloadFile;
33 | import es.voghdev.pdfviewpager.library.remote.DownloadFileUrlConnectionImpl;
34 |
35 | /**
36 | * Sample Activity for API Levels under 21
37 | */
38 | public class LegacyPDFActivity extends AppCompatActivity implements DownloadFile.Listener{
39 | Button button;
40 | ProgressBar progressBar;
41 | TextView textView;
42 | DownloadFile downloadFile;
43 |
44 | @Override
45 | public void onCreate(Bundle savedInstanceState){
46 | super.onCreate(savedInstanceState);
47 | setTitle(R.string.legacy_pdf);
48 | setContentView(R.layout.activity_legacy);
49 |
50 | bindViews();
51 |
52 | downloadFile = new DownloadFileUrlConnectionImpl(this, new Handler(), this);
53 | button.setOnClickListener(new View.OnClickListener() {
54 | @Override
55 | public void onClick(View view) {
56 | button.setVisibility(View.INVISIBLE);
57 | downloadFile.download(getString(R.string.sample_pdf_url), new File(getExternalFilesDir("pdf"), "legacy.pdf").getAbsolutePath());
58 | textView.setText(R.string.downloading);
59 | }
60 | });
61 |
62 | }
63 |
64 | private void bindViews() {
65 | button = (Button) findViewById(R.id.btn_download);
66 | textView = (TextView) findViewById(R.id.textView1);
67 | progressBar = (ProgressBar) findViewById(R.id.progressBar);
68 | }
69 |
70 | public static void open(Context context){
71 | Intent i = new Intent(context, LegacyPDFActivity.class);
72 | context.startActivity(i);
73 | }
74 |
75 | private void launchOpenPDFIntent(String destinationPath) {
76 | File file = new File(destinationPath);
77 | Intent intent = new Intent(Intent.ACTION_VIEW);
78 | intent.setDataAndType(Uri.fromFile(file), "application/pdf");
79 | intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
80 | startActivity(intent);
81 | }
82 |
83 | @Override
84 | public void onSuccess(String url, String destinationPath) {
85 | button.setVisibility(View.VISIBLE);
86 | progressBar.setProgress(100);
87 | textView.setText(R.string.downloaded_wait);
88 | launchOpenPDFIntent(destinationPath);
89 | }
90 |
91 | @Override
92 | public void onFailure(Exception e) {
93 | button.setVisibility(View.INVISIBLE);
94 | progressBar.setProgress(0);
95 | textView.setText( String.format("Download error: %s", e.getMessage()) );
96 | }
97 |
98 | @Override
99 | public void onProgressUpdate(int progress, int total) {
100 | if(progressBar.getMax() != total )
101 | progressBar.setMax(total);
102 | progressBar.setProgress(progress);
103 | }
104 | }
--------------------------------------------------------------------------------
/sample/src/main/java/es/voghdev/pdfviewpager/RemotePDFActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager;
17 |
18 | import android.content.Context;
19 | import android.content.Intent;
20 | import android.os.Bundle;
21 | import android.support.v7.app.AppCompatActivity;
22 | import android.view.View;
23 | import android.widget.Button;
24 | import android.widget.EditText;
25 | import android.widget.LinearLayout;
26 |
27 | import es.voghdev.pdfviewpager.library.adapter.PDFPagerAdapter;
28 | import es.voghdev.pdfviewpager.library.remote.DownloadFile;
29 | import es.voghdev.pdfviewpager.library.remote.RemotePDFViewPager;
30 | import es.voghdev.pdfviewpager.library.util.FileUtil;
31 |
32 | public class RemotePDFActivity extends AppCompatActivity implements DownloadFile.Listener {
33 | LinearLayout root;
34 | RemotePDFViewPager remotePDFViewPager;
35 | EditText etPdfUrl;
36 | Button btnDownload;
37 | PDFPagerAdapter adapter;
38 |
39 | @Override
40 | public void onCreate(Bundle savedInstanceState){
41 | super.onCreate(savedInstanceState);
42 | setTitle(R.string.remote_pdf_example);
43 | setContentView(R.layout.activity_remote_pdf);
44 |
45 | root = (LinearLayout) findViewById(R.id.remote_pdf_root);
46 | etPdfUrl = (EditText) findViewById(R.id.et_pdfUrl);
47 | btnDownload = (Button) findViewById(R.id.btn_download);
48 |
49 | setDownloadButtonListener();
50 | }
51 |
52 | @Override
53 | protected void onDestroy() {
54 | super.onDestroy();
55 |
56 | if(adapter != null)
57 | adapter.close();
58 | }
59 |
60 | protected void setDownloadButtonListener() {
61 | final Context ctx = this;
62 | final DownloadFile.Listener listener = this;
63 | btnDownload.setOnClickListener(new View.OnClickListener() {
64 | @Override
65 | public void onClick(View view) {
66 | remotePDFViewPager = new RemotePDFViewPager(ctx, getUrlFromEditText(), listener);
67 | hideDownloadButton();
68 | }
69 | });
70 | }
71 |
72 | protected String getUrlFromEditText() {
73 | return etPdfUrl.getText().toString().trim();
74 | }
75 |
76 | public static void open(Context context){
77 | Intent i = new Intent(context, RemotePDFActivity.class);
78 | context.startActivity(i);
79 | }
80 |
81 | public void showDownloadButton(){
82 | btnDownload.setVisibility(View.VISIBLE);
83 | }
84 | public void hideDownloadButton(){
85 | btnDownload.setVisibility(View.INVISIBLE);
86 | }
87 |
88 | public void updateLayout(){
89 | root.removeAllViewsInLayout();
90 | root.addView(etPdfUrl, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
91 | root.addView(btnDownload, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
92 | root.addView(remotePDFViewPager, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
93 | }
94 |
95 | @Override
96 | public void onSuccess(String url, String destinationPath) {
97 | adapter = new PDFPagerAdapter(this, FileUtil.extractFileNameFromURL(url));
98 | remotePDFViewPager.setAdapter(adapter);
99 | updateLayout();
100 | showDownloadButton();
101 | }
102 |
103 | @Override
104 | public void onFailure(Exception e) {
105 | e.printStackTrace();
106 | showDownloadButton();
107 | }
108 |
109 | @Override
110 | public void onProgressUpdate(int progress, int total) {
111 |
112 | }
113 | }
114 |
115 |
--------------------------------------------------------------------------------
/library/src/main/java/es/voghdev/pdfviewpager/library/remote/DownloadFileUrlConnectionImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager.library.remote;
17 |
18 | import android.content.Context;
19 | import android.os.Handler;
20 |
21 | import java.io.BufferedInputStream;
22 | import java.io.File;
23 | import java.io.FileOutputStream;
24 | import java.io.IOException;
25 | import java.io.InputStream;
26 | import java.net.HttpURLConnection;
27 | import java.net.MalformedURLException;
28 | import java.net.URL;
29 |
30 | public class DownloadFileUrlConnectionImpl implements DownloadFile {
31 | private static final int KILOBYTE = 1024;
32 |
33 | private static final int BUFFER_LEN = 1 * KILOBYTE;
34 | private static final int NOTIFY_PERIOD = 150 * KILOBYTE;
35 |
36 | Context context;
37 | Handler uiThread;
38 | Listener listener = new NullListener();
39 |
40 | public DownloadFileUrlConnectionImpl(Context context, Handler uiThread, Listener listener) {
41 | this.context = context;
42 | this.uiThread = uiThread;
43 | this.listener = listener;
44 | }
45 |
46 | @Override
47 | public void download(final String url, final String destinationPath) {
48 | new Thread(new Runnable() {
49 | @Override
50 | public void run() {
51 | try{
52 | File file = new File(destinationPath);
53 | FileOutputStream fileOutput = new FileOutputStream(file);
54 | HttpURLConnection urlConnection = null;
55 | URL urlObj = new URL(url);
56 | urlConnection = (HttpURLConnection) urlObj.openConnection();
57 | int totalSize = urlConnection.getContentLength();
58 | int downloadedSize = 0;
59 | int counter = 0;
60 | byte[] buffer = new byte[BUFFER_LEN];
61 | int bufferLength = 0;
62 | InputStream in = new BufferedInputStream(urlConnection.getInputStream());
63 |
64 | while ( (bufferLength = in.read(buffer)) > 0 ) {
65 | fileOutput.write(buffer, 0, bufferLength);
66 | downloadedSize += bufferLength;
67 | counter += bufferLength;
68 | if(listener != null && counter > NOTIFY_PERIOD){
69 | notifyProgressOnUiThread(downloadedSize, totalSize);
70 | counter = 0;
71 | }
72 | }
73 |
74 | urlConnection.disconnect();
75 | fileOutput.close();
76 |
77 | }catch(MalformedURLException e){
78 | notifyFailureOnUiThread(e);
79 | }catch(IOException e){
80 | notifyFailureOnUiThread(e);
81 | }
82 |
83 | notifySuccessOnUiThread(url, destinationPath);
84 | }
85 | }).start();
86 | }
87 |
88 | protected void notifySuccessOnUiThread(final String url, final String destinationPath) {
89 | if(uiThread == null)
90 | return;
91 |
92 | uiThread.post(new Runnable() {
93 | @Override
94 | public void run() {
95 | listener.onSuccess(url, destinationPath);
96 | }
97 | });
98 | }
99 |
100 | protected void notifyFailureOnUiThread(final Exception e){
101 | if(uiThread == null)
102 | return;
103 |
104 | uiThread.post(new Runnable() {
105 | @Override
106 | public void run() {
107 | listener.onFailure(e);
108 | }
109 | });
110 | }
111 |
112 | private void notifyProgressOnUiThread(final int downloadedSize, final int totalSize) {
113 | if(uiThread == null)
114 | return;
115 |
116 | uiThread.post(new Runnable() {
117 | @Override
118 | public void run() {
119 | listener.onProgressUpdate(downloadedSize, totalSize);
120 | }
121 | });
122 | }
123 |
124 | protected class NullListener implements Listener{
125 | public void onSuccess(String url, String destinationPath) {}
126 | public void onFailure(Exception e) {}
127 | public void onProgressUpdate(int progress, int total) {}
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/library/src/main/java/es/voghdev/pdfviewpager/library/adapter/PDFPagerAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Olmo Gallegos Hernández.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package es.voghdev.pdfviewpager.library.adapter;
17 |
18 | import android.app.Activity;
19 | import android.content.Context;
20 | import android.graphics.Bitmap;
21 | import android.graphics.pdf.PdfRenderer;
22 | import android.net.Uri;
23 | import android.os.ParcelFileDescriptor;
24 | import android.support.v4.view.PagerAdapter;
25 | import android.support.v4.view.ViewPager;
26 | import android.util.Log;
27 | import android.util.SparseArray;
28 | import android.view.LayoutInflater;
29 | import android.view.View;
30 | import android.view.ViewGroup;
31 | import android.widget.ImageView;
32 |
33 | import java.io.File;
34 | import java.io.IOException;
35 | import java.lang.ref.WeakReference;
36 | import java.net.URI;
37 |
38 | import es.voghdev.pdfviewpager.library.R;
39 |
40 | public class PDFPagerAdapter extends PagerAdapter {
41 | String pdfPath;
42 | Context context;
43 | PdfRenderer renderer;
44 | SparseArray> bitmaps;
45 | LayoutInflater inflater;
46 |
47 | public PDFPagerAdapter(Context context, String pdfPath) {
48 | this.pdfPath = pdfPath;
49 | this.context = context;
50 | bitmaps = new SparseArray<>();
51 | init();
52 | }
53 |
54 | @SuppressWarnings("NewApi")
55 | protected void init() {
56 | try {
57 | renderer = new PdfRenderer(getSeekableFileDescriptor(pdfPath));
58 | inflater = (LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
59 | }catch(IOException e){
60 | e.printStackTrace();
61 | Log.e("PDFPagerAdapter", e.getMessage());
62 | }
63 | }
64 |
65 | protected ParcelFileDescriptor getSeekableFileDescriptor(String path) throws IOException {
66 | ParcelFileDescriptor pfd;
67 |
68 | File pdfCopy = new File(path);
69 | if(pdfCopy.exists()){
70 | pfd = ParcelFileDescriptor.open(pdfCopy, ParcelFileDescriptor.MODE_READ_ONLY);
71 | return pfd;
72 | }
73 |
74 | if(isAnAsset(path)){
75 | pdfCopy = new File(context.getCacheDir(), path);
76 | pfd = ParcelFileDescriptor.open(pdfCopy, ParcelFileDescriptor.MODE_READ_ONLY);
77 | }else{
78 | URI uri = URI.create(String.format("file://%s", path));
79 | pfd = context.getContentResolver().openFileDescriptor(Uri.parse(uri.toString()), "rw");
80 | }
81 |
82 | return pfd;
83 | }
84 |
85 | private boolean isAnAsset(String path) {
86 | return !path.startsWith("/");
87 | }
88 |
89 | @Override
90 | @SuppressWarnings("NewApi")
91 | public Object instantiateItem(ViewGroup container, int position) {
92 | View v = inflater.inflate(R.layout.view_pdf_page, container, false);
93 | ImageView iv = (ImageView) v.findViewById(R.id.imageView);
94 |
95 | if(renderer == null || getCount() < position)
96 | return v;
97 |
98 | PdfRenderer.Page page = getPDFPage(position);
99 |
100 | Bitmap bitmap = Bitmap.createBitmap(page.getWidth(), page.getHeight(),
101 | Bitmap.Config.ARGB_8888);
102 | page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
103 | page.close();
104 |
105 | bitmaps.put(position, new WeakReference(bitmap));
106 | iv.setImageBitmap(bitmap);
107 | ((ViewPager) container).addView(v, 0);
108 |
109 | return v;
110 | }
111 |
112 | @SuppressWarnings("NewApi")
113 | private PdfRenderer.Page getPDFPage(int position) {
114 | return renderer.openPage(position);
115 | }
116 |
117 | @Override
118 | public void destroyItem(ViewGroup container, int position, Object object) {
119 | // b.recycle() causes crashes if called here.
120 | // All bitmaps are recycled in close().
121 | }
122 |
123 | @SuppressWarnings("NewApi")
124 | public void close(){
125 | releaseAllBitmaps();
126 | if(renderer != null)
127 | renderer.close();
128 | }
129 |
130 | protected void releaseAllBitmaps() {
131 | for(int i=0; bitmaps != null && i \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PdfViewPager
2 |
3 | Android widget to display PDF documents in your Activities or Fragments.
4 |
5 | Important note: **PDFViewPager** uses *PdfRenderer* class, which works **only on API 21 or later**.
6 | See [PDFRenderer documentation][6].
7 |
8 | If you are targeting pre-Lollipop devices, have a look at the [legacy sample][7]
9 |
10 | Installation
11 | ------------
12 |
13 | hopefully, the library will be available soon as a gradle dependency.
14 | In the meanwhile, you can checkout the source.
15 |
16 | Usage - Remote PDF's
17 | --------------------
18 |
19 | ![Screenshot][remotePDFScreenshot]
20 |
21 | Use **RemotePDFViewPager** to load from remote URLs
22 |
23 | 1.- Add INTERNET, READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions on your AndroidManifest.xml
24 |
25 |
26 |
27 |
28 |
29 | 2.- Make your Activity or Fragment implement DownloadFile.Listener
30 |
31 | public class RemotePDFActivity extends AppCompatActivity implements DownloadFile.Listener {
32 |
33 | 3.- Create a **RemotePDFViewPager** object
34 |
35 | RemotePDFViewPager remotePDFViewPager =
36 | new RemotePDFViewPager(context, "http://partners.adobe.com/public/developer/en/xml/AdobeXMLFormsSamples.pdf", this);
37 |
38 | 4.- Configure the corresponding callbacks and they will be called on each situation.
39 |
40 | @Override
41 | public void onSuccess(String url, String destinationPath) {
42 | // That's the positive case. PDF Download went fine
43 |
44 | adapter = new PDFPagerAdapter(this, "AdobeXMLFormsSamples.pdf");
45 | remotePDFViewPager.setAdapter(adapter);
46 | setContentView(remotePDFViewPager);
47 | }
48 |
49 | @Override
50 | public void onFailure(Exception e) {
51 | // This will be called if download fails
52 | }
53 |
54 | @Override
55 | public void onProgressUpdate(int progress, int total) {
56 | // You will get download progress here
57 | // Always on UI Thread so feel free to update your views here
58 | }
59 |
60 | 5.- Don't forget to close adapter in *onDestroy* to release all resources
61 |
62 | @Override
63 | protected void onDestroy() {
64 | super.onDestroy();
65 |
66 | adapter.close();
67 | }
68 |
69 | Usage - Local PDF's
70 | -------------------
71 |
72 | Use **PDFViewPager** class to load PDF from assets
73 |
74 | ![Screenshot][localPDFScreenshot]
75 |
76 | 1.- Copy your assets to cache directory (lib will do that for you in future versions)
77 |
78 | CopyAsset copyAsset = new CopyAssetThreadImpl(context, new Handler());
79 | copyAsset.copy(asset, new File(getCacheDir(), "sample.pdf").getAbsolutePath());
80 |
81 | 2.- Create your **PDFViewPager** passing your PDF file, located in *assets* (see [sample][8])
82 |
83 | pdfViewPager = new PDFViewPager(this, "sample.pdf");
84 |
85 | 2b.- Or directly, declare it on your XML layout
86 |
87 |
92 |
93 | 3.- Release adapter in *onDestroy*
94 |
95 | @Override
96 | protected void onDestroy() {
97 | super.onDestroy();
98 |
99 | ((PDFPagerAdapter)pdfViewPager.getAdapter()).close();
100 | }
101 |
102 | Usage - PDF's on SD card
103 | ------------------------
104 |
105 | ![Screenshot][sdcardPDFScreenshot]
106 |
107 | Use **PDFViewPager** class to load PDF from your SD card
108 |
109 | 1.- Create a **PDFViewPager** object, passing the file location in your SD card
110 |
111 | PDFViewPager pdfViewPager = new PDFViewPager(context, getPdfPathOnSDCard());
112 |
113 | protected String getPdfPathOnSDCard() {
114 | File f = new File(getExternalFilesDir("pdf"), "adobe.pdf");
115 | return f.getAbsolutePath();
116 | }
117 |
118 | TODOs
119 | -----
120 |
121 | - [X] Load PDF documents from SD card
122 | - [ ] Make PDF documents zoomable with pinch and double tap
123 | - [ ] Unify all features in only one **PDFViewPager** class
124 | - [X] Support API Levels under 21, by downloading PDF and invoking system native intent.
125 | - [ ] UI tests
126 |
127 | Developed By
128 | ------------
129 |
130 | * Olmo Gallegos Hernández - [@voghDev][9] - [mobiledevstories.com][10]
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 | # License
140 |
141 | Copyright 2015 Olmo Gallegos Hernández
142 |
143 | Licensed under the Apache License, Version 2.0 (the "License");
144 | you may not use this file except in compliance with the License.
145 | You may obtain a copy of the License at
146 |
147 | http://www.apache.org/licenses/LICENSE-2.0
148 |
149 | Unless required by applicable law or agreed to in writing, software
150 | distributed under the License is distributed on an "AS IS" BASIS,
151 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
152 | See the License for the specific language governing permissions and
153 | limitations under the License.
154 |
155 | Contributing
156 | ------------
157 |
158 | fork the project into your GitHub account
159 | checkout your GitHub repo for the project
160 | implement your changes
161 | commit your changes, push them
162 | review your code and send me a pull request if you consider it
163 |
164 | [remotePDFScreenshot]: ./screenshots/remote.gif
165 | [localPDFScreenshot]: ./screenshots/local.gif
166 | [sdcardPDFScreenshot]: ./screenshots/sdcard.gif
167 | [6]: http://developer.android.com/reference/android/graphics/pdf/PdfRenderer.html
168 | [7]: https://github.com/voghDev/PdfViewPager/blob/master/sample/src/main/java/es/voghdev/pdfviewpager/LegacyPDFActivity.java
169 | [8]: https://github.com/voghDev/PdfViewPager/tree/master/sample/src/main/java/es/voghdev/pdfviewpager
170 | [9]: http://twitter.com/voghDev
171 | [10]: http://www.mobiledevstories.com
172 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------