Abdulmumin Alhusah

mail@pastecode.io avatar
unknown
plain_text
2 years ago
6.0 kB
1
Indexable
Never
package com.example.myapplication

import android.content.DialogInterface
import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_main.view.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        button.setOnClickListener{
            var num =  editTextNumber.text.toString()
            var bigThen = 6000
            if (num <= bigThen.toString()){
                Toast.makeText(this,"خطا",Toast.LENGTH_SHORT).show()
            }else{
                var GB = num.toDouble()
                GB *= 1024.0
                textView2.text = GB.toString()

                var MB = num.toDouble()
                MB *= 1048576.0
                textView2.text = MB.toString()

                var KB = num.toDouble()
                KB *= 1.073711824
                textView2.text = KB.toString()

                var Byte = num.toDouble()
                Byte *= 1.099511627776
                textView2.text = Byte.toString()
                Toast.makeText(this,"تم", Toast.LENGTH_SHORT).show()
            }
            button2.setOnClickListener {

                val dialogBuilder = AlertDialog.Builder(this)

                dialogBuilder.setMessage("هل ترغب باغلاق البرنامج؟ ")
                    .setCancelable(false)

                    .setPositiveButton("نعم", DialogInterface.OnClickListener {
                            dialog, id -> finish()
                    })

                    .setNegativeButton("الغاء", DialogInterface.OnClickListener {
                            dialog, id -> dialog.cancel()
                    })

                val alert = dialogBuilder.create()

                alert.setTitle("تحذير")

                alert.show()
            }

        }
        urlBut.setOnClickListener {
            val openURL = Intent(Intent.ACTION_VIEW)
            openURL.data = Uri.parse("https://Unitconverters.net/")
            startActivity(openURL)
        }

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#CCFFFF"
    android:backgroundTint="#CCFFFF"
    tools:context=".MainActivity">


    <TextView
        android:id="@+id/textView2"
        android:layout_width="349dp"
        android:layout_height="38dp"
        android:background="#E1DEC4"
        android:text="القيمة بالميجا بايت "
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="22dp"
        tools:layout_editor_absoluteY="177dp" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="349dp"
        android:layout_height="38dp"
        android:background="#E1DEC4"
        android:text="القيمة بالكيلو بايت "
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="251dp" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="349dp"
        android:layout_height="38dp"
        android:background="#E1DEC4"
        android:text="القيمة بالبايت بايت "
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="22dp"
        tools:layout_editor_absoluteY="324dp" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="349dp"
        android:layout_height="38dp"
        android:background="#E1DEC4"
        android:text="القيمة بالبت بايت "
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="22dp"
        tools:layout_editor_absoluteY="405dp" />

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:backgroundTint="#000000"
        android:text="أضغط هنا للتحويل"

        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="-10dp"
        tools:layout_editor_absoluteY="474dp" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="69dp"
        android:text="خروج"
        app:layout_constraintTop_toTopOf="@+id/button"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="164dp" />

    <EditText
        android:id="@+id/editTextNumber"
        android:layout_width="257dp"
        android:layout_height="50dp"
        android:background="#8E8B8B"
        android:backgroundTint="#8E8B8B"
        android:ems="10"
        android:inputType="number"
        app:layout_constraintBottom_toTopOf="@+id/textView2"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="MissingConstraints,SpeakableTextPresentCheck"
        tools:layout_editor_absoluteX="53dp" />

    <Button
        android:id="@+id/urlBut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Unitconverters.net"
        tools:layout_editor_absoluteX="113dp"
        tools:layout_editor_absoluteY="607dp"
        tools:ignore="MissingConstraints" />


</androidx.constraintlayout.widget.ConstraintLayout>
    }
}