package tech.recreational.kde;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.view.View;
import android.view.Window;

import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.FragmentManager;

import com.google.androidgamesdk.GameActivity;

public class KDEActivity extends GameActivity {
    static {
        System.loadLibrary("kde");
    }

    static Window window;

    public void openLink(String url){
        try {
            Uri uri = Uri.parse(url);
            View view = window.getDecorView().getRootView();
            Context context = view.getContext();
            Intent browserIntent = new Intent(Intent.ACTION_VIEW);
            browserIntent.setData(uri);
            browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            PackageManager manager = context.getPackageManager();
            // Verify that the intent will resolve to an activity
            if (browserIntent.resolveActivity(manager) != null) {
                // Here we use an intent without a Chooser unlike the next example
                context.startActivity(browserIntent);
            }
        }
        catch (Exception e){
        }
    }

    protected void onResume() {
        super.onResume();
        hideSystemBars();
    }

    private void hideSystemBars() {
        window = getWindow();
        View view = window.getDecorView();
        WindowInsetsControllerCompat windowInsetsController = ViewCompat
                .getWindowInsetsController(view);
        if (windowInsetsController == null)
            return;
        windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
        windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());
    }
}
