Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-27462
Browse files Browse the repository at this point in the history
  • Loading branch information
ssekhri committed Dec 12, 2019
2 parents e786964 + b999f27 commit 2c9508f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public class GeolocationModule extends KrollModule implements Handler.Callback,
private static final double SIMPLE_LOCATION_PASSIVE_DISTANCE = 0.0;
private static final double SIMPLE_LOCATION_PASSIVE_TIME = 0;
private static final double SIMPLE_LOCATION_NETWORK_DISTANCE = 10.0;
private static final double SIMPLE_LOCATION_NETWORK_TIME = 10000;
private static final double SIMPLE_LOCATION_NETWORK_TIME = 3000;
private static final double SIMPLE_LOCATION_GPS_DISTANCE = 3.0;
private static final double SIMPLE_LOCATION_GPS_TIME = 3000;
private static final double SIMPLE_LOCATION_NETWORK_DISTANCE_RULE = 200;
Expand All @@ -136,6 +136,7 @@ public class GeolocationModule extends KrollModule implements Handler.Callback,
//currentLocation is conditionally updated. lastLocation is unconditionally updated
//since currentLocation determines when to send out updates, and lastLocation is passive
private Location lastLocation;
private ArrayList<KrollFunction> currentPositionCallback = new ArrayList<>();

private FusedLocationProvider fusedLocationProvider;

Expand Down Expand Up @@ -200,6 +201,20 @@ public boolean handleMessage(Message message)
public void onLocationChanged(Location location)
{
lastLocation = location;

// Execute current position callbacks.
if (currentPositionCallback.size() > 0) {
ArrayList<KrollFunction> currentPositionCallbackClone =
(ArrayList<KrollFunction>) currentPositionCallback.clone();
currentPositionCallback.clear();
for (KrollFunction callback : currentPositionCallbackClone) {
callback.call(this.getKrollObject(),
new Object[] { buildLocationEvent(
lastLocation, tiLocation.locationManager.getProvider(lastLocation.getProvider())) });
}
}

// Fire 'location' event listeners.
if (shouldUseUpdate(location)) {
fireEvent(TiC.EVENT_LOCATION,
buildLocationEvent(location, tiLocation.locationManager.getProvider(location.getProvider())));
Expand All @@ -225,50 +240,42 @@ public void onProviderStateChanged(String providerName, int state)
switch (state) {
case LocationProviderProxy.STATE_DISABLED:
message += " is disabled";
Log.i(TAG, message, Log.DEBUG_MODE);
fireEvent(TiC.EVENT_LOCATION, buildLocationErrorEvent(state, message));

break;

case LocationProviderProxy.STATE_ENABLED:
message += " is enabled";
Log.d(TAG, message, Log.DEBUG_MODE);

break;

case LocationProviderProxy.STATE_OUT_OF_SERVICE:
message += " is out of service";
Log.d(TAG, message, Log.DEBUG_MODE);
fireEvent(TiC.EVENT_LOCATION, buildLocationErrorEvent(state, message));

break;

case LocationProviderProxy.STATE_UNAVAILABLE:
message += " is unavailable";
Log.d(TAG, message, Log.DEBUG_MODE);
fireEvent(TiC.EVENT_LOCATION, buildLocationErrorEvent(state, message));

break;

case LocationProviderProxy.STATE_AVAILABLE:
message += " is available";
Log.d(TAG, message, Log.DEBUG_MODE);

break;

case LocationProviderProxy.STATE_UNKNOWN:
message += " is in a unknown state [" + state + "]";
Log.d(TAG, message, Log.DEBUG_MODE);
fireEvent(TiC.EVENT_LOCATION, buildLocationErrorEvent(state, message));

break;

default:
message += " is in a unknown state [" + state + "]";
Log.d(TAG, message, Log.DEBUG_MODE);
fireEvent(TiC.EVENT_LOCATION, buildLocationErrorEvent(state, message));

break;
}
Log.d(TAG, message, Log.DEBUG_MODE);

if (state != LocationProviderProxy.STATE_ENABLED && state != LocationProviderProxy.STATE_AVAILABLE) {
fireEvent(TiC.EVENT_LOCATION, buildLocationErrorEvent(state, message));

// Execute current position callbacks.
if (currentPositionCallback.size() > 0) {
ArrayList<KrollFunction> currentPositionCallbackClone =
(ArrayList<KrollFunction>) currentPositionCallback.clone();
currentPositionCallback.clear();
for (KrollFunction callback : currentPositionCallbackClone) {
callback.call(this.getKrollObject(), new Object[] { buildLocationErrorEvent(state, message) });
}
}
}
}

Expand Down Expand Up @@ -670,6 +677,20 @@ public void getCurrentPosition(KrollFunction callback)
}
if (callback != null) {
Location latestKnownLocation = tiLocation.getLastKnownLocation();
if (latestKnownLocation == null) {
latestKnownLocation = lastLocation;
}

// TIMOB-27572: Samsung devices require a location provider to be registered
// in order to obtain last known location.
if (latestKnownLocation == null) {
if (numLocationListeners == 0) {
numLocationListeners++;
enableLocationProviders(simpleLocationProviders);
}
currentPositionCallback.add(callback);
return;
}

if (latestKnownLocation != null) {
callback.call(
Expand Down
21 changes: 18 additions & 3 deletions iphone/Classes/TiUIiOSProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,24 @@ - (void)setStatusBarBackgroundColor:(id)value
ENSURE_UI_THREAD(setStatusBarBackgroundColor, value);
ENSURE_SINGLE_ARG(value, NSString);

UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = [[TiUtils colorValue:value] _color];
if ([TiUtils isIOSVersionOrGreater:@"13.0"]) {
#if IS_SDK_IOS_13
UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
CGRect frame = keyWindow.windowScene.statusBarManager.statusBarFrame;
UIView *view = [keyWindow viewWithTag:TI_STATUSBAR_TAG];
if (!view) {
view = [[UIView alloc] initWithFrame:frame];
view.tag = TI_STATUSBAR_TAG;
[keyWindow addSubview:view];
}
view.frame = frame;
view.backgroundColor = [[TiUtils colorValue:value] _color];
#endif
} else {
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = [[TiUtils colorValue:value] _color];
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ enum {

#define TI_SEARCHBAR_HEIGHT 56

#define TI_STATUSBAR_TAG 11101

#ifdef DEBUG
#define FRAME_DEBUG(f) \
NSLog(@"FRAME -- size=%fx%f, origin=%f,%f", f.size.width, f.size.height, f.origin.x, f.origin.y);
Expand Down
20 changes: 20 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/Modules/TiUIWindowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIVi
withObject:nil
afterDelay:[[UIApplication sharedApplication] statusBarOrientationAnimationDuration]];

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
[self performSelector:@selector(updateStatusBarView)
withObject:nil
afterDelay:[[UIApplication sharedApplication] statusBarOrientationAnimationDuration]];
#endif

[super viewWillTransitionToSize:size
withTransitionCoordinator:coordinator];
[self willChangeSize];
Expand Down Expand Up @@ -1046,6 +1052,20 @@ - (void)cleanupWindowDecorations
}
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
- (void)updateStatusBarView
{
if ([TiUtils isIOSVersionOrGreater:@"13.0"]) {
UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
CGRect frame = keyWindow.windowScene.statusBarManager.statusBarFrame;
UIView *view = [keyWindow viewWithTag:TI_STATUSBAR_TAG];
if (view) {
view.frame = frame;
}
}
}
#endif

- (TiViewProxy *)safeAreaView
{
return self.safeAreaViewProxy;
Expand Down

0 comments on commit 2c9508f

Please sign in to comment.