package com.example.angluswang.superflashlight;

import android.app.Activity;
import android.hardware.Camera;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

/**
 * Created by Jeson on 2016/5/30.
 * 基类
 */

public class BaseActivity extends Activity {
    protected ImageView imgFlashlight;
    protected ImageView imgFlashController;
    protected ImageView imgWarmingup;
    protected ImageView imgWarmingdown;
    protected EditText etMorseCode;
    protected ImageView imgViewBulb;
    protected HideTextView mHideTextViewBulb;
    protected HideTextView mHideTextViewColor;
    protected HideTextView mHideTextViewPoliceLight;

    protected android.hardware.Camera mCamera;
    protected Camera.Parameters mParameters;

    protected FrameLayout uiFalshlight;
    protected LinearLayout uiMainLayout;
    protected LinearLayout uiWarnning;
    protected LinearLayout uiMorse;
    protected FrameLayout uiBulb;
    protected FrameLayout uiColorLight;
    protected FrameLayout uiPoliceLight;
    protected LinearLayout uiSetting;

    protected uiType mCurrentType = uiType.UI_TYPE_FLASH_LIGHT;
    protected uiType mLastType = uiType.UI_TYPE_FLASH_LIGHT;

    protected int mDefaultScreenBrightness;

    // 列举有哪些功能项
    protected enum uiType {
        UI_TYPE_UIMAIN,
        UI_TYPE_FLASH_LIGHT,
        UI_TYPE_WARNING_LIGHT,
        UI_TYPE_BULB,
        UI_TYPE_COLOR,
        UI_TYPE_MORSE,
        UI_TYPE_POLICE_LIGHT,
        UI_TYPE_SETTING
    }

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

        initView();

        mDefaultScreenBrightness = getScreenBrightness();
    }

    private void initView() {
        imgFlashController = (ImageView) findViewById(R.id.id_flashlight_controller);
        imgFlashlight = (ImageView) findViewById(R.id.id_flashlight);
        imgWarmingup = (ImageView) findViewById(R.id.img_warming_on);
        imgWarmingdown = (ImageView) findViewById(R.id.img_warming_off);
        etMorseCode = (EditText) findViewById(R.id.et_morse_code);
        imgViewBulb = (ImageView) findViewById(R.id.iv_bulb);
        mHideTextViewBulb = (HideTextView) findViewById(R.id.tv_hide_bulb);
        mHideTextViewColor = (HideTextView) findViewById(R.id.tv_hide_color);
        mHideTextViewPoliceLight = (HideTextView) findViewById(R.id.tv_hide_police_light);

        uiFalshlight = (FrameLayout) findViewById(R.id.framelayout_flash_light);
        uiMainLayout = (LinearLayout) findViewById(R.id.linear_layout_main);
        uiWarnning = (LinearLayout) findViewById(R.id.linear_layout_warnning);
        uiMorse = (LinearLayout) findViewById(R.id.linear_layout_morse);
        uiBulb = (FrameLayout) findViewById(R.id.framelayout_bulb);
        uiColorLight = (FrameLayout) findViewById(R.id.framelayout_color_light);
        uiPoliceLight = (FrameLayout) findViewById(R.id.framelayout_police_light);

//        uiSetting = (FrameLayout) findViewById(R.id.framelayout_setting);
    }

    protected void hideAllUi() {
        uiFalshlight.setVisibility(View.GONE);
        uiMainLayout.setVisibility(View.GONE);
        uiWarnning.setVisibility(View.GONE);
        uiMorse.setVisibility(View.GONE);
        uiBulb.setVisibility(View.GONE);
        uiColorLight.setVisibility(View.GONE);
        uiPoliceLight.setVisibility(View.GONE);

//        uiSetting.setVisibility(View.GONE);
    }

    /**
     * 改变屏幕的亮度
     */
    public void screenBrightness(float value) {
        try {
            WindowManager.LayoutParams layout = getWindow().getAttributes();
            layout.screenBrightness = value;
            getWindow().setAttributes(layout);

        } catch (Exception e) {

        }
    }

    /**
     * 获得当前屏幕的亮度，获取的值为0~255的一个数值
     */
    public int getScreenBrightness() {
        int value = 0;
        try {
            value = Settings.System.getInt(getContentResolver(),
                    Settings.System.SCREEN_BRIGHTNESS);
        } catch (Exception e) {

        }
        return value;
    }
}

@@ -163,16 +163,49 @@
 ttings;%0A
+import android.view.MotionEvent;%0A
 import a
@@ -392,16 +392,45 @@
 rLayout;
+%0Aimport android.widget.Toast;
 %0A%0A/**%0A *
@@ -1468,24 +1468,73 @@
 rightness;%0A%0A
+    protected int mFinishCount = 0; // %E5%AE%9E%E7%8E%B0%E6%8C%89%E8%BF%94%E5%9B%9E%E9%94%AE%E8%AE%A1%E6%95%B0%0A%0A
     // %E5%88%97%E4%B8%BE%E6%9C%89%E5%93%AA%E4%BA%9B
@@ -4391,11 +4391,478 @@
 e;%0A    %7D
+%0A%0A    @Override%0A    public boolean dispatchTouchEvent(MotionEvent ev) %7B%0A        mFinishCount = 0;%0A        return super.dispatchTouchEvent(ev);%0A    %7D%0A%0A    /**%0A     *  %E9%87%8D%E5%86%99%E8%AF%A5%E6%96%B9%E6%B3%95%EF%BC%8C%E5%AE%9E%E7%8E%B0%E4%B8%A4%E6%AC%A1%E6%8C%89%E8%BF%94%E5%9B%9E%E9%94%AE%E9%80%80%E5%87%BA%E5%8A%9F%E8%83%BD%0A     */%0A    @Override%0A    public void finish() %7B%0A        mFinishCount ++;%0A        if (mFinishCount == 1) %7B%0A            Toast.makeText(this, %22%E5%86%8D%E6%8C%89%E4%B8%80%E6%AC%A1%E9%80%80%E5%87%BA!%22,%0A                    Toast.LENGTH_SHORT).show();%0A        %7D else if (mFinishCount == 2) %7B%0A            super.finish();%0A        %7D%0A    %7D
 %0A%7D%0A

实现 按两次返回键 退出程序功能