├── settings.gradle
├── app
├── libs
│ └── iTextpdf.jar
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable-hdpi
│ │ │ ├── pdf.png
│ │ │ ├── click.9.png
│ │ │ ├── ic_launcher.png
│ │ │ ├── video_return_press.png
│ │ │ ├── video_return_default.png
│ │ │ ├── videoplay_menu_default.png
│ │ │ └── videoplay_menu_press.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable
│ │ │ ├── videolist_press.xml
│ │ │ ├── iv_video_return.xml
│ │ │ ├── bg_ocr_btn_press.xml
│ │ │ ├── textcolor_ocr_result.xml
│ │ │ ├── videolist_menu.xml
│ │ │ ├── et_shape_ocr_result.xml
│ │ │ └── progress_ocr.xml
│ │ ├── values
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ ├── drawables.xml
│ │ │ └── styles.xml
│ │ ├── anim
│ │ │ ├── open_ocr_result.xml
│ │ │ └── close_ocr_result.xml
│ │ ├── values-v11
│ │ │ └── styles.xml
│ │ ├── menu
│ │ │ └── main.xml
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ ├── values-v14
│ │ │ └── styles.xml
│ │ └── layout
│ │ │ ├── activity_pdf.xml
│ │ │ ├── dialog_pdf_model.xml
│ │ │ ├── dialog_pdf_center.xml
│ │ │ ├── activity_main.xml
│ │ │ └── item_pdf_list.xml
│ │ ├── gen
│ │ └── com
│ │ │ └── example
│ │ │ └── mypdf
│ │ │ ├── R.java
│ │ │ ├── Manifest.java
│ │ │ └── BuildConfig.java
│ │ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── mypdf
│ │ │ ├── VideoModel.java
│ │ │ ├── BitmapUtil.java
│ │ │ ├── PdfActivity.java
│ │ │ ├── PdfUtils.java
│ │ │ ├── PdfCenterDialog.java
│ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
├── build.gradle
└── lint.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── import-summary.txt
├── gradlew.bat
└── gradlew
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/libs/iTextpdf.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuwennengcan/MyPdf/HEAD/app/libs/iTextpdf.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuwennengcan/MyPdf/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/pdf.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuwennengcan/MyPdf/HEAD/app/src/main/res/drawable-hdpi/pdf.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/click.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuwennengcan/MyPdf/HEAD/app/src/main/res/drawable-hdpi/click.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuwennengcan/MyPdf/HEAD/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuwennengcan/MyPdf/HEAD/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuwennengcan/MyPdf/HEAD/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuwennengcan/MyPdf/HEAD/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/video_return_press.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuwennengcan/MyPdf/HEAD/app/src/main/res/drawable-hdpi/video_return_press.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/video_return_default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuwennengcan/MyPdf/HEAD/app/src/main/res/drawable-hdpi/video_return_default.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/videoplay_menu_default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuwennengcan/MyPdf/HEAD/app/src/main/res/drawable-hdpi/videoplay_menu_default.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/videoplay_menu_press.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuwennengcan/MyPdf/HEAD/app/src/main/res/drawable-hdpi/videoplay_menu_press.png
--------------------------------------------------------------------------------
/app/src/main/gen/com/example/mypdf/R.java:
--------------------------------------------------------------------------------
1 | /*___Generated_by_IDEA___*/
2 |
3 | package com.example.mypdf;
4 |
5 | /* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */
6 | public final class R {
7 | }
--------------------------------------------------------------------------------
/app/src/main/gen/com/example/mypdf/Manifest.java:
--------------------------------------------------------------------------------
1 | /*___Generated_by_IDEA___*/
2 |
3 | package com.example.mypdf;
4 |
5 | /* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */
6 | public final class Manifest {
7 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/videolist_press.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/open_ocr_result.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/close_ocr_result.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/gen/com/example/mypdf/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /*___Generated_by_IDEA___*/
2 |
3 | package com.example.mypdf;
4 |
5 | /* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */
6 | public final class BuildConfig {
7 | public final static boolean DEBUG = Boolean.parseBoolean(null);
8 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/iv_video_return.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_ocr_btn_press.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/textcolor_ocr_result.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/videolist_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 | 64dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | MyPdf
5 | Hello world!
6 | Settings
7 | 生成PDF
8 | PDF文件中心
9 | 关闭
10 | 查看PDF文件
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_pdf.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/et_shape_ocr_result.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
14 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 16
5 | buildToolsVersion "26.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.example.mypdf"
9 | minSdkVersion 16
10 | targetSdkVersion 16
11 | }
12 |
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile 'com.android.support:support-v4:18.0.0'
23 | compile files('libs/iTextpdf.jar')
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_pdf_model.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/progress_ocr.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/mypdf/VideoModel.java:
--------------------------------------------------------------------------------
1 | package com.example.mypdf;
2 |
3 | public class VideoModel {
4 | private String name;
5 | private String path;
6 | private long length;
7 | public VideoModel() {
8 | super();
9 | }
10 | public VideoModel(String name, String path, long length) {
11 | super();
12 | this.name = name;
13 | this.path = path;
14 | this.length = length;
15 | }
16 | public String getName() {
17 | return name;
18 | }
19 | public void setName(String name) {
20 | this.name = name;
21 | }
22 | public String getPath() {
23 | return path;
24 | }
25 | public void setPath(String path) {
26 | this.path = path;
27 | }
28 | public long getLength() {
29 | return length;
30 | }
31 | public void setLength(long length) {
32 | this.length = length;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/res/values/drawables.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFFFFFFF
4 | #FFFF0033
5 | #56abe4
6 | #FFFFFF
7 | #000000
8 | #56abe4
9 | #555555
10 |
11 | #888888
12 | #ffffff
13 |
14 | #f3f3f3
15 | #666666
16 | #1a000000
17 | #77000000
18 |
19 |
--------------------------------------------------------------------------------
/app/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/mypdf/BitmapUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.mypdf;
2 |
3 | import java.io.File;
4 | import java.text.DecimalFormat;
5 | import java.text.SimpleDateFormat;
6 | import java.util.Date;
7 |
8 | public class BitmapUtil {
9 |
10 | /**
11 | * 通过文件路径获取文件的创建时间
12 | */
13 | public static String getFileCreatedTime(String filePath) {
14 | String string = "";
15 | File file = new File(filePath);
16 | Date date = new Date(file.lastModified());
17 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy年M月d日 HH:mm:ss");
18 | string = sdf.format(date);
19 | return string;
20 | }
21 |
22 | /**
23 | * 通过文件路径获取文件的大小,并自动格式化
24 | */
25 | public static String getVideoLength(String filePath) {
26 | String string = "0B";
27 | DecimalFormat df = new DecimalFormat("#.00");
28 | File file = new File(filePath);
29 | long length = file.length();
30 | if (length == 0) { // 文件大小为0,直接返回0B
31 | return string;
32 | }
33 | if (length < 1024) { // 文件小于1KB,单位为 B
34 | string = df.format((double) length) + "B";
35 | } else if (length < 1048576) {// 文件小于1M,单 位为 KB
36 | string = df.format((double) length / 1024) + "K";
37 | } else if (length < 1073741824) {// 文件小于1G,单位为 MB
38 | string = df.format((double) length / 1048576) + "M";
39 | } else {
40 | string = df.format((double) length / 1073741824) + "G";
41 | }
42 | return string;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/mypdf/PdfActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.mypdf;
2 |
3 | import java.io.IOException;
4 |
5 | import android.app.Activity;
6 | import android.content.Intent;
7 | import android.os.Bundle;
8 | import android.widget.EditText;
9 |
10 | import com.itextpdf.text.pdf.PdfReader;
11 | import com.itextpdf.text.pdf.parser.PdfTextExtractor;
12 |
13 | public class PdfActivity extends Activity {
14 |
15 | private EditText et_content ; //读取pdf文件内容显示的控件
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | init();
21 | }
22 |
23 | /**
24 | * 初始化操作
25 | */
26 | private void init() {
27 | initView();
28 | initData();
29 | }
30 |
31 | /**
32 | * 初始化数据
33 | */
34 | private void initData() {
35 | Intent intent = getIntent();
36 | String path = intent.getStringExtra("path");
37 | readPdfContent(path);
38 | }
39 |
40 | /**
41 | * 初始化控件
42 | */
43 | private void initView() {
44 | setContentView(R.layout.activity_pdf);
45 | et_content = (EditText) findViewById(R.id.et_pdf);
46 |
47 | }
48 |
49 | /**
50 | * 读取Pdf文件的内容
51 | * @param path :文件地址
52 | */
53 | public void readPdfContent(String path){
54 | try {
55 | PdfReader pr = new PdfReader(path);
56 | int page = pr.getNumberOfPages();
57 | String content = "";
58 | for(int i = 1 ;i fileList = new ArrayList();
25 | String[] string = null;
26 | String path = ADDRESS;
27 | File file = new File(path);
28 | if (file.exists() && file.isDirectory()) {
29 | File[] files = file.listFiles();
30 | for (int i = 0; i < files.length; i++) {
31 | if (files[i].getAbsolutePath().endsWith(".pdf")) {
32 | fileList.add(files[i]);
33 | }
34 | }
35 | Collections.sort(fileList, new FileComparator());
36 | string = new String[fileList.size()];
37 | for (int i = 0; i < string.length; i++) {
38 | string[i] = fileList.get(i).getAbsolutePath().toString();
39 | }
40 | }
41 | return string;
42 | }
43 |
44 | /**
45 | * 将文件按时间升序排列
46 | */
47 | static class FileComparator implements Comparator {
48 |
49 | @Override
50 | public int compare(File lhs, File rhs) {
51 | if (lhs.lastModified() < rhs.lastModified()) {
52 | return 1;// 最后修改的照片在前
53 | } else {
54 | return -1;
55 | }
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_pdf_center.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
14 |
23 |
24 |
32 |
33 |
34 |
35 |
41 |
42 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/import-summary.txt:
--------------------------------------------------------------------------------
1 | ECLIPSE ANDROID PROJECT IMPORT SUMMARY
2 | ======================================
3 |
4 | Ignored Files:
5 | --------------
6 | The following files were *not* copied into the new Gradle project; you
7 | should evaluate whether these are still needed in your project and if
8 | so manually move them:
9 |
10 | * ic_launcher-web.png
11 | * proguard-project.txt
12 |
13 | Replaced Jars with Dependencies:
14 | --------------------------------
15 | The importer recognized the following .jar files as third party
16 | libraries and replaced them with Gradle dependencies instead. This has
17 | the advantage that more explicit version information is known, and the
18 | libraries can be updated automatically. However, it is possible that
19 | the .jar file in your project was of an older version than the
20 | dependency we picked, which could render the project not compileable.
21 | You can disable the jar replacement in the import wizard and try again:
22 |
23 | android-support-v4.jar => com.android.support:support-v4:18.0.0
24 |
25 | Moved Files:
26 | ------------
27 | Android Gradle projects use a different directory structure than ADT
28 | Eclipse projects. Here's how the projects were restructured:
29 |
30 | * AndroidManifest.xml => app\src\main\AndroidManifest.xml
31 | * assets\ => app\src\main\assets
32 | * libs\iTextpdf.jar => app\libs\iTextpdf.jar
33 | * lint.xml => app\lint.xml
34 | * res\ => app\src\main\res\
35 | * src\ => app\src\main\java\
36 |
37 | Next Steps:
38 | -----------
39 | You can now build the project. The Gradle project needs network
40 | connectivity to download dependencies.
41 |
42 | Bugs:
43 | -----
44 | If for some reason your project does not build, and you determine that
45 | it is due to a bug or limitation of the Eclipse to Gradle importer,
46 | please file a bug at http://b.android.com with category
47 | Component-Tools.
48 |
49 | (This import summary is for your information only, and can be deleted
50 | after import once you are satisfied with the results.)
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
14 |
15 |
23 |
24 |
31 |
32 |
41 |
42 |
43 |
50 |
51 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_pdf_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
20 |
21 |
22 |
26 |
27 |
34 |
35 |
40 |
41 |
47 |
48 |
55 |
56 |
57 |
58 |
59 |
60 |
65 |
66 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/mypdf/PdfCenterDialog.java:
--------------------------------------------------------------------------------
1 | package com.example.mypdf;
2 |
3 | import android.app.AlertDialog;
4 | import android.app.Dialog;
5 | import android.app.DialogFragment;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.os.Bundle;
9 | import android.view.Gravity;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.View.OnClickListener;
13 | import android.view.ViewGroup;
14 | import android.view.ViewGroup.LayoutParams;
15 | import android.view.WindowManager;
16 | import android.widget.AdapterView;
17 | import android.widget.AdapterView.OnItemClickListener;
18 | import android.widget.BaseAdapter;
19 | import android.widget.Button;
20 | import android.widget.ImageView;
21 | import android.widget.ListView;
22 | import android.widget.TextView;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | /**
28 | * PDF文件浏览中心
29 | * @author can
30 | *@since 2016-10-28
31 | */
32 | public class PdfCenterDialog extends DialogFragment implements OnClickListener{
33 |
34 | private Button btn_close; //关闭识别结果框的按钮
35 | private ListView lv; //显示pdf文件集合控件
36 | private String[] strings; //pdf文件数组
37 | private List list;//pdf文件集合
38 |
39 | public PdfCenterDialog() {
40 | super();
41 | initData();
42 | }
43 |
44 | /**
45 | * 初始化数据
46 | */
47 | private void initData() {
48 | strings = PdfUtils.getString();
49 | list = new ArrayList();
50 | if (strings != null)
51 | for (int i = 0; i < strings.length; i++) {
52 | VideoModel model = new VideoModel();
53 | String url = strings[i];
54 | model.setName(url.substring(url.lastIndexOf('/') + 1));
55 | model.setPath(url);
56 | list.add(model);
57 | }
58 | }
59 |
60 | @SuppressWarnings("deprecation")
61 | @Override
62 | public Dialog onCreateDialog(Bundle savedInstanceState) {
63 | View views = LayoutInflater.from(getActivity()).inflate(
64 | R.layout.dialog_pdf_center, null);
65 | lv = (ListView) views.findViewById(R.id.lv_pdf_center);
66 | lv.setAdapter(new MyPdfAdapter(getActivity(), list));
67 | lv.setOnItemClickListener(new OnItemClickListener() {
68 |
69 | @Override
70 | public void onItemClick(AdapterView> parent, View view,
71 | int position, long id) {
72 | String path = PdfUtils.getString()[position];
73 | Intent intent = new Intent(getActivity(),PdfActivity.class);
74 | intent.putExtra("path", path);
75 | startActivity(intent);
76 | }
77 | });
78 | btn_close = (Button) views.findViewById(R.id.btn_close_pdf_center);
79 | btn_close.setOnClickListener(this);
80 | AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
81 | AlertDialog show = builder.show();
82 | show.getWindow().getAttributes().windowAnimations = R.style.dialog_ocr_result; //设置动画
83 | show.getWindow().setContentView(views);// 自定义布局
84 | show.getWindow().setLayout(LayoutParams.MATCH_PARENT,
85 | getActivity().getWindowManager().getDefaultDisplay().getHeight()*2/3);// 宽高
86 | show.getWindow().setGravity(Gravity.BOTTOM);// 位置 展示位置
87 | show.getWindow().clearFlags(
88 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
89 | return show;
90 | }
91 |
92 | @Override
93 | public void onClick(View v) {
94 | switch (v.getId()) {
95 | case R.id.btn_close_pdf_center: //关闭
96 | this.dismiss();
97 | break;
98 | }
99 | }
100 |
101 | /**
102 | * PDF文件适配器
103 | * @author can
104 | */
105 | class MyPdfAdapter extends BaseAdapter{
106 |
107 | private Context ct ;
108 | private List list;
109 |
110 | public MyPdfAdapter(Context c,List mList) {
111 | super();
112 | this.ct = c;
113 | this.list = mList;
114 | }
115 |
116 | @Override
117 | public int getCount() {
118 | return list.size();
119 | }
120 |
121 | @Override
122 | public Object getItem(int position) {
123 | return list.get(position);
124 | }
125 |
126 | @Override
127 | public long getItemId(int position) {
128 | return position;
129 | }
130 |
131 | @Override
132 | public View getView(int position, View convertView, ViewGroup parent) {
133 | VH vh ;
134 | if(convertView==null){
135 | convertView = LayoutInflater.from(ct).inflate(R.layout.item_pdf_list, null);
136 | vh = new VH();
137 | vh.tv_name = (TextView) convertView
138 | .findViewById(R.id.tv_name_pdf_list);
139 | vh.tv_time = (TextView) convertView
140 | .findViewById(R.id.tv_time_pdf_list);
141 | vh.iv = (ImageView) convertView
142 | .findViewById(R.id.iv_pdf_list);
143 | vh.tv_length = (TextView) convertView
144 | .findViewById(R.id.tv_length_pdf_list);
145 | convertView.setTag(vh);
146 | }else{
147 | vh = (VH) convertView.getTag();
148 | }
149 | vh.tv_name.setText(list.get(position).getName());
150 | String path = list.get(position).getPath();
151 | vh.tv_time.setText(BitmapUtil.getFileCreatedTime(path));
152 | vh.tv_length.setText(BitmapUtil.getVideoLength(path));
153 | return convertView;
154 | }
155 |
156 | class VH {
157 | ImageView iv;
158 | TextView tv_name,tv_time,tv_length;
159 | }
160 |
161 | }
162 |
163 | }
164 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/mypdf/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.mypdf;
2 |
3 | import java.io.File;
4 | import java.io.FileNotFoundException;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 | import java.text.SimpleDateFormat;
8 | import java.util.Date;
9 |
10 | import android.app.ActionBar.LayoutParams;
11 | import android.app.Activity;
12 | import android.app.FragmentTransaction;
13 | import android.app.ProgressDialog;
14 | import android.graphics.drawable.BitmapDrawable;
15 | import android.os.Bundle;
16 | import android.os.Handler;
17 | import android.os.Handler.Callback;
18 | import android.os.Message;
19 | import android.view.LayoutInflater;
20 | import android.view.View;
21 | import android.view.View.OnClickListener;
22 | import android.widget.Button;
23 | import android.widget.EditText;
24 | import android.widget.ImageView;
25 | import android.widget.PopupWindow;
26 | import android.widget.Toast;
27 |
28 | import com.itextpdf.text.Document;
29 | import com.itextpdf.text.DocumentException;
30 | import com.itextpdf.text.Font;
31 | import com.itextpdf.text.Paragraph;
32 | import com.itextpdf.text.pdf.BaseFont;
33 | import com.itextpdf.text.pdf.PdfWriter;
34 |
35 | public class MainActivity extends Activity implements OnClickListener {
36 |
37 | private ImageView iv_back; // 退出界面按钮
38 | private ImageView iv_menu; // 打开菜单按钮
39 | private EditText et_pdf; // 内容编辑框
40 | private Button btn_pdf; // 生成文件按钮
41 | private Button btn_lookPdf; //查看PDF文件按钮
42 |
43 | private ProgressDialog myDialog; // 保存进度框
44 | private PopupWindow ppw_lookpdf; //查看PDF文件弹出框
45 |
46 | private static final int PDF_SAVE_START = 1;// 保存PDF文件的开始意图
47 | private static final int PDF_SAVE_RESULT = 2;// 保存PDF文件的结果开始意图
48 |
49 | @Override
50 | protected void onCreate(Bundle savedInstanceState) {
51 | super.onCreate(savedInstanceState);
52 | setContentView(R.layout.activity_main);
53 | init();
54 | }
55 |
56 | private Handler handler = new Handler(new Callback() {
57 |
58 | @Override
59 | public boolean handleMessage(Message msg) {
60 | switch (msg.what) {
61 | case PDF_SAVE_START:
62 | if (!myDialog.isShowing())
63 | myDialog.show();
64 | break;
65 |
66 | case PDF_SAVE_RESULT:
67 | if (myDialog.isShowing())
68 | myDialog.dismiss();
69 | Toast.makeText(MainActivity.this, "保存成功", Toast.LENGTH_SHORT)
70 | .show();
71 | break;
72 | }
73 | return false;
74 | }
75 | });
76 |
77 | /**
78 | * 初始化操作
79 | */
80 | private void init() {
81 | initView();
82 | initProgress();
83 | initPop();
84 | }
85 |
86 | /**
87 | * 初始化popupwindow
88 | */
89 | @SuppressWarnings("deprecation")
90 | private void initPop() {
91 | View view = LayoutInflater.from(this).inflate(
92 | R.layout.dialog_pdf_model, null);
93 | btn_lookPdf = (Button) view.findViewById(R.id.btn_ocr_look_pdf);
94 | btn_lookPdf.setOnClickListener(this);
95 | ppw_lookpdf = new PopupWindow(view,
96 | LayoutParams.WRAP_CONTENT,
97 | LayoutParams.WRAP_CONTENT);
98 | ppw_lookpdf.setFocusable(true);
99 | ppw_lookpdf.setOutsideTouchable(true);
100 | ppw_lookpdf.setBackgroundDrawable(new BitmapDrawable());
101 | ppw_lookpdf.setTouchable(true);
102 | }
103 |
104 | /**
105 | * 初始化识别进度框
106 | */
107 | private void initProgress() {
108 | myDialog = new ProgressDialog(this, ProgressDialog.THEME_HOLO_LIGHT);
109 | myDialog.setIndeterminateDrawable(getResources().getDrawable(
110 | R.drawable.progress_ocr));
111 | myDialog.setMessage("正在保存PDF文件...");
112 | myDialog.setCanceledOnTouchOutside(false);
113 | myDialog.setCancelable(false);
114 | }
115 |
116 | /**
117 | * 初始化控件
118 | */
119 | private void initView() {
120 | iv_back = (ImageView) findViewById(R.id.iv_pdf_back);
121 | iv_menu = (ImageView) findViewById(R.id.iv_pdf_menu);
122 | et_pdf = (EditText) findViewById(R.id.et_pdf);
123 | btn_pdf = (Button) findViewById(R.id.btn_pdf);
124 | iv_back.setOnClickListener(this);
125 | iv_menu.setOnClickListener(this);
126 | btn_pdf.setOnClickListener(this);
127 | }
128 |
129 | @Override
130 | public void onClick(View v) {
131 | switch (v.getId()) {
132 | case R.id.btn_pdf: //生成pdf
133 | turnToPdf();
134 | break;
135 | case R.id.iv_pdf_back://退出界面
136 | this.finish();
137 | break;
138 | case R.id.iv_pdf_menu://打开查看pdf
139 | openPdfDialog(v);
140 | break;
141 | case R.id.btn_ocr_look_pdf:
142 | lookPdf();
143 | break;
144 | }
145 | }
146 |
147 | /**
148 | * 查看PDF文件
149 | */
150 | private void lookPdf() {
151 | ppw_lookpdf.dismiss();
152 | PdfCenterDialog dialog = new PdfCenterDialog();
153 | FragmentTransaction ft = getFragmentManager().beginTransaction();
154 | ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
155 | dialog.show(ft, "");
156 | }
157 |
158 | /**
159 | * 打开进入pdf文件的显示框
160 | */
161 | private void openPdfDialog(View v) {
162 | ppw_lookpdf.showAsDropDown(v);
163 | }
164 |
165 | /**
166 | * 识别结果转为PDF文件
167 | */
168 | private void turnToPdf() {
169 | if (et_pdf.getText().toString().equals("")
170 | || et_pdf.getText().toString() == null) {
171 | Toast.makeText(this, "请输入内容", Toast.LENGTH_SHORT).show();
172 | return;
173 | }
174 | File file = new File(PdfUtils.ADDRESS);
175 | if (!file.exists())
176 | file.mkdirs();
177 | long time = System.currentTimeMillis();
178 | Date date = new Date(time);
179 | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
180 | final String pdf_address = PdfUtils.ADDRESS + File.separator + "PDF_"
181 | + sdf.format(date) + ".pdf";
182 | handler.sendEmptyMessage(PDF_SAVE_START);
183 | new Thread(new Runnable() {
184 | @Override
185 | public void run() {
186 | Document doc = new Document();// 创建一个document对象
187 | FileOutputStream fos;
188 | try {
189 | fos = new FileOutputStream(pdf_address); // pdf_address为Pdf文件保存到sd卡的路径
190 | PdfWriter.getInstance(doc, fos);
191 | doc.open();
192 | doc.setPageCount(1);
193 | doc.add(new Paragraph(et_pdf.getText().toString(),
194 | setChineseFont())); // result为保存的字符串
195 | // ,setChineseFont()为pdf字体
196 | // 一定要记得关闭document对象
197 | doc.close();
198 | fos.flush();
199 | fos.close();
200 | handler.sendEmptyMessage(PDF_SAVE_RESULT);
201 | } catch (FileNotFoundException e1) {
202 | e1.printStackTrace();
203 | } catch (DocumentException e) {
204 | e.printStackTrace();
205 | } catch (IOException e) {
206 | e.printStackTrace();
207 | }
208 | }
209 | }).start();
210 |
211 | }
212 |
213 | /**
214 | * 设置PDF字体(较为耗时)
215 | */
216 | public Font setChineseFont() {
217 | BaseFont bf = null;
218 | Font fontChinese = null;
219 | try {
220 | // STSong-Light : Adobe的字体
221 | // UniGB-UCS2-H : pdf 字体
222 | bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",
223 | BaseFont.NOT_EMBEDDED);
224 | fontChinese = new Font(bf, 12, Font.NORMAL);
225 | } catch (DocumentException e) {
226 | e.printStackTrace();
227 | } catch (IOException e) {
228 | e.printStackTrace();
229 | }
230 | return fontChinese;
231 | }
232 |
233 | }
234 |
--------------------------------------------------------------------------------