Skip to content

Commit

Permalink
Status bar color fix for pre-lollipop versions oppia#1042
Browse files Browse the repository at this point in the history
  • Loading branch information
prathameshbhalekar committed May 18, 2020
1 parent 344d228 commit 85a8c38
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions utility/src/main/java/org/oppia/util/statusbar/StatusBarColor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,33 @@ class StatusBarColor {
* @param activity the reference of the activity from which this method is called.
* @param statusBarLight passed Boolean true if the status bar theme is light, else passed Boolean false
*/
fun statusBarColorUpdate(colorId: Int, activity: AppCompatActivity, statusBar:View?, statusBarLight: Boolean) {
fun statusBarColorUpdate(
colorId: Int,
activity: AppCompatActivity,
statusBar: View?,
statusBarLight: Boolean
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (statusBarLight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
}
activity.window.statusBarColor = ContextCompat.getColor(activity, colorId)
}
else{
} else {
activity.window.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
val statusBarHeight=getStatusBarHeight(activity.resources)
statusBar!!.layoutParams.height=statusBarHeight
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
)
val statusBarHeight = getStatusBarHeight(activity.resources)
statusBar!!.layoutParams.height = statusBarHeight
statusBar.setBackgroundColor(colorId)
}
}
private fun getStatusBarHeight(resources: Resources):Int{
var statusBarHeight=0
val id=resources.getIdentifier("status_bar_height","dimen","android")
if(id>0){
statusBarHeight=resources.getDimensionPixelSize(id)

private fun getStatusBarHeight(resources: Resources): Int {
var statusBarHeight = 0
val id = resources.getIdentifier("status_bar_height", "dimen", "android")
if (id > 0) {
statusBarHeight = resources.getDimensionPixelSize(id)
}
return statusBarHeight
}
Expand Down

0 comments on commit 85a8c38

Please sign in to comment.