Commit 56d809b0 authored by Ishankha K.C's avatar Ishankha K.C

activity vocal screen

parent b6c2fd89
......@@ -323,17 +323,6 @@
<option name="screenX" value="1080" />
<option name="screenY" value="2424" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="29" />
<option name="brand" value="samsung" />
<option name="codename" value="x1q" />
<option name="id" value="x1q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy S20" />
<option name="screenDensity" value="480" />
<option name="screenX" value="1440" />
<option name="screenY" value="3200" />
</PersistentDeviceSelectionData>
</list>
</option>
</component>
......
......@@ -17,6 +17,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.BabyCare"
tools:targetApi="31">
<activity
android:name=".activities.LiveVocalActivity"
android:exported="false" />
<activity
android:name=".activities.ApplicationSettingsActivity"
android:exported="false" />
......
......@@ -45,7 +45,9 @@ public class DashboardActivity extends AppCompatActivity {
animationChanger(this);
});
btn2.setOnClickListener(v -> {
Intent intent = new Intent(this, LiveVocalActivity.class);
startActivity(intent);
animationChanger(this);
});
btn3.setOnClickListener(v -> {
Intent intent = new Intent(this, ActivityLogsActivity.class);
......
......@@ -10,6 +10,7 @@ import static com.kaluwa.enterprises.babycare.utils.Utils.animationChanger;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
......@@ -46,7 +47,7 @@ public class LiveFeedActivity extends AppCompatActivity {
private static final String TAG = "LiveFeedActivity";
private ImageView ivLiveFeed;
private Button lfFlashBtn;
private ImageView lfFlashBtn;
private TextView tvLlStatusValue;
private Handler handler = new Handler();
......@@ -74,37 +75,45 @@ public class LiveFeedActivity extends AppCompatActivity {
// Start updating
handler.post(updateRunnable);
// Toggle flashlight
lfFlashBtn.setOnClickListener(v -> toggleFlashlight());
}
private void toggleFlashlight() {
String currentText = lfFlashBtn.getText().toString();
String url = currentText.equals("FLASH ON") ? LIVE_FEED_URL+"/flashlight/on" : LIVE_FEED_URL+"/flashlight/off";
String newText = currentText.equals("FLASH ON") ? "FLASH OFF" : "FLASH ON";
lfFlashBtn.setOnClickListener(new View.OnClickListener() {
boolean isFlashOn = false; // Track flash status
// Call the API in a background thread
new Thread(() -> {
try {
URL apiUrl = new URL(url);
HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int responseCode = connection.getResponseCode();
if (responseCode == 200) {
// Update the button text on the main thread
runOnUiThread(() -> lfFlashBtn.setText(newText));
} else {
Log.e(TAG, "Failed to call API: " + responseCode);
}
connection.disconnect();
} catch (IOException e) {
Log.e(TAG, "Error calling flashlight API", e);
@Override
public void onClick(View v) {
// Determine the URL and icon based on the flash status
String url = isFlashOn ? LIVE_FEED_URL + "/flashlight/off" : LIVE_FEED_URL + "/flashlight/on";
int iconResId = isFlashOn ? R.drawable.ico_flash_off : R.drawable.ico_flash_on; // Icons for flash on/off
// Call the API in a background thread
new Thread(() -> {
try {
URL apiUrl = new URL(url);
HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int responseCode = connection.getResponseCode();
if (responseCode == 200) {
// Successfully called the API, update the ImageView and flash status on the main thread
runOnUiThread(() -> {
lfFlashBtn.setImageResource(iconResId); // Update the ImageView icon
isFlashOn = !isFlashOn; // Toggle the flash status
});
} else {
Log.e(TAG, "Failed to call API: " + responseCode);
}
connection.disconnect();
} catch (IOException e) {
Log.e(TAG, "Error calling flashlight API", e);
}
}).start();
}
}).start();
});
}
@Override
protected void onStart() {
super.onStart();
......@@ -130,13 +139,24 @@ public class LiveFeedActivity extends AppCompatActivity {
private void fetchAndDisplayImage() {
new Thread(() -> {
try {
URL url = new URL(LIVE_FEED_URL+"/cam-hi.jpg");
URL url = new URL(LIVE_FEED_URL + "/cam-hi.jpg");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(input);
runOnUiThread(() -> ivLiveFeed.setImageBitmap(bitmap));
// Ensure the bitmap is mutable by creating a copy if necessary
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
// Create a matrix to flip the bitmap both horizontally and vertically
Matrix matrix = new Matrix();
matrix.setScale(-1.0f, -1.0f); // Flip both horizontally (X-axis) and vertically (Y-axis)
// Create a new bitmap using the matrix
Bitmap flippedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
runOnUiThread(() -> ivLiveFeed.setImageBitmap(flippedBitmap)); // Set the flipped bitmap in the ImageView
} catch (Exception e) {
Log.e(TAG, "Error fetching image", e);
// If there's an error, set the default image
......
package com.kaluwa.enterprises.babycare.activities;
import static com.kaluwa.enterprises.babycare.config.TokenSaver.clearToken;
import static com.kaluwa.enterprises.babycare.utils.Utils.animationChanger;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.Toolbar;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.kaluwa.enterprises.babycare.MainActivity;
import com.kaluwa.enterprises.babycare.R;
public class LiveVocalActivity extends AppCompatActivity {
private ImageView lvSoundBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_live_vocal);
// define actionbar
defineActionbar();
lvSoundBtn = findViewById(R.id.lvSoundBtn);
lvSoundBtn.setOnClickListener(new View.OnClickListener() {
boolean isSoundOff = true; // To track the current state
@Override
public void onClick(View v) {
if (isSoundOff) {
lvSoundBtn.setImageResource(R.drawable.ico_sound); // Switch to sound on icon
} else {
lvSoundBtn.setImageResource(R.drawable.ico_no_sound); // Switch to no sound icon
}
isSoundOff = !isSoundOff; // Toggle the state
}
});
}
private void defineActionbar() {
Toolbar toolbar = findViewById(R.id.b_care_action_bar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
toolbar.setNavigationIcon(R.drawable.ico_menu_32);
toolbar.setNavigationOnClickListener(v -> {
// Initializing the popup menu and giving the reference as current context
PopupMenu popupMenu = new PopupMenu(this, toolbar);
popupMenu.setGravity(Gravity.BOTTOM);
popupMenu.getMenuInflater().inflate(R.menu.menu_main, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(item -> {
int id = item.getItemId();
if (id == R.id.mm_device_setting) {
Toast.makeText(this, "You Clicked " + item.getTitle(), Toast.LENGTH_SHORT).show();
} else if (id == R.id.mm_app_setting) {
Toast.makeText(this, "You Clicked " + item.getTitle(), Toast.LENGTH_SHORT).show();
} else if (id == R.id.mm_logout) {
clearToken(getApplicationContext());
Toast.makeText(this, "Logout successful.", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
animationChanger(this);
}
return true;
});
popupMenu.show();
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.user_action_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
if (id == R.id.user) {
Intent intent = new Intent(this, UserProfileActivity.class);
startActivity(intent);
animationChanger(this);
} else {
Toast.makeText(this, "No item.", Toast.LENGTH_SHORT).show();
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
super.onBackPressed();
animationChanger(this);
}
}
\ No newline at end of file
......@@ -41,7 +41,7 @@ public class BabyEmotionWebSocketListener extends WebSocketListener {
// Capitalize the first letter
String capitalizedEmotion = emotion.substring(0, 1).toUpperCase() + emotion.substring(1);
if (capitalizedEmotion.equals("Null")) {
statusValueTextView.setText("No emotion detected!");
statusValueTextView.setText("Not detected!");
} else {
statusValueTextView.setText(capitalizedEmotion);
}
......
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="35dp" android:viewportHeight="100" android:viewportWidth="100" android:width="35dp">
<path android:fillColor="#000000" android:pathData="M50,21c-6.2,7.7 -11.5,14 -11.9,14 -0.3,-0 -5.3,-4.7 -11.1,-10.5 -9.9,-9.9 -13,-12.1 -13,-9.2 0,1.6 69.1,70.7 70.8,70.7 2.8,-0 0.6,-3.1 -9.8,-13.5l-11,-11 6.5,-8c9,-11.2 8.9,-11.4 -4.3,-11.7l-10.9,-0.3 4.7,-16.5c2.6,-9.1 4.6,-16.8 4.3,-17.3 -1.2,-2.1 -4,0.5 -14.3,13.3z" android:strokeColor="#00000000"/>
<path android:fillColor="#000000" android:pathData="M28.2,48.3c-7.6,9.5 -7.4,9.7 5.8,9.7 6.1,-0 11,0.4 11,0.9 0,0.5 -2,7.5 -4.5,15.6 -5.4,17.7 -5.4,17.8 -3.4,18.3 1.1,0.2 4.9,-3.8 11.1,-11.5 5.2,-6.5 9.7,-12.3 10.1,-12.9 0.3,-0.6 -5.2,-6.8 -12.2,-13.8l-12.8,-12.8 -5.1,6.5z" android:strokeColor="#00000000"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="35dp" android:viewportHeight="100" android:viewportWidth="100" android:width="35dp">
<path android:fillColor="#000000" android:pathData="M42.1,30.9c-10.5,13.1 -19.1,24.6 -19.1,25.5 0,1.4 1.5,1.6 11,1.6 6.1,-0 11,0.4 11,0.9 0,0.5 -2,7.5 -4.5,15.6 -5.4,17.7 -5.4,17.8 -3.4,18.3 1.9,0.3 39.9,-46.5 39.9,-49.1 0,-1.4 -1.7,-1.7 -10.8,-1.9l-10.9,-0.3 4.7,-16.5c2.6,-9.1 4.6,-16.8 4.3,-17.3 -1.3,-2.2 -4.8,1.5 -22.2,23.2z" android:strokeColor="#00000000"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="35dp" android:viewportHeight="100" android:viewportWidth="100" android:width="35dp">
<path android:fillColor="#000000" android:pathData="M1,1.8c0,1.9 95.8,98.2 97.8,98.2 3,-0 0.7,-4.1 -6.3,-11l-7.4,-7.4 4,-4.4c2.3,-2.4 5.5,-7.3 7.2,-11 2.9,-6.1 3.2,-7.5 3.1,-16.2 0,-12.4 -2.5,-18.8 -10.2,-27.1 -5.3,-5.8 -12.3,-10.5 -13.6,-9.2 -1.5,1.5 -0.3,3.2 4.5,6.3 6.5,4.2 11.4,10.8 13.9,18.9 4,12.6 1.7,24 -6.8,34.6 -3.9,4.8 -5,5 -8.3,1.9l-2.8,-2.7 2.8,-3.6c4.5,-5.8 6.3,-10.1 6.8,-16.6 0.6,-7.2 -0.7,-12.8 -4.5,-18.3 -3.1,-4.7 -10.6,-10.7 -12.2,-9.7 -1.9,1.2 -0.9,3 3.4,6.2 10.8,7.9 12.5,24.9 3.7,35.4l-3,3.4 -3.7,-3.7 -3.7,-3.6 2.6,-3.2c3.3,-3.9 4.1,-6.9 3.2,-11.7 -1.1,-6.3 -9.8,-12.9 -12,-9.3 -0.3,0.5 0.9,1.9 2.8,3 6.1,3.6 7.4,9.9 3.1,15l-2.7,3.1 -4.3,-4.2 -4.4,-4.3 0,-20.1c0,-16.5 -0.3,-20.4 -1.6,-22.3 -2.9,-4.2 -5.9,-2.9 -15.8,6.8l-9.2,9 -11.9,-12c-11.8,-11.8 -14.5,-13.7 -14.5,-10.2z" android:strokeColor="#00000000"/>
<path android:fillColor="#000000" android:pathData="M20.7,30.7c-0.4,0.3 -0.7,9 -0.7,19.3l0,18.6 12.8,12.7c9.9,9.7 13.5,12.7 15.5,12.7 4.8,-0 5.7,-2.9 5.7,-18.5l0,-14 -15.8,-15.8c-8.6,-8.6 -16,-15.7 -16.3,-15.7 -0.3,-0 -0.9,0.3 -1.2,0.7z" android:strokeColor="#00000000"/>
<path android:fillColor="#000000" android:pathData="M2,34c-1.8,1.8 -2,3.3 -2,16 0,17.1 0.5,18 10,18l6,-0 0,-18 0,-18 -6,-0c-4.7,-0 -6.4,0.4 -8,2z" android:strokeColor="#00000000"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="35dp" android:viewportHeight="100" android:viewportWidth="100" android:width="35dp">
<path android:fillColor="#000000" android:pathData="M37.7,17.8l-13.7,13.7 0,18.5 0,18.5 13.8,13.8c7.5,7.5 14.5,13.7 15.4,13.7 0.9,-0 2.4,-0.7 3.2,-1.6 1.4,-1.4 1.6,-6.8 1.6,-44.4 0,-37.6 -0.2,-43 -1.6,-44.4 -0.8,-0.9 -2.3,-1.6 -3.2,-1.6 -1,-0 -7.9,6.2 -15.5,13.8z" android:strokeColor="#00000000"/>
<path android:fillColor="#000000" android:pathData="M78.4,22.5c-0.4,1.1 0.7,2.7 3.4,5.1 2.2,1.9 5.3,6 6.9,9.2 2.3,4.7 2.8,7 2.8,13.2 0,6.2 -0.5,8.5 -2.8,13.2 -1.6,3.2 -4.7,7.3 -6.9,9.2 -2.7,2.4 -3.8,4 -3.4,5.1 0.8,2.2 3.1,0.8 8.5,-5 6.6,-7.1 8.6,-12.4 8.6,-22.5 0,-10.1 -2,-15.4 -8.6,-22.5 -5.4,-5.8 -7.7,-7.2 -8.5,-5z" android:strokeColor="#00000000"/>
<path android:fillColor="#000000" android:pathData="M71.4,32.5c-0.4,0.9 0.4,2.4 2.1,3.7 3.4,2.7 6.5,9.2 6.5,13.8 0,4.6 -3.1,11.1 -6.5,13.8 -1.7,1.3 -2.5,2.8 -2.1,3.7 0.8,2.2 1.8,1.9 5.5,-1.7 5.1,-4.9 6.5,-8.5 6.5,-15.8 0,-7.3 -1.4,-10.9 -6.5,-15.8 -3.7,-3.6 -4.7,-3.9 -5.5,-1.7z" android:strokeColor="#00000000"/>
<path android:fillColor="#000000" android:pathData="M6,34c-1.8,1.8 -2,3.3 -2,16 0,17.1 0.5,18 10,18l6,-0 0,-18 0,-18 -6,-0c-4.7,-0 -6.4,0.4 -8,2z" android:strokeColor="#00000000"/>
<path android:fillColor="#000000" android:pathData="M64.6,42.5c-0.3,0.9 0.3,2.4 1.4,3.5 1.1,1.1 2,2.9 2,4 0,1.1 -0.9,2.9 -2,4 -1.9,1.9 -1.8,5 0.1,5 1.6,-0 4.8,-3.9 5.5,-6.5 0.8,-3.3 -0.2,-7.1 -2.6,-9.5 -2.4,-2.4 -3.6,-2.5 -4.4,-0.5z" android:strokeColor="#00000000"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="2dp"/>
<solid android:color="#000000"/> <!-- You can change the color as needed -->
</shape>
......@@ -43,19 +43,21 @@
android:src="@drawable/live_offline"
android:background="@drawable/borders"/>
<Button
android:id="@+id/lfFlashBtn"
android:layout_width="150dp"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="28dp"
android:layout_marginRight="40dp"
android:background="@drawable/positive_btn_background"
android:fontFamily="@font/abril_fatface_regular"
android:padding="6dp"
android:text="FLASH ON"
android:textColor="@color/white"
android:textSize="18sp" />
android:orientation="horizontal"
android:layout_marginTop="60dp"
android:gravity="center">
<ImageView
android:id="@+id/lfFlashBtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ico_flash_off"
app:tint="@color/dark_purple"/>
</LinearLayout>
</LinearLayout>
<!-- New LinearLayout for displaying the status -->
......@@ -66,6 +68,7 @@
app:layout_constraintTop_toBottomOf="@+id/llLiveFeedBox"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:orientation="horizontal"
android:gravity="center"
android:padding="16dp">
......@@ -74,7 +77,7 @@
android:id="@+id/tvLlStatusLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Baby's Mood:"
android:text="Mood:"
android:textColor="@color/black"
android:textSize="18sp"
android:layout_marginEnd="8dp"/>
......@@ -83,7 +86,7 @@
android:id="@+id/tvLlStatusValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No emotion detected!"
android:text="Not detected!"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="18sp"/>
......
<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.LiveVocalActivity">
<include
layout="@layout/appbar"/>
<ImageView
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/b_care_action_bar"
app:layout_constraintBottom_toBottomOf="parent"
android:src="@drawable/background"
android:contentDescription="background-image"
android:scaleType="centerCrop"
android:alpha="0.4"/>
<LinearLayout
android:id="@+id/lvLiveFeedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@+id/background"
app:layout_constraintStart_toStartOf="@id/background"
app:layout_constraintEnd_toEndOf="@id/background"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="16dp">
<ImageView
android:id="@+id/ivLiveVocalFeed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxHeight="350dp"
android:scaleType="centerInside"
android:background="@drawable/borders"/>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="center_horizontal|center_vertical"
android:background="@android:color/black"/> <!-- This is the horizontal line -->
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="60dp"
android:gravity="center">
<ImageView
android:id="@+id/lvSoundBtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ico_no_sound"
app:tint="@color/dark_purple"/>
</LinearLayout>
</LinearLayout>
<!-- New LinearLayout for displaying the status -->
<LinearLayout
android:id="@+id/lvStatusBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/lvLiveFeedBox"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:orientation="horizontal"
android:gravity="center"
android:padding="16dp">
<TextView
android:id="@+id/tvLvStatusLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vocal Mood:"
android:textColor="@color/black"
android:textSize="18sp"
android:layout_marginEnd="8dp"/>
<TextView
android:id="@+id/tvLvStatusValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not detected!"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="18sp"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment