gt: 		int statusBarColor = parseColor(headerBg);
context: package de.tutao.tutanota;
  
  import static de.tutao.tutanota.Utils.parseColor;
  
  import android.annotation.SuppressLint;
  import android.app.job.JobInfo;
  import android.app.job.JobScheduler;
  import android.content.ActivityNotFoundException;
  import android.content.ClipData;
  import android.content.ClipboardManager;
  import android.content.ComponentName;
  import android.content.Context;
  import android.content.Intent;
  import android.content.SharedPreferences;
  import android.content.pm.PackageManager;
  import android.graphics.Color;
  import android.graphics.drawable.ColorDrawable;
  import android.net.MailTo;
  import android.net.Uri;
  import android.os.Bundle;
  import android.os.PowerManager;
  import android.preference.PreferenceManager;
  import android.provider.Settings;
  import android.util.Log;
  import android.view.ContextMenu;
  import android.view.View;
  import android.webkit.CookieManager;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.widget.Toast;
  
  import androidx.annotation.ColorInt;
  import androidx.annotation.MainThread;
  import androidx.annotation.NonNull;
  import androidx.annotation.RequiresPermission;
  import androidx.core.content.ContextCompat;
  import androidx.fragment.app.FragmentActivity;
  
  import org.jdeferred.Deferred;
  import org.jdeferred.Promise;
  import org.jdeferred.impl.DeferredObject;
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.io.UnsupportedEncodingException;
  import java.net.URLEncoder;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Objects;
  import java.util.concurrent.ConcurrentHashMap;
  import java.util.concurrent.TimeUnit;
  
  import de.tutao.tutanota.alarms.AlarmNotificationsManager;
  import de.tutao.tutanota.alarms.SystemAlarmFacade;
  import de.tutao.tutanota.data.AppDatabase;
  import de.tutao.tutanota.push.LocalNotificationsFacade;
  import de.tutao.tutanota.push.PushNotificationService;
  import de.tutao.tutanota.push.SseStorage;
  
  public class MainActivity extends FragmentActivity {
  	public static final String OPEN_USER_MAILBOX_ACTION = "de.tutao.tutanota.OPEN_USER_MAILBOX_ACTION";
  	public static final String OPEN_CALENDAR_ACTION = "de.tutao.tutanota.OPEN_CALENDAR_ACTION";
  	public static final String OPEN_USER_MAILBOX_MAILADDRESS_KEY = "mailAddress";
  	public static final String OPEN_USER_MAILBOX_USERID_KEY = "userId";
  	public static final String IS_SUMMARY_EXTRA = "isSummary";
  	private static final String ASKED_BATTERY_OPTIMIZTAIONS_PREF = "askedBatteryOptimizations";
  	private static final String TAG = "MainActivity";
  
  	private static int requestId = 0;
  	private final Map<Integer, Deferred<ActivityResult, Exception, Void>> requests = new ConcurrentHashMap<>();
  
  	private WebView webView;
  	public SseStorage sseStorage;
  	public Native nativeImpl;
  	boolean firstLoaded = false;
  
  	@SuppressLint({"SetJavaScriptEnabled", "StaticFieldLeak"})
  	@Override
  	protected void onCreate(Bundle savedInstanceState) {
  		Log.d(TAG, "App started");
  		AndroidKeyStoreFacade keyStoreFacade = AndroidKeyStoreFacadeFactory.create(this);
  		sseStorage = new SseStorage(AppDatabase.getDatabase(this, /*allowMainThreadAccess*/false),
  				keyStoreFacade);
  		AlarmNotificationsManager alarmNotificationsManager = new AlarmNotificationsManager(sseStorage,
  				new Crypto(this), new SystemAlarmFacade(this), new LocalNotificationsFacade(this));
  		nativeImpl = new Native(this, sseStorage, alarmNotificationsManager);
  
  		doApplyTheme(this.nativeImpl.themeManager.getCurrentThemeWithFallback());
  
  		super.onCreate(savedInstanceState);
  
  		this.setupPushNotifications();
  
  		webView = new WebView(this);
  		webView.setBackgroundColor(Color.TRANSPARENT);
  		setContentView(webView);
  		if (BuildConfig.DEBUG) {
  			WebView.setWebContentsDebuggingEnabled(true);
  		}
  		WebSettings settings = webView.getSettings();
  
  		settings.setJavaScriptEnabled(true);
  		settings.setDomStorageEnabled(true);
  		settings.setJavaScriptCanOpenWindowsAutomatically(false);
  		settings.setAllowUniversalAccessFromFileURLs(true);
  		// Reject cookies by external content
  		CookieManager.getInstance().setAcceptCookie(false);
  		CookieManager.getInstance().removeAllCookies(null);
  
  		this.nativeImpl.getWebAppInitialized().then(result -> {
  			if (!firstLoaded) {
  				handleIntent(getIntent());
  			}
  			firstLoaded = true;
  
  			webView.post(() -> { // use webView.post to switch to main thread again to be able to observe sseStorage
  				sseStorage.observeUsers().observe(this, (userInfos) -> {
  					if (userInfos.isEmpty()) {
  						Log.d(TAG, "invalidateAlarms");
  						nativeImpl.sendRequest(JsRequest.invalidateAlarms, new Object[]{});
  					}
  				});
  			});
  		});
  
  		this.webView.setWebViewClient(new WebViewClient() {
  			@Override
  			public boolean shouldOverrideUrlLoading(WebView view, String url) {
  				Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
  				try {
  					startActivity(intent);
  				} catch (ActivityNotFoundException e) {
  					Toast.makeText(MainActivity.this, "Could not open link: " + url, Toast.LENGTH_SHORT)
  							.show();
  				}
  				return true;
  			}
  
  		});
  
  		// Handle long click on links in the WebView
  		this.registerForContextMenu(this.webView);
  
  		Map<String, String> queryParameters = new HashMap<>();
  		// If opened from notifications, tell Web app to not login automatically, we will pass
  		// mailbox later when loaded (in handleIntent())
  		if (getIntent() != null
  				&& (OPEN_USER_MAILBOX_ACTION.equals(getIntent().getAction()) || OPEN_CALENDAR_ACTION.equals(getIntent().getAction()))) {
  			queryParameters.put("noAutoLogin", "true");
  		}
  
  		startWebApp(queryParameters);
  	}
  
  	@Override
  	protected void onStart() {
  		super.onStart();
  		Log.d(TAG, "onStart");
  		nativeImpl.getWebAppInitialized().then(__ -> {
  			nativeImpl.sendRequest(JsRequest.visibilityChange, new Object[]{true});
  		});
  	}
  
  	@Override
  	protected void onStop() {
  		Log.d(TAG, "onStop");
  		nativeImpl.getWebAppInitialized().then(__ -> {
  			nativeImpl.sendRequest(JsRequest.visibilityChange, new Object[]{false});
  		});
  		super.onStop();
  	}
  
  	@MainThread
  	private void startWebApp(Map<String, String> parameters) {
  		webView.loadUrl(getInitialUrl(parameters));
  		nativeImpl.setup();
  	}
  
  	@Override
  	protected void onNewIntent(Intent intent) {
  		super.onNewIntent(intent);
  		handleIntent(intent);
  	}
  
  	private void handleIntent(Intent intent) {
  
  		// When we redirect to the app from outside, for example after doing payment verification,
  		// we don't want to do any kind of intent handling
  		Uri data = intent.getData();
  		if (data != null && data.toString().startsWith("tutanota://")) {
  			return;
  		}
  
  		if (intent.getAction() != null) {
  			switch (intent.getAction()) {
  				// See descriptions of actions in AndroidManifest.xml
  				case Intent.ACTION_SEND:
  				case Intent.ACTION_SEND_MULTIPLE:
  				case Intent.ACTION_SENDTO:
  				case Intent.ACTION_VIEW:
  					share(intent);
  					break;
  				case MainActivity.OPEN_USER_MAILBOX_ACTION:
  					openMailbox(intent);
  					break;
  				case MainActivity.OPEN_CALENDAR_ACTION:
  					openCalendar(intent);
  					break;
  			}
  		}
  	}
  
  
  	@Override
  	protected void onSaveInstanceState(@NonNull Bundle outState) {
  		super.onSaveInstanceState(outState);
  		webView.saveState(outState);
  	}
  
  	public void applyTheme() {
  		Map<String, String> theme = nativeImpl.themeManager.getCurrentThemeWithFallback();
  		runOnUiThread(() -> doApplyTheme(theme));
  	}
  
  	private void doApplyTheme(@NonNull Map<String, String> theme) {
  		Log.d(TAG, "changeTheme: " + theme.get("themeId"));
  
  		@ColorInt
  		int backgroundColor = parseColor(Objects.requireNonNull(theme.get("content_bg")));
  		getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor));
  		View decorView = getWindow().getDecorView();
  
  		String headerBg = Objects.requireNonNull(theme.get("header_bg"));
  		@ColorInt
  