feat: redesign main UI with MaterialCardView selection menu and dark theme styling
This commit is contained in:
1
.idea/deploymentTargetSelector.xml
generated
1
.idea/deploymentTargetSelector.xml
generated
@@ -4,6 +4,7 @@
|
||||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
<DialogSelection />
|
||||
</SelectionState>
|
||||
</selectionStates>
|
||||
</component>
|
||||
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -6,6 +6,7 @@ import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothSocket;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
@@ -43,6 +44,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
private static final UUID BTMODULEUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
|
||||
private final static int REQUEST_ENABLE_BT = 1; // used to identify adding bluetooth names
|
||||
private boolean bluetoothDenied = false;
|
||||
private TextView tvStatus;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -55,6 +57,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
tvStatus = findViewById(R.id.tvStatus);
|
||||
updateStatus("Desligado", Color.parseColor("#F44336"));
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this,
|
||||
new String[]{Manifest.permission.BLUETOOTH_CONNECT, Manifest.permission.BLUETOOTH_SCAN},
|
||||
@@ -70,33 +74,48 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
public void cafeCurto(View view) {
|
||||
Toast.makeText(this, "Café Curto", Toast.LENGTH_SHORT).show();
|
||||
private void updateStatus(String status, int color) {
|
||||
runOnUiThread(() -> {
|
||||
if (tvStatus != null) {
|
||||
tvStatus.setText("● " + status);
|
||||
tvStatus.setTextColor(color);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void cafeCurto(View view) {
|
||||
if (mConnectedThread != null) {
|
||||
Toast.makeText(this, "Café Curto", Toast.LENGTH_SHORT).show();
|
||||
mConnectedThread.enviarComando("1");
|
||||
} else {
|
||||
ligarBluetooth();
|
||||
Toast.makeText(this, "A tentar ligar à máquina...", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public void CafeMedio(View view) {
|
||||
Toast.makeText(this, "Café Médio", Toast.LENGTH_SHORT).show();
|
||||
|
||||
if (mConnectedThread != null) {
|
||||
Toast.makeText(this, "Café Médio", Toast.LENGTH_SHORT).show();
|
||||
mConnectedThread.enviarComando("2");
|
||||
} else {
|
||||
ligarBluetooth();
|
||||
Toast.makeText(this, "A tentar ligar à máquina...", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public void cafeLongo(View view) {
|
||||
|
||||
Toast.makeText(this, "Café Longo", Toast.LENGTH_SHORT).show();
|
||||
|
||||
if (mConnectedThread != null) {
|
||||
Toast.makeText(this, "Café Longo", Toast.LENGTH_SHORT).show();
|
||||
mConnectedThread.enviarComando("3");
|
||||
} else {
|
||||
ligarBluetooth();
|
||||
Toast.makeText(this, "A tentar ligar à máquina...", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public void ligarBluetooth() {
|
||||
if (mBTAdapter == null) {
|
||||
updateStatus("Sem Bluetooth", Color.parseColor("#F44336"));
|
||||
runOnUiThread(() ->
|
||||
Toast.makeText(MainActivity.this, "Dispositivo não suporta Bluetooth", Toast.LENGTH_LONG).show()
|
||||
);
|
||||
@@ -109,6 +128,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
}
|
||||
else{
|
||||
updateStatus("A ligar...", Color.parseColor("#FFC107"));
|
||||
final String address = "98:D3:21:FC:7F:DF";
|
||||
new Thread() {
|
||||
public void run() {
|
||||
@@ -121,6 +141,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
} catch (IOException e) {
|
||||
fail = true;
|
||||
Log.d("bluetooth","Socket creation failed");
|
||||
updateStatus("Falha ao ligar", Color.parseColor("#F44336"));
|
||||
}
|
||||
try {
|
||||
if (ActivityCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
|
||||
@@ -133,13 +154,17 @@ public class MainActivity extends AppCompatActivity {
|
||||
try {
|
||||
fail = true;
|
||||
mBTSocket.close();
|
||||
updateStatus("Desligado", Color.parseColor("#F44336"));
|
||||
} catch (IOException e2) {
|
||||
Log.d("bluetooth","Socket creation failed");
|
||||
}
|
||||
}
|
||||
if (fail == false) {
|
||||
updateStatus("Ligado", Color.parseColor("#4CAF50"));
|
||||
mConnectedThread = new ConnectedThread(mBTSocket);
|
||||
mConnectedThread.start();
|
||||
} else {
|
||||
reconnect();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
@@ -175,16 +200,34 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
private class ConnectedThread extends Thread {
|
||||
private final OutputStream mmOutStream;
|
||||
private final InputStream mmInStream;
|
||||
|
||||
public ConnectedThread(BluetoothSocket socket) {
|
||||
OutputStream tmpOut = null;
|
||||
InputStream tmpIn = null;
|
||||
try {
|
||||
tmpOut = socket.getOutputStream();
|
||||
tmpIn = socket.getInputStream();
|
||||
} catch (IOException e) {
|
||||
Log.e("Bluetooth", "Erro ao obter OutputStream", e);
|
||||
Log.e("Bluetooth", "Erro ao obter Streams", e);
|
||||
}
|
||||
|
||||
mmOutStream = tmpOut;
|
||||
mmInStream = tmpIn;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
byte[] buffer = new byte[1024];
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
int bytes = mmInStream.read(buffer);
|
||||
if (bytes == -1) break;
|
||||
} catch (IOException e) {
|
||||
Log.e("Bluetooth", "Conexão perdida", e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
reconnect();
|
||||
}
|
||||
|
||||
public void enviarComando(String input){
|
||||
@@ -192,19 +235,34 @@ public class MainActivity extends AppCompatActivity {
|
||||
try {
|
||||
mmOutStream.write(bytes);
|
||||
} catch (IOException e) {
|
||||
Log.e("Bluetooth", "Erro ao obter OutputStream", e);
|
||||
Log.e("Bluetooth", "Erro ao enviar", e);
|
||||
reconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void reconnect() {
|
||||
runOnUiThread(() -> {
|
||||
desligarBluetooth();
|
||||
updateStatus("A tentar reconectar...", Color.parseColor("#FFC107"));
|
||||
new Handler(getMainLooper()).postDelayed(() -> {
|
||||
if (!bluetoothDenied) {
|
||||
ligarBluetooth();
|
||||
}
|
||||
}, 3000);
|
||||
});
|
||||
}
|
||||
private void desligarBluetooth() {
|
||||
try {
|
||||
if (mConnectedThread != null) {
|
||||
mConnectedThread.interrupt();
|
||||
mConnectedThread = null;
|
||||
}
|
||||
if (mBTSocket != null) {
|
||||
mBTSocket.close();
|
||||
mBTSocket = null;
|
||||
}
|
||||
updateStatus("Desligado", Color.parseColor("#F44336"));
|
||||
} catch (IOException e) {
|
||||
Log.e("Bluetooth", "Erro ao desligar", e);
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 69 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 163 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 336 KiB |
@@ -1,65 +1,241 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<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:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity"
|
||||
android:id="@+id/main">
|
||||
android:background="#16100c"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<!-- Header / Logo Area -->
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@drawable/cafe"
|
||||
android:scaleType="centerCrop"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="130sp"
|
||||
android:id="@+id/logo"
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="160dp"
|
||||
android:layout_marginTop="48dp"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/logo"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_margin="16sp"/>
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/botoes"
|
||||
android:layout_marginTop="150dp"
|
||||
android:layout_centerVertical="false"
|
||||
<TextView
|
||||
android:id="@+id/titleText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_centerHorizontal="true">
|
||||
<ImageButton
|
||||
android:id="@+id/cafeCurto"
|
||||
style="@style/botao"
|
||||
android:layout_width="85dp"
|
||||
android:layout_height="85dp"
|
||||
android:text="@string/cafeCurto"
|
||||
android:layout_marginTop="8dp"
|
||||
android:fontFamily="sans-serif-light"
|
||||
android:text="Selecione o seu café"
|
||||
android:textColor="#F2E6D8"
|
||||
android:textSize="26sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/logo" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvStatus"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:text="A Ligar..."
|
||||
android:textColor="#FFC107"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/titleText" />
|
||||
|
||||
<!-- Cards Container -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:orientation="vertical"
|
||||
android:clipToPadding="false"
|
||||
android:padding="8dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/titleText">
|
||||
|
||||
<!-- Short Coffee Card -->
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:onClick="cafeCurto"
|
||||
android:src="@drawable/cafecurto"
|
||||
android:scaleType="fitXY"
|
||||
android:layout_gravity="center"/>
|
||||
<ImageButton
|
||||
android:id="@+id/cafeMedio"
|
||||
style="@style/botao"
|
||||
android:layout_width="85dp"
|
||||
android:layout_height="85dp"
|
||||
android:text="@string/cafeMedio"
|
||||
app:cardBackgroundColor="#211812"
|
||||
app:cardCornerRadius="16dp"
|
||||
app:cardElevation="8dp"
|
||||
app:rippleColor="#D4AF37"
|
||||
app:strokeColor="#3A2D23"
|
||||
app:strokeWidth="1dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:padding="16dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iconCurto"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:src="@drawable/cafecurto"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleCurto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:text="CAFÉ CURTO"
|
||||
android:textColor="#D4AF37"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toEndOf="@id/iconCurto"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/descCurto"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/descCurto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:fontFamily="sans-serif"
|
||||
android:text="Intenso e Encapsulado"
|
||||
android:textColor="#A89F91"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintStart_toEndOf="@id/iconCurto"
|
||||
app:layout_constraintTop_toBottomOf="@id/titleCurto"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<!-- Medium Coffee Card -->
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:onClick="CafeMedio"
|
||||
android:src="@drawable/cafemedio"
|
||||
android:scaleType="fitXY"
|
||||
android:layout_gravity="center"/>
|
||||
<ImageButton
|
||||
android:id="@+id/cafeLongo"
|
||||
style="@style/botao"
|
||||
android:layout_width="85dp"
|
||||
android:layout_height="85dp"
|
||||
android:text="@string/cafeLongo"
|
||||
app:cardBackgroundColor="#211812"
|
||||
app:cardCornerRadius="16dp"
|
||||
app:cardElevation="8dp"
|
||||
app:rippleColor="#D4AF37"
|
||||
app:strokeColor="#3A2D23"
|
||||
app:strokeWidth="1dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:padding="16dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iconMedio"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:src="@drawable/cafemedio"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleMedio"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:text="CAFÉ MÉDIO"
|
||||
android:textColor="#D4AF37"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toEndOf="@id/iconMedio"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/descMedio"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/descMedio"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:fontFamily="sans-serif"
|
||||
android:text="Equilibrado e Suave"
|
||||
android:textColor="#A89F91"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintStart_toEndOf="@id/iconMedio"
|
||||
app:layout_constraintTop_toBottomOf="@id/titleMedio"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<!-- Long Coffee Card -->
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:onClick="cafeLongo"
|
||||
android:src="@drawable/cafelongo"
|
||||
android:scaleType="fitXY"
|
||||
android:layout_gravity="center"/>
|
||||
app:cardBackgroundColor="#211812"
|
||||
app:cardCornerRadius="16dp"
|
||||
app:cardElevation="8dp"
|
||||
app:rippleColor="#D4AF37"
|
||||
app:strokeColor="#3A2D23"
|
||||
app:strokeWidth="1dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:padding="16dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iconLongo"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:src="@drawable/cafelongo"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleLongo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:text="CAFÉ LONGO"
|
||||
android:textColor="#D4AF37"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toEndOf="@id/iconLongo"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/descLongo"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/descLongo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:fontFamily="sans-serif"
|
||||
android:text="Rico e Encorpado"
|
||||
android:textColor="#A89F91"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintStart_toEndOf="@id/iconLongo"
|
||||
app:layout_constraintTop_toBottomOf="@id/titleLongo"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
Reference in New Issue
Block a user