package com.example.jinyu_rfid.base;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.Window;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;

import com.example.jinyu_rfid.R;
import com.google.gson.Gson;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import okhttp3.MediaType;


public class BaseActivity extends AppCompatActivity {


    public static String url = "http://rfidtest.jinyutyres.com:8199/rfid";
    public ProgressDialog dialog;
    public Gson gson;
    public MediaType JSON = MediaType.parse("application/json; charset=utf-8");
    private MyReceiver myReceiver;
    public MediaPlayer music;
    public Context context;
    @SuppressLint("SimpleDateFormat")
    public SimpleDateFormat format= new SimpleDateFormat( "yyyyMMdd_HHmmss");
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e("TAG", this.getLocalClassName() );
        gson = new Gson();
        this.context=this;
        initDialog();

        music = MediaPlayer.create(this, R.raw.msg);


    }

    public class MyReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            var scannerdata = intent.getStringExtra("scannerdata");
            sanCodeCall(scannerdata);
        }
    }

    private void initDialog() {
        dialog = new ProgressDialog(this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        dialog.setMessage("loading...");
    }

    private void initSan() {
        myReceiver = new MyReceiver();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.rfid.SCAN");
        registerReceiver(myReceiver, intentFilter);

    }


    // @Override
    // protected void onDestroy() {
    //     super.onDestroy();
    //     unregisterReceiver(myReceiver);
    // }

    public void titleToolClick(View view) {
        finish();
    }

    public void sanCodeCall(String code) {

    }




}