package com.lc.myapplication.security.locks.dialog;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.lc.myapplication.security.locks.R;
import com.lc.myapplication.security.locks.activity.PassCodeActivity;
import com.lc.myapplication.security.locks.databinding.PermissionDialogBinding;
import com.lc.myapplication.security.locks.databinding.SettingDialogBinding;
import com.lc.myapplication.security.locks.tool.LockPremission;
import com.lc.myapplication.security.locks.value.MeValues;

public class SettingDialog extends DialogFragment {
    private Context mcon;
    private SettingDialogBinding settingDialogBinding;
    public SettingDialog(Context context){
        mcon = context;
    }
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        settingDialogBinding = SettingDialogBinding.inflate(inflater,null,false);
        initdialog();
        return settingDialogBinding.getRoot();
    }

    private void initdialog() {
        Window window = getDialog().getWindow();
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        window.getDecorView().setPadding(0, 10, 0, 0);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.gravity = Gravity.BOTTOM;
        wl.height = WindowManager.LayoutParams.WRAP_CONTENT;
        wl.width = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(wl);
        setCancelable(true);
        settingDialogBinding.setdialogFra.setVisibility(View.VISIBLE);
        settingDialogBinding.setDialogChange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    Intent intent = new Intent(getActivity(), PassCodeActivity.class);
                    intent.putExtra(MeValues.KEY_SHOW,true);
                    intent.putExtra(MeValues.KEYCODE_TYPE, 2);
                    startActivity(intent);
            }
        });
        settingDialogBinding.setDialogShare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent sharedIntent = new Intent();
                sharedIntent.setAction(Intent.ACTION_SEND);
                sharedIntent.setType("text/*");
                sharedIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_app));    //设置要分享的内容
                startActivity(Intent.createChooser(sharedIntent, "Share"));
            }
        });
        settingDialogBinding.setDialogRate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url = getString(R.string.share_app);
                Intent intent2 = new Intent(Intent.ACTION_VIEW);
                intent2.setData(Uri.parse(url));
                startActivity(intent2);
            }
        });
        settingDialogBinding.setDialogPrivacy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    String url = getString(R.string.url_privacy);
                    Intent intent3 = new Intent(Intent.ACTION_VIEW);
                    intent3.setData(Uri.parse(url));
                    startActivity(intent3);
            }
        });
    }


    @Override
    public void onResume() {
        super.onResume();
    }
}
