Преглед на файлове

Загрузить файлы ''

Talengek9984 преди 3 години
родител
ревизия
9058430580
променени са 4 файла, в които са добавени 406 реда и са изтрити 0 реда
  1. 95 0
      MainActivity.kt
  2. 64 0
      SignIn_Screen.kt
  3. 30 0
      VolleySingleton.kt
  4. 217 0
      Памятка.txt

+ 95 - 0
MainActivity.kt

@@ -0,0 +1,95 @@
+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()
+    }
+
+
+
+
+
+
+
+}

+ 64 - 0
SignIn_Screen.kt

@@ -0,0 +1,64 @@
+package com.app.demoe
+
+import android.content.Intent
+import androidx.appcompat.app.AppCompatActivity
+import android.os.Bundle
+import android.util.Log
+import com.android.volley.DefaultRetryPolicy
+import com.android.volley.Request
+import com.android.volley.toolbox.JsonObjectRequest
+import com.app.demoe.databinding.ActivitySignInScreenBinding
+import org.json.JSONObject
+
+class SignIn_Screen : AppCompatActivity() {
+    lateinit var bindingClass: ActivitySignInScreenBinding
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        bindingClass = ActivitySignInScreenBinding.inflate(layoutInflater)
+        setContentView(bindingClass.root)
+
+        // Run volley
+        bindingClass.bSingin.setOnClickListener {
+            val url = "http://smarthome.madskill.ru/auth/user"
+
+            // Post parameters
+            // Form fields and values
+            val params = HashMap<String,String>()
+            params.put("email", "vasya@mail.com")
+            params.put("password", "qwerty")
+            params.put("uuid", "5FA1B987-3890-4A87-9712-ACDEAD0173AE")
+            params.put("hash", "5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9")
+            val jsonObject = (params as Map<*, *>?)?.let { it1 -> JSONObject(it1) }
+
+
+
+            // Volley post request with parameters
+            val request = JsonObjectRequest(Request.Method.OPTIONS,url,jsonObject,
+                { response ->
+                    // Process the json
+                    try {
+                        Log.d("tag1","Response: $response" )
+
+                    }catch (e:Exception){
+                        bindingClass.textView.text = "Exception: $e"
+                    }
+
+                }, {
+                    // Error in request
+                    Log.d("tag1","Volley error: $it")
+                })
+
+
+            // 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)
+        }
+    }
+}

+ 30 - 0
VolleySingleton.kt

@@ -0,0 +1,30 @@
+package com.app.demoe
+
+import android.content.Context
+import com.android.volley.Request
+import com.android.volley.RequestQueue
+import com.android.volley.toolbox.Volley
+
+
+class VolleySingleton constructor(context: Context) {
+    companion object {
+        @Volatile
+        private var INSTANCE: VolleySingleton? = null
+        fun getInstance(context: Context) =
+            INSTANCE ?: synchronized(this) {
+                INSTANCE ?: VolleySingleton(context).also {
+                    INSTANCE = it
+                }
+            }
+    }
+
+    private val requestQueue: RequestQueue by lazy {
+        // applicationContext is key, it keeps you from leaking the
+        // Activity or BroadcastReceiver if someone passes one in.
+        Volley.newRequestQueue(context.applicationContext)
+    }
+
+    fun <T> addToRequestQueue(req: Request<T>) {
+        requestQueue.add(req)
+    }
+}

+ 217 - 0
Памятка.txt

@@ -0,0 +1,217 @@
+ lateinit var bindingClass: ActivitySignInScreenBinding
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        bindingClass = ActivitySignInScreenBinding.inflate(layoutInflater)
+        setContentView(bindingClass.root)
+
+        // Run volley
+        bindingClass.bSingin.setOnClickListener {
+            val url = "http://smarthome.madskill.ru/auth/user"
+
+            // Post parameters
+            // Form fields and values
+            val params = HashMap<String,String>()
+            params.put("email", "vasya@mail.com")
+            params.put("password", "qwerty")
+            params.put("uuid", "5FA1B987-3890-4A87-9712-ACDEAD0173AE")
+            params.put("hash", "5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9")
+            val jsonObject = (params as Map<*, *>?)?.let { it1 -> JSONObject(it1) }
+
+
+
+            // Volley post request with parameters
+            val request = JsonObjectRequest(Request.Method.OPTIONS,url,jsonObject,
+                { response ->
+                    // Process the json
+                    try {
+                        Log.d("tag1","Response: $response" )
+
+                    }catch (e:Exception){
+                        bindingClass.textView.text = "Exception: $e"
+                    }
+
+                }, {
+                    // Error in request
+                    Log.d("tag1","Volley error: $it")
+                })
+
+
+            // 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)
+        }
+    }
+}
+
+
+
+.....................................................................................
+
+
+
+
+import android.content.Context
+import com.android.volley.Request
+import com.android.volley.RequestQueue
+import com.android.volley.toolbox.Volley
+
+
+class VolleySingleton constructor(context: Context) {
+    companion object {
+        @Volatile
+        private var INSTANCE: VolleySingleton? = null
+        fun getInstance(context: Context) =
+            INSTANCE ?: synchronized(this) {
+                INSTANCE ?: VolleySingleton(context).also {
+                    INSTANCE = it
+                }
+            }
+    }
+
+    private val requestQueue: RequestQueue by lazy {
+        // applicationContext is key, it keeps you from leaking the
+        // Activity or BroadcastReceiver if someone passes one in.
+        Volley.newRequestQueue(context.applicationContext)
+    }
+
+    fun <T> addToRequestQueue(req: Request<T>) {
+        requestQueue.add(req)
+    }
+}
+
+
+
+
+
+....................................................................................
+
+
+
+
+
+var start:Boolean=true
+        Thread{
+            while (start){
+                Thread.sleep(5000)
+                runOnUiThread {
+                    val intent = Intent(this, MainActivity2::class.java)
+                    startActivity(intent)
+                }
+                start = false
+            }
+        }.start()
+    }
+
+
+
+...................................................................................
+
+
+
+
+    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")
+                })
+
+
+            // 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()
+    }
+
+....................................................................................
+
+
+
+                    val toast = Toast.makeText(applicationContext,
+                        "Текст",
+                        Toast.LENGTH_SHORT)
+                    toast.setGravity(Gravity.CENTER, 0, 0)
+                    toast.show()
+
+...................................................................................
+
+
+
+    <uses-permission android:name="android.permission.INTERNET"/>
+
+
+..................................................................................
+
+
+
+buildFeatures{
+        viewBinding true
+    }
+}
+
+dependencies {
+
+    implementation 'com.android.volley:volley:1.2.1'
+
+.................................................................................
+
+
+