Skip to content

Commit

Permalink
Methods for get, set & update the flags implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
nklhtv committed Nov 17, 2016
1 parent 5884f97 commit d840c02
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions android/src/main/java/com/nh/system/ui/flags/SystemUiFlags.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.nh.system.ui.flags;

import android.app.Activity;
import android.view.View;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.MapBuilder;

import java.util.Map;
Expand Down Expand Up @@ -33,4 +37,46 @@ public Map<String, Object> getConstants() {

return constants;
}

@ReactMethod
public void getCurrentSystemUiFlags(final Callback cb) {
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
int currentSystemUiFlags = currentActivity.getWindow().getDecorView().getSystemUiVisibility();
cb.invoke(currentSystemUiFlags);
}
}
});
}

@ReactMethod
public void setSystemUiFlags(final int systemUiFlags) {
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
currentActivity.getWindow().getDecorView().setSystemUiVisibility(systemUiFlags);
}
}
});
}

@ReactMethod
public void updateSystemUiFlags(final int systemUiFlags) {
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
int currentSystemUiFlags = currentActivity.getWindow().getDecorView().getSystemUiVisibility();
int newSystemUiFlags = currentSystemUiFlags | systemUiFlags;
currentActivity.getWindow().getDecorView().setSystemUiVisibility(newSystemUiFlags);
}
}
});
}
}

0 comments on commit d840c02

Please sign in to comment.