package com.algobase.share.compat;

import android.os.Build;

import android.view.View;
import android.view.ViewGroup;

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.content.pm.PackageManager;
import android.content.pm.ApplicationInfo;


public class Activity extends android.app.Activity { 

 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter)
 { if (Build.VERSION.SDK_INT >= 26)
     return super.registerReceiver(receiver,filter,RECEIVER_EXPORTED);
   else
     return super.registerReceiver(receiver,filter);
 }


 public void adjustLayout(View layout, int bg_clr)
 {
   if (layout == null) return;

   PackageManager pm  = getPackageManager();
   String pkg_name = getPackageName();

   try {
    ApplicationInfo ai = pm.getApplicationInfo(pkg_name,0);
    if (ai.targetSdkVersion < 35) return;
   } catch(Exception ex) {}
   

   Resources res = getResources();

   int r1 = res.getIdentifier("status_bar_height","dimen","android");
   int margin_top = res.getDimensionPixelSize(r1);

   int r2 = res.getIdentifier("navigation_bar_height","dimen","android");
   int margin_bottom = res.getDimensionPixelSize(r1);

   layout.setPadding(0,margin_top,0,margin_bottom);
   layout.setBackgroundColor(bg_clr);

/*
     WindowInsetsController insetController = window.getInsetsController();
     insetController.setSystemBarsAppearance(
                           WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
                           WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS);
*/
  }

  public void adjustLayout(int res, int bg_clr) {
    adjustLayout(findViewById(res),bg_clr);
  }

  public void adjustContentView(int bg_clr)
  { View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0);
    adjustLayout(view,bg_clr);
   }


}


