2018-06-20 17:39:29 -03:00
|
|
|
package io.lbry.browser.reactmodules;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
2018-08-16 10:48:34 +01:00
|
|
|
import android.content.SharedPreferences;
|
2018-07-29 09:12:45 +01:00
|
|
|
import android.view.View;
|
2018-06-20 17:39:29 -03:00
|
|
|
import android.view.WindowManager;
|
|
|
|
|
2018-08-16 10:48:34 +01:00
|
|
|
import com.facebook.react.bridge.Promise;
|
2018-06-20 17:39:29 -03:00
|
|
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
|
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
|
|
import com.facebook.react.bridge.ReactMethod;
|
|
|
|
|
2018-08-16 10:48:34 +01:00
|
|
|
import io.lbry.browser.MainActivity;
|
|
|
|
|
2018-06-20 17:39:29 -03:00
|
|
|
public class UtilityModule extends ReactContextBaseJavaModule {
|
|
|
|
private Context context;
|
|
|
|
|
|
|
|
public UtilityModule(ReactApplicationContext reactContext) {
|
|
|
|
super(reactContext);
|
|
|
|
this.context = reactContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return "UtilityModule";
|
|
|
|
}
|
|
|
|
|
|
|
|
@ReactMethod
|
|
|
|
public void keepAwakeOn() {
|
2018-07-29 09:12:45 +01:00
|
|
|
final Activity activity = getCurrentActivity();
|
|
|
|
|
|
|
|
if (activity != null) {
|
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-06-20 17:39:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
@ReactMethod
|
|
|
|
public void keepAwakeOff() {
|
2018-07-29 09:12:45 +01:00
|
|
|
final Activity activity = getCurrentActivity();
|
|
|
|
|
|
|
|
if (activity != null) {
|
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ReactMethod
|
|
|
|
public void hideNavigationBar() {
|
2018-08-16 18:42:07 +01:00
|
|
|
final Activity activity = MainActivity.getActivity();
|
|
|
|
if (activity != null) {
|
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
View decorView = activity.getWindow().getDecorView();
|
|
|
|
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
|
|
|
|
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
|
|
|
|
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
|
|
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
|
|
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-29 09:12:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ReactMethod
|
|
|
|
public void showNavigationBar() {
|
2018-08-16 18:42:07 +01:00
|
|
|
final Activity activity = MainActivity.getActivity();
|
|
|
|
if (activity != null) {
|
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
View decorView = activity.getWindow().getDecorView();
|
|
|
|
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
|
|
|
|
View.SYSTEM_UI_FLAG_VISIBLE);
|
|
|
|
}
|
|
|
|
});
|
2018-07-29 09:12:45 +01:00
|
|
|
}
|
2018-06-20 17:39:29 -03:00
|
|
|
}
|
2018-08-16 10:48:34 +01:00
|
|
|
|
|
|
|
@ReactMethod
|
|
|
|
public void getDeviceId(final Promise promise) {
|
|
|
|
SharedPreferences sp = context.getSharedPreferences(MainActivity.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
|
|
|
String deviceId = sp.getString(MainActivity.DEVICE_ID_KEY, null);
|
|
|
|
promise.resolve(deviceId);
|
|
|
|
}
|
2018-06-20 17:39:29 -03:00
|
|
|
}
|