T

G
mail@pastecode.io avatar
unknown
actionscript
2 years ago
2.6 kB
3
Indexable
Never
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

    private EditText loginEditText;
    private EditText passwordEditText;
    private Button loginButton;
    private Button callPatrolButton;

    private static final String ADMIN_LOGIN = "Admin";
    private static final String ADMIN_PASSWORD = "1234";
    private static final String PATROL_PHONE_NUMBER = "733 894 095";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        loginEditText = findViewById(R.id.login_edit_text);
        passwordEditText = findViewById(R.id.password_edit_text);
        loginButton = findViewById(R.id.login_button);
        callPatrolButton = findViewById(R.id.call_patrol_button);

        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String login = loginEditText.getText().toString();
                String password = passwordEditText.getText().toString();
                if (login.equals(ADMIN_LOGIN) && password.equals(ADMIN_PASSWORD)) {
                    Toast.makeText(MainActivity.this, "Zalogowano pomyślnie", Toast.LENGTH_SHORT).show();
                    callPatrolButton.setVisibility(View.VISIBLE);
                } else {
                    Toast.makeText(MainActivity.this, "Niepoprawny login lub hasło", Toast.LENGTH_SHORT).show();
                }
            }
        });

        callPatrolButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "Wysyłanie SMS...", Toast.LENGTH_SHORT).show();
                // oczekiwanie na 10 sekund
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                sendSMS(PATROL_PHONE_NUMBER, "Proszę o przyjazd grupy interwencyjnej. Nazwa użytkownika: " + ADMIN_LOGIN);
            }
        });
    }

    private void sendSMS(String phoneNumber, String message) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));
        intent.putExtra("sms_body", message);
        startActivity(intent);
    }
}