Skip to content

Commit

Permalink
support for custom color for progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
issotina committed Jun 11, 2019
1 parent 5edbc53 commit fe0454e
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 24 deletions.
Binary file modified lib/src/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<activity android:name=".uikit.CustomTabActivity"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme"
android:theme="@style/TransparentCompat"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:windowSoftInputMode="adjustResize"/>

Expand Down
51 changes: 42 additions & 9 deletions lib/src/main/java/co/opensi/kkiapay/uikit/CustomTabActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.app.Activity
import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.drawable.LayerDrawable
import android.os.Build
import android.os.Bundle
import android.os.CountDownTimer
import android.transition.Visibility
import android.util.Log
import android.view.View
import android.webkit.*
import android.widget.ProgressBar
import android.widget.Toast
import androidx.annotation.ColorInt
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import co.opensi.kkiapay.R
import co.opensi.kkiapay.uikit.Me.Companion.KKIAPAY_TRANSACTION_ID
import kotlinx.android.synthetic.main.custom_tab_activity.*
Expand All @@ -23,21 +30,20 @@ import kotlinx.android.synthetic.main.custom_tab_activity.*
* created at 01/03/2019
*/

internal class CustomTabActivity: AppCompatActivity() {
internal class CustomTabActivity: Activity() {
@SuppressLint("SetJavaScriptEnabled")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.custom_tab_activity)

loading_view.playAnimation()
web_view.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null)
web_view.setBackgroundColor(0x3EFFFFFF.toInt())

web_view.setBackgroundColor(0x00000000);
web_view.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

web_view.settings

intent?.run {
val url = getStringExtra(EXTRA_URL)
var theme = getIntExtra(EXTRA_THEME,R.color.pink )
tintIndeterminateProgress(progressbar, ContextCompat.getColor(applicationContext,theme))
web_view.run {
settings.run {
javaScriptEnabled = true
Expand All @@ -53,6 +59,11 @@ internal class CustomTabActivity: AppCompatActivity() {
return super.shouldOverrideUrlLoading(view, url)
}

override fun onLoadResource(view: WebView?, url: String?) {
return super.onLoadResource(view, url)

}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
shouldOverrideUrlLoading(request?.url?.toString() ?: "")
Expand All @@ -70,10 +81,15 @@ internal class CustomTabActivity: AppCompatActivity() {

override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
loading_view.visibility = View.GONE
loading_view.cancelAnimation()
Log.i("CustomTabActivity", "onPageFinished")
Log.e("CustomTabActivity", "onPageFinished " + url)
val timer = object: CountDownTimer(990,990) {
override fun onTick(millisUntilFinished: Long) {}

override fun onFinish() {
progressbar.visibility = View.GONE
}
}
timer.start()
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
Expand Down Expand Up @@ -109,5 +125,22 @@ internal class CustomTabActivity: AppCompatActivity() {

companion object {
internal const val EXTRA_URL = "me.kkiapay.uikit.EXTRA_URL"
internal const val EXTRA_THEME = "me.kkiapay.uikit.EXTRA_THEME"

}

fun tintIndeterminateProgress(progress: ProgressBar, @ColorInt color: Int ){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
progress.indeterminateTintList = ColorStateList.valueOf(color)
} else {
(progress.indeterminateDrawable as? LayerDrawable)?.apply {
if (numberOfLayers >= 2) {
setId(0, android.R.id.progress)
setId(1, android.R.id.secondaryProgress)
val progressDrawable = findDrawableByLayerId(android.R.id.progress).mutate()
progressDrawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP)
}
}
}
}
}
4 changes: 3 additions & 1 deletion lib/src/main/java/co/opensi/kkiapay/uikit/Kkiapay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class Me internal constructor(context: Context, private val apiKey: String, priv
* Possibility to configure the color [themeColor]
* and the shop logo [imageResource]
*/
data class SdkConfig(@RawRes private val imageResource: Int = -1, @ColorRes private val themeColor: Int = -1){
data class SdkConfig(@RawRes private val imageResource: Int = -1, @ColorRes internal val themeColor: Int = -1){
internal var imageUrl: String = ""
internal var color: String = ""

Expand Down Expand Up @@ -237,6 +237,8 @@ internal class RequestPaymentAction(private val user: User) {
Intent(activity, CustomTabActivity::class.java).apply {
putExtra(CustomTabActivity.EXTRA_URL,
"$KKIAPAY_URL/?=${user.toBase64(sdkConfig)}")
putExtra(CustomTabActivity.EXTRA_THEME,
sdkConfig.themeColor)
}, KKIAPAY_REQUEST_CODE)
}
}
Expand Down
16 changes: 7 additions & 9 deletions lib/src/main/res/layout/custom_tab_activity.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@android:color/white"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
>

<WebView android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/web.view"
android:background="@android:color/white"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"/>

<com.airbnb.lottie.LottieAnimationView
<ProgressBar
android:id="@+id/progressbar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:theme="@style/progressBarBlue"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:layout_centerInParent="true"
android:id="@+id/loading_view"
app:lottie_rawRes="@raw/load"
app:lottie_loop="true"
app:lottie_autoPlay="true" />
android:visibility="visible" />

</RelativeLayout>

4 changes: 4 additions & 0 deletions lib/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="pink">#F11C33</color>
</resources>
13 changes: 9 additions & 4 deletions lib/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<style name="TransparentCompat" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
</style>

<style name="progressBarBlue" parent="@style/Theme.AppCompat">
<item name="colorAccent">@color/pink</item>
</style>
</resources>

0 comments on commit fe0454e

Please sign in to comment.