MainActivity.kt 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package com.app.demoe
  2. import android.content.Intent
  3. import android.os.Bundle
  4. import android.util.Log
  5. import android.view.Gravity
  6. import android.widget.Toast
  7. import androidx.appcompat.app.AppCompatActivity
  8. import com.android.volley.DefaultRetryPolicy
  9. import com.android.volley.Request
  10. import com.android.volley.toolbox.JsonObjectRequest
  11. import com.app.demoe.databinding.ActivityMainBinding
  12. import org.json.JSONObject
  13. class MainActivity : AppCompatActivity() {
  14. lateinit var bindingClass:ActivityMainBinding
  15. override fun onCreate(savedInstanceState: Bundle?) {
  16. super.onCreate(savedInstanceState)
  17. bindingClass = ActivityMainBinding.inflate(layoutInflater)
  18. setContentView(bindingClass.root)
  19. bindingClass.imageView1.animate().setDuration(4500).rotationBy(360f).start()
  20. // Run volley
  21. val url = "http://smarthome.madskill.ru/app"
  22. // Post parameters
  23. // Form fields and values
  24. val params= HashMap<String,String>()
  25. params.put("appId", "com.example.myapplication")
  26. params.put("competitor", "Competitor-1")
  27. val jsonObject = JSONObject(params.toString())
  28. val request = JsonObjectRequest(Request.Method.POST,url,jsonObject,
  29. { response->
  30. // Process the json
  31. try {
  32. Log.d("tag1","Response: $response")
  33. }catch (e:Exception){
  34. Log.d("tag1","Exception: $e")
  35. }
  36. }, {
  37. // Error in request
  38. Log.d("tag1","Volley error: $it")
  39. val toast = Toast.makeText(applicationContext,
  40. "Текст",
  41. Toast.LENGTH_SHORT)
  42. toast.setGravity(Gravity.CENTER, 0, 0)
  43. toast.show()
  44. })
  45. // Volley request policy, only one time request to avoid duplicate transaction
  46. request.retryPolicy = DefaultRetryPolicy(
  47. DefaultRetryPolicy.DEFAULT_TIMEOUT_MS,
  48. // 0 means no retry
  49. 0, // DefaultRetryPolicy.DEFAULT_MAX_RETRIES = 2
  50. 1f // DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
  51. )
  52. // Add the volley post request to the request queue
  53. VolleySingleton.getInstance(this).addToRequestQueue(request)
  54. var start_acty = true
  55. Thread{
  56. while (start_acty){
  57. Thread.sleep(5000)
  58. runOnUiThread{
  59. val intent = Intent(this, SignIn_Screen::class.java)
  60. startActivity(intent)
  61. }
  62. start_acty = false
  63. }
  64. }.start()
  65. }
  66. }