Skip to content

Commit

Permalink
Merge pull request #1 from Getdriven/plugin-upgrade
Browse files Browse the repository at this point in the history
Plugin upgrade to v2 embedding
  • Loading branch information
Sameerkash authored Oct 14, 2021
2 parents 104e8b9 + b68cdb4 commit e3e836b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 35 deletions.
8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ group 'com.sameer.flutterstatusbarcolor.flutterstatusbarcolor'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.21'
ext.kotlin_version = '1.5.30'
repositories {
mavenCentral()
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

rootProject.allprojects {
repositories {
mavenCentral()
google()
jcenter()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,47 @@
package com.sameer.flutterstatusbarcolor.flutterstatusbarcolor

import android.os.Build
import android.animation.ValueAnimator
import android.app.Activity
import android.os.Build
import android.view.View
import android.animation.ValueAnimator
import androidx.annotation.NonNull
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.PluginRegistry.Registrar

class FlutterStatusbarcolorPlugin private constructor(private val activity: Activity?) : MethodCallHandler {
companion object {
@JvmStatic
fun registerWith(registrar: Registrar): Unit {
val channel = MethodChannel(registrar.messenger(), "plugins.sameer.com/statusbar")
channel.setMethodCallHandler(FlutterStatusbarcolorPlugin(registrar.activity()))
}

class FlutterStatusbarcolorPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {

/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private lateinit var channel: MethodChannel

private var activity: Activity? = null

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "plugins.sameer.com/statusbar")
channel.setMethodCallHandler(this)
}

override fun onMethodCall(call: MethodCall, result: Result): Unit {
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}


override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if (activity == null) return result.success(null)

when (call.method) {
"getstatusbarcolor" -> {
var statusBarColor: Int = 0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
statusBarColor = activity.window.statusBarColor
statusBarColor = activity!!.window.statusBarColor
}
result.success(statusBarColor)
}
Expand All @@ -35,12 +50,12 @@ class FlutterStatusbarcolorPlugin private constructor(private val activity: Acti
val animate: Boolean = call.argument("animate")!!
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (animate) {
val colorAnim = ValueAnimator.ofArgb(activity.window.statusBarColor, statusBarColor)
colorAnim.addUpdateListener { anim -> activity.window.statusBarColor = anim.animatedValue as Int }
colorAnim.setDuration(300)
val colorAnim = ValueAnimator.ofArgb(activity!!.window.statusBarColor, statusBarColor)
colorAnim.addUpdateListener { anim -> activity!!.window.statusBarColor = anim.animatedValue as Int }
colorAnim.duration = 300
colorAnim.start()
} else {
activity.window.statusBarColor = statusBarColor
activity!!.window.statusBarColor = statusBarColor
}
}
result.success(null)
Expand All @@ -49,17 +64,17 @@ class FlutterStatusbarcolorPlugin private constructor(private val activity: Acti
val usewhiteforeground: Boolean = call.argument("whiteForeground")!!
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (usewhiteforeground) {
activity.window.decorView.systemUiVisibility = activity.window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
activity!!.window.decorView.systemUiVisibility = activity!!.window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
} else {
activity.window.decorView.systemUiVisibility = activity.window.decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
activity!!.window.decorView.systemUiVisibility = activity!!.window.decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
}
}
result.success(null)
}
"getnavigationbarcolor" -> {
var navigationBarColor: Int = 0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
navigationBarColor = activity.window.navigationBarColor
navigationBarColor = activity!!.window.navigationBarColor
}
result.success(navigationBarColor)
}
Expand All @@ -68,12 +83,12 @@ class FlutterStatusbarcolorPlugin private constructor(private val activity: Acti
val animate: Boolean = call.argument("animate")!!
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (animate) {
val colorAnim = ValueAnimator.ofArgb(activity.window.navigationBarColor, navigationBarColor)
colorAnim.addUpdateListener { anim -> activity.window.navigationBarColor = anim.animatedValue as Int }
val colorAnim = ValueAnimator.ofArgb(activity!!.window.navigationBarColor, navigationBarColor)
colorAnim.addUpdateListener { anim -> activity!!.window.navigationBarColor = anim.animatedValue as Int }
colorAnim.setDuration(300)
colorAnim.start()
} else {
activity.window.navigationBarColor = navigationBarColor
activity!!.window.navigationBarColor = navigationBarColor
}
}
result.success(null)
Expand All @@ -82,14 +97,30 @@ class FlutterStatusbarcolorPlugin private constructor(private val activity: Acti
val usewhiteforeground: Boolean = call.argument("whiteForeground")!!
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (usewhiteforeground) {
activity.window.decorView.systemUiVisibility = activity.window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv()
activity!!.window.decorView.systemUiVisibility = activity!!.window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv()
} else {
activity.window.decorView.systemUiVisibility = activity.window.decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
activity!!.window.decorView.systemUiVisibility = activity!!.window.decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
}
}
result.success(null)
}
else -> result.notImplemented()
}
}

override fun onAttachedToActivity(binding: ActivityPluginBinding) {
this.activity = binding.activity
}

override fun onDetachedFromActivityForConfigChanges() {
this.activity = null
}

override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
this.activity = binding.activity
}

override fun onDetachedFromActivity() {
this.activity = null
}
}
8 changes: 4 additions & 4 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.5.30'
repositories {
mavenCentral()
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
mavenCentral()
google()
jcenter()
}
}

Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_statusbarcolor_ns
description: A package can help you to change your flutter app's statusbar's color or navigationbar's color programmatically.
version: 0.3.0-nullsafety
version: 0.4.0-nullsafety
homepage: https://github.com/Sameerkash/flutter_statusbarcolor

dependencies:
Expand Down

0 comments on commit e3e836b

Please sign in to comment.