Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.shwenjin:mupdflib:V1.0.9'
}
dependencies {
implementation("com.github.shwenjin:mupdflib:V1.0.9")
}
<dependency>
<groupId>com.github.shwenjin</groupId>
<artifactId>mupdflib</artifactId>
<version>V1.0.9</version>
</dependency>
libraryDependencies += "com.github.shwenjin" % "mupdflib" % "V1.0.9"
:dependencies [[com.github.shwenjin/mupdflib "V1.0.9"]]
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.shwenjin:mupdflib:V1.0.2'
}
<com.artifex.mupdfdemo.WJPdfView
android:id="@+id/mupdf"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.artifex.mupdfdemo.WJPdfView>
执行
WJPdfView pdfView= (WJPdfView) findViewById(R.id.mupdf);
pdfView.openPDF("xxx.pdf");
销毁
pdfView.onDestroy();
横竖屏切换
private ScreenSwitchUtils instance;
instance = ScreenSwitchUtils.init(this.getApplicationContext());
mPdfView.setOnPdfListener(new WJPdfView.OnPdfListener() {
@Override
public void finish() {
MainActivity.this.finish();
}
@Override
public void onCompletion() {
//观看完成
}
@Override
public void toggleScreen() {
//横竖屏切换
instance.toggleScreen();
}
@Override
public void onstart() {
//启动换横屏监听
instance.start(MainActivity.this);
}
});
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (instance.isPortrait()) {
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
if(mPdfView.getVisibility()==View.VISIBLE) {
mPdfView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));//设置显示的高度
mPdfView.requestLayout();
mPdfView.updateAdapter();
}
} else {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
if(mPdfView.getVisibility()==View.VISIBLE) {
mPdfView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
mPdfView.requestLayout();
mPdfView.updateAdapter();
}
}
}
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:configChanges="screenSize|keyboardHidden|orientation" />
-keep class com.artifex.mupdfdemo.** {*;}