package com.dwin.DwinTools;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class NavigationBarActivity extends AppCompatActivity implements View.OnClickListener {

    private final String TAG = NavigationBarActivity.class.getSimpleName();
    public static final String DWIN_NAVIGATION_BAR = "android.intent.action.dwin_navigation_bar";
    private Button mButtonNavigationBarShow,mButtonNavigationBarHide;

    //发送"0"则显示导航栏，发送"1"则隐藏导航栏
    public static final String DWIN_NAVIGATION_BAR_SHOW_VALUE = "0";
    public static final String DWIN_NAVIGATION_BAR_HIDE_VALUE = "1";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigation_bar);

        mButtonNavigationBarShow = findViewById(R.id.btn_navigation_bar_show);
        mButtonNavigationBarHide = findViewById(R.id.btn_navigation_bar_hide);

        mButtonNavigationBarShow.setOnClickListener(this);
        mButtonNavigationBarHide.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_navigation_bar_show:
                setNavigationBar(DWIN_NAVIGATION_BAR_SHOW_VALUE);
                break;
            case R.id.btn_navigation_bar_hide:
                setNavigationBar(DWIN_NAVIGATION_BAR_HIDE_VALUE);
                break;
        }
    }

    /**
     * 通过发送广播，系统则会进行相应的隐藏\显示导航栏
     * @param value 是否显示导航栏的值
     */
    private void setNavigationBar(String value){
        Log.v(TAG,"Dwin test sendBroadcast!");
        Intent sr = new Intent(DWIN_NAVIGATION_BAR);
        sr.putExtra("message", value);
        sendBroadcast(sr);
    }
}
