package com.android.chmo.ui.activity.me;

import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.widget.Toast;

import com.android.chmo.R;
import com.android.chmo.base.BaseActivity;
import com.netease.nim.uikit.support.permission.MPermission;
import com.netease.nim.uikit.support.permission.annotation.OnMPermissionDenied;
import com.netease.nim.uikit.support.permission.annotation.OnMPermissionGranted;

import butterknife.OnClick;

/**
 * Created by Administrator on 2018/8/20.
 */

public class AboutActivity extends BaseActivity {
    @Override
    protected int getContentResId() {
        return R.layout.activity_about;
    }

    @Override
    public void initView() {

    }

    @OnClick(R.id.call)
    public void call() {
        checkCallPermission();
    }

    public void checkCallPermission() {
        MPermission.with(this)
                .setRequestCode(30)
                .permissions( new String[] {
                        Manifest.permission.CALL_PHONE}).request();
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        MPermission.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
    }

    @OnMPermissionGranted(30)
    public void onCallPermissionSuccess(){
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:15805170379");
        intent.setData(data);
        startActivity(intent);
    }

    @OnMPermissionDenied(30)
    public void onCallPermissionFailed(){
        Toast.makeText(getContext(), "拨号所需权限未授权", Toast.LENGTH_SHORT).show();
    }
}
