Skip to content

Commit

Permalink
Merge pull request #13 from KaungMyat-Min/feature/uiCustomize
Browse files Browse the repository at this point in the history
  • Loading branch information
afreakyelf authored Feb 2, 2021
2 parents fb1bdbf + bcd0c7a commit 603c4d5
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 24 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ open_pdf.setOnClickListener {

That's pretty much it and you're all wrapped up.

### Ui Customizations
You need to add the custom theme to styles.xml/themes.xml file and override the required attribute values.
Parent theme can be either **Theme.PdfView.Light** or **Theme.PdfView.Dark** or the one with no actionbar from the application.
Note: If parent is not one of the themes from this library, all of the pdfView attributes should be added to that theme.

<style name="Theme.PdfView.SelectedTheme" parent="@style/Theme.PdfView.Light">
<item name="pdfView_backIcon">@drawable/ic_arrow_back</item>
...
</style>

#### Supported attributes

| Attribute Name | Type | Expected changes |
|--|--|--|
|pdfView_backIcon|drawable|Navigation icon|
|pdfView_downloadIcon|drawable|Download icon|
|pdfView_downloadIconTint|color|Download icon tint|
|pdfView_actionBarTint|color|Actionbar background color|
|pdfView_titleTextStyle|style|Actionbar title text appearance|
|pdfView_progressBar|style|Progress bar style|

## Donations
If this project help you reduce time to develop, you can give me a cup of coffee :)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/rajat/pdfviewer/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MainActivity : AppCompatActivity() {
startActivity(
PdfViewerActivity.launchPdfFromUrl(
this, download_file_url,
"Title", "dir"
"Title", "dir",true
)
)
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_loading.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:viewportHeight="508.48"
android:viewportWidth="508.48" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@color/colorPrimary" android:pathData="M114.928,174.046l-28.8,28.8C114.48,109.944 212.776,57.617 305.677,85.969c35.405,10.805 66.498,32.506 88.851,62.012l25.488,-19.312C350.79,37.151 220.481,19.078 128.962,88.304c-37.933,28.692 -64.873,69.53 -76.322,115.694l-30.016,-29.952L0,196.654l68.8,68.8l68.8,-68.8L114.928,174.046z"/>
<path android:fillColor="@color/colorPrimaryDark" android:pathData="M439.68,242.702l-68.8,68.8l22.624,22.624l29.136,-29.12c-28.103,93.051 -126.317,145.702 -219.368,117.599c-37.011,-11.178 -69.311,-34.231 -91.912,-65.599l-25.968,18.688c32.093,44.868 80.787,75.048 135.248,83.824c11.162,1.812 22.452,2.727 33.76,2.736c95.518,-0.045 178.669,-65.284 201.44,-158.048l29.952,29.92l22.688,-22.624L439.68,242.702zM438.88,288.798l0.816,-0.816l1.184,1.2L438.88,288.798z"/>
</vector>
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/progress_circle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_loading"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="900" />
7 changes: 5 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
<Button
android:id="@+id/open_pdf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:text="Open pdf"
android:textAllCaps="false"
android:backgroundTint="@color/colorPrimary"
android:textColor="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,27 @@
<item name="colorAccent">@color/colorAccent</item>
</style>


<style name="Theme.PdfView.SelectedTheme" parent="@style/Theme.PdfView.Light">
<item name="pdfView_actionBarTint">@color/colorPrimary</item>
<item name="pdfView_downloadIconTint">#ffffff</item>
<item name="pdfView_titleTextStyle">@style/actionBarTitleAppearance</item>
<item name="pdfView_progressBar">@style/customProgressBar</item>
</style>

<style name="actionBarTitleAppearance" parent="TextAppearance.AppCompat.Title">
<item name="android:gravity">center</item>
<item name="android:layout_gravity">center</item>
<item name="android:textColor">#ffffff</item>
</style>

<style name="customProgressBar" parent="Widget.AppCompat.ProgressBar">
<item name="android:layout_gravity">center</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:indeterminateDrawable">@drawable/progress_circle</item>
<item name="android:interpolator">@android:interpolator/accelerate_decelerate</item>
<item name="android:visibility">gone</item>
</style>

</resources>
1 change: 1 addition & 0 deletions pdfViewer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta8"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.6'
implementation 'com.google.android.material:material:1.2.1'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
Expand Down
2 changes: 1 addition & 1 deletion pdfViewer/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<application android:requestLegacyExternalStorage="true">
<activity
android:name=".PdfViewerActivity"
android:theme="@style/Theme.AppCompat.NoActionBar" />
android:theme="@style/Theme.PdfView.SelectedTheme" />
</application>

</manifest>
16 changes: 13 additions & 3 deletions pdfViewer/src/main/java/com/rajat/pdfviewer/PdfViewerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import kotlinx.android.synthetic.main.activity_pdf_viewer.*
import kotlinx.android.synthetic.main.pdf_view_tool_bar.*
import java.io.File

/**
Expand Down Expand Up @@ -171,9 +172,18 @@ class PdfViewerActivity : AppCompatActivity() {

private fun setUpToolbar(toolbarTitle: String) {
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
supportActionBar?.title = toolbarTitle
supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
setDisplayShowHomeEnabled(true)
if(tvAppBarTitle!=null) {
tvAppBarTitle?.text = toolbarTitle
setDisplayShowTitleEnabled(false)
}else{
setDisplayShowTitleEnabled(true)
title = toolbarTitle
}
}

}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
Expand Down
9 changes: 9 additions & 0 deletions pdfViewer/src/main/res/drawable/ic_arrow_back.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#ffffff"
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />
</vector>
9 changes: 9 additions & 0 deletions pdfViewer/src/main/res/drawable/ic_arrow_back_alt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#000000"
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />
</vector>
23 changes: 9 additions & 14 deletions pdfViewer/src/main/res/layout/activity_pdf_viewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,24 @@
android:orientation="vertical"
tools:context=".PdfViewerActivity">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize" />
<include layout="@layout/pdf_view_tool_bar" />

<FrameLayout
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.rajat.pdfviewer.PdfRendererView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:pdfView_divider="@drawable/divider"
app:pdfView_engine="internal"
app:pdfView_showDivider="false" />
<com.rajat.pdfviewer.PdfRendererView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:pdfView_divider="@drawable/divider"
app:pdfView_engine="internal"
app:pdfView_showDivider="false" />

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
style="?pdfView_progressBar"
android:visibility="gone" />

</FrameLayout>
Expand Down
26 changes: 26 additions & 0 deletions pdfViewer/src/main/res/layout/pdf_view_tool_bar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?pdfView_actionBarTint"
app:navigationIcon="?pdfView_backIcon">

<TextView
android:id="@+id/tvAppBarTitle"
style="?pdfView_titleTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:longClickable="false"
android:text="@string/pdfView_appName" />

</androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout>
4 changes: 2 additions & 2 deletions pdfViewer/src/main/res/menu/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

<item
android:id="@+id/download"
android:icon="@android:drawable/stat_sys_download"
android:iconTint="#888A87"
android:icon="?pdfView_downloadIcon"
android:title="Download"
app:iconTint="?attr/pdfView_downloadIconTint"
app:showAsAction="always" />
</menu>
13 changes: 13 additions & 0 deletions pdfViewer/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,17 @@
<attr name="pdfView_showDivider" format="boolean" />
<attr name="pdfView_divider" format="reference" />
</declare-styleable>

<!-- icons -->
<attr name="pdfView_backIcon" format="reference" />
<attr name="pdfView_downloadIcon" format="reference" />

<!-- icon color -->
<attr name="pdfView_downloadIconTint" format="reference|color" />
<attr name="pdfView_actionBarTint" format="reference|color" />

<!-- Text Appearance Customizations - Common -->
<attr name="pdfView_titleTextStyle" format="reference" />

<attr name="pdfView_progressBar" format="reference"/>
</resources>
1 change: 1 addition & 0 deletions pdfViewer/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="pdfView_appName">Pdf View</string>
<string name="content_des">PDF PAGE</string>
</resources>
40 changes: 40 additions & 0 deletions pdfViewer/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.PdfView.SelectedTheme" parent="@style/Theme.PdfView.Light" />

<style name="Theme.PdfView.Light" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="pdfView_backIcon">@drawable/ic_arrow_back</item>
<item name="pdfView_downloadIcon">@android:drawable/stat_sys_download</item>
<item name="pdfView_downloadIconTint">#888A87</item>
<item name="pdfView_actionBarTint">#000000</item>
<item name="pdfView_titleTextStyle">@style/pdfView_titleTextAppearance</item>
<item name="pdfView_progressBar">@style/pdfView_progressBarStyle</item>
</style>

<style name="Theme.PdfView.Dark" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="pdfView_backIcon">@drawable/ic_arrow_back_alt</item>
<item name="pdfView_downloadIcon">@android:drawable/stat_sys_download</item>
<item name="pdfView_downloadIconTint">#2f2f2f</item>
<item name="pdfView_actionBarTint">#ffffff</item>
<item name="pdfView_titleTextStyle">@style/pdfView_titleTextAppearanceDark</item>
<item name="pdfView_progressBar">@style/pdfView_progressBarStyle</item>
</style>

<style name="pdfView_titleTextAppearance" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:gravity">center_vertical</item>
<item name="android:textColor">#ffffff</item>
</style>

<style name="pdfView_titleTextAppearanceDark" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:gravity">center_vertical</item>
<item name="android:textColor">#2f2f2f</item>
</style>

<style name="pdfView_progressBarStyle" parent="Widget.AppCompat.ProgressBar">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center</item>
</style>

</resources>

0 comments on commit 603c4d5

Please sign in to comment.