package com.sheep.gamegroup.absBase;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.widget.Toast;

import com.sheep.gamegroup.util.ActivityManager;
import com.sheep.gamegroup.util.Jump2View;
import com.sheep.gamegroup.util.UMConfigUtils;
import com.sheep.gamegroup.view.activity.AccountAndSecurityAct;
import com.sheep.jiuyan.samllsheep.utils.SpUtils;
import com.umeng.analytics.MobclickAgent;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;

import java.util.Map;

import butterknife.ButterKnife;

/**
 * Created by kemllor on 2017/12/15.
 */

public abstract class BaseActivity extends AppCompatActivity {

    protected ProgressDialog  mPd;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        initView();
        initListener();
        initData();
    }

    public void  showProgress(){
        if(mPd!=null){
            hideProgress();
        }
        mPd = new ProgressDialog(this);
//        View view= LayoutInflater.from(this).inflate(R.layout.dialog_layout,null);
//        mPd.setContentView(view);//自己定义布局
        mPd.setMessage("数据加载中...");
        mPd.setCancelable(true);//能否够被取消
//        mPd.setProgressStyle(ProgressDialog.STYLE_SPINNER);//圆环风格
        mPd.show();
    }
    protected void  showProgress(boolean cancel){
        if(mPd!=null){
            hideProgress();
        }
        mPd = new ProgressDialog(this);
//        View view= LayoutInflater.from(this).inflate(R.layout.dialog_layout,null);
//        mPd.setContentView(view);//自己定义布局
        mPd.setMessage("数据加载中...");
        mPd.setCancelable(cancel);//能否够被取消
//        mPd.setProgressStyle(ProgressDialog.STYLE_SPINNER);//圆环风格
        mPd.show();
    }


    public void  hideProgress(){
        this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if(mPd!=null){
                    mPd.dismiss();
                }
            }
        });

    }
    protected   void  showToast(final String msg){
        this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(BaseActivity.this,msg,Toast.LENGTH_LONG).show();
            }
        });


    }









    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        /*if (BuildConfig.DEBUG)
            if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
                Intent intent = Chuck.getLaunchIntent(BaseActivity.this);
                startActivity(intent);
                return true;
            }*/
        return super.onKeyDown(keyCode, event);
    }

    protected abstract int getLayoutId();

    public abstract void initView();

    public abstract void initListener();

    public abstract void initData();



}
