Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(android): simplify window & activity #249

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/android/StatusBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
*/
package org.apache.cordova.statusbar;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsControllerCompat;

Expand All @@ -52,6 +52,9 @@ public class StatusBar extends CordovaPlugin {
private static final String STYLE_DEFAULT = "default";
private static final String STYLE_LIGHT_CONTENT = "lightcontent";

private AppCompatActivity activity;
private Window window;

/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
Expand All @@ -64,10 +67,12 @@ public void initialize(final CordovaInterface cordova, CordovaWebView webView) {
LOG.v(TAG, "StatusBar: initialization");
super.initialize(cordova, webView);

this.cordova.getActivity().runOnUiThread(() -> {
activity = this.cordova.getActivity();
window = activity.getWindow();

activity.runOnUiThread(() -> {
// Clear flag FLAG_FORCE_NOT_FULLSCREEN which is set initially
// by the Cordova.
Window window = cordova.getActivity().getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

// Read 'StatusBarOverlaysWebView' from config.xml, default is true.
Expand All @@ -94,8 +99,6 @@ public void initialize(final CordovaInterface cordova, CordovaWebView webView) {
@Override
public boolean execute(final String action, final CordovaArgs args, final CallbackContext callbackContext) {
LOG.v(TAG, "Executing action: " + action);
final Activity activity = this.cordova.getActivity();
final Window window = activity.getWindow();

switch (action) {
case ACTION_READY:
Expand Down Expand Up @@ -175,7 +178,6 @@ private void setStatusBarBackgroundColor(final String colorPref) {
return;
}

final Window window = cordova.getActivity().getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // SDK 19-30
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); // SDK 21
window.setStatusBarColor(color);
Expand All @@ -196,7 +198,6 @@ private void setStatusBarTransparent(final boolean isTransparent) {

private void setStatusBarStyle(final String style) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !style.isEmpty()) {
Window window = cordova.getActivity().getWindow();
View decorView = window.getDecorView();
WindowInsetsControllerCompat windowInsetsControllerCompat = WindowCompat.getInsetsController(window, decorView);

Expand Down