Skip to content

Commit

Permalink
[Android] Add systemNavigationBarDividerColor (flutter#22538)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamdikahloun committed Nov 16, 2020
1 parent e2b31dd commit 0ce1137
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Expand Up @@ -14,6 +14,7 @@
import android.view.SoundEffectConstants;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
Expand Down Expand Up @@ -268,9 +269,10 @@ private void setSystemChromeSystemUIOverlayStyle(
window.setStatusBarColor(systemChromeStyle.statusBarColor);
}
}
if (systemChromeStyle.systemNavigationBarDividerColor != null) {
// Not available until Android P.
// window.setNavigationBarDividerColor(systemNavigationBarDividerColor);
if (systemChromeStyle.systemNavigationBarDividerColor != null && Build.VERSION.SDK_INT >= 28) {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
window.setNavigationBarDividerColor(systemChromeStyle.systemNavigationBarDividerColor);
}
view.setSystemUiVisibility(flags);
currentTheme = systemChromeStyle;
Expand Down
Expand Up @@ -15,10 +15,12 @@
import android.content.Context;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.view.View;
import android.view.Window;
import io.flutter.embedding.engine.systemchannels.PlatformChannel;
import io.flutter.embedding.engine.systemchannels.PlatformChannel.ClipboardContentFormat;
import io.flutter.embedding.engine.systemchannels.PlatformChannel.SystemChromeStyle;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -110,4 +112,25 @@ public void platformPlugin_hasStrings() {
clipboardManager.setPrimaryClip(clip);
assertFalse(platformPlugin.mPlatformMessageHandler.clipboardHasStrings());
}

@Config(sdk = 29)
@Test
public void setNavigationBarDividerColor() {
View fakeDecorView = mock(View.class);
Window fakeWindow = mock(Window.class);
when(fakeWindow.getDecorView()).thenReturn(fakeDecorView);
Activity fakeActivity = mock(Activity.class);
when(fakeActivity.getWindow()).thenReturn(fakeWindow);
PlatformChannel fakePlatformChannel = mock(PlatformChannel.class);
PlatformPlugin platformPlugin = new PlatformPlugin(fakeActivity, fakePlatformChannel);
SystemChromeStyle style = new SystemChromeStyle(0XFF000000, null, 0XFFC70039, null, 0XFF006DB3);

if (Build.VERSION.SDK_INT >= 28) {
platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style);

assertEquals(0XFF006DB3, fakeActivity.getWindow().getNavigationBarDividerColor());
assertEquals(0XFFC70039, fakeActivity.getWindow().getStatusBarColor());
assertEquals(0XFF000000, fakeActivity.getWindow().getNavigationBarColor());
}
}
}

0 comments on commit 0ce1137

Please sign in to comment.