package com.sheep.gamegroup.view.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.projection.MediaProjectionManager;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.sheep.gamegroup.util.Jump2View;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.service.FloatShotScreenService;
import com.sheep.jiuyan.samllsheep.utils.G;

import static com.sheep.gamegroup.util.DataUtil.REQUEST_MEDIA_PROJECTION;

/**
 * Created by realicing on 2018/5/10.
 * realicing@sina.com
 */
public class MiddleScreenShotAct extends Activity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_middle_screen_shot);

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            //5.0 之后才允许使用屏幕截图
            MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) this.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
            if (mediaProjectionManager != null) {
                startActivityForResult(mediaProjectionManager.createScreenCaptureIntent(), REQUEST_MEDIA_PROJECTION);
                return;
            }
        }
        G.showToast("您的系统版本过低，暂不支持该功能");
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case REQUEST_MEDIA_PROJECTION:
                if (resultCode == RESULT_OK && data != null) {
                    FloatShotScreenService.getInstance().setResultData(data);
//                    Jump2View.getInstance().startShotScreenFloat(this, FloatShotScreenService.SCREEN_SHOT);
                    G.showToast("请重新点击小绵羊悬浮窗进行截图！");
                    finish();
                }
                break;
        }
    }
}
