package cc.winboll.studio.powerbell.activities;

/**
 * @Author ZhanGSKen<zhangsken@qq.com>
 * @Date 2025/06/19 20:35
 * @Describe 应用窗口基类
 */
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
import cc.winboll.studio.powerbell.BuildConfig;
import cc.winboll.studio.powerbell.R;

@SuppressLint("SetTextI18n")
public abstract class WinBoLLActivity extends AppCompatActivity implements IWinBoLLActivity {

    public static final String TAG = "WinBoLLActivity";
	
	protected TextView mTagView;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
		changeFullScreen(this);
    }
	

    @Override
    protected void onStart() {
        super.onStart();
        addVersionNameToContentView();
    }

    protected void addVersionNameToContentView() {
        if (!isTagViewVisible()) {
            return;
        }
        if (mTagView == null) {
            mTagView = new TextView(this);
            mTagView.setTextColor(Color.GRAY);
            mTagView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
            mTagView.setText("MIMO SDK V" + BuildConfig.VERSION_NAME);
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
				ViewGroup.LayoutParams.WRAP_CONTENT,
				ViewGroup.LayoutParams.WRAP_CONTENT);
            params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
            FrameLayout frameLayout = findViewById(android.R.id.content);
            frameLayout.addView(mTagView, params);
        }
    }

    protected boolean isTagViewVisible() {
        return true;
    }

    public void setupToolbar() {
        Toolbar mToolbar = findViewById(R.id.toolbar);
        if (mToolbar != null) {
            setSupportActionBar(mToolbar);
            if (getSupportActionBar() != null) {
                getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            }
        }
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        //GlobalApplication.getWinBoLLActivityManager().add(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //GlobalApplication.getWinBoLLActivityManager().registeRemove(this);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            //GlobalApplication.getWinBoLLActivityManager().startWinBoLLActivity(getApplicationContext(), MainActivity.class);
            return true;
        }
        // 在switch语句中处理每个ID，并在处理完后返回true，未处理的情况返回false。
        return super.onOptionsItemSelected(item);
    }

	@Override
	public void onBackPressed() {
		super.onBackPressed();
		//GlobalApplication.getWinBoLLActivityManager().startWinBoLLActivity(getApplicationContext(), MainActivity.class);
	}
	
	public void changeFullScreen(Activity activity) {
        Window window =  activity.getWindow();
        if (window == null){
            return;
        }
        View decorView = window.getDecorView();
        if (decorView == null){
            return;
        }
        int flag = decorView.getSystemUiVisibility();
        flag |= View.SYSTEM_UI_FLAG_FULLSCREEN;
        flag |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
        flag |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        flag |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
        flag |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        decorView.setSystemUiVisibility(flag);
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
}
