123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- 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'
- .................................................................................
- val qwe = Intent(this, MainActivity3::class.java)
- qwe.putExtra("token", bindingClass.textView.text.toString())
-
- val token = intent.getStringExtra("token").toString()
- bindingClass.textView5.text = token
-
-
- ................................................................................
|