1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package com.app.demoe
- import android.content.Intent
- import android.os.Bundle
- import android.util.Log
- import android.view.Gravity
- import android.widget.Toast
- import androidx.appcompat.app.AppCompatActivity
- import com.android.volley.DefaultRetryPolicy
- import com.android.volley.Request
- import com.android.volley.toolbox.JsonObjectRequest
- import com.app.demoe.databinding.ActivityMainBinding
- import org.json.JSONObject
- class MainActivity : AppCompatActivity() {
- lateinit var bindingClass:ActivityMainBinding
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- bindingClass = ActivityMainBinding.inflate(layoutInflater)
- setContentView(bindingClass.root)
- bindingClass.imageView1.animate().setDuration(4500).rotationBy(360f).start()
- // Run volley
- val url = "http://smarthome.madskill.ru/app"
- // Post parameters
- // Form fields and values
- val params= HashMap<String,String>()
- params.put("appId", "com.example.myapplication")
- params.put("competitor", "Competitor-1")
- val jsonObject = JSONObject(params.toString())
- val request = JsonObjectRequest(Request.Method.POST,url,jsonObject,
- { response->
- // Process the json
- try {
- Log.d("tag1","Response: $response")
- }catch (e:Exception){
- Log.d("tag1","Exception: $e")
- }
- }, {
- // Error in request
- Log.d("tag1","Volley error: $it")
- val toast = Toast.makeText(applicationContext,
- "Текст",
- Toast.LENGTH_SHORT)
- toast.setGravity(Gravity.CENTER, 0, 0)
- toast.show()
- })
- // Volley request policy, only one time request to avoid duplicate transaction
- request.retryPolicy = DefaultRetryPolicy(
- DefaultRetryPolicy.DEFAULT_TIMEOUT_MS,
- // 0 means no retry
- 0, // DefaultRetryPolicy.DEFAULT_MAX_RETRIES = 2
- 1f // DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
- )
- // Add the volley post request to the request queue
- VolleySingleton.getInstance(this).addToRequestQueue(request)
- var start_acty = true
- Thread{
- while (start_acty){
- Thread.sleep(5000)
- runOnUiThread{
- val intent = Intent(this, SignIn_Screen::class.java)
- startActivity(intent)
- }
- start_acty = false
- }
- }.start()
- }
- }
|