Памятка.txt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. lateinit var bindingClass: ActivitySignInScreenBinding
  2. override fun onCreate(savedInstanceState: Bundle?) {
  3. super.onCreate(savedInstanceState)
  4. bindingClass = ActivitySignInScreenBinding.inflate(layoutInflater)
  5. setContentView(bindingClass.root)
  6. // Run volley
  7. bindingClass.bSingin.setOnClickListener {
  8. val url = "http://smarthome.madskill.ru/auth/user"
  9. // Post parameters
  10. // Form fields and values
  11. val params = HashMap<String,String>()
  12. params.put("email", "vasya@mail.com")
  13. params.put("password", "qwerty")
  14. params.put("uuid", "5FA1B987-3890-4A87-9712-ACDEAD0173AE")
  15. params.put("hash", "5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9")
  16. val jsonObject = (params as Map<*, *>?)?.let { it1 -> JSONObject(it1) }
  17. // Volley post request with parameters
  18. val request = JsonObjectRequest(Request.Method.OPTIONS,url,jsonObject,
  19. { response ->
  20. // Process the json
  21. try {
  22. Log.d("tag1","Response: $response" )
  23. }catch (e:Exception){
  24. bindingClass.textView.text = "Exception: $e"
  25. }
  26. }, {
  27. // Error in request
  28. Log.d("tag1","Volley error: $it")
  29. })
  30. // Volley request policy, only one time request to avoid duplicate transaction
  31. request.retryPolicy = DefaultRetryPolicy(
  32. DefaultRetryPolicy.DEFAULT_TIMEOUT_MS,
  33. // 0 means no retry
  34. 0, // DefaultRetryPolicy.DEFAULT_MAX_RETRIES = 2
  35. 1f // DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
  36. )
  37. // Add the volley post request to the request queue
  38. VolleySingleton.getInstance(this).addToRequestQueue(request)
  39. }
  40. }
  41. }
  42. .....................................................................................
  43. import android.content.Context
  44. import com.android.volley.Request
  45. import com.android.volley.RequestQueue
  46. import com.android.volley.toolbox.Volley
  47. class VolleySingleton constructor(context: Context) {
  48. companion object {
  49. @Volatile
  50. private var INSTANCE: VolleySingleton? = null
  51. fun getInstance(context: Context) =
  52. INSTANCE ?: synchronized(this) {
  53. INSTANCE ?: VolleySingleton(context).also {
  54. INSTANCE = it
  55. }
  56. }
  57. }
  58. private val requestQueue: RequestQueue by lazy {
  59. // applicationContext is key, it keeps you from leaking the
  60. // Activity or BroadcastReceiver if someone passes one in.
  61. Volley.newRequestQueue(context.applicationContext)
  62. }
  63. fun <T> addToRequestQueue(req: Request<T>) {
  64. requestQueue.add(req)
  65. }
  66. }
  67. ....................................................................................
  68. var start:Boolean=true
  69. Thread{
  70. while (start){
  71. Thread.sleep(5000)
  72. runOnUiThread {
  73. val intent = Intent(this, MainActivity2::class.java)
  74. startActivity(intent)
  75. }
  76. start = false
  77. }
  78. }.start()
  79. }
  80. ...................................................................................
  81. lateinit var bindingClass:ActivityMainBinding
  82. override fun onCreate(savedInstanceState: Bundle?) {
  83. super.onCreate(savedInstanceState)
  84. bindingClass = ActivityMainBinding.inflate(layoutInflater)
  85. setContentView(bindingClass.root)
  86. bindingClass.imageView1.animate().setDuration(4500).rotationBy(360f).start()
  87. // Run volley
  88. val url = "http://smarthome.madskill.ru/app"
  89. // Post parameters
  90. // Form fields and values
  91. val params= HashMap<String,String>()
  92. params.put("appId", "com.example.myapplication")
  93. params.put("competitor", "Competitor-1")
  94. val jsonObject = JSONObject(params.toString())
  95. val request = JsonObjectRequest(Request.Method.POST,url,jsonObject,
  96. { response->
  97. // Process the json
  98. try {
  99. Log.d("tag1","Response: $response")
  100. }catch (e:Exception){
  101. Log.d("tag1","Exception: $e")
  102. }
  103. }, {
  104. // Error in request
  105. Log.d("tag1","Volley error: $it")
  106. })
  107. // Volley request policy, only one time request to avoid duplicate transaction
  108. request.retryPolicy = DefaultRetryPolicy(
  109. DefaultRetryPolicy.DEFAULT_TIMEOUT_MS,
  110. // 0 means no retry
  111. 0, // DefaultRetryPolicy.DEFAULT_MAX_RETRIES = 2
  112. 1f // DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
  113. )
  114. // Add the volley post request to the request queue
  115. VolleySingleton.getInstance(this).addToRequestQueue(request)
  116. var start_acty = true
  117. Thread{
  118. while (start_acty){
  119. Thread.sleep(5000)
  120. runOnUiThread{
  121. val intent = Intent(this, SignIn_Screen::class.java)
  122. startActivity(intent)
  123. }
  124. start_acty = false
  125. }
  126. }.start()
  127. }
  128. ....................................................................................
  129. val toast = Toast.makeText(applicationContext,
  130. "Текст",
  131. Toast.LENGTH_SHORT)
  132. toast.setGravity(Gravity.CENTER, 0, 0)
  133. toast.show()
  134. ...................................................................................
  135. <uses-permission android:name="android.permission.INTERNET"/>
  136. ..................................................................................
  137. buildFeatures{
  138. viewBinding true
  139. }
  140. }
  141. dependencies {
  142. implementation 'com.android.volley:volley:1.2.1'
  143. .................................................................................
  144. val qwe = Intent(this, MainActivity3::class.java)
  145. qwe.putExtra("token", bindingClass.textView.text.toString())
  146. val token = intent.getStringExtra("token").toString()
  147. bindingClass.textView5.text = token
  148. ................................................................................