Ver Fonte

Toolbars, show pdf OK

Wayne há 6 anos atrás
pai
commit
275ed4c648
100 ficheiros alterados com 601 adições e 19 exclusões
  1. 7 1
      app/build.gradle
  2. BIN
      app/libs/kmpdfkit-1.0.7.aar
  3. 5 1
      app/src/main/AndroidManifest.xml
  4. 5 0
      app/src/main/java/com/kdanmobile/pdfreaderviewapp/MainActivity.kt
  5. 0 0
      app/src/main/jniLibs/armeabi-v7a/libkmpdf.so
  6. 0 0
      app/src/main/jniLibs/armeabi/libkmpdf.so
  7. 0 0
      app/src/main/jniLibs/mips/libkmpdf.so
  8. 0 0
      app/src/main/jniLibs/x86/libkmpdf.so
  9. 2 2
      app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
  10. 2 2
      app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
  11. BIN
      app/src/main/res/mipmap-hdpi/ic_launcher.png
  12. BIN
      app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
  13. BIN
      app/src/main/res/mipmap-hdpi/ic_launcher_round.png
  14. BIN
      app/src/main/res/mipmap-mdpi/ic_launcher.png
  15. BIN
      app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
  16. BIN
      app/src/main/res/mipmap-mdpi/ic_launcher_round.png
  17. BIN
      app/src/main/res/mipmap-xhdpi/ic_launcher.png
  18. BIN
      app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
  19. BIN
      app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
  20. BIN
      app/src/main/res/mipmap-xxhdpi/ic_launcher.png
  21. BIN
      app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
  22. BIN
      app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
  23. BIN
      app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
  24. BIN
      app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
  25. BIN
      app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
  26. 4 0
      app/src/main/res/values/ic_launcher_background.xml
  27. 1 1
      reader/build.gradle
  28. BIN
      reader/libs/armeabi-v7a/libkmpdf.so
  29. BIN
      reader/libs/armeabi/libkmpdf.so
  30. BIN
      reader/libs/mips/libkmpdf.so
  31. BIN
      reader/libs/x86/libkmpdf.so
  32. 4 1
      reader/src/main/AndroidManifest.xml
  33. 330 0
      reader/src/main/java/com/kdanmobile/reader/HorizontalView.java
  34. 107 6
      reader/src/main/java/com/kdanmobile/reader/ReaderActivity.kt
  35. 5 5
      reader/src/main/java/com/kdanmobile/reader/ReaderViewModel.kt
  36. 68 0
      reader/src/main/java/com/kdanmobile/reader/Utils.kt
  37. BIN
      reader/src/main/res/drawable-hdpi/ic_bookmark.png
  38. BIN
      reader/src/main/res/drawable-hdpi/ic_bookmark_border.png
  39. BIN
      reader/src/main/res/drawable-hdpi/ic_chevron_left.png
  40. BIN
      reader/src/main/res/drawable-hdpi/ic_chevron_right.png
  41. BIN
      reader/src/main/res/drawable-hdpi/ic_kdan_cloud.png
  42. BIN
      reader/src/main/res/drawable-hdpi/ic_pagelist_bookmk_h.png
  43. BIN
      reader/src/main/res/drawable-hdpi/ic_pagelist_bookmk_nor.png
  44. BIN
      reader/src/main/res/drawable-hdpi/ic_pagelist_outline_h.png
  45. BIN
      reader/src/main/res/drawable-hdpi/ic_pagelist_outline_nor.png
  46. BIN
      reader/src/main/res/drawable-hdpi/ic_pagelist_search_h.png
  47. BIN
      reader/src/main/res/drawable-hdpi/ic_pagelist_search_nor.png
  48. BIN
      reader/src/main/res/drawable-hdpi/ic_pagelist_thumbnail_h.png
  49. BIN
      reader/src/main/res/drawable-hdpi/ic_pagelist_thumbnail_nor.png
  50. BIN
      reader/src/main/res/drawable-hdpi/ic_pagelist_title_bookmk.png
  51. BIN
      reader/src/main/res/drawable-hdpi/ic_pagelist_title_outine.png
  52. BIN
      reader/src/main/res/drawable-hdpi/ic_pagelist_title_thumbnail.png
  53. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_freehand_s1.png
  54. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_freehand_s10.png
  55. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_freehand_s2.png
  56. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_freehand_s3.png
  57. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_freehand_s4.png
  58. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_freehand_s5.png
  59. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_freehand_s6.png
  60. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_freehand_s7.png
  61. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_freehand_s8.png
  62. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_freehand_s9.png
  63. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_fullscreen.png
  64. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_fullscreen_h.png
  65. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_setting_h.png
  66. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_settings.png
  67. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_text.png
  68. BIN
      reader/src/main/res/drawable-hdpi/ic_tool_unfullscreen.png
  69. BIN
      reader/src/main/res/drawable-hdpi/ic_view_all.png
  70. 8 0
      reader/src/main/res/drawable-hdpi/selector_tool_settings.xml
  71. 45 0
      reader/src/main/res/drawable-xhdpi/bg_reader_tool_bar_left.xml
  72. BIN
      reader/src/main/res/drawable-xhdpi/ic_bookmark.png
  73. BIN
      reader/src/main/res/drawable-xhdpi/ic_bookmark_border.png
  74. BIN
      reader/src/main/res/drawable-xhdpi/ic_chevron_left.png
  75. BIN
      reader/src/main/res/drawable-xhdpi/ic_chevron_right.png
  76. BIN
      reader/src/main/res/drawable-xhdpi/ic_kdan_cloud.png
  77. BIN
      reader/src/main/res/drawable-xhdpi/ic_pagelist_bookmk_h.png
  78. BIN
      reader/src/main/res/drawable-xhdpi/ic_pagelist_bookmk_nor.png
  79. BIN
      reader/src/main/res/drawable-xhdpi/ic_pagelist_outline_h.png
  80. BIN
      reader/src/main/res/drawable-xhdpi/ic_pagelist_outline_nor.png
  81. BIN
      reader/src/main/res/drawable-xhdpi/ic_pagelist_search_h.png
  82. BIN
      reader/src/main/res/drawable-xhdpi/ic_pagelist_search_nor.png
  83. BIN
      reader/src/main/res/drawable-xhdpi/ic_pagelist_thumbnail_h.png
  84. BIN
      reader/src/main/res/drawable-xhdpi/ic_pagelist_thumbnail_nor.png
  85. BIN
      reader/src/main/res/drawable-xhdpi/ic_pagelist_title_thumbnail.png
  86. BIN
      reader/src/main/res/drawable-xhdpi/ic_tool_fullscreen.png
  87. BIN
      reader/src/main/res/drawable-xhdpi/ic_tool_fullscreen_h.png
  88. BIN
      reader/src/main/res/drawable-xhdpi/ic_tool_ink.png
  89. BIN
      reader/src/main/res/drawable-xhdpi/ic_tool_setting_h.png
  90. BIN
      reader/src/main/res/drawable-xhdpi/ic_tool_settings.png
  91. BIN
      reader/src/main/res/drawable-xhdpi/ic_tool_text.png
  92. BIN
      reader/src/main/res/drawable-xhdpi/ic_tool_unfullscreen.png
  93. BIN
      reader/src/main/res/drawable-xhdpi/ic_view_all.png
  94. 8 0
      reader/src/main/res/drawable-xhdpi/selector_tool_fullscreen.xml
  95. BIN
      reader/src/main/res/drawable-xxhdpi/ic_bookmark.png
  96. BIN
      reader/src/main/res/drawable-xxhdpi/ic_bookmark_border.png
  97. BIN
      reader/src/main/res/drawable-xxhdpi/ic_chevron_left.png
  98. BIN
      reader/src/main/res/drawable-xxhdpi/ic_chevron_right.png
  99. BIN
      reader/src/main/res/drawable-xxhdpi/ic_kdan_cloud.png
  100. 0 0
      reader/src/main/res/drawable-xxhdpi/ic_view_all.png

+ 7 - 1
app/build.gradle

@@ -29,7 +29,7 @@ android {
 
 dependencies {
     implementation fileTree(dir: 'libs', include: ['*.jar'])
-    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
     implementation 'com.android.support:appcompat-v7:28.0.0'
     implementation 'com.android.support.constraint:constraint-layout:1.1.3'
     testImplementation 'junit:junit:4.12'
@@ -38,3 +38,9 @@ dependencies {
 
     implementation project(':reader')
 }
+
+repositories {
+    flatDir {
+        dirs 'libs', '../reader/libs'
+    }
+}

BIN
app/libs/kmpdfkit-1.0.7.aar


+ 5 - 1
app/src/main/AndroidManifest.xml

@@ -2,6 +2,9 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.kdanmobile.pdfreaderviewapp">
 
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+
     <application
         android:name=".MyApplication"
         android:allowBackup="true"
@@ -19,7 +22,8 @@
         </activity>
         <activity
             android:name=".MyReaderActivity"
-            android:exported="true"/>
+            android:exported="true"
+            android:theme="@style/ReaderActivityNoActionBarNoTitle" />
     </application>
 
 </manifest>

+ 5 - 0
app/src/main/java/com/kdanmobile/pdfreaderviewapp/MainActivity.kt

@@ -20,8 +20,13 @@ class MainActivity : AppCompatActivity() {
             Toast.makeText(this, "Cannot find Quick Start.pdf", Toast.LENGTH_SHORT).show()
             return
         }
+
+//        val intent = Intent(this, ReaderActivity2::class.java)
+//        intent.putExtra(TestReaderActivity.KEY, quickStartPdf.absolutePath)
+
         val intent = Intent(this, MyReaderActivity::class.java)
         intent.putExtra(MyReaderActivity.KEY_FILE_ABSOLUTE, quickStartPdf.absolutePath)
+
         startActivity(intent)
     }
 }

app/libs/armeabi-v7a/libkmpdf.so → app/src/main/jniLibs/armeabi-v7a/libkmpdf.so


app/libs/armeabi/libkmpdf.so → app/src/main/jniLibs/armeabi/libkmpdf.so


app/libs/mips/libkmpdf.so → app/src/main/jniLibs/mips/libkmpdf.so


app/libs/x86/libkmpdf.so → app/src/main/jniLibs/x86/libkmpdf.so


+ 2 - 2
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
-    <background android:drawable="@drawable/ic_launcher_background" />
-    <foreground android:drawable="@drawable/ic_launcher_foreground" />
+    <background android:drawable="@color/ic_launcher_background"/>
+    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
 </adaptive-icon>

+ 2 - 2
app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
-    <background android:drawable="@drawable/ic_launcher_background" />
-    <foreground android:drawable="@drawable/ic_launcher_foreground" />
+    <background android:drawable="@color/ic_launcher_background"/>
+    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
 </adaptive-icon>

BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png


BIN
app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png


BIN
app/src/main/res/mipmap-hdpi/ic_launcher_round.png


BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png


BIN
app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png


BIN
app/src/main/res/mipmap-mdpi/ic_launcher_round.png


BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png


BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png


BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_round.png


BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png


BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png


BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png


BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png


BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png


BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png


+ 4 - 0
app/src/main/res/values/ic_launcher_background.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <color name="ic_launcher_background">#A64554</color>
+</resources>

+ 1 - 1
reader/build.gradle

@@ -41,5 +41,5 @@ dependencies {
 
     testImplementation 'junit:junit:4.12'
 
-    implementation(name: 'kmpdfkit-1.0.7', ext: 'aar')
+    api(name: 'kmpdfkit-1.0.7', ext: 'aar')
 }

BIN
reader/libs/armeabi-v7a/libkmpdf.so


BIN
reader/libs/armeabi/libkmpdf.so


BIN
reader/libs/mips/libkmpdf.so


BIN
reader/libs/x86/libkmpdf.so


+ 4 - 1
reader/src/main/AndroidManifest.xml

@@ -3,7 +3,10 @@
     package="com.kdanmobile.reader">
 
     <application>
-        <activity android:name=".ReaderActivity"></activity>
+        <activity
+            android:name=".ReaderActivity"
+            android:theme="@style/ReaderActivityNoActionBarNoTitle"
+            />
     </application>
 
 </manifest>

+ 330 - 0
reader/src/main/java/com/kdanmobile/reader/HorizontalView.java

@@ -0,0 +1,330 @@
+package com.kdanmobile.reader;
+
+import android.app.Activity;
+import android.content.Context;
+import android.support.annotation.NonNull;
+import android.util.AttributeSet;
+import android.util.DisplayMetrics;
+import android.view.GestureDetector;
+import android.view.MotionEvent;
+import android.widget.LinearLayout;
+import android.widget.Scroller;
+
+/**
+ * @类名:HorizontalView
+ * @类描述:自定义线性布局,实现布局整个滑动功能
+ * @作者:zhouguifang
+ * @创建时间:2015-7-6-下午5:59:49
+ * @修改人:
+ * @修改时间:
+ * @修改备注:
+ * @版本:
+ * @Copyright:(c)-2015kdan mobile
+ */
+@SuppressWarnings("ALL")
+public class HorizontalView extends LinearLayout implements
+		GestureDetector.OnGestureListener {
+	// private static final String TAG = "Scroller";
+	private final GestureDetector mGestureDetector;
+
+	private Scroller mScroller;
+
+	private float last_position = 0;
+	private float start_position = 0;
+
+	private float x1, x2, y1, y2;
+	private boolean isFirst = true;
+	private boolean isResult = false;
+
+	private int moveDistance = 266;
+	public boolean isOpen = false;
+	private boolean isOk = false;
+	private boolean isScroll = true;
+
+	private boolean isFirstPager = true;
+
+	private static final int MOVING_DIAGONALLY = 0;
+	private static final int MOVING_LEFT = 1;
+	private static final int MOVING_RIGHT = 2;
+	private static final int MOVING_UP = 3;
+	private static final int MOVING_DOWN = 4;
+
+	public HorizontalView(Context context, AttributeSet attrs) {
+		super(context, attrs);
+		mScroller = new Scroller(context);
+		mGestureDetector = new GestureDetector(this);
+	}
+
+	public void setScroll(boolean isScroll) {
+		this.isScroll = isScroll;
+	}
+
+	public void setFirstPager(boolean isFirstPager) {
+		this.isFirstPager = isFirstPager;
+	}
+
+	@Override
+	public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
+		// Out.println("dispatchTouchEvent...");
+		switch (ev.getAction()) {
+		case MotionEvent.ACTION_DOWN:
+			// Out.println("ACTION_DOWN...");
+			x1 = ev.getX();
+			y1 = ev.getY();
+			break;
+		case MotionEvent.ACTION_MOVE:
+			// Out.println("ACTION_MOVE...");
+			if (isFirst) {
+				x2 = ev.getX();
+				y2 = ev.getY();
+				float x = Math.abs(x1 - x2);
+				float y = Math.abs(y1 - y2);
+				float distance = (x * x) + (y * y);
+				// Out.println("isFirst...dis:" + distance);
+				DisplayMetrics displayMetrics = new DisplayMetrics();
+                Activity activity = (Activity) getContext();
+                activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
+                float density = displayMetrics.density;
+				if (distance > (density * 5)) {
+					isFirst = false;
+					if (x > y) {
+						// 第一页向右滑动||第一页向左滑动且控件是打开的
+						if ((((x1 - x2) < 0) && isFirstPager)
+                                || (((x1 - x2) > 0) && isFirstPager && isOpen)) {
+							isResult = true;
+							start_position = ev.getX();
+							last_position = ev.getX();
+						}
+					}
+				}
+			}
+			break;
+		case MotionEvent.ACTION_UP:
+			// LogUtil.print_i(HorizontalView.class,"ACTION_UP...");
+			isFirst = true;
+			isResult = false;
+			break;
+		}
+		return super.dispatchTouchEvent(ev);
+	}
+
+	@Override
+	public boolean onInterceptTouchEvent(MotionEvent ev) {
+        return isScroll && isResult || super.onInterceptTouchEvent(ev);
+    }
+
+	@Override
+	public boolean onTouchEvent(@NonNull MotionEvent event) {
+		mGestureDetector.onTouchEvent(event);
+		int action = event.getAction();
+		float x = event.getX();
+		switch (action) {
+		case MotionEvent.ACTION_DOWN:
+			start_position = event.getX();
+			last_position = event.getX();
+			break;
+		case MotionEvent.ACTION_MOVE:
+			// LogUtil.print_i(HorizontalView.class,"onTouchEvent...ACTION_MOVE");
+			float distant = x - start_position;
+			if (!isOpen) {
+				if (distant > moveDistance) {
+					distant = moveDistance;
+				}
+				if (distant < 0) {
+					distant = 0;
+				}
+				x = distant + start_position;
+			} else {
+				if (distant > 0) {
+					distant = 0;
+				}
+				if (distant < -moveDistance) {
+					distant = -moveDistance;
+				}
+			}
+			x = distant + start_position;
+			smoothScrollBy((int) (last_position - x), 0, 0);
+			last_position = x;
+			break;
+		case MotionEvent.ACTION_UP:
+			if (!isOk) {
+				if (isOpen) {
+					if ((mScroller.getFinalX() + ((moveDistance * 7) / 8)) > 0) {
+						smoothScrollTo(0, 0);
+						isOpen = false;
+					} else {
+						smoothScrollTo(0 - moveDistance, 0);
+						isOpen = true;
+					}
+				} else {
+					if ((mScroller.getFinalX() + ((moveDistance) / 8)) > 0) {
+						smoothScrollTo(0, 0);
+						isOpen = false;
+					} else {
+						smoothScrollTo(0 - moveDistance, 0);
+						isOpen = true;
+					}
+				}
+			}
+			isOk = false;
+			return false;
+		}
+		return super.onTouchEvent(event);
+	}
+
+	@Override
+	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
+                           float velocityY) {
+		switch (directionOfTravel(velocityX, velocityY)) {
+		case MOVING_LEFT:
+			smoothScrollTo(0, 0);
+			isOpen = false;
+			break;
+		case MOVING_RIGHT:
+			smoothScrollTo(0 - moveDistance, 0);
+			isOpen = true;
+			break;
+		default:
+			// LogUtil.print_i(HorizontalView.class,"x:" + mScroller.getFinalX() + "  Y:"
+			// + mScroller.getFinalY());
+			if (isOpen) {
+				if ((mScroller.getFinalX() + ((moveDistance * 7) / 8)) > 0) {
+					smoothScrollTo(0, 0);
+					isOpen = false;
+				} else {
+					smoothScrollTo(0 - moveDistance, 0);
+					isOpen = true;
+				}
+			} else {
+				if ((mScroller.getFinalX() + ((moveDistance) / 8)) > 0) {
+					smoothScrollTo(0, 0);
+					isOpen = false;
+				} else {
+					smoothScrollTo(0 - moveDistance, 0);
+					isOpen = true;
+				}
+			}
+			break;
+		}
+		isOk = true;
+		return true;
+	}
+
+	public void animateToggle() {
+		if (isOpen) {
+			smoothScrollTo(0, 0);
+		} else {
+			smoothScrollTo(0 - moveDistance, 0);
+		}
+		isOpen = !isOpen;
+	}
+	
+	/**
+	 * @方法说明:计算移动方向
+	 * @方法名称:directionOfTravel
+	 * @param vx
+	 * @param vy
+	 * @return
+	 * @返回值:int
+	 */
+	private static int directionOfTravel(float vx, float vy) {
+		if (Math.abs(vx) > (2 * Math.abs(vy)))
+			return (vx > 0) ? MOVING_RIGHT : MOVING_LEFT;
+		else if (Math.abs(vy) > (2 * Math.abs(vx)))
+			return (vy > 0) ? MOVING_DOWN : MOVING_UP;
+		else
+			return MOVING_DIAGONALLY;
+	}
+
+	/**
+	 * @方法说明:调用此方法滚动到目标位置
+	 * @方法名称:smoothScrollTo
+	 * @param fx
+	 * @param fy
+	 * @返回值:void
+	 */
+	public void smoothScrollTo(int fx, int fy) {
+		int dx = fx - mScroller.getFinalX();
+		int dy = fy - mScroller.getFinalY();
+		smoothScrollBy(dx, dy);
+	}
+
+	/**
+	 * @方法说明:调用此方法滚动到目标位置
+	 * @方法名称:smoothScrollTo
+	 * @param fx
+	 * @param fy
+	 * @param drution
+	 * @返回值:void
+	 */
+	public void smoothScrollTo(int fx, int fy, int drution) {
+		int dx = fx - mScroller.getFinalX();
+		int dy = fy - mScroller.getFinalY();
+		mScroller.startScroll(mScroller.getFinalX(), mScroller.getFinalY(), dx,
+				dy, drution);
+		invalidate();
+	}
+
+	/**
+	 * @方法说明:调用此方法设置滚动的相对偏移
+	 * @方法名称:smoothScrollBy
+	 * @param dx
+	 * @param dy
+	 * @返回值:void
+	 */
+	public void smoothScrollBy(int dx, int dy) {
+		// 设置mScroller的滚动偏移量
+		mScroller.startScroll(mScroller.getFinalX(), mScroller.getFinalY(), dx,
+				dy, 500);
+		invalidate();// 这里必须调用invalidate()才能保证computeScroll()会被调用,否则不一定会刷新界面,看不到滚动效果
+	}
+
+	public void smoothScrollBy(int dx, int dy, int drution) {
+		// 设置mScroller的滚动偏移量
+		mScroller.startScroll(mScroller.getFinalX(), mScroller.getFinalY(), dx,
+				dy, drution);
+		invalidate();// 这里必须调用invalidate()才能保证computeScroll()会被调用,否则不一定会刷新界面,看不到滚动效果
+	}
+
+	@Override
+	public void computeScroll() {
+		// 先判断mScroller滚动是否完成
+		if (mScroller.computeScrollOffset()) {
+			// 这里调用View的scrollTo()完成实际的滚动
+			scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
+
+			// 必须调用该方法,否则不一定能看到滚动效果
+			postInvalidate();
+		}
+		super.computeScroll();
+	}
+
+	public void setMoveDistance(int distance) {
+		moveDistance = distance;
+	}
+
+	@Override
+	public boolean onDown(MotionEvent e) {
+		return false;
+	}
+
+	@Override
+	public void onShowPress(MotionEvent e) {
+	}
+
+	@Override
+	public boolean onSingleTapUp(MotionEvent e) {
+		return false;
+	}
+
+	@Override
+	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
+                            float distanceY) {
+		return false;
+	}
+
+	@Override
+	public void onLongPress(MotionEvent e) {
+
+	}
+}

+ 107 - 6
reader/src/main/java/com/kdanmobile/reader/ReaderActivity.kt

@@ -1,12 +1,19 @@
 package com.kdanmobile.reader
 
+import android.annotation.SuppressLint
 import android.arch.lifecycle.Observer
 import android.arch.lifecycle.ViewModelProviders
 import android.net.Uri
+import android.os.Build
 import android.support.v7.app.AppCompatActivity
 import android.os.Bundle
+import android.support.constraint.ConstraintSet
+import android.view.Menu
+import android.view.View
 import com.kdanmobile.kmpdfkit.pdfcommon.KMPDFReaderView
+import com.kdanmobile.reader.Utils.applyConstraintSet
 import kotlinx.android.synthetic.main.activity_reader.*
+import kotlin.Exception
 
 open class ReaderActivity : AppCompatActivity() {
 
@@ -16,29 +23,123 @@ open class ReaderActivity : AppCompatActivity() {
 
     private lateinit var viewModel: ReaderViewModel
 
+    // For hide/show toolbars
+    private var isHideToolbar = false
+    private lateinit var originConstraintSet: ConstraintSet
+
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.activity_reader)
+        setSupportActionBar(toolbar_readerActivity)
+
+        cloneOriginConstraintSet()
+        setupBottomToolbar()
+
         val factory = ReaderViewModelFactory()
         viewModel = ViewModelProviders.of(this, factory).get(ReaderViewModel::class.java)
-
+        viewModel.isOpenedFileLiveData.observe(this, Observer(this::onIsOpenedFileUpdate))
+        viewModel.fileNameLiveData.observe(this, Observer { tv_readerActivity_title.text = it })
         viewModel.isOpenedFileLiveData.value?.also { isOpened ->
             if (isOpened) return@also
-            val filePath = intent.getStringExtra("file_absolutepath")
+            val filePath = intent.getStringExtra(KEY_FILE_ABSOLUTE)
             val uri = Uri.parse(filePath)
-            viewModel.openPdfFile(this, uri)
+            viewModel.openPdfFile(this, uri, intent.type)
+        }
+    }
+
+    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
+        menuInflater.inflate(R.menu.reader_more, menu)
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+            menu?.findItem(R.id.item_reader_more_print)?.isVisible = false
+        }
+        // TODO: Check is pdf file or epub file, these action support only pdf file
+        val isPdf = true
+        if (!isPdf) {
+            menu?.apply {
+                findItem(R.id.item_reader_more_text_reflow)?.isVisible = false
+                findItem(R.id.item_reader_more_file_info)?.isVisible = false
+                findItem(R.id.item_reader_more_print)?.isVisible = false
+            }
+        }
+        return true
+    }
+
+    @SuppressLint("RestrictedApi")
+    override fun onPrepareOptionsPanel(view: View?, menu: Menu?): Boolean {
+        /** Force show action menu item icon **/
+        menu?.also {
+            if ("MenuBuilder" != it::javaClass.get().simpleName) return@also
+            try {
+                val method = it.javaClass.getDeclaredMethod("setOptionalIconsVisible", java.lang.Boolean.TYPE)
+                method.isAccessible = true
+                method.invoke(it, true)
+            } catch (e: Exception) {
+                // Do nothing
+                println(e.message)
+            }
+        }
+        return super.onPrepareOptionsPanel(view, menu)
+    }
+
+    private fun cloneOriginConstraintSet() {
+        originConstraintSet = ConstraintSet().apply {
+            clone(constrainLayout_readerActivity_root)
         }
-        viewModel.isOpenedFileLiveData.observe(this, Observer(this::onIsOpenedFileUpdate))
     }
 
     private fun onIsOpenedFileUpdate(isOpened: Boolean?) {
         if (isOpened == null) return
-        if (!isOpened) return
         val container = viewGroup_readerActivity_container
         container.removeAllViews()
+        if (!isOpened) return
         val context = this
-        val readerView = KMPDFReaderView(context)
+        val readerView = object : KMPDFReaderView(context) {
+            override fun onTapMainDocArea() {
+                super.onTapMainDocArea()
+                when (isHideToolbar) {
+                    true -> showAllToolbars()
+                    false -> hideAllToolbars()
+                }
+                isHideToolbar = !isHideToolbar
+            }
+        }
         viewModel.setReaderView(readerView)
         container.addView(readerView)
     }
+
+    private fun showAllToolbars() {
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+            // TODO : Implement show toolbars on Android api level < 19 devices
+        } else {
+            constrainLayout_readerActivity_root.applyConstraintSet(originConstraintSet)
+        }
+    }
+
+    private fun hideAllToolbars() {
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+            // TODO : Implement hide toolbars on Android api level < 19 devices
+        } else {
+            constrainLayout_readerActivity_root.applyConstraintSet(this, R.layout.activity_reader_hide_all)
+        }
+    }
+
+    private fun hideTopLeftBottomToolbars() {
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+            // TODO : Implement hide toolbars on Android api level < 19 devices
+        } else {
+            constrainLayout_readerActivity_root.applyConstraintSet(this, R.layout.activity_reader_hide_top_left_bottom)
+        }
+    }
+
+    private fun setupBottomToolbar() {
+        val context = this
+        /** Set buttons color **/
+        val normalColor = R.color.reader_bottom_toolbar_bottom_color_normal
+        val pressColor = R.color.reader_bottom_toolbar_bottom_color_press
+        Utils.setTintDrawableList(context, ib_readerActivity_bottomToolbarPrevious, R.drawable.ic_chevron_left, normalColor, pressColor)
+        Utils.setTintDrawableList(context, ib_readerActivity_bottomToolbarNext, R.drawable.ic_chevron_right, normalColor, pressColor)
+        Utils.setTintDrawableList(context, ib_readerActivity_bottomToolbarBookmark, R.drawable.ic_bookmark_border, normalColor, pressColor)
+        Utils.setTintDrawableList(context, ib_readerActivity_bottomToolbarViewAll, R.drawable.ic_view_all, normalColor, pressColor)
+        Utils.setTintDrawableList(context, ib_readerActivity_bottomToolbarKdanCloud, R.drawable.ic_kdan_cloud, normalColor, pressColor)
+    }
 }

+ 5 - 5
reader/src/main/java/com/kdanmobile/reader/ReaderViewModel.kt

@@ -35,6 +35,7 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
     private var kmpdfFactory: KMPDFFactory? = null
     private var kmpdfDocumentController: KMPDFDocumentController? = null
     val isOpenedFileLiveData = MutableLiveData<Boolean>().apply { value = false }
+    val fileNameLiveData = MutableLiveData<String>()
 
     @JvmOverloads
     fun openPdfFile(context: Context, uri: Uri, type: String? = null): Boolean {
@@ -52,6 +53,7 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
         val factory = KMPDFFactory.open(context, uri, type) ?: return false
         kmpdfFactory = factory
         kmpdfFactory?.also {
+            fileNameLiveData.postValue(it.fileName)
             return when {
                 it.needPassWord() -> {
                     false
@@ -148,16 +150,14 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
     }
 
     private fun updateViewDirection() {
-        kmpdfDocumentController?.apply {
-            pdfViewMode = viewDirection.mode
-            refresh(true)
-        }
+        kmpdfDocumentController?.pdfViewMode = viewDirection.mode
+        kmpdfDocumentController?.refresh(false)
     }
 
     private fun updateCrop() {
         kmpdfDocumentController?.apply {
             cropMode = isCrop
-            refresh(true)
+            refresh(false)
         }
     }
 }

+ 68 - 0
reader/src/main/java/com/kdanmobile/reader/Utils.kt

@@ -0,0 +1,68 @@
+package com.kdanmobile.reader
+
+import android.content.Context
+import android.content.res.ColorStateList
+import android.graphics.drawable.StateListDrawable
+import android.os.Build
+import android.support.annotation.LayoutRes
+import android.support.annotation.RequiresApi
+import android.support.constraint.ConstraintLayout
+import android.support.constraint.ConstraintSet
+import android.support.v4.content.ContextCompat
+import android.support.v4.graphics.drawable.DrawableCompat
+import android.support.v7.widget.AppCompatImageButton
+import android.support.v7.widget.AppCompatImageView
+import android.transition.TransitionManager
+import android.view.View
+import android.widget.ImageView
+
+object Utils {
+    /**
+     * @param:
+     * @author: luozhipeng
+     * @Decreption:通过tint实现图片selector
+     * @create at: 8/8/16 16:17
+     **/
+    fun setTintDrawableList(context: Context, view: View, srcResourceId: Int, colorResId: Int, colorPressedResId: Int) {
+        var drawable = ContextCompat.getDrawable(context, srcResourceId)
+        val colors = intArrayOf(ContextCompat.getColor(context, colorPressedResId), ContextCompat.getColor(context, colorPressedResId), ContextCompat.getColor(context, colorResId))
+        val states = arrayOfNulls<IntArray>(3)
+        states[0] = intArrayOf(android.R.attr.state_pressed)
+        states[1] = intArrayOf(android.R.attr.state_selected)
+        states[2] = intArrayOf()
+        val colorList = ColorStateList(states, colors)
+        val stateListDrawable = StateListDrawable()
+        stateListDrawable.addState(states[0], drawable)//注意顺序
+        stateListDrawable.addState(states[1], drawable)
+        stateListDrawable.addState(states[2], drawable)
+        val state = stateListDrawable.constantState
+        drawable = DrawableCompat.wrap(if (state == null) stateListDrawable else state.newDrawable()).mutate()
+        DrawableCompat.setTintList(drawable!!, colorList)
+        drawable.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)
+
+        if (view is AppCompatImageView) {
+            view.setImageDrawable(drawable)
+        }
+
+        if (view is ImageView) {
+            view.setImageDrawable(drawable)
+        }
+
+        if (view is AppCompatImageButton) {
+            view.setImageDrawable(drawable)
+        }
+    }
+
+    @RequiresApi(Build.VERSION_CODES.KITKAT)
+    fun ConstraintLayout.applyConstraintSet(constraintSet: ConstraintSet) {
+        TransitionManager.beginDelayedTransition(this)
+        constraintSet.applyTo(this)
+    }
+
+    @RequiresApi(Build.VERSION_CODES.KITKAT)
+    fun ConstraintLayout.applyConstraintSet(context: Context, @LayoutRes layoutResId: Int) {
+        val constraintSet = ConstraintSet()
+        constraintSet.clone(context, layoutResId)
+        this.applyConstraintSet(constraintSet)
+    }
+}

BIN
reader/src/main/res/drawable-hdpi/ic_bookmark.png


BIN
reader/src/main/res/drawable-hdpi/ic_bookmark_border.png


BIN
reader/src/main/res/drawable-hdpi/ic_chevron_left.png


BIN
reader/src/main/res/drawable-hdpi/ic_chevron_right.png


BIN
reader/src/main/res/drawable-hdpi/ic_kdan_cloud.png


BIN
reader/src/main/res/drawable-hdpi/ic_pagelist_bookmk_h.png


BIN
reader/src/main/res/drawable-hdpi/ic_pagelist_bookmk_nor.png


BIN
reader/src/main/res/drawable-hdpi/ic_pagelist_outline_h.png


BIN
reader/src/main/res/drawable-hdpi/ic_pagelist_outline_nor.png


BIN
reader/src/main/res/drawable-hdpi/ic_pagelist_search_h.png


BIN
reader/src/main/res/drawable-hdpi/ic_pagelist_search_nor.png


BIN
reader/src/main/res/drawable-hdpi/ic_pagelist_thumbnail_h.png


BIN
reader/src/main/res/drawable-hdpi/ic_pagelist_thumbnail_nor.png


BIN
reader/src/main/res/drawable-hdpi/ic_pagelist_title_bookmk.png


BIN
reader/src/main/res/drawable-hdpi/ic_pagelist_title_outine.png


BIN
reader/src/main/res/drawable-hdpi/ic_pagelist_title_thumbnail.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_freehand_s1.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_freehand_s10.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_freehand_s2.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_freehand_s3.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_freehand_s4.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_freehand_s5.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_freehand_s6.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_freehand_s7.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_freehand_s8.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_freehand_s9.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_fullscreen.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_fullscreen_h.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_setting_h.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_settings.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_text.png


BIN
reader/src/main/res/drawable-hdpi/ic_tool_unfullscreen.png


BIN
reader/src/main/res/drawable-hdpi/ic_view_all.png


+ 8 - 0
reader/src/main/res/drawable-hdpi/selector_tool_settings.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item android:drawable="@drawable/ic_tool_setting_h" android:state_pressed="true"/>
+    <item android:drawable="@drawable/ic_tool_setting_h" android:state_enabled="true" android:state_focused="true"/>
+    <item android:drawable="@drawable/ic_tool_settings"/>
+
+</selector>

+ 45 - 0
reader/src/main/res/drawable-xhdpi/bg_reader_tool_bar_left.xml

@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape android:shape="rectangle">
+            <solid android:color="#04000000" />
+            <corners
+                android:topRightRadius="6dp"
+                android:bottomRightRadius="6dp"
+                />
+        </shape>
+    </item>
+    <item
+        android:top="0dp"
+        android:right="1dp"
+        android:bottom="1dp"
+        android:left="0dp"
+        >
+        <shape android:shape="rectangle">
+            <solid android:color="#0E000000" />
+            <corners
+                android:topRightRadius="5dp"
+                android:bottomRightRadius="5dp"
+                />
+        </shape>
+    </item>
+
+    <item
+        android:top="0dp"
+        android:right="2dp"
+        android:bottom="2dp"
+        android:left="0dp"
+        >
+        <shape android:shape="rectangle">
+            <padding
+                android:right="2dp"
+                android:bottom="2dp"
+                />
+            <solid android:color="#dff5f5f5" />
+            <corners
+                android:topRightRadius="4dp"
+                android:bottomRightRadius="4dp"
+                />
+        </shape>
+    </item>
+</layer-list>

BIN
reader/src/main/res/drawable-xhdpi/ic_bookmark.png


BIN
reader/src/main/res/drawable-xhdpi/ic_bookmark_border.png


BIN
reader/src/main/res/drawable-xhdpi/ic_chevron_left.png


BIN
reader/src/main/res/drawable-xhdpi/ic_chevron_right.png


BIN
reader/src/main/res/drawable-xhdpi/ic_kdan_cloud.png


BIN
reader/src/main/res/drawable-xhdpi/ic_pagelist_bookmk_h.png


BIN
reader/src/main/res/drawable-xhdpi/ic_pagelist_bookmk_nor.png


BIN
reader/src/main/res/drawable-xhdpi/ic_pagelist_outline_h.png


BIN
reader/src/main/res/drawable-xhdpi/ic_pagelist_outline_nor.png


BIN
reader/src/main/res/drawable-xhdpi/ic_pagelist_search_h.png


BIN
reader/src/main/res/drawable-xhdpi/ic_pagelist_search_nor.png


BIN
reader/src/main/res/drawable-xhdpi/ic_pagelist_thumbnail_h.png


BIN
reader/src/main/res/drawable-xhdpi/ic_pagelist_thumbnail_nor.png


BIN
reader/src/main/res/drawable-xhdpi/ic_pagelist_title_thumbnail.png


BIN
reader/src/main/res/drawable-xhdpi/ic_tool_fullscreen.png


BIN
reader/src/main/res/drawable-xhdpi/ic_tool_fullscreen_h.png


BIN
reader/src/main/res/drawable-xhdpi/ic_tool_ink.png


BIN
reader/src/main/res/drawable-xhdpi/ic_tool_setting_h.png


BIN
reader/src/main/res/drawable-xhdpi/ic_tool_settings.png


BIN
reader/src/main/res/drawable-xhdpi/ic_tool_text.png


BIN
reader/src/main/res/drawable-xhdpi/ic_tool_unfullscreen.png


BIN
reader/src/main/res/drawable-xhdpi/ic_view_all.png


+ 8 - 0
reader/src/main/res/drawable-xhdpi/selector_tool_fullscreen.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item android:drawable="@drawable/ic_tool_fullscreen_h" android:state_pressed="true"/>
+    <item android:drawable="@drawable/ic_tool_fullscreen_h" android:state_enabled="true" android:state_focused="true"/>
+    <item android:drawable="@drawable/ic_tool_fullscreen"/>
+
+</selector>

BIN
reader/src/main/res/drawable-xxhdpi/ic_bookmark.png


BIN
reader/src/main/res/drawable-xxhdpi/ic_bookmark_border.png


BIN
reader/src/main/res/drawable-xxhdpi/ic_chevron_left.png


BIN
reader/src/main/res/drawable-xxhdpi/ic_chevron_right.png


BIN
reader/src/main/res/drawable-xxhdpi/ic_kdan_cloud.png


+ 0 - 0
reader/src/main/res/drawable-xxhdpi/ic_view_all.png


Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff