package com.hh.arome.utlis.device;

import android.content.Context;
import android.content.Intent;

import com.common.pos.api.util.PosUtil;

import java.io.DataOutputStream;
import java.io.IOException;

/**
 * 设备控制部分方法
 */
public class FaceScenicUtile {
    Context context;
    public FaceScenicUtile(Context context){
        this.context=context;
    }
    private static final String ACTION_HIDE_NAV_BAR = "com.android.internal.policy.impl.hideNavigationBar";
    private static final String ACTION_SHOW_NAV_BAR = "com.android.internal.policy.impl.showNavigationBar";
    private static final String ACTION_CLOSE_STATUS_BAR = "com.android.systemui.statusbar.phone.statusclose";
    private static final String ACTION_OPEN_STATUS_BAR = "com.android.systemui.statusbar.phone.statusopen";
    //底部导航栏
    public void showNavigationBar(Context context, boolean display) {
        if (context != null) {
            Intent intent = new Intent();
            intent.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
            intent.setAction(display? ACTION_SHOW_NAV_BAR : ACTION_HIDE_NAV_BAR);
            context.sendBroadcast(intent);
        }
    }
    //下拉通知栏
    public void enableStatusBar(Context context, boolean enabled) {
        if (context != null) {
            Intent intent = new Intent();
            intent.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
            intent.setAction(enabled ? ACTION_OPEN_STATUS_BAR : ACTION_CLOSE_STATUS_BAR);
            context.sendBroadcast(intent);
        }
    }
    /**
     * 补光灯控制方法
     * @param powerStatus powerStatus（电平状态）：1-高电平(开) 0-低电平（关）
     * @return
     */
    public void setLedPower(boolean powerStatus){
        PosUtil.setLedPower(powerStatus ? 1 : 0);

    }
    /**
     * 补光灯亮度 调节
     * @return
     */
    public void setLedLight(boolean powerStatus){
        PosUtil.setLedLight(powerStatus ? 200 : 0);
    }
    /**
     * LED 灯亮度控制方法
     */
    public void setLEDLights(int progress){
        String cmd = "echo " + progress +
                " >/sys/class/backlight/backlight_extend/brightness";
        try {
            Process p = Runtime.getRuntime().exec("sh");
            DataOutputStream os = new
                    DataOutputStream(p.getOutputStream());
            os.writeBytes(cmd + "\n");
            os.writeBytes("exit\n");
            os.flush();
            p.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
