This commit is contained in:
Lu Wang 2017-10-25 11:00:51 -07:00
commit e41c06334e
5 changed files with 128 additions and 19 deletions

View File

@ -15,7 +15,7 @@ environment:
nodejs_version: "4" nodejs_version: "4"
matrix: matrix:
- PLATFORM: windows-10-store - PLATFORM: windows-10-store
JUST_BUILD: --justBuild
install: install:
- npm cache clean -f - npm cache clean -f
- node --version - node --version
@ -25,4 +25,4 @@ install:
build: off build: off
test_script: test_script:
- cordova-paramedic --config pr\%PLATFORM% --plugin . --justBuild - cordova-paramedic --config pr\%PLATFORM% --plugin . %JUST_BUILD%

View File

@ -8,6 +8,22 @@ env:
- TRAVIS_NODE_VERSION="4.2" - TRAVIS_NODE_VERSION="4.2"
matrix: matrix:
include: include:
- env: PLATFORM=browser-chrome
os: linux
language: node_js
node_js: '4.2'
- env: PLATFORM=browser-firefox
os: linux
language: node_js
node_js: '4.2'
- env: PLATFORM=browser-safari
os: linux
language: node_js
node_js: '4.2'
- env: PLATFORM=browser-edge
os: linux
language: node_js
node_js: '4.2'
- env: PLATFORM=ios-9.3 - env: PLATFORM=ios-9.3
os: osx os: osx
osx_image: xcode7.3 osx_image: xcode7.3
@ -47,14 +63,13 @@ matrix:
components: components:
- tools - tools
before_install: before_install:
- npm cache clean -f
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm - rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm
&& git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm
install $TRAVIS_NODE_VERSION install $TRAVIS_NODE_VERSION
- node --version - node --version
- if [[ "$PLATFORM" =~ android ]]; then gradle --version; fi - if [[ "$PLATFORM" =~ android ]]; then gradle --version; fi
- if [[ "$PLATFORM" =~ ios ]]; then npm install -g ios-deploy; fi - if [[ "$PLATFORM" =~ ios ]]; then npm install -g ios-deploy; fi
- if [[ "$PLATFORM" =~ android ]]; then echo y | android update sdk -u --filter android-22,android-23,android-24,android-25; - if [[ "$PLATFORM" =~ android ]]; then echo y | android update sdk -u --filter android-22,android-23,android-24,android-25,android-26;
fi fi
- git clone https://github.com/apache/cordova-paramedic /tmp/paramedic && pushd /tmp/paramedic - git clone https://github.com/apache/cordova-paramedic /tmp/paramedic && pushd /tmp/paramedic
&& npm install && popd && npm install && popd

View File

@ -32,7 +32,7 @@ StatusBar
> The `StatusBar` object provides some functions to customize the iOS and Android StatusBar. > The `StatusBar` object provides some functions to customize the iOS and Android StatusBar.
:warning: Report issues on the [Apache Cordova issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20Statusbar%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC) :warning: Report issues on the [Apache Cordova issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20(Open%2C%20%22In%20Progress%22%2C%20Reopened)%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22cordova-plugin-statusbar%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC)
## Installation ## Installation
@ -167,6 +167,7 @@ Supported Platforms
------------------- -------------------
- iOS - iOS
- Android 6+
- Windows Phone 7 - Windows Phone 7
- Windows Phone 8 - Windows Phone 8
- Windows Phone 8.1 - Windows Phone 8.1
@ -183,6 +184,7 @@ Supported Platforms
------------------- -------------------
- iOS - iOS
- Android 6+
- Windows Phone 7 - Windows Phone 7
- Windows Phone 8 - Windows Phone 8
- Windows Phone 8.1 - Windows Phone 8.1
@ -199,6 +201,7 @@ Supported Platforms
------------------- -------------------
- iOS - iOS
- Android 6+
- Windows Phone 7 - Windows Phone 7
- Windows Phone 8 - Windows Phone 8
- Windows Phone 8.1 - Windows Phone 8.1
@ -215,6 +218,7 @@ Supported Platforms
------------------- -------------------
- iOS - iOS
- Android 6+
- Windows Phone 7 - Windows Phone 7
- Windows Phone 8 - Windows Phone 8
- Windows Phone 8.1 - Windows Phone 8.1

View File

@ -34,6 +34,7 @@ import org.apache.cordova.CordovaWebView;
import org.apache.cordova.LOG; import org.apache.cordova.LOG;
import org.apache.cordova.PluginResult; import org.apache.cordova.PluginResult;
import org.json.JSONException; import org.json.JSONException;
import java.util.Arrays;
public class StatusBar extends CordovaPlugin { public class StatusBar extends CordovaPlugin {
private static final String TAG = "StatusBar"; private static final String TAG = "StatusBar";
@ -60,6 +61,9 @@ public class StatusBar extends CordovaPlugin {
// Read 'StatusBarBackgroundColor' from config.xml, default is #000000. // Read 'StatusBarBackgroundColor' from config.xml, default is #000000.
setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000")); setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000"));
// Read 'StatusBarStyle' from config.xml, default is 'lightcontent'.
setStatusBarStyle(preferences.getString("StatusBarStyle", "lightcontent"));
} }
}); });
} }
@ -159,6 +163,46 @@ public class StatusBar extends CordovaPlugin {
else return args.getBoolean(0) == false; else return args.getBoolean(0) == false;
} }
if ("styleDefault".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setStatusBarStyle("default");
}
});
return true;
}
if ("styleLightContent".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setStatusBarStyle("lightcontent");
}
});
return true;
}
if ("styleBlackTranslucent".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setStatusBarStyle("blacktranslucent");
}
});
return true;
}
if ("styleBlackOpaque".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setStatusBarStyle("blackopaque");
}
});
return true;
}
return false; return false;
} }
@ -198,4 +242,35 @@ public class StatusBar extends CordovaPlugin {
} }
} }
} }
private void setStatusBarStyle(final String style) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (style != null && !style.isEmpty()) {
View decorView = cordova.getActivity().getWindow().getDecorView();
int uiOptions = decorView.getSystemUiVisibility();
String[] darkContentStyles = {
"default",
};
String[] lightContentStyles = {
"lightcontent",
"blacktranslucent",
"blackopaque",
};
if (Arrays.asList(darkContentStyles).contains(style.toLowerCase())) {
decorView.setSystemUiVisibility(uiOptions | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
return;
}
if (Arrays.asList(lightContentStyles).contains(style.toLowerCase())) {
decorView.setSystemUiVisibility(uiOptions & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
return;
}
LOG.e(TAG, "Invalid style, must be either 'default', 'lightcontent' or the deprecated 'blacktranslucent' and 'blackopaque'");
}
}
}
} }

View File

@ -100,6 +100,7 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
//add a small delay for iOS 7 ( 0.1 seconds ) //add a small delay for iOS 7 ( 0.1 seconds )
__weak CDVStatusBar* weakSelf = self; __weak CDVStatusBar* weakSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self resizeStatusBarBackgroundView];
[weakSelf resizeWebView]; [weakSelf resizeWebView];
}); });
} }
@ -437,11 +438,7 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
// there is a possibility that when the statusbar was hidden, it was in a different orientation // there is a possibility that when the statusbar was hidden, it was in a different orientation
// from the current one. Therefore we need to expand the statusBarBackgroundView as well to the // from the current one. Therefore we need to expand the statusBarBackgroundView as well to the
// statusBar's current size // statusBar's current size
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; [self resizeStatusBarBackgroundView];
statusBarFrame = [self invertFrameIfNeeded:statusBarFrame];
CGRect sbBgFrame = _statusBarBackgroundView.frame;
sbBgFrame.size = statusBarFrame.size;
_statusBarBackgroundView.frame = sbBgFrame;
[self.webView.superview addSubview:_statusBarBackgroundView]; [self.webView.superview addSubview:_statusBarBackgroundView];
} }
@ -452,9 +449,18 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
} }
} }
-(void)resizeStatusBarBackgroundView {
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
statusBarFrame = [self invertFrameIfNeeded:statusBarFrame];
CGRect sbBgFrame = _statusBarBackgroundView.frame;
sbBgFrame.size = statusBarFrame.size;
_statusBarBackgroundView.frame = sbBgFrame;
}
-(void)resizeWebView -(void)resizeWebView
{ {
BOOL isIOS7 = (IsAtLeastiOSVersion(@"7.0")); BOOL isIOS7 = (IsAtLeastiOSVersion(@"7.0"));
BOOL isIOS11 = (IsAtLeastiOSVersion(@"11.0"));
if (isIOS7) { if (isIOS7) {
CGRect bounds = [self.viewController.view.window bounds]; CGRect bounds = [self.viewController.view.window bounds];
@ -473,13 +479,22 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
CGFloat height = statusBarFrame.size.height; CGFloat height = statusBarFrame.size.height;
if (!self.statusBarOverlaysWebView) { if (!self.statusBarOverlaysWebView) {
if (_statusBarVisible) { frame.origin.y = height;
// CB-10158 If a full screen video is playing the status bar height will be 0, set it to 20 if _statusBarVisible
frame.origin.y = height > 0 ? height: 20;
}
} else { } else {
// Even if overlay is used, we want to handle in-call/recording/hotspot larger status bar
frame.origin.y = height >= 20 ? height - 20 : 0; frame.origin.y = height >= 20 ? height - 20 : 0;
if (isIOS11) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
if (@available(iOS 11.0, *)) {
float safeAreaTop = self.webView.safeAreaInsets.top;
if (height >= safeAreaTop && safeAreaTop >0) {
// Sometimes when in-call/recording/hotspot larger status bar is present, the safeAreaTop is 40 but we want frame.origin.y to be 20
frame.origin.y = safeAreaTop == 40 ? 20 : height - safeAreaTop;
} else {
frame.origin.y = 0;
}
}
#endif
}
} }
frame.size.height -= frame.origin.y; frame.size.height -= frame.origin.y;
self.webView.frame = frame; self.webView.frame = frame;